RH134 Ch 6: LVM — Flexible Storage

Logical Volume Manager puts a layer between disks and file systems so space can be pooled and resized without repartitioning.

Building blocks. A physical volume (PV) is a disk or partition prepared for LVM. PVs are pooled into a volume group (VG), which is divided into fixed-size physical extents (4 MiB by default). Logical volumes (LVs) are carved from the VG and carry the file systems.

bash pvcreate /dev/vdc vgcreate vgdata /dev/vdc vgcreate -s 8M … sets the extent size lvcreate -L 1G -n lvreports vgdata by size lvcreate -l 50 -n lvbuild vgdev by extents (-l 100%FREE for all) mkfs.xfs /dev/vgdata/lvreports

pvs, vgs and lvs give summaries; pvdisplay, vgdisplay and lvdisplay give detail (extent size, free extents). An LV is reachable as /dev/vg/lv and /dev/mapper/vg-lv; mount it in fstab by UUID like any file system.

Growing. Add space to the VG with vgextend vgdata /dev/vdd (after pvcreate), then grow the LV and its file system in one step:

bash lvextend -r -L 3G /dev/vgapp/lvlogs or -L +1G, or -l +100%FREE

Without -r you must run xfsgrowfs /mountpoint (XFS) or resize2fs /dev/vg/lv (ext4) yourself. XFS cannot shrink.

Swap on LVM. lvcreate -L 512M -n lvswap vgapp, mkswap, an fstab swap line and swapon -a.

Removing. Unmount, delete the fstab line, then lvremove vg/lv. To take a disk out of a VG: pvmove /dev/vdd to migrate extents, vgreduce vg /dev/vdd, pvremove /dev/vdd.

Common exam mistakes - Extending the LV but not the file system (df still shows the old size). - Getting the size wrong when the task gives extents: multiply by the VG's extent size. - Leaving a stale fstab line after removing an LV — the next boot drops to emergency mode.