Tutorial on using LVM to adjust hard disk partitions on Ubuntu systems

Source: Internet
Author: User
Tags file system gparted backup

Let's first introduce the basics of hard disk partitioning:

Physical media The physical media

You should feel that the word "physics" has a great extension, although we're just beginning to assume it's just a hard drive, or a partition. For example,/DEV/HDA,/DEV/HDA6,/DEV/SDA. You can convert any contiguous block on a block device to a ...

Physical volume physical Volume (PV)

A PV is nothing more than a physical medium that has many management data added to it-once you add it, the LVM thinks it is ... One of the holders.

Physical partitions physical extents (PE)

Physical partitions are really like large chunks of data, usually several MB. PE can be assigned to a ...

Volume Group Volume Group (VG)

A VG is made up of many physical partitions (possibly from multiple physical volumes or hard disks). Although it may be tempting to think that a VG is made up of several hard drives (such as/dev/hda and/DEV/SDA), it is more precise that it contains many of the PE provided by these hard drives.

From this volume group, PE can be assigned to a ...

Logical Volume Logical Volume (LV)

Yes, we finally got somewhere. A logical volume is the end result of our work, and here is where we store the information. This equates to the idea of traditional partitioning.

As with the usual partitions, you can create a representative on a logical volume.

File system filesystem

File system is the form you want it to be: standard EXT2,REISERFS,NWFS,XFS,JFX,NTFS, etc. For the Linux kernel, there is no difference between normal partitions and logical volumes.

I tried to draw an ASCII image to make these visualizations.

A physical volume that contains a number of physical partitions:

+-–[Physical Volume]-–+

| PE | PE | PE | PE | PE | PE |

+ ————————— –+

A volume group that contains 2 physical volumes (PV) with 6 physical partitions:

+--[Volume Group] ————-+

| +–[pv]--–+ +–[pv]--–+ |

| | PE | PE | PE | | PE | PE | PE | |

| + ———— –+ + ———— –+ |

+ ——————————— –+

We are now doing a further extension:

+--[Volume Group] ————-+

| +–[pv]--–+ +–[pv]--–+ |

| | PE | PE | PE | | PE | PE | PE | |

| +–+-+-+-+ +-+--+--+–+ |

| | | | +-–/| | |

| | | | | | | |

| +–+-+-+-+ +--+--+–+ |

| | Logical | | Logical | |

| | Volume | | Volume | |

| | | | | |

| | /home | | /var | |

| + ———— + + ———— –+ |

+ ——————————— –+

This shows us two file systems that span two disks. The/home file system contains 4 physical partitions, and the/var file system contains 2.

Easily adjust partitions and make snapshots using LVM on Ubuntu

The Ubuntu installer provides an easy "use LVM" checkbox. The description says that enabling logical volume management allows you to make snapshots and easier to resize your hard disk partitions--and here's how to do that.

LVM is a technology that is somewhat similar to a RAID array or "storage space" on Windows. Although this technique is more useful on the server, it can also be used on desktop PCs.

Should you use LVM when you install new Ubuntu?

The first question is, do you want to use LVM when installing Ubuntu? If so, then Ubuntu makes it easy to do it with a little mouse, but the option is not enabled by default. As the installer says, it allows you to resize partitions, create snapshots, combine multiple disks into a single logical volume, and so on-all of which can be done while the system is running. Unlike traditional partitions, you do not need to turn off your system, from a live CD or USB drive, and then adjust the partitions when they are not in use.

Quite frankly, ordinary Ubuntu desktop users may not realize whether they are using LVM. But if you want to do something more advanced in the future, then the LVM will help. LVM may be more complex and may cause problems when you recover data in the future-especially if you are inexperienced. There will be no significant loss of performance--LVM is completely implemented in the Linux kernel.

Logical Volume Management description

Earlier, we have explained what it means to be LVM. In a nutshell, it provides an abstraction layer between your physical disk and the partitions that are present in your system. For example, your computer might have two hard drives, all 1 TB in size. You have to have at least two partitions on these disks, each with a size of 1 TB.

LVM provides an abstraction layer on these partitions. Instead of traditional partitions on disk, LVM treats these disks as separate "physical volumes" after you initialize them. You can then create a "logical volume" based on these physical volumes. For example, you can combine these two 1 TB disks into a 2 TB partition, and your system will see only one 2 TB volume, and the LVM will handle all of this in the background. A set of physical volumes and a set of logical volumes are called "Volume Groups", and a typical system will have only one volume group.

This abstraction layer makes it easy to resize partitions, combine multiple disks into a single volume, or even create a "snapshot" of a file system for a running partition without uninstalling the partition first.

Note that if you do not create a backup, it would be a bad idea to combine multiple disks into one volume. It's like a raid 0--if you combine two 1 TB volumes into a 2 TB volume, as long as one of the hard drives fails, you will lose important data on the volume. So, if you're going this way, then the backup is important.

Graphical tools for managing LVM volumes

Typically, LVM is managed through Linux terminal commands. This can work on Ubuntu, but there's a simpler graphical approach that you can use. If you're a Linux user, familiar with gparted or a similar partition manager, forget it.--gparted does not support LVM disks at all.

However, you can use the disk tools that are included with Ubuntu. The tool is also called the GNOME Disk tool, or palimpsest. Click on the icon in the dash to turn it on, search for "disk" and tap Enter. Unlike GParted, the disk tool will display LVM partitions under "Other devices," so you can format these partitions as needed, or you can adjust other options. The tool can also be used on live CD or USB drive.

Unfortunately, the disk tool does not support most of the powerful features of LVM, no management volume groups, extended partitions, or snapshots. For these operations, you can implement them through a terminal, but not necessarily. Instead, you can open the Ubuntu Software Center, search the keyword LVM, and then install the Logical Volume Management tool, which you can run with the sudo apt-get install SYSTEM-CONFIG-LVM command in the terminal window. Once installed, you can open the logical volume management tool from the dash.

This graphical configuration tool is developed by the Red Hat Company, although a bit old, but it is the only graphical way, you can use it to do the above, the end of those commands left behind.

For example, you want to add a new physical volume to the volume group. You can open the tool, select the new disk under uninitialized entries, and click the "Initialize Entry" button. You can then find a new physical volume under the unallocated volume, and you can add it to the "UBUNTU-VG" volume group using the "Add to existing Volume Group" button, which is the volume group that Ubuntu created during setup.

The Volume group view lists the overview of all your physical and logical volumes. Here, we have two physical partitions across two separate hard drives, we have a swap partition and a root partition, which is the partition chart for Ubuntu default settings. Because we've added a second physical partition from another drive, there's a lot of unused space out there.

To extend a logical partition to a physical space, you can select it in the logical view, click Edit Properties, and then modify the size to enlarge the partition. You can also narrow the partition here.

SYSTEM-CONFIG-LVM Other options allow you to set up snapshots and mirrors. For a traditional desktop, you may not need these features, but you can also use graphical processing here. Remember, you can also use a terminal command to do all of this.

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.