Chapter 18: Logical volume management

LVM cheat sheet

The chapter on one page: what to remember, the commands to have at your fingertips, and flashcards for quick revision.

The chapter in eight sentences

Cheat sheet

Create and inspect

CommandDoes
pvcreate DEV · pvs · pvdisplayPhysical volumes
vgcreate [-s 8M] VG DEV… · vgs · vgdisplayVolume groups
lvcreate -n LV -L 1G VG · lvs · lvdisplayLogical volumes
lvs -o +devices,lv_pathWhere each LV lives
mkfs.xfs /dev/VG/LV · mountFile system and mount

Resize and move

CommandDoes
vgextend VG PVAdd a PV to a group
lvextend -r -L +512M LV · -l +100%FREEGrow LV and file system
xfs_growfs DIR · resize2fs DEVGrow only the file system
lvreduce -r -L 200M LVShrink ext4 (unmounted)
pvmove OLD [NEW]Move extents between PVs
vgreduce VG PV · pvremove PVRetire a disk

Maintain and repair

CommandDoes
lvrename VG old new · lvremove VG/LVRename, remove
vgremove VG · pvremove PVRemove group, PV
lvchange -ay VG/LV · vgchange -ay VGActivate
lvmdevices · pvs -a · pvscanWhich devices LVM sees
vgcfgbackup VG · /etc/lvm/backupLayout backup
fstab/dev/VG/LV /dir xfs defaults 0 0 · swap: /dev/VG/LV none swap defaults 0 0

Flashcards

LVM layers?
Disk/partition → PV → VG → LV → file system (or swap).
Show them?
pvs · vgs · lvs · lsblk -f · pvdisplay · vgdisplay · lvdisplay
Build in five commands?
pvcreate · vgcreate · lvcreate -n NAME -L SIZE VG · mkfs.xfs /dev/VG/LV · mount
Size options of lvcreate/lvextend?
-L 1G (size, +1G adds) · -l 50%FREE or +100%FREE (extents/percent)
Grow an LV and its file system?
lvextend -r -L +512M /dev/VG/LV (xfs_growfs / resize2fs inside)
Add a disk to a group?
pvcreate /dev/sdc1 · vgextend VG /dev/sdc1
Shrink?
ext4 only: lvreduce -r -L SIZE LV (unmounted). XFS cannot shrink.
Replace a disk online?
vgextend (new) · pvmove OLD NEW · vgreduce VG OLD · pvremove OLD
Rename, remove?
lvrename VG old new · lvremove VG/LV · vgremove VG · pvremove PV
fstab for an LV?
/dev/VG/LV /mnt xfs defaults 0 0 (update after lvrename)
LV does not exist for mount?
lvchange -ay VG/LV (check the a flag in lvs)
Layout backups?
vgcfgbackup · /etc/lvm/backup · vgcfgrestore; data needs its own backup