Using Logical Volume Management

George Toft

Issue #0, linuxjournal.com

With LVM, you can combine partitions or drives into one large storage pool, called a volume group, and from there create logical volumes for filesystems.

Logical Volume Management (LVM) is an abstraction layer over the hard drives, which allows the Linux kernel to access the filesystems normally, yet each filesystem may be comprised of multiple hard drives. The main benefit you may see with LVM is when you run out of space in a filesystem (/home, for example), you can either resize the filesystems on the fly, or add another hard drive and spread /home across the two drives. If you are running short on two filesystems, the new drive can be used to augment both filesystems.

Notice how I have avoided the use of the word “partition”? Partitions do not exist under LVM. Under most Linux systems, a partition is used to create a filesystem (formatted with ext2, ext3, or reiserfs), then the filesystem is mounted to a mount point. LVM can use your partitions, and combine them together in one large storage pool (called a volume group). From that volume group (VG), you create logical volumes (LV), which is like a partition, from which you create the filesystems. Page 3 of the LVM Whitepaper (PDF) describes this concept in detail.

LVM from the Trenches

Last December, I set up my Linux workstation. Since I didn't really know how I would use the machine over the next few months, I decided to install LVM - I was trained in IBM AIX LVM, so I knew what it could do. I also chose to create my filesystems using ReiserFS, which turned out to be a huge benefit. Four months later, I filled the /home filesystem. Traditionally, I would have been forced to move stuff around, and make a bunch of symlinks to use the space on another file system, or repartition, reformat and reload my data. In this case, /home was 100% full, but my /share and /tmp filesystems had several gigabytes of unused space on them. The LVM HOWTO descibes a classic scenario like this one that illustrates exactly why LVM is an excellent tool.

Obviously, the solution was to resize the LV's. However, I had an old unused 4GB hard drive (more on this later) that I wanted to add to the mix. I installed the new hard drive, set its partition type to LVM (the whitepaper says this is not necessary for LVM, but old habits die hard, and I did this before reading the whitepaper), and added it to the VG. When that was done, I resized the LV's to use the 4GB drive and to take some space from /share and /tmp, and I gave it to /home.

This all sounds so simple, but of course, it was not. My first snag was in trying to resize the reiserfs on /home. Since I am using SuSE 7.3, I used YaST2. It showed me that my filesystem was resized, yet df showed me the truth - my filesystem was still the same size. Undaunted, I tried several more times. I fired up YaST1, and it resized the ReiserFS with no problems.

The second snag is the old 4GB drive itself. My other drives were 7200 RPM Fast IDE drives. The 4GB drive was a 5400 RPM [slow] IDE drive. Because LVM blended it in so well to the VG, I now suffered a data throughput performance hit. Before I used the 4GB drive, I could move data from filesystem to filesystem with a sustained data transfer rate of about 8 - 10MB/sec. With the old drive in place, my sustained data transfer rate was 1 - 1.5MB/sec. It looks like you are limited to the speed of the slowest drive on the filesystem, which makes sense.

Distribution Support for LVM

Since LVM is a kernel device driver, it works with all Linux distributions, however, only some distributions support LVM during installation. As of this writing, only Mandrake (see figure 1) and SuSE (see figure 2) support implementing LVM during Linux installation.

Figure 1: Selecting LVM in the Mandrake installer

Figure 1: Selecting LVM in the SuSE installer

SuSE's YaST administration tool provides a GUI-based logical volume management interface. As mentioned earlier, I noticed YaST2 does not resize ReiserFS VG's properly. YaST1 works correctly.

This brings me back to the benefit of using ReiserFS that I mentioned earlier - the ability to resize the filesystem on the fly. The ext3 filesystem has the ability to be resized, however, that filesystem must be unmounted during resizing, and ReiserFS can be resized while it is mounted and in use.

Regardless of which Linux distribution you use, you may always use the command line to manage your LVM installation. The LVM whitepaper provides an excellent discussion on using these tools.

George Toft has been heavily involved in Linux system administration for five years. He enjoys helping newbies and is currently teaching Introduction to Unix/Linux at a local community college. He also maintains a web site devoted to Linux and Linux Security at www.georgetoft.com/linux.

email: george@georgetoft.com