LVM (Logical Volume Manager)

Definition

LVM (Logical Volume Manager) is a device mapper framework that provides logical volume management on Linux. It abstracts physical disks into logical volumes, enabling flexible storage management including resizing, snapshots, and striping without downtime.

LVM sits between the physical disks and the filesystem, adding a layer of abstraction that makes storage management more flexible than raw partitions.

LVM Architecture

Physical Disks (PVs)
    ↓
Volume Group (VG) — pool of physical extents
    ↓
Logical Volumes (LVs) — carved from VG
    ↓
Filesystems (ext4, XFS, Btrfs)
Component Description
PV (Physical Volume) A physical disk or partition
VG (Volume Group) Pool of PVs combined together
LV (Logical Volume) Virtual partition carved from VG
PE (Physical Extent) Smallest unit of storage on a PV (typically 4MB)
LE (Logical Extent) Smallest unit of storage on an LV

LVM Operations

Operation Command Description
Create PV pvcreate /dev/sdb Initialize disk as PV
Create VG vgcreate vg0 /dev/sdb /dev/sdc Combine PVs into VG
Create LV lvcreate -L 100G -n lv0 vg0 Create 100G LV from VG
Format mkfs.ext4 /dev/vg0/lv0 Create filesystem on LV
Extend LV lvextend -L +50G /dev/vg0/lv0 Add space to LV
Shrink LV lvreduce -L -50G /dev/vg0/lv0 Remove space from LV
Snapshot lvcreate -s -L 10G -n snap vg0/lv0 Create point-in-time copy
Remove LV lvremove /dev/vg0/lv0 Delete LV
Remove VG vgremove vg0 Delete volume group
Remove PV pvremove /dev/sdb Remove physical volume

LVM vs Traditional Partitions

Feature LVM Traditional Partitions
Resize online Yes No (usually)
Span multiple disks Yes No
Snapshots Yes No
Flexibility High Low
Complexity Moderate Simple
Performance Slight overhead Direct

LVM Snapshots

LVM snapshots create a point-in-time copy of a logical volume:

  • Copy-on-write: Original data is saved before modification
  • Thin provisioning: Snapshots start small and grow as data changes
  • Use case: Backups, testing, disaster recovery
  • Limitation: Snapshot must be large enough to hold changes
  • Raid — alternative to LVM with built-in RAID and snapshots
  • Btrfs — Linux filesystem with LVM-like features
  • Disk — physical storage devices managed by LVM
  • Filesystem — ext4, XFS on top of LVM logical volumes

References