Linux Lake 07: The trap of hard disk partitioning and its response

Source: Internet
Author: User

The reason why I think of writing this, because I am tossing Linux system, there are many times fell into the hard disk partition trap experience. In recent days, once again fell into the pit, tossing two geniuses to climb out of the pit. After the multi-query data, finally figured out the hard disk partition some concepts. The following records it down to warn the newcomer.

The

Talking about my own experience of falling out of the pit is all about the WinXP and Linux collisions. Years ago, I started to install WinXP and Linux on a computer at the same time, as long as the first installation of WinXP and then install the Linux order, there will be no problem, the Linux installation program will automatically identify the multi-system, after the installation can successfully start a multi-system. One day, I felt that Linux alone was enough, so I had Linux installed on my entire hard drive. Another day, I think still want to use WinXP, so I reinstall WinXP (do not say to me virtual machine, many years ago my computer also only 256M of memory, virtual machine is not running), the results found that the WinXP installation program has no way to partition the hard disk. This pit is caused by LVM in Linux, WinXP can not recognize the LVM partition, the era of WinPE, DOS Toolbox all the tools are not able to identify LVM, and then my knowledge of Linux only in the installation of the system only when the partition, Do not know the Linux system also has fdisk, parted such tools, so it took a long time to climb out of the pit. Now, years later, I fell into the pit again. I work with the computer is WinXP system (celestial national conditions, you understand), in order to do some reverse telecommuting, I installed an Ubuntu up, the two systems have been peaceful. Until one day, I put the Ubuntu system again toss, so reinstall, because in the partition when accidentally chose the default "clear the entire disk and install Ubuntu", and then the hard disk is the entire lattice off, WinXP No. I thought, "This is a lot of things, I put another WinXP not to be finished." But the problem comes, no matter how I install it, the WinXP system just won't start. Later, it became clear that the pit was caused by a GPT partition on the hard drive. So why did I let Ubuntu automatically partition it into a GPT partition? This is also blame this HP work machine compare wonderful, it is support legacy BIOS, also support EFI, when the original WinXP exist, it is of course MBR partition (MSDOS partition), so install Ubuntu is used MBR partition, and then to Ubuntu automatic partition, It sees that the motherboard supports EFI and automatically drives the hard disk into GPT partition. I also toss a few days to understand this truth, finally in the Ubuntu LiveCD parted program, with the help of a Mklabel msdos command to change the hard disk from the GPT partition to MBR partition, and then sequentially installed WinXP and Ubuntu, To climb out of the pit.

For those who long-term management of large computer rooms and large storage capacity of the server's friends, for hard disk partitions, they must have done their homework early. Not like me, until the problem to learn the relevant knowledge. For the hard disk partition of this knowledge, I summarize the following (just a simple summary, the specific content please search the element):

1. The traditional BIOS only supports booting from the MBR partition's hard disk. The partition table of the MBR partition is saved in the first sector of the hard disk, and only 64 bytes, so there can be up to four table entries. In other words, we can only divide the hard disk into 4 primary partitions, or divide it into 3 primary partitions and an extended partition. Extended partitions can also be divided into multiple logical partitions. MBR partition advantage is simple, we all use, so we all understand, many operating systems can be from the MBR partition of the hard disk boot. The disadvantage is that the MBR partition does not recognize more than 2T of hard disk space, nor can there be more than 2T partition;

2, GPT partition of the hard disk can solve all the shortcomings of the MBR partition, it does not have 4 primary partition limit, want to divide several primary partition can divide several primary partition, it can identify more than 2T of hard disk space, the size of each partition can also exceed 2T. However, its disadvantage is that it requires operating system support. For example, only WinXP 64-bit, win Vista, Win 7 and win 8, and the newer Linux distributions support GPT partition hard disks. Moreover, if there is no EFI support, the above system can only use the GPT partition of the hard disk as a data disk, unable to boot from the GPT partition of the hard disk;

3. To boot from a GPT partition's hard disk, the motherboard uses EFI, the hard disk uses GPT partition, the operating system supports GPT and EFI three conditions are indispensable. Currently, newer 64-bit Linux and WIN8 systems are supported by EFI, so they need to be booted from a GPT partition's hard drive. Now the computer motherboard has gradually abandoned the legacy BIOS, and only support EFI. (Transition products like my work machine will be less and fewer.) Currently, many of the motherboards that are preloaded with WIN8 are almost exclusively supported by EFI. Therefore, learning about GPT and EFI knowledge is imperative;

4, the above partition policy is fixed partition. Once the hard disk partition is complete, the partition size cannot be changed, and if you want to change the size of the partition, only repartition. And because there is no way to divide multiple hard disks into one area, so how to divide, the size of each partition is limited. So we need a dynamic partitioning thing. LVM is such a thing, it is called logical volume management. The mechanism for using LVM is this: first mark the hard disk partition or the entire hard disk as a physical volume (PV), then create a volume group (VG), add one or more physical volumes to the volume group, and finally partition the volume group, each of which is called a logical volume (LV). The advantage of LVM is that you can add physical volumes to the volume group at any time to extend the size of the volume group so that the logical volume can be dynamically resized. This is particularly useful in the server, for example, there is an original 100 users of the server, its/home directory will have 100 users of the main directory, if you assign each of them 20G space, will occupy a 2T hard disk, if then to 100 users what to do? If using LVM can solve this problem, we can add a 3T hard disk, and then add this hard disk to the volume group can expand the size of the volume group, and then adjust the size of the logical volume of home/home. LVM can be used with both MBR and GPT.

The above knowledge points are validated by the policy of automatic partitioning during the Ubuntu 14.04 installation process. First, for PCs that only support the legacy BIOS, the partitioning options for installing Ubuntu are as follows:

At this point, the option to start LVM is not selected. After installing the operating system, use the parted program to view the hard disk partition, and view the/etc/fstab file to see which partition corresponds to which file system, such as:

The output from the Print command in the parted program in the image above shows that the partition table type of the hard disk is Msdos, which is the MBR partition. The hard disk is divided into a primary partition SDA1 and an extended partition sda2, the primary partition sda1 is 20.4G, the extended partition sda2 only 1072M, and the extended partition has only one logical partition SDA5. By/etc/fstab you can see that the primary partition sda1 mounted to the root directory, and the logical partition SDA5 to swap space.

The above partitioning scheme is the simplest and most common one. Let's see what the effect of enabling LVM is. Select the option to turn on LVM in the Select Partition scheme interface, such as:

After installing the operating system, or through the parted program and/etc/fstab to see the partition and usage of the hard disk, such as:

As you can see, the type of the partitioned table is still msdos. The hard disk still has only one primary partition SDA1 and one extended partition Sda2, but the primary partition sda1 only 255M, Extended partition Sda2 is 21.2G, the same extended partition is divided into a logical partition SDA5, the logical partition SDA5 occupy all the 21.2G space in the extended partition, and the SDA5 flag is LVM, indicating that the partition is marked as a physical volume (PV), it must be added to a volume group (VG). As you can see from the/etc/fstab file, the primary partition SDA1 mounted to/boot, while the root and swap spaces are mounted with two logical volumes (LV).

The LVM command allows you to view information about volume groups, physical volumes, and logical volumes in the system, such as:

With the PVs and Pvdisplay commands, you can see that there is only one physical volume in the system, which is/DEV/SDA5, which is added to the volume group UBUNTU-VG. With the VGS and Vgdisplay commands, you can see that there is only one volume group in the system, which is UBUNTU-VG, which is divided into two logical volumes.

Look again:

The LVS and Lvdisplay commands allow you to see that the volume group is divided into two logical volumes, which are mounted to the root directory and swap space, respectively.

You can also do more with LVM commands, such as creating new volume groups, adding new physical volumes to volume groups, increasing or decreasing the size of logical volumes, and so on. Specifically with what command, a help can be done.

Finally, take a look at how Ubuntu partitions in case the motherboard only supports EFI. The installation start-up interface is as follows:

The installation interface is different from the installation interface under the legacy BIOS system, and the traditional installation interface is as follows:

In EFI mode, select Automatic partitioning. After installing the operating system, use parted and/etc/fstab to view the partition and usage of the hard disk, such as:

As you can see, the partition table type of the hard disk is GPT, and the hard disk is divided into three zones, all of which are primary partitions. The size of the 1th partition sda1 is 537M, the file system is FAT32, its mount path is/boot/efi, and the other two partitions one mount to the root directory, one for swap space. From the above information we are not difficult to infer: only the motherboard that supports EFI can boot from a GPT partition's hard disk, and the 1th partition of the hard disk must be the FAT32 file system, which holds the various files that EFI needs.

If you do not select Auto Partition when installing Ubuntu system, but choose the last "other option" to customize the partition, you will find that the custom partitioning function provided by Ubuntu is limited. There is no way to choose whether to use MBR partitioning or GPT partitioning, nor is there an option to enable LVM. If you need more flexible management, or only click on the "Try Ubuntu" button to enter the LiveCD Ubuntu system, use the parted command and LVM commands to manually manage the hard disk partition.

Extended reading:

In addition to hard disk partitioning, there are some common hard disk management features that you might use:

1, the creation of RAID, you can use the MDADM program;

2, to view the space occupied by partitions or folders, using DF and Du program;

3. Specify disk quotas and use quota software packages;

4, check the file system, UUID, volume label of each partition, use Blkid program.

(Jingshan Ranger in 2014-07-13 published in the blog Park, reproduced please indicate the source. )

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.