TranslateProject/sources/tech/20150318 How to Use LVM on Ubuntu for Easy Partition Resizing and Snapshots.md
2015-03-18 16:08:40 +08:00

7.5 KiB
Raw Blame History

How to Use LVM on Ubuntu for Easy Partition Resizing and Snapshots

Ubuntus installer offers an easy “Use LVM” checkbox. The description says it enables Logical Volume Management so you can take snapshots and more easily resize your hard disk partitions — heres how to do that.

LVM is a technology thats similar to RAID arrays or Storage Spaces on Windows in some ways. While this technology is particularly useful on servers, it can be used on desktop PCs, too.

Should You Use LVM With Your New Ubuntu Installation?

The first question is whether you even want to use LVM with your Ubuntu installation. Ubuntu makes this easy to enable with a quick click, but this option isnt enabled by default. As the installer says, this allows you to resize partitions, create snapshots, merge multiple disks into a single logical volume, and so on — all while the system is running. Unlike with typical partitions, you dont have to shut down your system, boot from a live CD or USB drive, and resize your partitions while they arent in use.

To be perfectly honest, the average Ubuntu desktop user probably wont realize whether theyre using LVM or not. But, if you want to do more advanced things later, LVM can help. LVM is potentially more complex, which could cause problems if you need to recover your data later — especially if youre not that experienced with it. There shouldnt be a noticeable performance penalty here — LVM is implemented right down in the Linux kernel.

Logical Volume Management Explained

Were previously explained what LVM is. In a nutshell, it provides a layer of abstraction between your physical disks and the partitions presented to your operating system. For example, your computer might have two hard drives inside it, each 1 TB in size. Youd have to have at least two partitions on these disks, and each of these partitions would be 1 TB in size.

LVM provides a layer of abstraction over this. Instead of the traditional partition on a disk, LVM would treat the disks as two separate “physical volumes” after you initialize them. You could then create “logical volumes” based on these physical volumes. For example, you could combine those two 1 TB disks into a single 2 TB partition. Your operating system would just see a 2 TB volume, and LVM would deal with everything in the background. A group of physical volumes and logical volumes is known as a “volume group.” A typical system will just have a single volume group.

This layer of abstraction makes it possibly to easily resize partitions, combine multiple disks into a single volume, and even take “snapshots” of a partitions file system while its running, all without unmounting it.

Note that merging multiple disks into a single volume can be a bad idea if youre not creating backups. Its like with RAID 0 — if you combine two 1 TB volumes into a single 2 TB volume, you could lose important data on the volume if just one of your hard disks fails. Backups are crucial if you go this route.

Graphical Utilities for Managing Your LVM Volumes

Traditionally, LVM volumes are managed with Linux terminal commands.These will work for you on Ubuntu, but theres an easier, graphical method anyone can take advantage of. If youre a Linux user used to using GParted or a similar partition manager, dont bother — GParted doesnt have support for LVM disks.

Instead, you can use the Disks utility included along with Ubuntu for this. This utility is also known as GNOME Disk Utility, or Palimpsest. Launch it by clicking the icon on the dash, searching for Disks, and pressing Enter. Unlike GParted, the Disks utility will display your LVM partitions under “Other Devices,” so you can format them and adjust other options if you need to. This utility will also work from a live CD or USB drive, too.

Unfortunately, the Disks utility doesnt include support for taking advantage of LVMs most powerful features. Theres no options for managing your volume groups, extending partitions, or taking snapshots. You could do that from the terminal, but you dont have to. Instead, you can open the Ubuntu Software Center, search for LVM, and install the Logical Volume Management tool. You could also just run the sudo apt-get install system-config-lvm command in a terminal window. After its installed, you can open the Logical Volume Management utility from the dash.

This graphical configuration tool was made by Red Hat. Its a bit dated, but its the only graphical way to do this stuff without resorting to terminal commands.

Lets say you wanted to add a new physical volume to your volume group. Youd open the tool, select the new disk under Uninitialized Entries, and click the “Initialize Entry” button. Youd then find the new physical volume under Unallocated Volumes, and you could use the “Add to existing Volume Group” button to add it to the “ubuntu-vg” volume group Ubuntu created during the installation process.

The volume group view shows you a visual overview of your physical volumes and logical volumes. Here, we have two physical partitions across two separate hard drives. We have a swap partition and a root partition, just as Ubuntu sets up its partitioning scheme by default. Because weve added a second physical partition from another drive, theres now a good chunk of unused space.

To expand a logical partition into the physical space, you could select it under Logical View, click Edit Properties, and modify the size to grow the partition. You could also shrink it from here.

The other options in system-config-lvm allow you to set up snapshots and mirroring. You probably wont need these features on a typical desktop, but theyre available graphically here. Remember, you can also do all of this with terminal commands.


via: http://www.howtogeek.com/211937/how-to-use-lvm-on-ubuntu-for-easy-partition-resizing-and-snapshots/

译者:译者ID 校对:校对者ID

本文由 LCTT 原创翻译,Linux中国 荣誉推出