LVM Logical Volume Management: Create, Grow, and Snapshot
Manage disks with the PV/VG/LV model to resize volumes live and snapshot for backups — far more flexible than plain partitions.
Once you carve up a disk with traditional partitions, resizing it usually means unmounting, repartitioning, or even reinstalling. LVM (Logical Volume Manager) inserts a layer between your disks and your filesystems, letting you grow volumes without downtime, pool space across drives, and snapshot data on the fly. For any data disk you expect to maintain over time, it's the approach worth defaulting to.
The Three Building Blocks
LVM has three layers, from the bottom up:
- PV (Physical Volume) — a raw disk or partition handed over to LVM, such as /dev/vdb. This is where capacity comes from.
- VG (Volume Group) — a storage pool built from one or more PVs. Capacity is aggregated here.
- LV (Logical Volume) — a virtual partition carved out of a VG. This is what you actually format and mount.
In short: PVs supply space, the VG pools it, and LVs hand it out.
Building LVM From a Bare Disk
Say you've just attached an empty disk, /dev/vdb. Confirm the device name with lsblk, then run:
# 1. Turn the raw disk into a physical volume (no partitioning needed)
sudo pvcreate /dev/vdb
# 2. Create a volume group named data_vg from the PV
sudo vgcreate data_vg /dev/vdb
# 3. Carve a logical volume: fixed size, or use all free space
sudo lvcreate -L 20G -n data_lv data_vg
# sudo lvcreate -l 100%FREE -n data_lv data_vg
The logical volume shows up at /dev/datavg/datalv. Format and mount it:
sudo mkfs.ext4 /dev/data_vg/data_lv
sudo mkdir -p /mnt/data
sudo mount /dev/data_vg/data_lv /mnt/data
# Add it to fstab so it mounts on boot
echo '/dev/data_vg/data_lv /mnt/data ext4 defaults 0 2' | sudo tee -a /etc/fstab
Run pvs, vgs, and lvs any time to inspect usage at each layer.
Growing a Volume Online
This is LVM's most useful trick: adding capacity while the workload keeps running. If the VG still has free space, just extend the LV. If it's out of room, add a fresh disk to the group first:
# When the VG is full, add another disk
sudo pvcreate /dev/vdc
sudo vgextend data_vg /dev/vdc
# Extend the LV; -r grows the filesystem to match in one step
sudo lvextend -r -L +10G /dev/data_vg/data_lv
# Or claim everything that's free:
sudo lvextend -r -l +100%FREE /dev/data_vg/data_lv
The -r flag (--resizefs) calls resize2fs or xfsgrowfs for you; both ext4 and xfs grow online. Note the limits: xfs can only grow, never shrink; ext4 can shrink, but only while unmounted.
Snapshots: Backup and Rollback
A snapshot uses copy-on-write (COW) to track changes against the origin, giving you a frozen point-in-time view — ideal right before a backup or a risky upgrade:
# Create a snapshot; -s means snapshot, -L 5G reserves room for changes
sudo lvcreate -s -L 5G -n data_snap /dev/data_vg/data_lv
# Mount the snapshot for a consistent backup (rsync/tar)
sudo mount /dev/data_vg/data_snap /mnt/snap
If an upgrade goes wrong, roll back by merging the snapshot into the origin (unmount first; it applies after the next remount or reboot):
sudo umount /mnt/data
sudo lvconvert --merge /dev/data_vg/data_snap
Things to Watch
- A snapshot only holds changed blocks. If it fills up, it becomes invalid — keep an eye on Snap% in lvs.
- Snapshots slow writes to the origin. Treat them as temporary; lvremove them once you're done.
- A snapshot lives in the same VG as its origin. It is not an off-site backup and never replaces one.
Summary
LVM decouples the physical disk from the partition you actually use. Its PV/VG/LV layers let you add disks, grow filesystems live, and snapshot for backups and rollbacks. Compared with plain partitions — set once and stuck — LVM costs you a few extra commands and repays you with real operational flexibility. For data disks, make it your default.