Partition concept of CentOS System

Source: Internet
Author: User
Tags ide hard drive

Partition concept of CentOS System

Before talking about Linux system partitioning, we should first introduce the knowledge of Hard Disk partitioning and the partitions on the most popular windows systems.

I. System partitioning

First, we should popularize some knowledge about system partitions:

There are three hard disk partitions: Primary disk partitions, extended disk partitions, and logical partitions.


A hard disk has at least one primary partition and a maximum of four primary partitions. A maximum of four primary partitions can be created. The total number of primary and extended partitions cannot exceed 4. There can be several logical partitions.
In windows, the active primary partition is the boot partition of the hard disk, which is independent and the first partition of the hard disk. Normally, it is the C partition.

In linux, both the primary and logical partitions can be used to enable the system and boot the OS. grub is compatible with windows boot. After the primary partition is split, the remaining parts can be divided into extended partitions. Generally, the remaining parts are all divided into extended partitions, or the remaining parts are completely divided.


But extended partitions cannot be used directly. They are used in the form of logical partitions. Therefore, extended partitions can be divided into several logical partitions. Their relationships are contained, and all logical partitions are part of the extended partitions.


In linux, the first hard disk partition is an hda partition (or an sda partition), the primary Partition Number is a hda1-4, and the logical partition starts from 5.


Hard disk capacity = capacity of the primary partition + capacity of the extended partition capacity expansion partition capacity = total capacity of each logical Partition


The primary partition can also be a "Boot partition", which is determined by the operating system and the motherboard as the first partition of the hard disk. Therefore, disk C is always at the top of all disk partitions.


The MBR (primary Boot Record) Partition Table (primary Partition Table) can only store four partitions. To divide more partitions, an extended partition table (EBR) is required ), the extended partition table is placed on a primary partition with the System ID 0x05. The primary partition is an extended partition. The extended partition can be divided into several partitions, each of which is a logical partition.

MBR, extended partitions, and logical partitions

One is the information area for storing the hard disk, which is called the master boot recorder (MBR) and the other is the place where the actual file data is stored. MBR is the most important area of the entire hard disk. once the MBR physical entity is damaged, the hard disk is almost decommissioned. generally, MBR has 512 bytes and can be divided into two parts.
(1) The first part contains 446 bytes, which are used to store the Boot Code, namely, bootloader.
(2)The second part contains 64 bytes for storing the disk partition table. the information of each partition must be recorded in 16 bytes. Therefore, a hard disk can have up to four partitions. these four partitions are called primary partitions and extended partitions ).


Note: "hard disk partition" is usually used to modify the disk partition table. It defines "the nth disk block is from the x to the y ". therefore, when the system needs to read the nth disk block, it is to read the information from x to y on the hard disk.


Because only one extended partition can exist,Therefore, the four partitions can be four primary partitions or three primary partitions plus one extended partition, as shown below:
P + P
P + E
It is important to note that extended partitions cannot be used directly, but must be divided into logical partitions. in this case, a problem occurs. Since the extended partitions cannot be used directly, why do we need to divide a certain amount of space for the extended partitions? This is because what if you want to divide the hard disk into five partitions? Now, you need to extend the partition to help.
Since MBR can only store the data information of four partitions, if more than four partitions exist, the system allows another disk partition information to be stored in an additional hard disk space, which is an extended partition. if the hard disk is divided into 3 P + E, E actually tells the system that the disk partition table is in another partition table, that is, the extended partition actually points to the correct additional partition table. you cannot directly use extended partitions. You need to divide the extended partitions into logical partitions. Therefore, you can use more than five partitions by using extended partitions.


Note:
(1) In fact, it is not recommended that you divide the hard disk into four primary partitions. this is because if a 20 GB hard disk occupies 15 GB space for four primary partitions, the remaining 5 GB space is completely unavailable, because there are no redundant partition tables to record these spaces.
(2) Considering the continuity of the disk, it is generally recommended that the extended partition be placed in the last cylindrical.
(3) theoretically, only one primary partition is allowed for a hard disk, and other space is allocated to the extended partition.

Hard Disk Partitions are divided into two types: Basic partition and Extension partition. The sum of the number of basic partitions and extended partitions cannot be greater than four ,(According to the preceding partition concepts, the number of basic partitions cannot exceed 4, and the number of extended partitions can only be 1, so the sum of the two cannot exceed 4 ). The basic partition can be used immediately but cannot be partitioned. Extended partitions must be partitioned before they can be used, that is, they must be partitioned twice. So what will be further divided by extended partitions? It is a Logical partition, and there is no limit on the number of Logical partitions.

The partition that we use most often in windows is like this. First, we split a primary partition (the operating system is usually installed in the primary partition) and then divided it into an extended partition, because extended partitions cannot be directly used, you need to divide them into several logical partitions (the D, E, F, and G disks are the logical partitions ).

Ii. Differences between Windows and Linux partitions

In Windows, the physical address is separated (the primary partition and logical partition are separated), and a directory is created on the partition. In Windows, all paths start with the drive letter, such as C: // Program Files. the opposite is true for Linux, where a directory is first available and then the physical address (partition) is mapped to the directory. in Linux, all paths start from the root directory 【/]. By default, Linux can be divided into three partitions: boot partition, swap partition, and root partition. for Windows and Linux operating systems, each partition can have different file systems, such as FAT32 and NTFS. For users who are accustomed to using Dos or Windows, there are several partitions with several drives, and each partition will get a letter identifier, then you can use this letter to specify the files and directories in the partition. Their file structures are independent and easy to understand. But for Linux, this is no longer the case, because for Linux users,No matter how many partitions are available to which directory to use, it has only one root directory and an independent and unique file structure. In Linux, each partition is used to form a part of the entire file system, because it adopts a method called "Mount, its entire file system contains a complete set of files and directories and associates a partition with a directory. In this case, a partition to be loaded will make its storage space available in a directory. Next, let's take a look at how the Linux drive is identified. For an IDE hard drive, the drive identifier is "hdx ~", "Hd" indicates the type of the device where the partition is located. This indicates the IDE hard disk. "X" indicates the disk number (a is the basic disk, B is the basic slave disk, c is the auxiliary master disk, and d is the auxiliary slave disk ),"~" The first four partitions are represented by numbers 1 to 4. They are primary partitions or extended partitions. They are logical partitions starting from 5. For example, hda3 indicates the third primary or extended partition on the first IDE hard disk, and hdb2 indicates the second primary or extended partition on the second IDE hard disk. For a SCSI hard disk, it is marked as "sdx ~", The SCSI hard disk uses "sd" to indicate the type of the device where the partition is located. The rest are the same as the IDE hard disk. For example, sda1 indicates the first primary partition or extended partition on the first SCSI hard disk.3. Linux partitions in Linux, we can use the fdisk-l (root permission required) command to view the partition details of the installed Linux system.
[root@xiaoluo /]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00066e2b Device Boot Start End Blocks Id System/dev/sda1 * 1 64 512000 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 64 2611 20458496 8e Linux LVMDisk /dev/mapper/vg_xiaoluo-lv_root: 18.8 GB, 18832424960 bytes255 heads, 63 sectors/track, 2289 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/vg_xiaoluo-lv_swap: 2113 MB, 2113929216 bytes255 heads, 63 sectors/track, 257 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000

The above fdisk-l command shows that on my installed CentOS system, there are two sda1, sda2. and swap areas.

Linux partitions are different from other operating system partitions. The partition format is Ext2 and Swap, Ext2 is used to store system files, and Swap is used as the Swap partition of Linux. Now we can know that Linux requires at least two dedicated partitions (Linux Native and Linux Swap) and Linux cannot be installed in Dos/Windows partitions. In general, one or more hard disk partitions of the "Linux Native" type are installed in Linux. However, a "Mount Point" must be specified for each partition in Linux ), tell Linux which directory to use when it is started. A "Swap" partition is generally defined and does not need to define a load point. Next we will first popularize "Linux Native" and "Linux Swap ".

* SWAP Partition

SWAP partition is the SWAP partition for LINUX to temporarily store data. It is mainly used to store data that is not used in the primary memory for the time being and re-transfer it into the memory as needed, you do not need to specify the "Mout Point" (loading Point) for the partition used as the SWAP. Since it is used as the SWAP partition, we should specify the size for it, it must at least be equal to the actual amount of memory on the system. Generally, it is twice the size of the memory. If you have 16 MB memory, the size of the SWAP partition is about 32 MB, and so on. Note that the size of the SWAP partition should not exceed 128 MB. If you have 64 MB of memory, the maximum size of the SWAP partition can only be set to 127 MB, which is a waste of space, because the system does not need too many swap partitions. Similarly, if your memory is 127 MB or larger, the maximum size of the SWAP partition can be set to MB. Besides, you must note that if you have 128 MB (or larger) memory, you must remind the system that you have such a large memory. Otherwise, it may not recognize your MB memory. Details: After the installation process is successfully started, a boot: prompt is displayed. You only need to type boot: linux mem = Mb. In addition, you can create and use more than 16 swap partitions.

* Linux Native

Linux Native stores system files. It can only use the EXT2 partition type, as mentioned above. For Windows users, the operating system must be installed in the same partition. Is it commercial software! So you have no choice! For Linux, you have a lot of options. You can separate the system files into several zones (the loading point must be specified ), it can also be installed in the same partition (the loading point is "/"). Next, let's take a look at which partitions can be created (only a few commonly used columns ).

The/boot partition contains the kernel of the operating system and the files to be used during system startup. It is necessary to create this partition because most PCs are subject to BIOS restrictions, moreover, if you have a separate/boot partition, the computer can still start even if the primary root partition has a problem. The partition size is about 50 mb-100mb (the value varies depending on the Linux version ). However, if you want to use LILO to start a Linux system, the partitions containing/boot must be completely less than cylindrical 1023. Because the data after 8 GB cannot be read by LILO, Linux must be installed within 8 GB.

Based on the installed Linux version, you can select to divide the/boot partition into different spaces (I set 500 mb ), run the df [full directory] command to view the partition where a directory is located. For example:

[Root @ xiaoluo/] # df/boot/File System 1 K-available block used % mount point/dev/sda1 495844 50655 419589/boot
We can see that our/boot directory is mounted to the sda1 partition. Of course, we can unmount the/boot directory from this partition by running the following command:
[root@xiaoluo /]# umount /boot

Now we can see that there is nothing under/boot. We can set up a directory under/root directory, then mount this directory to the sda1 partition (not recommended ).

/Usr partition is the place where the software is stored in Linux. If possible, the maximum space should be allocated to it. /Home partition is the location of your home directory. The size of this partition depends on the number of users. If multiple users use a computer together, this partition is completely necessary. Moreover, root users can well control the use of computers by common users, such as using hard disks for users or user groups, restrict common users to which files to access. In fact, it is necessary for a single user to establish this partition. If this partition is not available, you can only log on to the system as the root user. This is dangerous, because the root user has absolute right to use the system, once you misoperate the system, the trouble will arise. /Var/log partition is the System log Record Partition. If this independent partition is set up, even if the system log file has a problem, they also do not affect the primary partitions of the operating system. /Tmp partition, used to store temporary files. This is necessary for multi-user systems or network servers. In this way, even if a large number of temporary files are generated during the running of the program, or the user has performed wrong operations on the system, other parts of the file system are still safe. Because this part of the file system is still subject to read/write operations, it usually occurs faster than other parts. /Bin partition, which stores standard system utilities. /Dev partition to store device files. /Opt partition, which stores optional installed software. /Sbin partition, which stores standard system management files.
To view the usage of Linux disks, run the following command:
[Root @ xiaoluo/] #Df-Hfile system capacity used available % mount point/dev/mapper/vg_xiaoluo-lv_root 18G 8.2G 8.3G 50%/tmpfs 245 M 228 K 245 M 1%/dev/shm/dev/ sda1 485 M 50 M 410 M 11%/boot/dev/sr0 391 M 391 M 0 100%/media/20130331_132633


Therefore, based on the above summary, we will summarize the notes for Linux partitions. When installing Linux, we generally allocate three partitions to them:

/Boot zone. Generally, the individual partition habits vary depending on the Linux version. I allocated MB to this partition.

Swap and swap areas are usually allocated two times the physical memory size, but it is better not to exceed 256 M. So I allocated M to this partition.

/Zone, that is, the root directory. This partition should be allocated as much space as possible, you can allocate the disks on which the Linux system is installed to the partition except the/boot and swap partitions.

This is basically the concept of Linux system partitioning. In the future study, we will continue to record what we learned about Linux !!!


Related Article

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.