LVM — the Logical Volume Manager — puts a layer of indirection between your disks and your filesystems. Instead of "this partition is this disk", you get pooled storage you can resize while it is in use. It is the reason server admins shrug at "we need more space on /var".
The three-layer model #
$ sudo pvcreate /dev/sdb /dev/sdc # physical volumes
$ sudo vgcreate tank /dev/sdb /dev/sdc # volume group: the pool
$ sudo lvcreate -n projects -L 500G tank # logical volume: a slice
$ sudo mkfs.ext4 /dev/tank/projects
$ sudo mount /dev/tank/projects /projects
Physical volumes are the raw disks or partitions. The volume group pools them — two 1 TB disks become 2 TB of tank. Logical volumes are carved out of the pool and hold filesystems, and they can span physical disks, which partitions cannot.
The resize superpower #
Grow a volume and its filesystem live, in three measured steps:
$ sudo lvextend -L +200G /dev/tank/projects
$ sudo resize2fs /dev/tank/projects # ext4 grows while mounted
Modern systems fold that into one command (lvextend -r), which also shrinks carefully — shrink the filesystem first, then the volume, never the reverse.
Surveying what you have #
| Command | Shows |
|---|---|
pvs / vgs / lvs | One-line summaries of each layer |
pvdisplay | Full physical volume detail |
vgdisplay | Pool size and free space |
lvs -a | Volumes, including snapshots |
Snapshots are LVM's quiet gift — a frozen view of a volume that costs only the changed blocks:
$ sudo lvcreate -s -n projects-snap -L 20G /dev/tank/projects
$ # ...experiment...
$ sudo lvremove /dev/tank/projects-snap
The volume a filesystem lives on still needs choosing — see ext4 vs btrfs — and mounting belongs to mount and fstab. More in the terminal notes.
