Linux hard disk GPT partitions and MBR partitions

Source: Internet
Author: User
Tags file system root directory advantage

  thought to write this, because I am in the process of tossing Linux system, there are many times to fall into the trap of the hard disk partition experience. In the last few days, once again fell into the pit, tossing two geniuses from the pit to crawl out. After a lot of inquiry data, finally understand the hard disk partition some concepts. Record it below to alert the newcomer.

Talking about my own experience of falling out of the pit is all about the fierce collision between WinXP and Linux. Years ago, I began to install WinXP and Linux on a computer at the same time, as long as the order to comply with the first installation of WinXP and then install Linux, there will be no problems, Linux installation program will automatically identify multiple systems, installation is completed after the smooth start of multiple systems. One day, I felt that Linux alone was enough, so I installed Linux on my entire hard drive. Another day, I think still want to use WinXP, so I reinstall WinXP (don't say to me virtual machine, many years ago my computer has only 256M of memory, virtual machine does not move at all), the results found that WinXP installation program can not be able to partition the hard disk. This crater is caused by the LVM in Linux, WinXP can't recognize the LVM partition, and all the tools in the WinPE and DOS Toolbox in that era couldn't recognize the LVM, and then my knowledge of Linux was only partitioned when I installed the system, Do not know the Linux system also has fdisk, parted such tools, so toss for a long time to climb out of the pit. Now, years later, I fell into a hole again. I work with the computer is the WinXP system (celestial condition, you know), in order to do some chat, I installed a Ubuntu up, the two systems have been peaceful. Until one day, I put the Ubuntu system again to hang, and then reload, because in the partition accidentally chose the default "clear the entire disk and install Ubuntu", and then the hard drive is the entire lattice off, WinXP is not. I thought, that's a big deal, and I'm not going to be finished with a WinXP. But the problem is, no matter how I install it, the WinXP system is not going to start. It was later realized 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? It also blames this HP's working machine is very exotic, it supports the legacy BIOS, also supports EFI, when the original WinXP exists, it uses of course the MBR partition (MSDOS partition), So the installation of Ubuntu is the use of the MBR partition, and then to the Ubuntu automatic partition, it saw the motherboard support EFI, the hard drive into a GPT partition automatically. I also toss for a few days to understand this truth, finally, with the help of Ubuntu LiveCD's parted program, use a mklabel msdos command to change the hard drive from GPT partition to MBR partition, and then install WinXP and Ubuntu sequentially, To get out of the pit.

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

1. The traditional BIOS only supports booting from the MBR partition's hard disk. The partition table for the MBR partition is stored 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 less than 3 primary partitions plus one extended partition. Extended partitions can be divided into multiple logical partitions. The advantage of an MBR partition is that it's simple, everyone uses it, so everyone knows that many operating systems can boot from the MBR partition's hard disk. The disadvantage is that the MBR partition can not recognize the hard disk space larger than 2T, and can not have more than 2T partition;

2, GPT partitions of the hard disk can solve all the disadvantages of the above MBR partition, it does not have 4 primary partition restrictions, want to divide several primary partitions can be divided into several primary partitions, it can identify more than 2T of hard disk space, each partition size can also exceed 2T. But its disadvantage is that it requires operating system support. For example, only WinXP 64, win Vista, Win 7 and win 8, and the newer Linux distributions support GPT partitioned hard drives. Moreover, if there is no EFI support, the above system can only be GPT partitions of the hard disk as a data disk, can not be from the GPT partition hard disk boot;

3. To boot from the GPT partition's hard disk, the motherboard uses EFI, the hard disk uses GPT partitions, the operating system supports GPT and EFI these three conditions are indispensable. The newer 64-bit Linux systems and WIN8 systems are currently supported EFI, so they all need to be started from a GPT partition's hard disk. Now the computer motherboard has gradually abandoned the legacy BIOS, but only to support EFI. (Like my work machine, there will be fewer and less transition products.) At present, many of the motherboard pre-installed WIN8 notebook motherboards almost only support EFI. Therefore, it is imperative to learn about the relevant knowledge of GPT and EFI;

4, the above zoning strategy is fixed partition. Once the hard disk partition is complete, the size of the partition is not changed, and if you want to change the size of the partition, only repartition. And since there is no way to divide multiple hard drives into one area, the size of each partition is limited. So we need a dynamic partitioning of things. LVM is such an dongdong, it is called logical volume management. The mechanism for using LVM is this: first, the hard disk partition or the entire hard disk is marked as a physical volume (PV), then a volume group (VG) is created, one or more physical volumes are added to the volume group, and the volume group is finally partitioned, each of which is called a logical volume (LV). The advantage of LVM is that you can add the physical volume group size to the volume group at any time to dynamically resize the logical volume. This is particularly useful in the server, for example, there is a server originally has 100 users, its/home directory will have 100 users of the home directory, if they each allocated 20G space, will occupy a 2T of hard disk, if this time to 100 users how to do? If you use LVM to solve this problem, we can add a 3T hard drive, and then add this hard drive to the volume group to enlarge the volume group size, and then adjust the size of the logical volume where/home is located. LVM can be used with both MBR and GPT.

The above knowledge points are validated by the following automatic partitioning strategy for the Ubuntu 14.04 installation process. First, for computers that support only the legacy BIOS, the partitioning option for installing Ubuntu is 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 partitions, and view the/etc/fstab file to see which partition corresponds to which file system, as shown below:

The output from the Print command in the parted program in the picture above shows that the partition table type of the hard disk is msdos, or 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 only one logical partition in the extended partition is SDA5. By/etc/fstab, you can see that the primary partition sda1 mounted to the root directory, and the logical partition SDA5 is swap space.

The above partitioning scheme is the simplest and most commonly used one. Let's look at the effect of enabling LVM. Select the option to open LVM on the interface of the Select partition scheme, as shown in the following figure:

After installing the operating system, or through the parted program and/etc/fstab to see the hard disk partition and use, the following figure:

As you can see from the diagram, the type of partitioned table is still msdos. The hard drive is still divided into one primary partition SDA1 and one extended partition Sda2, but the primary partition sda1 is only 255M, Extended partitions Sda2 There are 21.2G, the same extended partition is divided into one logical partition SDA5, the logical partition SDA5 occupies all 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 joined to a volume group ( VG). The/etc/fstab file shows that the primary partition SDA1 mounted to the/boot, while the root directory and the swap space mount two logical volumes (LV).

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

With the PVs and Pvdisplay commands, you can see that there is only one physical volume in the system, that 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, that is, UBUNTU-VG, which is divided into two logical volumes.

Then look at the following figure:

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

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. The specific command, a help can be done.

Finally, take a look at how Ubuntu partitions when the motherboard only supports EFI. The installed boot interface is as follows:

This 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 an automatic partition. After installing the operating system, use parted and/etc/fstab to view the partitions and usage of the hard disk, as shown in the following figure:

Through the above picture can be seen, the hard disk partition table type is GPT, hard disk is divided into three areas, are primary partitions. The 1th partition sda1 size is 537M, file system is FAT32, its mount path is/boot/efi, while the other two partitions one mount to the root directory, one is the swap space. It is not difficult to infer from the above that only motherboards that support EFI can only boot from the 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 the EFI requires.

If you are not choosing an automatic partition when installing an Ubuntu system, but choosing the last "other" option to customize the partition, you will find that the custom partitioning functionality provided by Ubuntu is limited. There's no way to choose whether to use an MBR partition or a GPT partition, or to enable LVM. If you need more flexible management, just click on the "Try Ubuntu" button to enter the LiveCD Ubuntu system and manually manage the hard drive partition using the parted command and LVM commands.

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.