Linux disk partitions, file systems, directories

Source: Internet
Author: User

This article is from the "Stones" blog, it is important to keep this source http://pengyl.blog.51cto.com/5591604/11789521, Linux on how to represent hard disk and partition hard disk partition including primary partition, extended partition, logical partition three kinds of types, The reason for this is that the partition information in the main boot sector of the hard disk is only 64 bytes (the primary boot sector has only 512 bytes of space), and the information for each partition occupies 16 bytes, so theoretically a disk can have up to 4 partitions. Of course, these 4 partitions are primary partitions. This is not a problem in the early days of the computer, but then as the hard disk space becomes larger, 4 partitions are far from enough, so the concept of extended partitioning is introduced. Extended partitions are also primary partitions, but new partitions can be created in the extended partition, which are referred to as logical partitions, and the number of logical partitions is no longer limited by the size of the primary boot sector, as the IDE disk can create up to 60 logical partitions.
In a Windows system, we typically create only one primary partition (that is, the C drive), then all the remaining disk space is zoned to the extended partition, and finally the logical partition is created in the extended partition. This logical relationship can be clearly seen in the Disk Management tool.

All disks in the Linux system and each partition on the disk are represented in the form of a file. For example, there is a hard disk in your computer, 3 partitions on the hard disk, then the Linux system will have the corresponding 4 device files, one is the hard disk device files, and each partition also has a device file, all the device files are unified in the/dev directory.
There are uniform rules for device file naming of different types of hard disks and partitions, which are described in the following form:
Hard disk: For the IDE interface of the hard disk device, represented as "HdX" form the file name, for the SATA or SCSI interface of the hard disk device, then the "SdX" as the file name, where "X" can be A, B, C, D and other alphanumeric numbers. For example, the 1th IDE device in the system is represented as "HDA" and a 2nd SATA device is represented as "SDB".
Partition: When the partition is represented, it is based on the file of the hard disk device, and the corresponding number of the partition is added behind it. For example, the 1th partition in the 1th IDE hard disk is represented as "hda1", the 2nd partition as "Hda2", the 3rd partition in the 2nd SATA hard disk as "sdb3", and the 4th partition as "SDB4" and so on.
It is important to note that because the number of primary partitions is only four, the sequence number of the primary and extended partitions is also limited to 1~4, and the ordinal of the logical partition will always start at 5. For example, even if a 1th IDE hard disk is divided into only one primary partition and one extended partition, the sequence number of the newly created 1th logical partition is still 5, which should be represented as "Sda5" and the 2nd logical partition as "Sda6".

In addition, for all mobile storage devices using USB interface, whether it is a mobile hard disk, USB drive, or the CD-ROM, all use/dev/sdxx device files. The device file for the optical drive (CD-ROM) generally defaults to/dev/cdrom, which is independent of the optical drive interface. 2.LVM knowledge points: Each Linux user will encounter this dilemma when installing Linux: How to accurately evaluate and allocate the capacity of each hard disk partition when partitioning the system, as the system administrator takes into account not only the capacity required for a current partition, but also the maximum capacity that may be required for that partition. Because if the estimate is inaccurate, the administrator may even want to back up the entire system, clear the hard disk, re-partition the hard disk, and then restore the data to the new partition when a partition is not sufficient.
While there are a lot of dynamic disk-tuning tools available now, such as Partation magic and so on, it does not solve the problem completely, because one partition may be exhausted again, and the other is the need to reboot the system to achieve it, and for many critical servers, downtime is unacceptable. And for adding a new hard disk, if you want a file system that spans multiple hard drives, the partition tuning program does not solve the problem.
Therefore, the perfect solution should be in the 0 downtime under the premise of the size of the file system can be easily adjusted to facilitate the implementation of the file system across different disks and partitions. Fortunately, the Logical Disk volume management (lvm,logical Volume Manager) mechanism provided by Linux is a perfect solution.
LVM is the short name of the Logical Disk volume management (Logical Volume Manager), which is a mechanism for managing disk partitions in a Linux environment, and LVM is a logical layer on top of hard disks and partitions to improve the flexibility of disk partition management. The LVM system administrator makes it easy to manage disk partitions, such as connecting several disk partitions to a single block of volume Group (volume group), forming a storage pool. Administrators can create logical volume groups (logical volumes) at will on the volume group, and further create file systems on logical volume groups. The administrator can easily adjust the size of the storage volume group through LVM, and the disk storage can be named, managed and assigned as a group, for example, "development" and "sales", instead of using the physical disk name "SDA" and "SDB". And when a new disk is added to the system, the LVM administrator does not have to move the disk's files to the new disk to take full advantage of the new storage space, but instead directly extend the file system across the disk.
Basic terminology for LVM
LVM is a logical layer that is added between the disk partition and the file system to mask the underlying disk partition layout for the file system, providing an abstract disk volume, and creating a file system on the disk volume. Here are a few LVM terms:
Physical storage media (the physical media)
This refers to the storage device of the system: the hard disk, such as:/DEV/HDA1,/DEV/SDA, etc., is the lowest layer of storage system storage unit.
Physical volume (physical volume)
A physical volume is a partition of a hard disk or a device that logically has the same function as a disk partition (for example, RAID), which is the basic storage logic block of LVM, but is compared to basic physical storage media (such as partitions, disks, etc.) and contains management parameters related to LVM.
Volume groups (Volume group)
LVM volume groups are similar to physical hard disks in non-LVM systems, which consist of physical volumes. You can create one or more LVM partitions (logical volumes) on a volume group, and an LVM volume group consists of one or more physical volumes.
Logical volumes (logical volume)
LVM logical volumes are similar to hard disk partitions in non-LVM systems, and file systems (such as/home or/usr) can be created on top of logical volumes.
PE (physical extent)
Each physical volume is divided into a basic unit called the PE (physical extents), with a uniquely numbered PE being the smallest unit that can be addressed by LVM. The size of the PE is configurable and defaults to 4MB.
LE (logical extent)
Logical volumes are also divided into addressable basic units called LE (Logical extents). In the same volume group, the size of Le is the same as the PE, and one by one corresponds. 3.RAID Knowledge points      raid, abbreviated for redundant Arrays of independent disks, Chinese as an inexpensive redundant disk array. Major RAID levels: RAID 0, RAID 1, RAID 5, RAID 6, RAID 0+1    disk array are also divided into soft array (software RAID) and hard array (Hardware RAID). A soft array is a software program that is provided by the computer's CPU to provide operational capability. Because the software program is not a complete system, it can only provide the most basic RAID fault tolerance function. Other functions such as hot spare hard disk settings, remote management and other features are one by one overdue. A hard array is a function of the control and computation of the entire array of disks by independently operating hardware. Does not rely on the system's CPU resources. Since the hard array is a complete system, all the required functions can be done in. As a result, hard arrays provide better functionality and performance than soft arrays. Also, hard arrays are the only option if you want to make the system also a disk array. So we can see that the RAID Level 5 disk array on the market is hard array. The soft array is only available for RAID 0 and RAID 1.RAID 0: Merging multiple smaller disks into one large disk, without redundancy, parallel I/O, the fastest. RAID 0 is also known as a stripe set. It is to put multiple disks together and become a large hard disk. When the data is stored, it segments the data by the number of disks, and then writes the data into these disks, and the system has data requests that can be executed in parallel by multiple disks, each of which performs its own portion of the data request. Parallel operations on this data can take full advantage of bus bandwidth and significantly improve overall disk access performance, so at all levels, RAID 0 is the fastest. However, RAID 0 does not have redundant functionality, and if one disk (physical) is damaged, all data is not available. RAID 1: The two groups of identical disk systems mirror each other, with no increase in speed, but allow for a single disk error with the highest reliability. RAID 1 is the mirror. The principle is that the data is stored on the primary hard drive and the same data is written on the mirrored drive. When the primary hard disk (physical) is damaged, the mirrored hard disk replaces the work of the primary hard disk. Data security for RAID 1 is best at all RAID levels because there is a mirrored hard disk for data backup. But its disk utilization is only 50%, which is the lowest level of disk utilization on all raid. RaID 5: A storage solution that combines storage performance, data security, and storage costs. RAID 5 does not back up the stored data, but instead stores the data and the corresponding parity information on each disk that makes up the RAID5, and the parity information and the corresponding data are stored on separate disks. When one of the RAID5 disk data is damaged, the remaining data and the corresponding parity information are used to recover the corrupted data. RAID 5 can be understood as a compromise between RAID 0 and RAID 1. RAID 5 can provide data security for the system, but with a lower level of protection than mirror and higher disk space utilization than mirror. RAID 5 has a similar data read speed as RAID 0, with only one parity information, which is slower than writing to a single disk. And because multiple data corresponds to one parity message, RAID 5 has a higher disk space utilization than RAID 1 and a relatively low storage cost. The utilization of the hard disk is n-1. RAID 6: A second independent parity information block is added compared to RAID 5. Two independent parity systems use different algorithms and the reliability of the data is very high. Even if two disks fail at the same time, it does not affect the use of the data. However, there is a greater amount of disk space allocated to the parity information, with a larger "write loss" relative to RAID 5. RAID 6 has very poor write performance, poor performance, and complex implementations that make raid 6 rarely used. RAID 0+1: Features both RAID 0 and RAID 1. RAID0+1 also provides data security through 100% backup of data, so raid 0+1 has the same disk space utilization as RAID 1 and high storage costs. RAID 0+1 is particularly suitable for areas where large amounts of data need to be accessed, but also for data security requirements, such as banking, finance, commercial supermarkets, warehousing warehouses, and various file management. Also known as RAID 10 redundancy     redundancy: With multiple devices working simultaneously, when one of the devices fails, other devices can take over the system of failure equipment to continue working. On a PC server, redundancy is often used in the disk subsystem and the power subsystem. 4. The file system type file system type used by Linux determines the way and efficiency of storing and reading file data to a partition, and the type of file system to be used when formatting the partition. In Windows systems, hard disk partitions are usually FAT32 or NTFS file systems, whereas in Linux systems, hard disk partitions are mostly EXT4 file systems.
EXT4, the 4th-generation extended file system, is the file system type that is used by default in RHEL6, and belongs to a typical journaled file system. It is characterized by maintaining log data with disk access records for easy recovery and better performance and stability.
In addition to the EXT4 file system, Linux also has a special swap type file system, swap file system is dedicated to the swap partition used. Swap partitions are similar to virtual memory in Windows systems, and can mitigate the problem of insufficient physical memory to some extent. The difference is that in a Windows system, a system file called Pagefile.sys is used as virtual memory, whereas in a Linux system a separate partition is partitioned as virtual memory, which is called a swap partition. The size of the swap partition is typically set to twice times the physical memory of the host, such as the host's physical memory size is 1GB, and the swap partition size is set to 2GB. 5. Linux directory structure in the Windows system, each partition is assigned a drive letter, in the resource manager through the drive letter can access the corresponding partition. Each partition uses a separate file system, and there is a root directory in each of these disks.
In the Linux system, all the directories and file data are organized into a tree-like directory structure, there is only one root directory in the whole system, all the partitions, directories, files are under the same root directory.
When locating a file or directory location in a Linux system, use "/" to separate it (different from "\" in Windows). In the entire tree directory structure, a separate "/" is used to represent the root directory, which is the starting point for the Linux file system. There are many subdirectories under the root directory that are divided by purpose, and a hard disk partition can be accessed only if it is mounted to a directory, and this specified directory is called a mount point. For example, to mount the partition "/dev/hda2" to the root directory "/", then access to the root directory "/" can be accessed to the "/dev/hda2" Partition, which is also known as the root partition. For beginners, in addition to the swap partition, generally only need to create 2 more partitions, respectively, as the root partition and/boot partition, the basic can meet the requirements. /root: Administrator's home directory;/bin: executable file, user command/boot: System boot related files such as kernel, INITRD, and Grub (bootloader)
/dev: Device files
Device files: Character devices, block devices
Block device: (hard disk, CD-ROM) random access, data block
Character Device: (keyboard, mouse) linear access, per character
Device number: Main device number (major device numbers) and this device number (minor device numbers)
The core of the system is to judge the device by these two numbers.
/etc: Configuration file
Home directory for Default user, home directory for each user usually defaults to/home/username
~: Indicates the current user's home directory
~username: Indicates USERNAME's home directory/var: files that change frequently during system execution
/lib: Function library directory used by the system
Static Library,. A
Dynamic libraries, Windows (. dll), Linux (. So:shared object)
/lib/modules: Kernel module file/usr:shared, read-only (global shared Read only)
System main program, graphics interface required files, additional function library, native self-installed software, shared directories and files
/usr/bin,/usr/sbin: General identity and administrator-executable files
/usr/lib: function library file for each application software

/usr/local:
/usr/local/bin
/usr/local/sbin
/usr/local/lib

/media: mount point directory, mobile device
/MNT: mount point directory, additional temporary file system
/OPT: Optional directory, installation directory for third-party programs,/usr/local/
/proc: Pseudo file system, kernel mapping file
/sys: Pseudo file system, property mapping file related to hardware device
/tmp: Temp file,/var/tmp
/sbin: Managing Commands
/lost+found: When a system error occurs, some missing fragments are placed in this directory

Linux disk partitions, file systems, directories

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.