Hubbry Logo
Logical Volume Manager (Linux)Logical Volume Manager (Linux)Main
Open search
Logical Volume Manager (Linux)
Community hub
Logical Volume Manager (Linux)
logo
7 pages, 0 posts
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Logical Volume Manager (Linux)
Logical Volume Manager (Linux)
from Wikipedia
Logical Volume Manager
Original authorHeinz Mauelshagen[1]
Stable release
2.03.36[2] Edit this on Wikidata / 24 October 2025; 3 days ago (24 October 2025)
Repositorysourceware.org/git/?p=lvm2.git
Written inC
Operating systemLinux, NetBSD
LicenseGPLv2
Websitesourceware.org/lvm2/

In Linux, Logical Volume Manager (LVM) is a device mapper framework that provides logical volume management for the Linux kernel. Most modern Linux distributions are LVM-aware to the point of being able to have their root file systems on a logical volume.[3][4][5]

Heinz Mauelshagen wrote the original LVM code in 1998, when he was working at Sistina Software, taking its primary design guidelines from the HP-UX's volume manager.[1]

Uses

[edit]

LVM is used for the following purposes:

  • Creating single logical volumes of multiple physical volumes or entire hard disks (somewhat similar to RAID 0, but more similar to JBOD), allowing for dynamic volume resizing.
  • Managing large hard disk farms by allowing disks to be added and replaced without downtime or service disruption, in combination with hot swapping.
  • On small systems (like a desktop), instead of having to estimate at installation time how big a partition might need to be, LVM allows filesystems to be easily resized as needed.
  • Performing consistent backups by taking snapshots of the logical volumes.
  • Encrypting multiple physical partitions with one password.

LVM can be considered as a thin software layer on top of the hard disks and partitions, which creates an abstraction of continuity and ease-of-use for managing hard drive replacement, repartitioning and backup.

Features

[edit]
Various elements of the LVM

Basic functionality

[edit]
  • Volume groups (VGs) can be resized online by absorbing new physical volumes (PVs) or ejecting existing ones.
  • Logical volumes (LVs) can be resized online by concatenating extents onto them or truncating extents from them.
  • LVs can be moved between PVs.
  • Creation of read-only snapshots of logical volumes (LVM1), leveraging a copy on write (CoW) feature,[6] or read/write snapshots (LVM2)
  • VGs can be split or merged in situ as long as no LVs span the split. This can be useful when migrating whole LVs to or from offline storage.
  • LVM objects can be tagged for administrative convenience.[7]
  • VGs and LVs can be made active as the underlying devices become available through use of the lvmetad daemon.[8]

Advanced functionality

[edit]
  • Hybrid volumes can be created using the dm-cache target, which allows one or more fast storage devices, such as flash-based SSDs, to act as a cache for one or more slower hard disk drives.[9]
  • Thinly provisioned LVs can be allocated from a pool.[10]
  • On newer versions of device mapper, LVM is integrated with the rest of device mapper enough to ignore the individual paths that back a dm-multipath device if devices/multipath_component_detection=1 is set in lvm.conf. This prevents LVM from activating volumes on an individual path instead of the multipath device.[11]

RAID

[edit]
  • LVs can be created to include RAID functionality, including RAID 1, 5 and 6.[12]
  • Entire LVs or their parts can be striped across multiple PVs, similarly to RAID 0.
  • A RAID 1 backend device (a PV) can be configured as "write-mostly", resulting in reads being avoided to such devices unless necessary.[13]
  • Recovery rate can be limited using lvchange --raidmaxrecoveryrate and lvchange --raidminrecoveryrate to maintain acceptable I/O performance while rebuilding a LV that includes RAID functionality.

High availability

[edit]

The LVM also works in a shared-storage cluster in which disks holding the PVs are shared between multiple host computers, but can require an additional daemon to mediate metadata access via a form of locking.

CLVM
A distributed lock manager is used to broker concurrent LVM metadata accesses. Whenever a cluster node needs to modify the LVM metadata, it must secure permission from its local clvmd, which is in constant contact with other clvmd daemons in the cluster and can communicate a desire to get a lock on a particular set of objects.
HA-LVM
Cluster-awareness is left to the application providing the high availability function. For the LVM's part, HA-LVM can use CLVM as a locking mechanism, or can continue to use the default file locking and reduce "collisions" by restricting access to only those LVM objects that have appropriate tags. Since this simpler solution avoids contention rather than mitigating it, no concurrent accesses are allowed, so HA-LVM is considered useful only in active-passive configurations.
lvmlockd
As of 2017, a stable LVM component that is designed to replace clvmd by making the locking of LVM objects transparent to the rest of LVM, without relying on a distributed lock manager.[14] It saw massive development during 2016.[15]

The above described mechanisms only resolve the issues with LVM's access to the storage. The file system selected to be on top of such LVs must either support clustering by itself (such as GFS2 or VxFS) or it must only be mounted by a single cluster node at any time (such as in an active-passive configuration).

Volume group allocation policy

[edit]

LVM VGs must contain a default allocation policy for new volumes created from it. This can later be changed for each LV using the lvconvert -A command, or on the VG itself via vgchange --alloc. To minimize fragmentation, LVM will attempt the strictest policy (contiguous) first and then progress toward the most liberal policy defined for the LVM object until allocation finally succeeds.

In RAID configurations, almost all policies are applied to each leg in isolation. For example, even if a LV has a policy of cling, expanding the file system will not result in LVM using a PV if it is already used by one of the other legs in the RAID setup. LVs with RAID functionality will put each leg on different PVs, making the other PVs unavailable to any other given leg. If this was the only option available, expansion of the LV would fail. In this sense, the logic behind cling will only apply to expanding each of the individual legs of the array.

Available allocation policies are:

  • Contiguous – forces all LEs in a given LV to be adjacent and ordered. This eliminates fragmentation but severely reduces a LV expandability.
  • Cling – forces new LEs to be allocated only on PVs already used by an LV. This can help mitigate fragmentation as well as reduce vulnerability of particular LVs should a device go down, by reducing the likelihood that other LVs also have extents on that PV.
  • Normal – implies near-indiscriminate selection of PEs, but it will attempt to keep parallel legs (such as those of a RAID setup) from sharing a physical device.
  • Anywhere – imposes no restrictions whatsoever. Highly risky in a RAID setup as it ignores isolation requirements, undercutting most of the benefits of RAID. For linear volumes, it can result in increased fragmentation.

Implementation

[edit]
Basic example of an LVM head
Inner workings of the version 1 of LVM. In this diagram, PE stands for a Physical Extent.

Typically, the first megabyte of each physical volume contains a mostly ASCII-encoded structure referred to as an "LVM header" or "LVM head". Originally, the LVM head used to be written in the first and last megabyte of each PV for redundancy (in case of a partial hardware failure); however, this was later changed to only the first megabyte. Each PV's header is a complete copy of the entire volume group's layout, including the UUIDs of all other PVs and of LVs, and allocation map of PEs to LEs. This simplifies data recovery if a PV is lost.

In the 2.6-series of the Linux Kernel, the LVM is implemented in terms of the device mapper, a simple block-level scheme for creating virtual block devices and mapping their contents onto other block devices. This minimizes the amount of relatively hard-to-debug kernel code needed to implement the LVM. It also allows its I/O redirection services to be shared with other volume managers (such as EVMS). Any LVM-specific code is pushed out into its user-space tools, which merely manipulate these mappings and reconstruct their state from on-disk metadata upon each invocation.

To bring a volume group online, the "vgchange" tool:

  1. Searches for PVs in all available block devices.
  2. Parses the metadata header in each PV found.
  3. Computes the layouts of all visible volume groups.
  4. Loops over each logical volume in the volume group to be brought online and:
    1. Checks if the logical volume to be brought online has all its PVs visible.
    2. Creates a new, empty device mapping.
    3. Maps it (with the "linear" target) onto the data areas of the PVs the logical volume belongs to.

To move an online logical volume between PVs on the same Volume Group, use the "pvmove" tool:

  1. Creates a new, empty device mapping for the destination.
  2. Applies the "mirror" target to the original and destination maps. The kernel will start the mirror in "degraded" mode and begin copying data from the original to the destination to bring it into sync.
  3. Replaces the original mapping with the destination when the mirror comes into sync, then destroys the original.

These device mapper operations take place transparently, without applications or file systems being aware that their underlying storage is moving.

Caveats

[edit]
  • Until Linux kernel 2.6.31,[16] write barriers were not supported (fully supported in 2.6.33). This means that the guarantee against filesystem corruption offered by journaled file systems like ext3 and XFS was negated under some circumstances.[17]
  • As of 2015, no online or offline defragmentation program exists for LVM. This is somewhat mitigated by fragmentation only happening if a volume is expanded and by applying the above-mentioned allocation policies. Fragmentation still occurs, however, and if it is to be reduced, non-contiguous extents must be identified and manually rearranged using the pvmove command.[18]
  • On most LVM setups, only one copy of the LVM head is saved to each PV, which can make the volumes more susceptible to failed disk sectors. This behavior can be overridden using vgconvert --pvmetadatacopies. If the LVM can not read a proper header using the first copy, it will check the end of the volume for a backup header. Most Linux distributions keep a running backup in /etc/lvm/backup, which enables manual rewriting of a corrupted LVM head using the vgcfgrestore command.

See also

[edit]

References

[edit]

Further reading

[edit]
Revisions and contributorsEdit on WikipediaRead on Wikipedia
from Grokipedia
The Logical Volume Manager (LVM) is a technology integrated into the via the device-mapper framework, enabling the abstraction of physical storage devices into flexible logical units for more efficient disk space management. It operates by combining multiple physical disks or partitions—known as physical volumes (PVs)—into pooled volume groups (VGs), from which resizable logical volumes (LVs) can be created and allocated to file systems or applications. This layered approach allows LVM to overcome the limitations of rigid partitioning schemes, providing dynamic control over storage resources without downtime in most cases. Developed in 1998 as an adaptation of the Unix Logical Volume Manager for , LVM evolved significantly with the release of LVM2 around 2004, which leveraged the kernel's device-mapper driver for improved scalability and features like snapshots. Originally designed to address the challenges of growing storage needs in enterprise systems, it has become a standard tool in major Linux distributions, including , , and , for handling complex storage configurations. LVM's key advantages include online resizing of logical volumes (expanding or shrinking them while mounted, though shrinking requires caution to avoid ), creation of point-in-time snapshots for backups and testing, and support for advanced provisioning techniques such as to optimize space usage. It also facilitates data relocation across devices, striping for improved performance, and or RAID-like redundancy within volume groups, making it particularly valuable for servers requiring and adaptability to changing storage demands. These capabilities reduce administrative overhead and enhance data protection compared to conventional methods.

Introduction

Overview

The Logical Volume Manager (LVM) is a framework that provides for the , creating a layer of over physical storage to enable the creation of logical storage volumes independent of the underlying hardware layout. Its primary purposes include flexible by pooling storage from multiple physical devices into volume groups, dynamic resizing of volumes without requiring system , and abstraction from physical hardware changes, such as adding or replacing disks seamlessly. LVM offers key benefits for storage management, particularly in enterprise environments, by supporting features like point-in-time snapshots for efficient backups and for , while ensuring independence from specific disk layouts to simplify administration and . These capabilities allow administrators to extend storage capacity online and relocate without corruption, enhancing reliability and operational flexibility across diverse hardware configurations. LVM evolved from the original LVM1 to LVM2, with the latter replacing LVM1 starting in 4 and integrating natively with the device-mapper driver introduced in 2.6 for improved performance and broader functionality. As of 2025, LVM continues as a standard and actively maintained feature in major distributions, including 9, , and , without significant paradigm shifts but with enhancements like stable installer support in recent releases.

History

The Logical Volume Manager (LVM) for originated in 1998, when Heinz Mauelshagen developed its initial code while working at Sistina Software, drawing primary design inspiration from the volume manager in to provide flexible disk management capabilities on . This early work addressed the need for a virtual-disk subsystem that supported online allocation and resizing of storage volumes, marking a significant advancement for storage management at the time. The first stable release of LVM1 occurred in 2000, licensed under the GPL, enabling system administrators to dynamically manage storage without and facilitating tasks like disk upgrades and reorganization. In December 2003, acquired Sistina Software for $31 million in stock, integrating LVM into its enterprise offerings and accelerating its adoption in commercial Linux distributions like (RHEL). Around 2004–2005, development shifted to LVM2, a ground-up rewrite that leveraged the device-mapper framework introduced in 2.6 (2003), improving , , and features such as for more efficient space utilization. This transition positioned LVM as a core component of modern storage stacks, with LVM2 becoming the standard implementation by the mid-2000s. Key milestones in the mid-2000s included the introduction of clustered LVM (CLVM) around 2005, which extended LVM2 for high-availability environments by enabling shared storage management across cluster nodes, as integrated into Cluster Suite. In 2012, with 3.5, LVM2 gained native support (levels 0, 1, 4, 5, 6, and 10), allowing logical volumes to incorporate redundancy directly without relying solely on external tools. Up to 2025, LVM has seen iterative enhancements focused on stability and integration rather than major overhauls; for instance, RHEL 9 (released in 2022) improved NVMe support and caching mechanisms, enabling faster block devices like SSDs to serve as write-back or write-through caches for slower storage. Distributions such as Arch Linux and Ubuntu have incorporated minor updates in 2023–2025 for better compatibility with file systems like Btrfs and ZFS, alongside enhanced stability in containerized setups like Kubernetes, as reflected in LVM2 releases up to version 2.03.36.

Core Components

Physical Volumes

Physical volumes (PVs) serve as the foundational building blocks in the Logical Volume Manager (LVM) for , representing the raw storage devices or partitions that are initialized and designated for use within the LVM framework. A PV is typically a whole disk, such as /dev/sdb, or a partition on a disk, like /dev/sda1, which has been prepared by writing an LVM-specific disk label and metadata to enable its integration into higher-level LVM constructs. The creation of a PV involves initializing the target block device using the pvcreate command, which writes the necessary LVM structures to the device, rendering any existing data irrecoverable unless backed up beforehand. For example, executing pvcreate /dev/sda1 labels the partition as an LVM PV and reserves a metadata area at the beginning of the device, with a default size of approximately 1 MiB (adjustable via the --metadatasize option, such as 4 MiB for larger volumes). This process begins at sector 1 (512 bytes offset), where a 512-byte LVM is placed, followed by the metadata area starting at a page-aligned offset (typically 4 KiB), and the first physical extent (PE) at 1 MiB by default. The device must be unused and accessible with administrative privileges, and the lvm2 package must be installed. LVM supports initializing multipath devices (e.g., via ) and RAID arrays (e.g., from mdadm) as PVs, provided they present as standard block devices. LVM metadata on a PV is stored in a compact ASCII text format within the reserved area, consisting of a header followed by a that records volume group configurations. Key elements include a unique random UUID for the PV, the total size of the device in bytes, and details on free extents (divided into fixed-size physical extents, defaulting to 4 MiB). LVM supports two primary metadata format versions: (associated with legacy LVM1, using a simpler text structure) and version 2 (standard for LVM2, offering greater flexibility in a still text-based but enhanced format that supports features like snapshots and clustering). By default, LVM2 creates one copy of the metadata at the start of the PV, with an optional second copy at the end for redundancy. PVs play a crucial role in aggregating storage for volume groups, where multiple PVs can be pooled to form a unified capacity. Resizing a PV with the pvresize command is possible on devices that support online resizing (e.g., certain or NVMe drives), but it requires caution to prevent data loss, as the operation adjusts the PV size and updates metadata without altering existing extents unless explicitly managed.

Volume Groups

A volume group (VG) in the Logical Volume Manager (LVM) for serves as a collection of one or more physical volumes (PVs), aggregating their storage into a unified pool of disk space from which logical volumes can be allocated. This pool is divided into fixed-size units known as physical extents (PEs), with a default size of 4 MiB that can be configured during VG creation to optimize for specific workloads, such as larger extents for high-capacity storage or smaller ones for finer . Each VG maintains its own set of attributes, including a unique name for identification and a (UUID) for internal referencing across systems, enabling scalability for enterprise environments. Volume groups are created using the vgcreate command, which initializes a new VG by associating specified PVs and optionally setting parameters like PE size with the -s option; for example, vgcreate myvg /dev/sda1 /dev/sdb1 forms a VG named "myvg" from two PVs. Existing VGs can be dynamically extended online with vgextend, allowing additional PVs to be added without downtime, such as vgextend myvg /dev/sdc1, which expands the pool's capacity immediately. Conversely, PVs can be removed from a VG using vgreduce after ensuring no extents are in use on the target PV, as in vgreduce myvg /dev/sda1, provided the VG has sufficient free space elsewhere to relocate data if needed. Activation policies control VG accessibility, with options like auto- on via the auto_activation_volume_list in /etc/lvm/lvm.conf or manual control using vgchange -ay to activate all VGs; in clustered environments, the -c y during creation or change enables shared access. LVM stores VG metadata as compact ASCII text on every PV within the group, typically in up to three redundant copies per PV (configurable with --metadatacopies) to ensure recoverability if a PV fails, with the primary copy at the beginning of the device and backups appended in a . This redundancy allows LVM tools to reconstruct the VG descriptor from any surviving PV using commands like vgcfgrestore. In clustered setups, such as those using Pacemaker or shared storage, VG locks are managed by the lvmlockd daemon (with locking_type=1 in lvm.conf) or the older clvmd service to serialize metadata updates and prevent concurrent modifications across nodes, ensuring data consistency without requiring exclusive locks on the entire VG. Within a VG, extents can be allocated contiguously—keeping logical extents on consecutive PEs for better in —or non-contiguously via policies like "anywhere" for flexibility in fragmented pools or "cling" to extend existing allocations preferentially; these are set at VG creation with vgcreate --alloc or adjusted later with vgchange. This approach allows efficient space utilization even as PVs are added or removed, abstracting the underlying physical layout from higher-level .

Logical Volumes

Logical volumes (LVs) in the Logical Volume Manager (LVM) for Linux function as virtual block devices that provide usable storage abstractions for file systems, databases, or applications. These devices are named in the form /dev/<vgname>/<lvname>, where <vgname> is the volume group name and <lvname> is a user-defined name for the logical volume. LVs are allocated from the free space pooled in a volume group (VG), divided into logical extents (LEs) that match the size of the VG's physical extents (PEs), typically 4 MiB by default. Each LE in an LV maps directly to a corresponding PE on one or more physical volumes (PVs), enabling flexible storage management without regard to the underlying physical layout. LVM supports three fundamental types of logical volumes to address different storage needs. Linear volumes, the default type, allocate a contiguous range of PEs to LEs in sequential order, creating a simple, unified block device from multiple PVs. Striped volumes enhance I/O performance by distributing data across multiple PVs in parallel, using round-robin allocation of extents similar to 0. Mirrored volumes ensure data redundancy by duplicating writes to multiple copies of the extents, akin to 1, with LVM handling synchronization across PVs. Logical volumes are created from a VG's available space using the lvcreate command, specifying the desired size in extents, megabytes, or other units. Resizing occurs online without downtime; extension adds free extents to the LV via lvextend or lvresize, while shrinking removes extents, both typically coordinated with filesystem tools (e.g., via the --resizefs option) to adjust mounted partitions seamlessly. The kernel's device-mapper subsystem manages the mapping by maintaining translation tables that route I/O requests from LEs to their associated PEs on PVs, ensuring transparent access to data. LVs support activation and deactivation to enable or disable them as block devices, controlled via tools like lvchange. In the original LVM1 implementation, logical volumes were limited to a maximum of 65,534 extents, constraining their size based on the extent size (e.g., about 256 GiB with the 4 MiB default). LVM2 removed this restriction, allowing up to billions of extents per LV and supporting volumes up to 8 exabytes on 64-bit systems, greatly improving scalability.

Features

Basic Functionality

The Logical Volume Manager (LVM) enables dynamic resizing of logical volumes (LVs), allowing administrators to extend or reduce storage capacity as needed without necessarily interrupting operations. Extending an LV online is supported by first increasing the LV size using the lvextend command, followed by resizing the associated filesystem, such as , with resize2fs while the filesystem remains mounted. This process leverages available free space in the volume group (VG) to allocate additional extents to the LV, ensuring minimal downtime for growing workloads. In contrast, shrinking an LV requires unmounting the filesystem first to avoid , as online reduction is not supported for safety reasons. LVM snapshots provide point-in-time copies of LVs using a copy-on-write (COW) mechanism, which efficiently captures the state of the original volume at the moment of creation without duplicating all data initially. These snapshots are created using the lvcreate -s command, specifying the source LV and allocating a small initial space from the VG for storing changes. As modifications occur on the original LV, unchanged blocks remain shared, while altered blocks are copied to the snapshot's reserved space before the update, ensuring the snapshot reflects the pre-change state. Space usage in the snapshot grows incrementally based solely on the volume of changes made to the original LV since its creation, making it suitable for short-term captures where divergence is limited. Snapshots integrate seamlessly with backup and recovery workflows, enabling consistent data copies for tools like rsync or dd without quiescing the production filesystem. Administrators can mount the snapshot as a read-only device and perform backups directly from it, capturing a frozen view while the original LV continues serving live operations. For recovery, restoring from such a backup involves recreating the LV from the backed-up snapshot data or merging it back if needed, providing a reliable method for point-in-time restoration. Data migration within LVM is facilitated by the pvmove command, which relocates physical extents (PEs) between physical volumes (PVs) in a VG without interrupting access to the affected LVs. This operation uses temporary to transfer data in sections, allowing for hardware upgrades or load balancing across storage devices while maintaining . The process respects the VG's allocation policies and requires sufficient free space on the destination PVs to complete successfully. A distinctive capability in LVM2 is the snapshot merge feature, introduced around 2010, which allows reverting an LV to its snapshot state by integrating the snapshot's data back into the origin using the lvconvert --merge command. This operation applies the differences captured in the COW area to the original LV, effectively undoing changes since the snapshot was taken, and is performed online without requiring an unmount in most cases. The merge completes by overwriting modified blocks in the origin with the snapshot's preserved versions, after which the snapshot is automatically removed.

Advanced Functionality

LVM's feature enables the over-allocation of storage space, allowing administrators to create logical volumes larger than the available physical capacity, with actual space allocated dynamically as data is written. This is achieved through thin pools, which serve as shared storage reservoirs for multiple thin logical volumes. To establish a thin pool, the lvcreate command is invoked with the -T option, specifying the pool's name, size, and optionally the chunk size for data blocks, typically ranging from 64 KiB to 1 MiB to balance efficiency and metadata overhead. significantly reduces storage waste in environments with variable usage patterns, such as hosts, by deferring allocation until necessary. A key advantage of thin provisioning lies in its support for space-efficient snapshots, which incur less overhead than traditional (COW) snapshots used in basic LVM functionality, as they avoid immediate full duplication of data blocks and instead reference shared extents in the thin pool until divergence occurs. This metadata-driven approach tracks changes via a separate thin pool metadata volume, which maps virtual blocks to physical ones and must be sized appropriately—defaults start at around 4 GiB but can be expanded to handle thousands of snapshots without exhaustion. LVM2 supports thin pool metadata up to approximately 16 GiB, accommodating larger-scale deployments with extensive snapshotting or overprovisioning ratios exceeding 10:1 and mitigating limitations where pools over 256 TiB risk metadata overflow with smaller sizes. Recent updates in version 2.03.36 (October 2025) include improvements to metadata handling for such configurations. Monitoring tools like lvs report thin pool usage, alerting to thresholds where overcommitment risks data unavailability if the pool fills unexpectedly. LVM caching leverages the device-mapper cache (dm-cache) module to enhance performance of HDD-based logical s by using faster SSDs as a front-end cache layer, promoting frequently accessed "hot" for reduced latency. Available modes include writeback, where both reads and writes are cached with deferred flushing to the origin for optimal speed, and writethrough, which caches reads but synchronizes writes immediately to ensure at the cost of higher latency. Passthrough mode bypasses caching for uncached blocks, minimizing overhead. Setup involves creating an origin logical on slow storage and a cache on fast storage within the same group, then attaching them via lvconvert --type cache --cachevol <cache_lv> <origin_lv>. This integration is particularly beneficial for mixed workloads, accelerating random I/O by up to several times depending on cache hit rates and SSD characteristics. Online defragmentation in LVM optimizes logical volume layouts by relocating physical extents without interrupting access, using the pvmove command to redistribute data across physical volumes in a volume group. This process consolidates fragmented extents—caused by repeated resizing or snapshot operations—into contiguous blocks, potentially improving sequential I/O performance on underlying filesystems like ext4. For example, pvmove /dev/vg/lv iteratively moves the entire logical volume's extents to free space elsewhere in the group, running in the background to avoid downtime. While not a dedicated defragmenter, this method effectively reorganizes storage online, with progress trackable via lvs -o +seg_pe_ranges.

RAID Integration

LVM integrates software capabilities directly into its logical volume framework, enabling administrators to create redundant and high-performance storage configurations managed entirely through LVM tools. This integration leverages the device-mapper (dm-raid) target in the , which bridges device-mapper with the MD subsystem to handle operations. Built-in support was added to LVM2 starting with version 2.02.87, released in August 2011, coinciding with kernel support from version 2.6.38 for the dm-raid target. The supported RAID levels include RAID0 for striping to enhance , RAID1 for to provide , RAID4/5/6 for parity-based with varying numbers of dedicated parity blocks, and RAID10 for combining and striping. When creating a RAID logical volume, LVM automatically generates subvolumes for , metadata, and parity as needed; for instance, the command lvcreate --type raid1 -m1 -L 10G -n my_raid_lv my_vg establishes a 10 GB mirrored volume named my_raid_lv in volume group my_vg. Health monitoring and repairs are facilitated by commands like lvconvert --repair, which can rebuild failed components in degraded arrays. Unlike the standalone tool, which manages arrays as independent /dev/md* devices, LVM operates seamlessly within volume groups, allowing logical volumes of mixed types— and non-—to coexist and share physical extents efficiently. This unified management simplifies administration by avoiding separate entities and enabling dynamic resizing or conversion between levels, such as upgrading from RAID5 to RAID6 via lvconvert. LVM arrays support degraded operation, continuing I/O with reduced capacity if a device fails, and automatic resynchronization upon adding or replacing physical volumes with vgextend or pvcreate. LVM can also incorporate hardware RAID arrays as underlying physical volumes, layering software RAID on top of hardware-accelerated redundancy for hybrid setups that balance performance and flexibility. This approach is particularly useful in enterprise environments, where hardware RAID provides initial protection and LVM adds advanced volume management.

High Availability

The Clustered Logical Volume Manager (CLVM) extends LVM2 to enable multiple nodes in a (HA) cluster to concurrently manage shared storage devices, such as those on a (SAN). CLVM achieves this by integrating with a (DLM), which coordinates access to physical volumes, volume groups, and logical volumes across nodes to prevent from simultaneous modifications. This setup relies on cluster communication frameworks like corosync for messaging and Pacemaker for resource orchestration, allowing volume groups to be marked as clustered during creation with the vgcreate --clustered y command. To configure CLVM, the clvmd daemon must run on each cluster node, coordinating LVM operations through DLM locks, while volume groups are activated cluster-wide using commands like vgchange -a y within Pacemaker-managed scripts to ensure synchronized access. For mirrored logical volumes in clustered environments, the cmirrord daemon provides mirrored logging to maintain log consistency across nodes, enabled via the with_cmirrord=true parameter in LVM configuration or Pacemaker resources. This setup supports active/active access models, where multiple nodes can read and write to shared logical volumes simultaneously, provided the underlying storage and locking mechanisms permit it. Failover in CLVM environments is handled by Pacemaker, which monitors node health and automatically migrates or activates volume groups and logical volumes to surviving nodes upon detecting a , such as through mechanisms. This automatic activation ensures minimal , with CLVM's locking preventing conflicts during the transition; for instance, DLM grants exclusive locks for configuration changes and shared locks for concurrent access. CLVM logical volumes are particularly suited for cluster filesystems like or , which can be mounted on shared LVs across nodes to support distributed workloads without single-point access restrictions. Despite these capabilities, CLVM has notable limitations in clustered setups: snapshots are not supported on shared volume groups due to the need for exclusive, single-node access during snapshot creation, which conflicts with distributed locking. All operations require DLM-mediated locks—exclusive for metadata changes and shared for access—potentially introducing latency in large clusters. Additionally, while traditional CLVM uses clvmd, modern implementations favor lvmlockd with DLM or sanlock for enhanced locking on shared storage. As of 2025, CLVM integrates with Container Storage Interface (CSI) drivers, such as those using sanlock for locking, to provision persistent volumes on shared SAN storage for containerized HA applications. In High Availability 15 SP7, LVM supports improved exclusive activation and fencing integration for shared volumes, enhancing lock recovery during node failures in cluster environments.

Management and Implementation

Tools and Commands

The Logical Volume Manager (LVM) in primarily utilizes a suite of command-line tools under the LVM2 project to manage physical volumes (PVs), volume groups (VGs), and logical volumes (LVs). These tools follow a consistent , with commands prefixed by pv for physical volumes, vg for volume groups, and lv for logical volumes. All LVM commands are part of the lvm binary and its derivatives, enabling administrators to initialize, extend, resize, display, and remove storage entities. Physical volume management tools include pvcreate, which initializes a disk or partition as a PV by writing an LVM label; basic syntax is pvcreate [-f] device, where -f forces overwrite if needed. pvdisplay reports detailed attributes of PVs, such as size and free space, using pvdisplay [-v] [device] for verbose output. pvmove relocates data from one PV to another within a VG, with syntax pvmove source destination to balance extents or evacuate a failing device. Volume group tools encompass vgcreate to combine PVs into a VG, invoked as vgcreate VG_name PV_device [PV_device...], allocating metadata on the devices. vgextend adds PVs to an existing VG with vgextend VG_name PV_device, while vgdisplay shows VG properties like total size and allocatable space via vgdisplay [-v] VG_name. For removal, vgremove deletes a VG after evacuating data, using vgremove VG_name. Logical volume tools allow creation and modification of LVs within VGs. lvcreate allocates space for an LV, e.g., lvcreate -L size -n LV_name VG_name for a linear LV of specified size. lvextend resizes an LV online by adding extents, such as lvextend -L +size /dev/VG/LV, often followed by filesystem resize. lvdisplay details LV attributes like type and status with lvdisplay [-v] LV_path, and lvremove deletes an LV after unmounting, using lvremove LV_path. For display and monitoring, summary commands provide concise overviews: pvs lists PV attributes in columns, vgs summarizes VGs, and lvs details LVs, all customizable with options like --units h for human-readable sizes or --separator "," for scripting. Low-level inspection uses dmsetup, part of the device-mapper subsystem, to query tables with dmsetup table device for mapping details underlying LVM devices. The lvconvert utility handles LV type conversions and advanced operations, such as lvconvert --type thin VG/LV to create a thin-provisioned LV or lvconvert --mirrors 2 VG/LV for . It also manages snapshots, raids, and caches by attaching or detaching pools. Cache statistics, such as hit rates, can be queried using lvs with options like -o +cache_used,cache_dirty,cache_read_hits,cache_read_misses. To detach the cache, use lvconvert --splitcache myvg/thinlv; this reverts the LV to its origin without the cache layer. LVM configuration is governed by /etc/lvm/lvm.conf, which sets global parameters like thresholds, locking types (e.g., use_lvmetad = 1 for metadata caching), and metadata backup locations; changes require restarting LVM services. A local override file, /etc/lvm/lvmlocal.conf, allows site-specific adjustments without modifying the main file. As of LVM2 version 2.03.36 (24 October 2025), cache management leverages lvconvert with cache-specific options. LVM integrates with via units such as lvm2-activation-generator.service for boot-time LV and lvm2-monitor.service for event monitoring, ensuring seamless startup and runtime handling in modern distributions.

Allocation Policies

The Logical Volume Manager (LVM) in Linux employs allocation policies to determine how physical extents (PEs) are selected from physical volumes (PVs) within a volume group (VG) when creating or extending logical volumes (LVs). These policies influence the spatial arrangement of data, balancing factors such as performance, fragmentation, and layout preservation. The default policy is typically "normal," but users can specify alternatives to suit specific workloads or hardware characteristics. Key policy types include contiguous, which requires PEs to be adjacent on the same PV, applied independently to each stripe in a striped LV or each mirror image in a mirrored LV; this minimizes seek times but may fail if sufficient contiguous space is unavailable. The normal policy, the standard default, allocates PEs starting from the lowest-numbered free extent while avoiding placement of parallel stripes or mirror legs on the same PV at the same offset to optimize I/O parallelism and reduce contention. Anywhere permits allocation from any available free extents without restrictions, potentially leading to suboptimal layouts like multiple stripes on a single PV but ensuring maximum flexibility when space is fragmented. Inherited defers to the VG's configured default policy or the existing LV's policy during extensions, promoting consistency across operations. Configuration of these policies occurs primarily through the --alloc option in commands such as lvcreate and lvextend for LV-specific settings, or vgcreate and vgchange for VG-wide defaults. VG-level defaults can also be defined in the /etc/lvm/lvm.conf file under the allocation section, allowing system-wide tuning without command-line overrides. When multiple policies are considered during allocation (e.g., via a command specifying a less strict fallback), LVM searches for the next free extent starting from the lowest logical extent number, attempting the strictest policy first (contiguous) and progressing to more permissive ones if needed. These policies directly impact operations involving and distribution: for striping, contiguous ensures aligned extents per stripe for efficiency, while normal spreads stripes across PVs to leverage parallelism; for , policies apply per leg to avoid overlap and enhance . An advanced policy, cling, restricts new allocations to PVs already containing extents of the LV, preserving the original data layout—particularly useful when extending snapshots to minimize overhead by keeping related data localized. In LVM2, allocation policies integrate with hardware optimizations, such as tuning for solid-state drives (SSDs) via the data_alignment parameter in lvm.conf, which aligns extents to boundaries like 1 MB to match SSD erase block sizes and improve I/O throughput. This feature enables automatic detection and adjustment of alignment offsets based on device topology, ensuring efficient data placement without manual intervention.

Basic Setup

A common initial configuration of LVM involves designating a physical disk as a physical volume (PV), grouping it into a volume group (VG), and then creating a logical volume (LV) from the VG for use as a filesystem. For example, to set up LVM on a new disk /dev/sdb, first initialize it as a PV with the command:

pvcreate /dev/sdb

pvcreate /dev/sdb

This labels the entire disk as an LVM PV, making its space available for allocation; note that this destroys any existing on the device. Next, create a VG named myvg using the PV:

vgcreate myvg /dev/sdb

vgcreate myvg /dev/sdb

This aggregates the PV's extents into the VG, allowing flexible allocation across the storage. Then, carve out a 10 GB LV named mylv from the VG:

lvcreate -L 10G -n mylv myvg

lvcreate -L 10G -n mylv myvg

Finally, format the LV with an ext4 filesystem to make it usable:

mkfs.ext4 /dev/myvg/mylv

mkfs.ext4 /dev/myvg/mylv

The resulting device /dev/myvg/mylv can then be mounted for data storage.

Resizing Example

LVM supports dynamic resizing of logical volumes online, without unmounting, provided the underlying filesystem supports it, such as ext4. Assuming additional space has been added to the VG (e.g., via a new PV), extend the mylv LV from 10 GB to 20 GB with:

lvextend -L +10G /dev/myvg/mylv

lvextend -L +10G /dev/myvg/mylv

This increases the LV size by extending its logical extents from the VG's free space. To make the additional space available to the filesystem while mounted, run:

resize2fs /dev/myvg/mylv

resize2fs /dev/myvg/mylv

This command resizes the filesystem online, expanding it to fill the new LV capacity; verification can be done with df -h.

Snapshot Workflow

Snapshots in LVM capture a point-in-time copy of an LV, useful for backups without halting the system. For a LV like /dev/myvg/root, create a 1 GB snapshot named rootsnap with:

lvcreate -L 1G -s -n rootsnap /dev/myvg/root

lvcreate -L 1G -s -n rootsnap /dev/myvg/root

This allocates space for changes (copy-on-write) since the snapshot, keeping the initial image intact. Mount the snapshot read-only at a backup mountpoint, such as /mnt/backup, assuming the LV uses ext4:

mount -o ro /dev/myvg/rootsnap /mnt/backup

mount -o ro /dev/myvg/rootsnap /mnt/backup

Perform the backup, e.g., using rsync or tar to copy files from /mnt/backup. After backup, unmount with umount /mnt/backup. To merge changes back into the origin (e.g., for rollback), deactivate both volumes if possible and run:

lvconvert --merge myvg/rootsnap

lvconvert --merge myvg/rootsnap

This reintegrates the snapshot data into the root LV, removing the snapshot afterward; for active root volumes, the merge defers until reboot.

Thin Pool Example

Thin provisioning allows overcommitting storage via a shared pool, ideal for sparse workloads. First, create a 50 GB thin pool named thinpool in the VG myvg:

lvcreate -L 50G -T myvg/thinpool

lvcreate -L 50G -T myvg/thinpool

This sets up the pool with data and metadata volumes for on-demand allocation. Then, create a thin LV of 100 GB virtual size (but only consuming actual space as used) named thinlv from the pool:

lvcreate -V 100G -T myvg/thinpool -n thinlv

lvcreate -V 100G -T myvg/thinpool -n thinlv

The thin LV /dev/myvg/thinlv appears as 100 GB but allocates physical extents lazily from the 50 GB pool.

LVM on NVMe with Cache

LVM integrates device-mapper cache (dm-cache) with to optimize hybrid storage setups, using fast NVMe devices as a cache layer atop slower storage for improved I/O . For example, create a 10 GB cache pool on an NVMe device /dev/nvme0n1 in myvg:

lvcreate --type cache-pool -L 10G -n cachepool myvg /dev/nvme0n1

lvcreate --type cache-pool -L 10G -n cachepool myvg /dev/nvme0n1

Then, attach it to an existing thin-provisioned LV like thinlv for caching:

lvconvert --type cache --cachepool myvg/cachepool myvg/thinlv

lvconvert --type cache --cachepool myvg/cachepool myvg/thinlv

This configuration caches hot data on NVMe while backing with thin-provisioned storage, verified via lvs -o +cache_percent.

Limitations

Caveats

LVM snapshots employ a (COW) mechanism, where changes to the origin are stored in the snapshot's allocated space; if the changes exceed this space and the snapshot becomes full, the snapshot becomes invalid, while the origin remains intact but further writes to it will fail until the snapshot is removed or resized. Traditional COW snapshots are not supported within clustered volume groups, as the locking mechanisms required for cluster-wide consistency are incompatible with snapshot operations. Resizing logical volumes carries significant risks, particularly when shrinking; attempting to reduce an LV without first adjusting the underlying filesystem to fit within the new boundaries will result in , as the filesystem may still blocks beyond the reduced LV extent. Resizing the root LV can also disrupt the boot process, as changes to its layout may invalidate the configuration or initramfs, necessitating manual reconfiguration of GRUB or equivalent to restore bootability. LVM metadata, stored in headers on physical volumes and within the volume group area, represents a potential ; if all PV headers become corrupted—due to disk failure, power loss, or media errors—the entire volume group may become inaccessible, rendering all contained logical volumes unusable. To mitigate this, regular backups of metadata using the vgcfgbackup command are strongly recommended, as these allow restoration via vgcfgrestore to recover the configuration in case of corruption. Compatibility issues persist with legacy LVM versions; LVM1, the original implementation, has been obsolete since approximately 2010, with no support in modern kernels or tools, leading to activation failures if encountered on upgraded systems. Version mismatches between LVM user-space tools (e.g., lvm2 package) and the kernel's device-mapper module can cause commands to fail or produce inconsistent results, requiring alignment of versions across the stack. Additionally, deploying LVM on loop devices—such as file-backed block devices—is discouraged for production use, as it incurs substantial overhead in I/O translation and resource consumption, leading to unreliable behavior under load.

Performance Considerations

The Logical Volume Manager (LVM) introduces performance overhead primarily through the indirection layer provided by the kernel's device-mapper subsystem, which handles mapping logical blocks to physical extents. This can result in a modest reduction in IOPS, typically around 1-5% for sequential workloads on linear volumes, due to the additional lookups required for extent mapping. In more complex scenarios involving random I/O or multiple volumes, overhead may increase to 15-45% as reported in benchmarks using filesystems and workloads, attributed to metadata access patterns. Tuning LVM configurations can mitigate much of this overhead. Selecting a larger physical extent (PE) size, such as 16 MiB or more for volumes exceeding several terabytes, reduces the total number of extents and associated metadata, thereby lowering lookup times and improving overall efficiency. For SSD-based storage, ensuring alignment to 1 MiB boundaries—achieved by default in modern LVM tools via the --dataalignment parameter—optimizes write amplification and sustains higher IOPS by aligning with flash erase block sizes. Benchmarks comparing LVM striping (RAID0) to mdadm RAID0 show similar throughput performance, with mdadm offering a slight edge (up to 5-10% higher) for small block sizes due to more direct kernel integration, while LVM provides comparable results for larger I/O patterns exceeding 64 KiB. LVM caching, using faster devices like SSDs as a front-end layer, significantly enhances random read performance; in writeback mode, it can deliver up to 10-fold improvements for workloads with high cache hit rates, such as database queries accessing frequently used data blocks. When compared to direct partitioning, linear LVM volumes exhibit minimal performance differences, often under 3% in sequential read/write throughput, as the mapping layer adds negligible latency for straightforward access patterns. However, features like snapshots introduce higher overhead, with traditional COW snapshots reducing by 3-6 times due to copy-on-write operations and increased metadata contention during concurrent writes.

References

Add your contribution
Related Hubs
User Avatar
No comments yet.