LVM2
LVM2 is the Linux Logical Volume Manager that provides enterprise-level volume management by grouping disks into volume groups and allocating space to logical volumes accessed as regular block devices.
Description
LVM2 is a rewrite of the Linux Logical Volume Manager, enabling advanced storage management. It groups arbitrary disks into volume groups (VGs), from which logical volumes (LVs) can be created and accessed like standard block devices. This supports flexible resizing, snapshots, striping, mirroring, thin provisioning, caching, and RAID configurations.
The suite includes comprehensive tools for managing physical volumes (PVs), volume groups, and logical volumes, plus device-mapper utilities for low-level operations. Key use cases include dynamic storage allocation, data redundancy through mirroring/RAID, efficient space utilization via thin provisioning, and performance optimization with caching. It's essential for server environments requiring scalable, resilient storage.
LVM2 integrates with the Linux Kernel Device Mapper, keeping device layout knowledge in user-space while handling volume management in kernel-space. This architecture supports not only LVM but also software RAID and other virtual block device drivers.
How It Works
LVM2 uses the Linux Kernel Device Mapper (dm) as its foundation—a minimalistic kernel-space driver for volume management. Device layout and metadata are managed in user-space, providing flexibility. Disks are initialized as Physical Volumes (PVs) with LVM labels and metadata. PVs are grouped into Volume Groups (VGs), which serve as a pool of storage. Logical Volumes (LVs) are carved from VGs and presented as block devices (/dev/mapper/VG-LV).
Advanced features like thin provisioning use thin-pools for overprovisioning, caching attaches fast devices to slow ones via cache-pools, and RAID/mirroring distribute data across PVs for redundancy/performance. The dmeventd daemon monitors device-mapper events, while lvmlockd handles shared storage locking. Tools interact via libdevmapper and liblvm2 libraries, using ioctl calls to manipulate kernel mappings.
Installation
sudo apt install lvm2Flags
Examples
pvcreate /dev/sdb /dev/sdcvgcreate datavg /dev/sdb /dev/sdclvcreate -L 50G -n evidence datavglvcreate -l 100%FREE -n data datavglvdisplay /dev/datavg/evidencevgdisplay -vlvextend -L +20G /dev/datavg/evidence && resize2fs /dev/datavg/evidencedmsetup ls --tree