This article deals with Logical Volume Management (LVM) and looks at how to set it up.
Many years ago, when 2 GB of storage was considered a lot, I beamed with pride after installing two hard disks, each 2 GB. With 4 GB, I was sure of never running low on space. Such pride is shortlived, as we know. Down the road, it was a limitation when I wanted to install more software into my Linux distro (those were the days when Red Hat Linux was the thing to have) and the disk that had my root partition just didn’t have the space. There had to be some way to resolve the issue; after all, my system had a total of four gigs, right? Was there a way I could, well, combine the two drives? Yes, there was: three letters of pure genius, LVM. Logical Volume Management, put simply, is a concept that combines physical drives and makes them appear as contiguous spaces.
The basics of LVM
LVM is a virtual layer that sits sandwiched between the operating system and your storage devices, i.e., hard disks. It creates groups of your hard disks, called Volume Groups (VGs). Within these VGs, you can create partitions, called Logical Volumes (LVs). The operating system will never know the difference; the behaviour is the same as accessing any regular disk/partition. The benefits of LVM over regular filesystems include: dynamic resizing of VGs, and live snapshots of partitions without unmounting them. Let’s now jump right in to how to set up LVM on our system. The OS I’m using for this is Ubuntu 12.10. There are two scenarios in which one would set up LVM: while performing a Linux install, or post-installation. LVM can be configured using command-line and GUI tools. I shall walk you through all of this.
Setting up LVM during Install
Ubuntu’s default installation image does not allow LVM, so we will use the Ubuntu Alternate Install disc. Grab the alternate ISO from the Ubuntu Download page (it’s under Additional options) and boot from it. I would like to go on record to state that I was able to do all the steps below using the standard ISO of Ubuntu 12.10 as well which means the alternate ISO is not required, even though Internet sources claim one must use the alternate ISO for LVM support.
On the disk partitioning screen (Figure 2), select Erase disk and install Ubuntu; check the Use LVM with the new Ubuntu installation and click Continue. After selecting the LVM partitioning option on the previous screen, the installer will automatically select the main hard drive to use for initialising the LVM set-up. The installer will then write a basic layout to disk. That’s about it. The installer now installs GRUB which happens in the MBR, since the BIOS can’t read LVMs. Any extra /boot partition required will automatically be created, and the installer will then proceed with the rest of the installation.
It’s super easy, isn’t it? Now, using LVM tools, you can configure your LVM to add or remove more disks, extend or shrink volumes, etc.
Setting up or configuring LVMs in an existing system
I will show you how to configure or modify the previously created volumes. The same steps may be used to set up a fresh LVM configuration if you have Ubuntu already installed.
Let’s install the GUI tool system-config-lvm. Initially available only from the Fedora RPM, this tool is now supported from the Ubuntu repos, thus saving you a lot of work including transcoding the RPM to DEB using alien. To install it is now as simple as issuing the following command at a terminal:
sudo apt-get update sudo apt-get install system-config-lvm
Once installation is complete, fire it up from the main menu (search for LVM), or you can launch it from a terminal with sudo system-config-lvm. The application’s main screen is shown in Figure 3.
Next, I will show you how to add a new disk and partition (physical volume) to the volume group, and extend the existing (root) logical volume. So, let’s touch upon adding and editing logical volumes.
Adding a new disk/partition to an existing volume group: The uninitialised disk is shown in the Uninitialised Entities branch; so initialise it by hitting the Initialise Entity button, and the tool proceeds to warn you and perform initialisation (Figures 4 and 5). Once initialised, the partition is moved into the Unallocated Volumes branch. Here, click the Add to Existing Volume Group button, which prompts you to select the volume group (VG) to which you will add this partition. This adds unused space to your Ubuntu VG. Then edit an LV, and add this unused space into it. Select the LV adjacent to the unused space, and hit the Edit button. Note that you can now extend the volume by dragging the slider. Drag as required, and hit OK! This will add the unused space to your LV.
This is how LVM configuration is done using the GUI. The command-line provides you with a comprehensive set of commands to do this, but it’s risky for a new user, since a wrong command can cause you to lose data.
LVM is very useful, since you can add, extend and remove volumes irrespective of the physical disks in the system; you can combine disks to appear as single drives. LVM eases upgrading and extending disk capacities. Fundamentally, working with LVM is almost the same as working with regular partitions; the only difference is that in the case of LVM, we deal with a logical space and its relation to physical space also known as storage virtualisation. I hope this article has whetted your appetite to explore storage technologies in greater depth. Have fun!