How Can Linux Logical Volume Management (LVM) Help You?

6178875631_e0d58dac91_qLogical Volume Management or LVM is commonly used for Linux storage.

If everyone is using it, there must be some good reason, right? Actually, there are several. Let’s see how we can take advantage of LVM.

LVM Terminology and Concepts

Physical volumes are disks or partitions. UEFI firmware needs a small EFI System Partition (or ESP), and boot loaders can’t handle the complexity of LVM, so your first disk will have a small ESP partition, a small partition for /boot, and a large third partition. That third partition plus all the other disks are your physical volumes.

A volume group is a collection of physical volumes lumped together in a pool of storage. When you add another physical volume you expand this volume group.

A logical volume is then a large virtual storage device created out of that volume group (and thus based on the collection of physical volumes). The logical volumes can be used just as if they were disks or partitions, the only difference being that they have names under /dev/mapper/* instead of being /dev/sd*.

If your head is spinning from the concepts and terminology, check out the Linux server administration course where we learn this a piece at a time and apply it to flexible storage.

Back to ”Why Linux LVM?”

The least ambitious answer is that using LVM is the path of least resistance. Many distributions use this by default. Maybe you just put up with much larger device names when you run commands like df and mount and otherwise ignore LVM.

The reason the distributions do it is that it makes some things easier for the users, which makes for happier users, which is very attractive to companies like Red Hat who want customers to pay hundreds to thousands of dollars per year for support for a free operating system that really isn’t all that hard to support yourself.

It’s easy to expand a file system under LVM:

  1. Add another disk.
  2. Define it as a physical volume.
  3. Expand the volume group.
  4. Expand the logical volume.
  5. Grow the file system to fill its logical volume.

That just takes four commands: pvcreate, vgextend, lvextend, and either resize2fs for Ext4 or xfs_growfs for XFS. That’s easy!

You might like the ability to name the volumes. Volumes named rootfs and database and projectX make a lot more sense in command output than device names like sda2 and sdb and sdc1.

Logical volumes make some enterprise tasks much more practical. Modern journaling file systems shouldn’t lose files, but it’s still a good idea to run fsck (on Ext4) or xfs_check (on XFS) once in a while.

But your enterprise has no down time, it’s never an acceptable time to say ”We need to take the server down for a few hours for some file system maintenance.”

LVM to the rescue!

With enough unused storage available in the volume group, you can create a snapshot of a live file system. Do your checks on that snapshot. Even with fast disks, today’s enormous file systems can take quite a while to check. But that’s fine, the live file system is continuously in use as we do the checks on the snapshot. If the snapshot checks out OK, then make your backup of the snapshot.

If the snapshot is not OK, if it has any inconsistency, that means that your file system needs repair work as soon as possible. Now we really need to take the system down overnight or at some least-bad time to do the repair work. But with journaling file systems that should happen very infrequently indeed, and meanwhile our production system has been up 24/7 as we were doing the consistency checking and backups on snapshots supported through LVM.

The Linux Optimization & Troubleshooting course has an exercise in which you use LVM snapshots for file system check and repair, check out that course to get some hands-on experience with it.

Containers are another great application for LVM, next week I’ll explain what that’s about!

Type to search

Do you mean "" ?

Sorry, no results were found for your query.

Please check your spelling and try your search again.