Quick Summary: LVM (Logical Volume Manager) is a Linux storage abstraction layer that sits between physical disks and filesystems. It allows you to resize partitions on-the-fly, span volumes across multiple disks, create instant snapshots for backups, and migrate data between disks without downtime. LVM is essential knowledge for any Linux administrator managing server storage.
What Is LVM?
Traditional disk partitioning is rigid — once you create a partition, resizing it requires unmounting, repartitioning, and risking data loss. LVM adds a flexible layer that lets you manage storage dynamically. Think of it as a pool of storage that you can carve up and resize at will.
LVM Architecture
| Layer | Component | Description |
|---|---|---|
| Bottom | Physical Volume (PV) | Physical disk or partition (/dev/sda1, /dev/sdb) |
| Middle | Volume Group (VG) | Pool combining one or more PVs |
| Top | Logical Volume (LV) | Virtual partitions created from VG space |
Essential LVM Commands
Physical Volume Operations
pvcreate /dev/sdb— Initialize a disk as a physical volumepvs— List physical volumes (short format)pvdisplay— Detailed PV information
Volume Group Operations
vgcreate data_vg /dev/sdb /dev/sdc— Create VG from two disksvgextend data_vg /dev/sdd— Add a disk to existing VGvgs— List volume groups
Logical Volume Operations
lvcreate -L 50G -n web_data data_vg— Create 50GB logical volumelvcreate -l 100%FREE -n backups data_vg— Use all remaining spacelvextend -L +20G /dev/data_vg/web_data— Extend by 20GBresize2fs /dev/data_vg/web_data— Resize the filesystem to matchlvs— List logical volumes
Resizing Volumes (Live)
- Check available space:
vgs(look at VFree column) - Extend the logical volume:
lvextend -L +10G /dev/vg/lv - Resize the filesystem:
resize2fs /dev/vg/lv(ext4) orxfs_growfs /mount(XFS) - Verify:
df -h
Key point: ext4 and XFS can be grown online (while mounted). Only ext4 can be shrunk, and shrinking requires unmounting first.
LVM Snapshots
Snapshots create an instant point-in-time copy of a logical volume — perfect for backups:
- Create:
lvcreate -L 5G -s -n snap_web /dev/data_vg/web_data - Mount:
mount /dev/data_vg/snap_web /mnt/snapshot - Backup from snapshot, then remove:
lvremove /dev/data_vg/snap_web
LVM vs Traditional Partitioning
| Feature | LVM | Traditional Partitions |
|---|---|---|
| Online resize | Yes (grow), ext4 (shrink offline) | No (requires unmount) |
| Span multiple disks | Yes | No |
| Snapshots | Yes | No |
| Disk migration | Online (pvmove) | Offline only |
| Complexity | Medium | Simple |
| Performance overhead | Minimal | None |
Frequently Asked Questions
Does LVM affect performance?
LVM adds negligible overhead (typically less than 1%). The benefits of flexible storage management far outweigh any minor performance impact. For maximum performance, use LVM striping across multiple disks.
Can I add more disk space without downtime?
Yes, this is LVM's primary advantage. Add a new physical disk to the volume group, then extend the logical volume and filesystem — all while the system is running and the filesystem is mounted.
Should I use LVM on all servers?
Yes, for production servers LVM is strongly recommended. Most modern Linux installers offer LVM as the default partitioning scheme. The flexibility to resize volumes without downtime is invaluable when disk space needs change over time.