An Introduction To Logical Volume Management (LVM)
Disks, partitions and file storage are fundamental to computing. The concepts behind partitioning and using a disk drive haven’t changed for decades. However, this can be somewhat limiting. Here is where Linux’s Volume Manager comes in handy.
Linux’s Logical Volume Manager (LVM) was designed to increase the flexibility of working with partitions by creating a layer of separation between the partition in which the files are stored from the underlying disks where the data is written. In doing this, LVM introduces new terminology for how it deals with the disks. This article will cover the benefits LVM brings, the new terminology and how the parts of the Logical Volumes work together.
What Does the LVM Do?
The key benefit that LVM brings is the ability to modify the filesystems your server is using without taking the system offline. With traditional partitioning systems you are generally limited to the partition sizes you choose when the system is initially configured. While partitions can be resized, it does involve taking the system offline in order to adjust the partition without it being mounted. This resizing can also take a fair amount of time which means more downtime while you do the work.
Another problem is that you can’t simply duplicate a partition for backup purposes while it’s in use without open files, like databases, becoming corrupt in your backup. LVM provides a snapshot system for duplicating an in use filesystem without any corruption on the duplicate. LVM also provides RAID0 like functionality where a filesystem can span over multiple disks. It can also replicate a RAID 1 system allowing filesystem mirroring. Finally, LVM also provides the ability to move your filesystem across different physical disks as required.
Partitioning Disks and Logical Volumes
So let’s look at some terminology involved when working with Logical Volumes. First, before LVM can get involved you will need to partition your disks with a regular partitioning tool such as fdisk or parted. The partitions you create are used by LVM as Physical Volumes or PVs. LVM can use one or more Physical Volumes on the system. The Physical Volume partitions you create can be whatever size you like. They can be part of a disk or a whole disk, and each disk can contain multiple Physical Volume partitions if you want.
Once we have Physical Volumes, we can then create Volume Groups. Volume Groups group Physical Volumes together to make spaces upon which we can create Logical Volumes. A Volume Group can consist of one or more Physical Volumes. They can be added and removed from Volume Groups on the fly allowing physical disks to be added and removed from your system when required.
Finally, we have the Logical Volumes. These sit within the Volume Groups, pretty much the same as creating a traditional partition on a hard disk. The Logical Volumes are what are formatted with our file systems and in which our files are stored. They are the key to the benefits of using LVM, in that they can be resized easily, moved around and duplicated without stopping your running system. This introduces a great deal of flexibility to the management of your system.
While you can create a large Volume Group spanning across all of your disks and then fill it with one or more Logical Volumes, the common practice is to create Logical Volumes to a size that meets the needs of the content estimated to be stored there, leaving the rest of the disk empty. This allows for the Logical Volumes to later be resized or moved as required by the changing needs of your server.
In a future article we’ll be looking at how you can start with some blank disks and end with multiple Logical Volumes, also we’ll be showing how to use LVM snapshots to create a backup of a Logical Volume.
Originally published at blog.100tb.com.