LVM - Logical Volume Manager
LVM
LVM adds a flexible layer between physical disks and filesystems so you can resize storage live.
Physical Volume (PV) → Volume Group (VG) → Logical Volume (LV) → filesystem
/dev/sdb1 vg_data lv_web
| Layer | Create | Inspect |
|---|---|---|
| PV | pvcreate /dev/sdb1 | pvs / pvdisplay |
| VG | vgcreate vg_data /dev/sdb1 | vgs / vgdisplay |
| LV | lvcreate -L 10G -n lv_web vg_data | lvs / lvdisplay |
Grow a volume (the killer feature):
$ lvextend -L +5G /dev/vg_data/lv_web
$ resize2fs /dev/vg_data/lv_web # ext4 - grow the FS
# xfs_growfs /data # xfs equivalent (mounted)
Exam tip: Extending is two steps - grow the LV (lvextend) then grow the filesystem (resize2fsfor ext4,xfs_growfsfor xfs). xfs can only grow, never shrink.