Logical Volume Manager
LVM layer management — physical volumes, volume groups, logical volumes, snapshots, and online resizing.
Physical Volumes
Show all physical volumes — quick inventory of PV-level storage
sudo pvs
Detailed PV info including PE size, free extents, and UUID
sudo pvdisplay /dev/sda2
Initialize a disk or partition as an LVM physical volume
sudo pvcreate /dev/sdb1
Move all extents off a PV before removing it — online data migration
sudo pvmove /dev/sdb1
Remove PV label after pvmove — allows disk removal or repurposing
sudo pvremove /dev/sdb1
Volume Groups
Show all volume groups — name, PV count, LV count, size, free
sudo vgs
Create a volume group from one or more physical volumes
sudo vgcreate vg_data /dev/sdb1
Extend a VG by adding a new physical volume — online capacity expansion
sudo vgextend vg_data /dev/sdc1
Remove a PV from a VG after pvmove — shrink the VG
sudo vgreduce vg_data /dev/sdb1
Logical Volumes
Show all logical volumes — name, VG, size, attributes
sudo lvs
Detailed LV info including segments, stripes, and allocation policy
sudo lvdisplay /dev/vg_data/lv_home
Create a 20G logical volume in a volume group
sudo lvcreate -L 20G -n lv_home vg_data
Create an LV using 100% of remaining free space — use all of it
sudo lvcreate -l 100%FREE -n lv_data vg_data
Extending and Resizing
Extend an LV by 10G and resize the filesystem in one step — ext4/xfs
sudo lvextend -L +10G --resizefs /dev/vg_data/lv_home
Extend to fill all free space in the VG and grow filesystem
sudo lvextend -l +100%FREE --resizefs /dev/vg_data/lv_home
Resize ext4 filesystem manually after lvextend (if --resizefs was omitted)
sudo resize2fs /dev/vg_data/lv_home
Grow XFS filesystem manually — xfs only grows, never shrinks
sudo xfs_growfs /mnt/data
Reducing (Dangerous)
Reduce an ext4 LV — UNMOUNT FIRST, e2fsck required, data loss risk
sudo umount /mnt/home
sudo e2fsck -f /dev/vg_data/lv_home
sudo resize2fs /dev/vg_data/lv_home 15G
sudo lvreduce -L 15G /dev/vg_data/lv_home
sudo mount /dev/vg_data/lv_home /mnt/home
XFS cannot be reduced. Btrfs can shrink but requires btrfs filesystem resize. Always back up before reducing.
|
Snapshots
Create a snapshot of an LV — COW, size is for changed blocks only
sudo lvcreate -s -L 5G -n lv_home_snap /dev/vg_data/lv_home
Mount a snapshot read-only for backup or inspection
sudo mount -o ro /dev/vg_data/lv_home_snap /mnt/snap
Remove a snapshot after backup — frees COW space
sudo lvremove /dev/vg_data/lv_home_snap
Check snapshot usage — if it fills 100% the snapshot is invalid
sudo lvs -o lv_name,data_percent,origin
Thin Provisioning
Create a thin pool — overcommit storage, allocate on write
sudo lvcreate -L 50G --thinpool thin_pool vg_data
Create a thin LV from the pool — virtual size can exceed pool
sudo lvcreate -V 100G --thin -n thin_vol vg_data/thin_pool
Monitor thin pool usage — critical to avoid overcommit exhaustion
sudo lvs -o lv_name,lv_size,data_percent,metadata_percent vg_data/thin_pool
RHCSA Patterns
Full workflow — disk to mounted filesystem (exam pattern)
sudo pvcreate /dev/sdb1
sudo vgcreate vg_exam /dev/sdb1
sudo lvcreate -L 500M -n lv_exam vg_exam
sudo mkfs.ext4 /dev/vg_exam/lv_exam
sudo mkdir -p /mnt/exam
sudo mount /dev/vg_exam/lv_exam /mnt/exam
echo '/dev/vg_exam/lv_exam /mnt/exam ext4 defaults 0 2' | sudo tee -a /etc/fstab
Verify LVM state end-to-end — confirm PV, VG, LV, and mount
sudo pvs && sudo vgs && sudo lvs && df -h /mnt/exam