What is logical volume management (LVM)?
Logical volume management (LVM) is a form of storage virtualization that offers system administrators a more flexible approach to managing disk storage space than traditional partitioning. This type of virtualization tool is located within the device-driver stack on the operating system.
Logical volume management in Linux with an example
LVM is a method of disk space management in the Linux operating system (OS). By creating a layer of abstraction over physical storage, LVM also allows system administrators (sys admins) to manage storage volumes across multiple physical hard disks.
With LVM, sys admins can increase disk input/output (I/O) by adding disk space to what is known as a "logical storage volume" (or simply "logical volume"). These logical volumes provide more flexibility for disk space creation, administration and management compared to traditional storage management methods that directly use physical storage and increase the maximum capacity of individual hard disk drives.
Suppose there are three disks of 1 terabyte (TB) capacity each. Each of these physical disks is a physical volume (PV), designated PV 1, PV 2, and PV 3.
The total or aggregate available physical storage is 3 TB.
All three disks are added to Volume Group 1. Two logical volumes (LVs) are created from the volume group: LV1 and LV2. Each LV has a capacity of 1.5 TB. Other LV combinations with different capacities can also be created, such as the following:
- 3 LVs of capacities 1 TB, 500 gigabytes (GB), 1.5 TB.
- 4 LVs of capacities 500 GB, 500 GB, 1 TB, and 1 TB.
- 5 LVs of capacities 500 GB, 500 GB, 500 GB, 500 GB, 1 TB.
In this way, LVM adds flexibility to storage needs without increasing the complexity of storage management.
An appropriate LVM tool makes it easy to allocate hard drives to physical volumes, create logical volumes from the physical volumes, and ultimately, increase the size of a hard drive partition.
How does logical volume management work?
LVM works by breaking the PVs into physical extents (PEs). The PEs -- contiguous areas of storage reserved for files -- are mapped onto logical extents (LEs) which are then pooled into volume groups (VGs). These groups are linked together into LVs that act as virtual disk partitions, which can be managed by using LVM and an appropriate LVM tool.
Extents are present in both PVs and LVs. In either case, they are small, fixed-size units of space. In particular, an extent is the smallest amount of space that can be allocated by LVM in Linux. All LVs in a VG are of the same size. LVM maintains a mapping between all logical and physical extents. This mapping is merely the LV, which can be expanded by adding more extents or shrunk by removing extents.
Why use logical volume management?
The goal of LVM is to facilitate managing the conflicting storage needs of multiple end users. The most common use case for LVM is to mark physical devices as PVs and then use these devices to create a VG pool from which LVs can be allocated to increase disk space.
Using the volume management approach, the administrator is not required to allocate all disk storage space at initial setup. Some can be held in reserve for later allocation. The sys admin can use LVM to segment logically sequential data or combine partitions, increasing throughput and making it simpler to resize and move storage volumes as needed.
Additionally, sys admins don't need to know the volume layout to create logical storage partitions. As long as they can supply the volume size and name, LVM will take care of all storage mapping, partitioning, handling, and management.
Sys admins can use the current version of LVM (2.03.21 as of 2023) and the device mapper driver in the Linux kernel framework (2.6 kernel) to designate existing storage devices (hard disks) as physical volumes and place them into volume groups. The combined storage space that is created can then be used to allocate logical storage volumes (logical units) as required. These LVs can then be treated as traditional partitions for storage needs.
What is a logical volume?
An LV is similar to a partition on a physical disk. Multiple LVs can be carved out of a VG, which itself is a storage pool consisting of multiple PVs. The aggregate storage capacity of the PVs is abstracted by the VG in order to create logical units of storage called LVs.
With LVM, storage volumes may be defined for various user groups within the enterprise, and new storage can be added to a particular group when desired without requiring user files to be redistributed, thus making the most efficient use of space. When old drives are retired, the data they contain can be transitioned to new drives, ideally without disrupting availability of services for end users.
What are the benefits of logical volume management?
The most obvious benefit of LVM is that it provides an easy and flexible way to scale storage capacity. Admins can scale capacity up or down as users' storage needs change by simply adding or removing extents from an LV. The processes for both increasing and decreasing capacity are logical and simple. Since LVM provides a logical command structure, the commands are easy to remember and therefore user-friendly.
Another advantage of LVM is that it allows for easy capacity reallocation, meaning the capacity can be reduced in one VG and added to another to match changing requirements. There's no need to reformat and repartition the underlying devices in order to take advantage of resizable storage volumes. Traditional partitioning does not provide that flexibility.
LVM supports RAID configurations, so sys admins can use LVs to configure RAIDs for data. Creating RAID volumes not only improves performance but also minimizes the probability of device failure. They can also create striped volumes where data is striped across multiple devices, thus improving throughput. Additionally, they can take point-in-time snapshots of LVs, both to ensure the consistency of data backups and to test changes without adversely impacting real data.
LVM also provides the flexibility to create two other types of volumes: thin volumes and cache volumes. Thinly provisioned LVs are larger than the available physical space while cache volumes improve the performance of slow block devices by using a fast block device (e.g., a solid-state drive).