Getting started with Linux: Hard Disk partitioning traps and Countermeasures

Source: Internet
Author: User

Getting started with Linux: Hard Disk partitioning traps and Countermeasures

The reason why I want to write this article is that I have experienced many hard disk partition traps during Linux system tossing. In the last few days, I fell into the trap again and climbed out of the trap for two days. After querying data from multiple parties, I finally understood some concepts of Hard Disk partitioning. Record it below to warn the recipient.

Speaking of my own pitfall experience, it is all related to the fierce collision between WinXP and Linux. Many years ago, I began to install WinXP and Linux on a computer at the same time. As long as I followed the sequence of first installing WinXP and then installing Linux, there will be no problems. The Linux installer will automatically identify multiple systems, after the installation is complete, the system can be started smoothly. One day, I thought it would be enough to use Linux alone, so I installed Linux on the entire hard disk. One day, I thought I would still use WinXP, So I re-installed WinXP (I don't want to talk about virtual machines. Many years ago, my computer only had MB of memory, and the virtual machine could not run, the WinXP installer cannot partition the hard disk. This pitfall is caused by LVM in Linux. WinXP cannot identify LVM partitions. in that era, all the tools in the WinPE and dostoolbox cannot identify LVM, at that time, my understanding of Linux only stuck in partitions when installing the system. I didn't even know that tools such as fdisk and parted are in the Linux system, so it took a long time to climb out of the pit. Years later, I fell into the trap again. I used WinXP at work (tianchao's national conditions, you know). I installed another Ubuntu to do some private work, and these two systems have never been safe. One day, I had to re-install the Ubuntu system, because I accidentally selected the default "Clear the entire disk and install Ubuntu" during partitioning ", then the hard disk is replaced by the entire frame, and WinXP is unavailable. I thought, how big is it? Isn't it enough for me to install another WinXP. But the problem arises. No matter how I install it, The WinXP system cannot be started. Later, I realized that this pitfall was caused by the use of GPT partition on the hard disk. So why do I divide Ubuntu into GPT partitions? It's strange that this HP's work-time machine is amazing. It supports legacy BIOS and EFI. When WinXP exists, it uses MBR partition (msdos partition), of course ), therefore, when Ubuntu is installed, the MBR partition is used. When Ubuntu is automatically partitioned, the hard disk is automatically partitioned into GPT partitions when the motherboard supports EFI. After several days, I learned this truth. Finally, with the help of the Ubuntu LiveCD parted program, I used a mklabel msdos command to change the hard disk from the GPT partition to the MBR partition, then install WinXP and Ubuntu In order to crawl from the trap.

For those who have been managing large data centers and servers with large storage capacity for a long time, they must have done their homework for hard disk partitioning. It's not like me that I will not learn relevant knowledge until I have encountered a problem. I will summarize the knowledge of Hard Disk partitioning as follows (just a simple summary, please search for details ):

1. The traditional BIOS only supports hard disk boot from MBR partition. The partition table of the MBR partition is saved in the first sector of the hard disk and only 64 bytes. Therefore, there can be up to four table items. That is to say, we can only divide the hard disk into four primary partitions, or divide the hard disk into less than or equal to three primary partitions and add an extended partition. Extended partitions can be divided into multiple logical partitions. The advantage of MBR partitioning is that it is simple for everyone to use, so everyone understands that many operating systems can start from the hard disk of MBR partition. The disadvantage is that MBR partitions cannot identify hard disk space larger than 2 TB, and there cannot be partitions larger than 2 TB;

2. the hard disk with GPT partition can solve all the disadvantages of the above MBR partition. It has no limit on four primary partitions. If you want to divide several primary partitions into several primary partitions, you can divide them into several primary partitions, it can identify hard disk space larger than 2 TB, and the size of each partition can also exceed 2 TB. However, its disadvantage is that it requires support from the operating system. For example, only Windows XP 64-bit, Windows Vista, Windows 7, and Windows 8 are supported. In addition, without the support of EFI, the above system can only treat the hard disk in the GPT partition as a data disk and cannot start from the hard disk in the GPT partition;

3. If you want to start a hard disk from a GPT partition, the motherboard uses EFI, the hard disk uses GPT partition, and the operating system supports GPT and EFI. Currently, the latest 64-bit Linux and Win8 systems both support EFI, so they all need to be started from the GPT partition hard disk. The current computer motherboard has gradually abandoned the legacy BIOS, and only supports EFI. (There will be fewer transitional products like my work machine .) At present, almost all the motherboard of many pre-installed Win8 laptops only support EFI. Therefore, it is imperative to learn the knowledge of GPT and EFI;

4. The preceding partition policies are fixed partitions. Once a hard disk partition is completed, the partition size cannot be changed. If you want to change the partition size, only re-partitioning is required. In addition, since there is no way to divide multiple hard disks into one partition, the size of each partition is limited. So we need a dynamic partition. LVM is such a thing, it is called logical volume management. The LVM mechanism is as follows: first mark the hard disk partition or the entire hard disk as a physical volume (PV), and then create a volume group (VG ), add one or more physical volumes to the volume group and partition the volume group. Each partition is called a logical volume (LV ). The advantage of LVM is that you can add the size of the physical volume expansion volume group to the volume group at any time to dynamically adjust the size of the logical volume. This is particularly useful on servers. For example, if a server has 100 users, ITS/home directory contains the home directories of 100 users, if 20 GB space is allocated to each of them, a 2 TB hard disk will be occupied. What if another 100 users are allocated at this time? If we use LVM, we can solve this problem smoothly. we can add a 3 t hard disk, and then add the hard disk to the volume group to expand the volume group size, then adjust the logical volume of/home. LVM can be used together with MBR or GPT.

The following uses the automatic partitioning policy during Ubuntu 14.04 installation to verify the above knowledge points. First, for computers that only support legacy BIOS, the options for installing Ubuntu are as follows:

In this case, the LVM startup option is not selected. After the operating system is installed, use the parted program to view the hard disk partition. You can view the/etc/fstab file to find out which partition corresponds to which file system, for example:

The output of the print command in the parted program in the figure above shows that the Partition Table type of the hard disk is msdos, that is, MBR partition. The hard disk is divided into a primary partition sda1 and an extended partition sda2. The primary partition sda1 occupies 20.4 GB, the extended partition sda2 only has 1072 MB, and the extended partition has only one logic partition sda5. You can see from/etc/fstab that the primary partition sda1 is mounted to the root directory, and the logical partition sda5 is the swap space.

The preceding partition scheme is the simplest and most commonly used one. Next let's take a look at what effect LVM is. Select the option to enable lvm on the select Partition Scheme interface, for example:

After installing the operating system, you can use the parted program and/etc/fstab to view the partition and usage of the hard disk, for example:

We can see that the Partition Table type is msdos. The hard disk is still divided into one primary partition sda1 and one extended partition sda2, but the primary partition sda1 only has 255 M, and the extended partition sda2 has 21.2 GB, similarly, extended partitions are only divided into one logical partition sda5. The logical partition sda5 occupies all 21.2G space in the extended partition, And the sda5 is marked as lvm, this indicates that the partition is marked as a physical volume (PV), which must be added to a volume group (VG. The/etc/fstab file shows that the primary partition sda1 is mounted to/boot, while the root directory and swap space are mounted to two logical volumes (LV ).

You can use the LVM command to view the volume group, physical volume, and logical volume information in the system, such:

Through the pvs and pvdisplay commands, we 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. The vgs and vgdisplay commands show that there is only one volume group in the system, which is ubuntu-vg. The volume group is divided into two logical volumes.

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • Next Page

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.