When installing the Linux system, you may encounter such a confused problem: Hard Disk partitioning.
How to plan the partition structure and how to divide a hard disk (including a mobile storage device) is more reasonable? To reduce the risks and unnecessary troubles caused by unreasonable hard disk partitioning, we will introduce how to plan the partition structure of a hard disk.
I. Hard Disk category and physical GEOMETRIC STRUCTURE
Hard Disks are mainly SCSI, IDE, and popular SATA; any hard disk must be produced according to certain standards; with the upgrade of the corresponding standards, hard Disk production technology is also upgrading; such as SCSI standards have gone through the SCSI-1, SCSI-2, SCSI-3; which we often see in the server site is based on Ultral-160 standards; the IDE follows the ATA standard, while the popular SATA is the upgraded version of the ATA standard. The IDE is a parallel device, while the SATA is a serial port. The development purpose of SATA is to replace the IDE;
The physical geometric structure of a hard disk is composed of a disk, a hard disk surface, a cylindrical disk, and a sector. A hard disk is enclosed by several discs to form a decent bar; each disc has an upper/lower surface. The head is in contact with the hard disk surface to read data;
Ii. Algorithm of hard disk capacity and partition size
The following information can be found through fdsik-l:
[Root @ yufei ~] # Fdisk-l
Disk/dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x00058a38
Device Boot Start End Blocks Id System
/Dev/sda1 × 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/Dev/sda2 26 1938 15360000 83 Linux
/Dev/sda3 1938 2004 524288 82 Linux swap/Solaris
Among them, heads is the hard disk, sectors is the sector, cylinders is the cylindrical, and each sector is 512 bytes, that is, 0.5 M;
Through the above example, we found that the hard disk has 255 hard disk faces, 63 sectors, and 2610 cylinders. Therefore, the entire hard disk volume conversion formula should be:
Number of magnetic surfaces x number of sectors x size of each sector 512 x number of cylinders = hard disk volume (unit: bytes)
Therefore, the hard disk size in this example should be calculated as follows:
255x63x512x2610 = 21467980800 bytes
Note: Hard Disk manufacturers and Operating System Conversion are not the same, hard disk manufacturers use a 10-digit conversion method, while the operating system uses a 2-digit conversion method. Therefore, when converting to M or G, the results of different algorithms are different. This is why we often see that the hard disk is marked as 40 GB, but it is a few GB in the operating system;
In the above example, the hard disk manufacturers algorithm and operating system arithmetic comparison:
Hard Disk manufacturers:
21467980800 bytes = 21467980.800 K = 21467.980800 M = 21.467980800G
(Convert to a large unit. divide each time by 1000)
Operating System:
21467980800 bytes = 20964825 K = 20473.4619140625 M = 19.99361515045166G
(Convert to a large unit. divide each time by 1024)
When viewing the partition size, we can use the algorithm provided by the manufacturer to calculate the partition size. Moving the decimal point forward by six digits is the Size expressed in G;
Iii. Hard Disk Partition criteria
Hard Disk Partitions are composed of primary partitions, extended partitions, and logical partitions. Therefore, we must follow this standard for hard disk partitions;
The maximum number of primary partitions (including extended partitions) is four. The number of primary partitions (including extended partitions) is determined by the Master Boot Recorder of the hard disk, MBR stores startup management programs (GRUB, LILO, NTLOARDER, etc.) and Partition Table records. The extended partition is also a primary partition. The extended partition can contain more logical partitions;
Therefore, the range of the primary partition (including the extended partition) is from 1 to 4, and the logical partition is from 5;
For example:
Device Boot Start End Blocks Id System
/Dev/hda1*1 765 6144831 7 HPFS/NTFS
/Dev/hda2 766 2805 16386300 c W95 FAT32 (LBA)
/Dev/hda3 2806 9729 55617030 5 Extended
/Dev/hda5 2806 3825 8193118 + 83 Linux
/Dev/hda6 3826 5100 10241406 83 Linux
/Dev/hda7 5101 5198 787153 + 82 Linux swap/Solaris
/Dev/hda8 5199 6657 11719386 83 Linux
/Dev/hda9 6658 7751 8787523 + 83 Linux
/Dev/hda10 7752 9729 15888253 + 83 Linux
In this example, we can see three primary partitions: hda1 hda1 hda3. The extended partition is composed of a hda5-hda10, which does not have primary partition 4, so the primary partition hda4 is not displayed. However, logical partitions cannot start from 4, because they are the location of the primary partition.
Iv. Representation of hard drive devices in Linux/Unix
IDE Hard Disks are generally expressed as hd * in Linux or other Unix-like systems, such as hda, hdb, etc... ...
SCSI and SATA hard disks are usually represented as sd * in Linux, such as sda, sdb, etc... ...
The mobile storage device is represented as sd * in linux, such as sda, sdb... ...
For details, refer to fdisk-l.
Sometimes you may only have one hard disk, but hdb is displayed in the operating system, which is related to the hard disk jumper. In addition, hdc mostly indicates that it is a optical drive device. If you have two hard disks: hda and hdb.
5. Reasonable planning and partitioning
For a partition of a hard disk, a hard disk should have four primary partitions, And the expansion is also regarded as one primary partition. The following situations exist:
1) Partitioning Method
One: four primary partitions with no extended partitions;
[Primary | partition 1] [primary | partition 2] [primary | partition 3] [primary | partition 4]
In this case, if you want to divide more than five partitions on a hard disk, this will not work.
2. One extended partition for three primary partitions;
[Primary | partition 1] [primary | partition 2] [primary | partition 3] [extended partition]
|
[Logic | partition 5] [logic | partition 6] [logic | partition 7] [logic | partition 8]… ...
This situation works, and the degree of freedom of the partition is relatively large, the partition is not restricted, can be divided into more than five partitions.
2) The most reasonable Partitioning Method
The most reasonable partitioning method: the primary partition is in front, the extended partition is in front, and then the logical partition is in the extended partition. The number of primary partitions and the number of extended partitions must be within four.
For example, the following partition is better.
[Primary | partition 1] [primary | partition 2] [primary | partition 3] [extended partition]
|
[Logic | partition 5] [logic | partition 6] [logic | partition 7] [logic | partition 8]… ...
[Primary | partition 1] [primary | partition 2] [extended partition]
|
[Logic | partition 5] [logic | partition 6] [logic | partition 7] [logic | partition 8]… ...
[Primary | partition 1] [extended partition]
|
[Logic | partition 5] [logic | partition 6] [logic | partition 7] [logic | partition 8]… ...
The most unreasonable partition partitioning method: the primary partition is surrounded by extended partitions.
For example
[Primary | partition 1] [primary | partition 2] [extended partition] [primary | partition 4] [Blank unpartitioned space]
|
[Logic | partition 5] [logic | partition 6] [logic | partition 7] [logic | partition 8]… ...
In this way, [extended partitions] between [primary | partition 2] and [primary | partition 4] have degrees of freedom, but what should I do if [blank and unpartitioned space] After [primary | partition 4? Unless primary partition 4 fully utilizes the space after the extended partition, it is impossible for you to create another partition after primary partition 4, making it impossible to divide logical partitions. Although this method also complies with the four primary partitions of a hard disk, the partitioning method of the primary partition surrounding the extended partition is not available.
6. Hard Disk Partitioning in Linux
The requirements of the System for hard disks are related to the services opened on the host, and the data classification and security. Linux is a multi-person, multi-task environment, so it is likely that there is a lot of data in it. If you need to reinstall it, moving and backing up data alone is already a pain point, so hard disk partitioning is very important. At the same time, Hard Drive planning is one of the main headaches for Linux beginners, this is because the hard disk partitioning technique requires a considerable understanding of the Linux File structure before it can be well planned. Therefore, we recommend that you separate/and Swap when learning Linux.
The following is a reference to the general host partition.
Generally, a large host does not store all the data in a hard disk partition (that is, there is only one/root directory). This has the following purposes:
1) Security: Your system is usually in/usr/, while personal data may be stored in/home, and some boot data may be stored in/etc. If you put all the data together, when your system is accidentally damaged by hackers, Or you accidentally delete some small items, the system crashes, so all the information will disappear ..... This may not matter to our city Jing Xiaomin. Just install it again, but this is not acceptable for some large enterprises. Therefore, we need to place data in Different Hard Disk Partitions separately, this is safer.
2) Convenience: If you need to upgrade your system, do you need to re-format the installation? Some data, such as the data in/home, is personal user data and does not seem to be related to the system. Therefore, if you place the data in different hard disk partitions, you will be more flexible when you want to upgrade or make some system changes.
When partitioning, we must take into account the future use of this host, and then analyze the large-capacity directories needed and frequently read/write directories according to the purpose, separate these important directories without putting them together with the root directory. When there is a problem with these hard disk partitions that read and write frequently, at least the system data in the root directory will not be affected, it is easier to save data.
In the default CentOS environment, the following directories are suitable for large capacity or frequent read/write operations:
/Boot
/
/Usr
/Home
/Var
Swap
Directory that cannot be separated from the root partition:/dev,/etc,/sbin,/bin,/lib. When the system starts, the kernel loads only one partition, that is /, during kernel startup, programs in the/dev,/etc,/sbin,/bin, And/lib directories must be loaded. Therefore, the preceding directories must be in the/root directory.
Maybe you can make your system into a partition distribution like this:
/
/Boot
/Usr
/Home
/Var
Swap
This is a common distribution of hard disks,
/The root directory can be allocated at least 256 MB;
/Boot is about 50 MB, because the boot file is not large;
/Var requires at least 1 GB, because your mail and proxy preset storage areas are in this directory, unless you want to change some settings.
/Home and/usr are usually the largest, because the data you install is in/usr/, and the user data is stored in/home, therefore, we recommend that you evenly allocate the remaining hard disk space to these two directories.
In any case, the environment and function usage of each host are different. Naturally, the hard disk allocation is different. Therefore, the above settings are for reference only, after you fully understand the entire Linux system, especially after using the Linux file and directory architecture, you will probably know how to set your host to the most appropriate one.
From: yufei blog™