Linux: The Role of the Logical Volume Manager (LVM)
scottalanmiller last edited by scottalanmiller
The standard, integrated Logical Volume Manager on Linux is simply known as LVM (technically it is now LVM2.) Linux' LVM is probably the best known logical volume manager in use today, even though logical volume managers are ubiquitous on all modern operating systems. It is so famous that the concept of logical volume managers is often tied to people's impressions of Linux LVM. Linux' LVM dates back to 1998
On Linux, the LVM subsystem provides for features like logical volume resizing (logical volumes replace partitions in this case), snapshots, block device aggregation and can even implement some RAID functionality. Software RAID functionality in LVM is a recent addition and is done by implementing the same MD RAID code that has long been available on Linux, resulting not in additional functionality but simply an integrating of toolsets.
Because LVM allows for flexibility in filesystem sizes, improves overall flexibility and provides for device flexibility and abstraction it is recommended for use in nearly all cases. The overhead of the LVM system, in terms of performance, is very low and generally ignored. Some performance enhancing mechanisms also rely on LVM, so in some cases performance can even be improved by using it (but not in the majority case.) As a new learner on Linux, you should likely focus on using LVM across the board until you feel you have a deep understanding of its role, risks and rewards. Essentially "when in doubt, use LVM." LVM is essentially ubiquitous on servers and common on desktops. Desktops can benefit heavily from LVM as well, especially through the availability of snapshots, but often desktop users do without this functionality.
LVM usage would most commonly be skipped in ephemeral server side systems where resizing, modifying and even taking backups is not done - servers are destroyed and created in an automated manner instead as is common in a full DevOps and Cloud unified administration model (we will talk about DevOps and Cloud and their effects on systems administration at a later time.)
Common Mechanisms in LVM
Linux LVM (and most LVM systems) use three basic "layers" within the LVM system. These are Physical Volumes (PVs), Volume Groups (VGs) and Logical Volumes (LVs.) Understanding the roles and interactions of each of these is critical to understanding how the LVM layer is managed.
At the lowest layer are the physical volumes. PVs are block devices that are presented to the system and are commonly physical disks, SAN LUNs, RAID arrays from a hardware RAID controller, RAID arrays from software RAID (MD RAID on Linux), partitions on top of any other block device or similar. When a block device is placed under LVM management, it is added as a PV. This alone provides no management and simply marks the device as being a part of LVM so that it is listed as one of LVM's available PVs rather than being available as a normal block device for other purposes.
The middle layer is the concept of a Volume Group or VG. A Volume Group comprises one or more PVs that have been added together to represent a singular block device or volume. You simply specify which Physical Volume(s) will be part of a single VG and the LVM system aggregates them and provides them as a single device. A VG can be comprised of not just different PVs but PVs based on different types of devices. This is not a common use case, but a great degree of flexibility is provided by this.
A VG cannot be used directly by the system. A VG is simply a container on which we can create one or more Logical Volumes. At this stage, a VG acts like a single block device and LVs are analogous to partitions, but partitions that can be flexibly adjusted in size at a later time. Unlike traditional partitions, LVs do not require geometric data and do not occupy "locations" within the VG. So we do not have an "inner partition" or an "outer partition". The LVM system allocates the space for the LVs within the VG on top of the PVs on its own.
The resulting Logical Volumes are usable block devices on which we commonly apply file systems and use directly. However, single LVs are block devices implementing the standard interface they can be used in any way in which a block device can be used. They can be accessed raw, take a filesystem, be added to a software RAID array and so forth.
It is most common in Linux that we put filesystems directly onto Logical Volumes. It is, however, only standard for LVM to be used with permanent storage devices and not removable ones such as USB drives, SD cards and external USB hard drives.
The BtrFS and ZFS filesystems, both of which are available for Linux, both include their own Logical Volume Management functionality inside of the filesystem itself fully integrated. While either filesystem could, of course, be used on top of an LVM LV as this is the nature of standard block devices, but this would be impractical and unexpected. The integrated logical volume management systems of BtrFS and ZFS are considered important value propositions of these systems.
Red Hat's LVM Manual is exceptionally detailed and complete: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Logical_Volume_Manager_Administration/index.html
Part of a series on Linux Systems Administration by Scott Alan Miller