LVM and growth
Understand LVM layers
Follow storage through physical volumes, volume groups, logical volumes, filesystems, and mount points.
8 minute lesson
LVM creates a flexible allocation layer between block devices and filesystems.
Without it, a filesystem is welded to its partition. Resizing means repartitioning, and one filesystem can’t span two disks. LVM solves this by pooling storage and handing it out in adjustable pieces.
The three layers
- A physical volume (PV) is a block device handed over to LVM. It contributes extents, fixed-size chunks (4 MiB by default), to a pool.
- A volume group (VG) is that pool. It can contain several physical volumes.
- A logical volume (LV) allocates extents from the pool and behaves like a normal block device. It normally holds a filesystem.
One inspection command per layer:
sudo pvs
# PV VG Fmt Attr PSize PFree
# /dev/sda3 vg0 lvm2 a-- <199.00g 49.00g
sudo vgs
# VG #PV #LV #SN Attr VSize VFree
# vg0 1 2 0 wz--n- <199.00g 49.00g
sudo lvs
# LV VG Attr LSize Pool Origin Data%
# root vg0 -wi-ao---- 50.00g
# data vg0 -wi-ao---- 100.00g
pvs shows each device and how much of it is unallocated (PFree). vgs sums the pool: VFree is what’s left for new or growing volumes. lvs lists the volumes carved out of it; the o in Attr means the volume is open, so something (a filesystem) is using it.
Match a path to its layers
Take a mounted directory and walk down:
findmnt /srv/data
# TARGET SOURCE FSTYPE OPTIONS
# /srv/data /dev/mapper/vg0-data ext4 rw,relatime
The source /dev/mapper/vg0-data names the volume group and logical volume. lsblk shows the same relationship as a tree, from sda3 up through vg0-data.
One thing to internalize now, because the next lesson depends on it: growing the logical volume and growing the filesystem are separate operations. lvs can report 150 GB while df still reports 100 GB, because the filesystem hasn’t been told about the new space yet. Each layer only knows its own size.
Run pvs, vgs, and lvs on a system using LVM. Match one mounted path to its logical volume, volume group, and physical volume.
Lesson completed