Chapter Objective: Create and manage physical volumes, volume groups, and logical volumes with LVM, resize a logical volume's filesystem, and create an LVM snapshot.
Key commands: pvcreate, vgcreate, lvcreate, lvextend, lvreduce
Why LVM?
Chapter 10 covered partitioning a disk directly — simple, but rigid: a partition's size is fixed at creation, and it's tied to one specific disk. LVM (Logical Volume Manager) adds a flexible layer between raw storage and filesystems, letting you resize volumes, span multiple disks, and take snapshots without the constraints of traditional partitioning.
LVM Building Blocks
| Layer | Abbreviation | Role |
|---|---|---|
| Physical Volume | PV | A disk or partition initialized for LVM use |
| Volume Group | VG | A pool of storage combining one or more PVs |
| Logical Volume | LV | A resizable "virtual partition" carved out of a VG's pool |
Creating a Logical Volume, Start to Finish
# 1. Initialize a partition (or whole disk) as a physical volume
sudo pvcreate /dev/sdb1
# 2. Create a volume group from one or more physical volumes
sudo vgcreate data_vg /dev/sdb1
# 3. Create a logical volume from the volume group's pool
sudo lvcreate -n data_lv -L 10G data_vg
# 4. Create a filesystem on the new logical volume
sudo mkfs.xfs /dev/data_vg/data_lv
# 5. Mount it, ideally added to /etc/fstab for persistence (see Chapter 10)
sudo mkdir -p /data
sudo mount /dev/data_vg/data_lv /data
Growing a Logical Volume
# Add more space to the volume group first, if needed
sudo pvcreate /dev/sdc1
sudo vgextend data_vg /dev/sdc1
# Grow the logical volume by a specific amount
sudo lvextend -L +5G /dev/data_vg/data_lv
# Or grow it to use ALL remaining free space in the VG
sudo lvextend -l +100%FREE /dev/data_vg/data_lv
# Grow the FILESYSTEM to match the larger logical volume (XFS)
sudo xfs_growfs /data
# Equivalent for ext4
sudo resize2fs /dev/data_vg/data_lv
lvextend only resizes the logical volume itself. Without a follow-up xfs_growfs or resize2fs, the extra space exists at the LVM level but the filesystem on top still reports its old, smaller size.
lvextend -r -L +5G /dev/data_vg/data_lv resizes the logical volume AND its filesystem in a single command, when the filesystem type supports online resize (XFS and ext4 both do).
Shrinking a Logical Volume
Shrinking is riskier and more involved than growing — the filesystem must be shrunk first, and only then the logical volume, or data can be lost.
# ext4 example — XFS cannot be shrunk at all (recall Chapter 10)
sudo umount /data
sudo e2fsck -f /dev/data_vg/data_lv
sudo resize2fs /dev/data_vg/data_lv 8G
sudo lvreduce -L 8G /dev/data_vg/data_lv
sudo mount /data
Snapshots
An LVM snapshot captures a point-in-time view of a logical volume, useful for taking a consistent backup or testing a risky change with an easy rollback point.
# Create a snapshot of an existing logical volume
sudo lvcreate -s -n data_lv_snap -L 2G /dev/data_vg/data_lv
# Mount the snapshot to browse or back it up separately
sudo mkdir -p /mnt/snap
sudo mount /dev/data_vg/data_lv_snap /mnt/snap
# Remove the snapshot once it's no longer needed
sudo umount /mnt/snap
sudo lvremove /dev/data_vg/data_lv_snap
Viewing LVM Status
# Summary views
pvs
vgs
lvs
# Detailed views
pvdisplay
vgdisplay
lvdisplay
pvs, vgs, lvs) give a quick one-line-per-item summary, good for a fast overview. The display variants give full detail on each item — reach for those when you need specifics like extent size or UUID.
Key Terms for Chapter 11
- Physical Volume (PV)
- A disk or partition initialized for use by LVM
- Volume Group (VG)
- A pool of storage space combining one or more physical volumes
- Logical Volume (LV)
- A resizable volume carved out of a volume group's pooled space
- lvextend
- Grows a logical volume's size within its volume group
- lvreduce
- Shrinks a logical volume's size, only safe after the filesystem is shrunk first
- snapshot
- A point-in-time, changes-only view of a logical volume
Review Questions
- What advantage does LVM offer over plain disk partitioning when a volume needs more space later?
- Put physical volume, volume group, and logical volume in the correct order from "raw disk" to "resizable storage unit."
- After running
lvextendto grow a logical volume, why mightdf -hstill show the old, smaller size? - Write the two commands needed to grow
/dev/data_vg/data_lvby 5G and immediately grow its XFS filesystem to match. - Why must a filesystem be shrunk BEFORE the logical volume it lives on, never after?
- Why can't an XFS-formatted logical volume be shrunk, regardless of the LVM commands used?
- Is an LVM snapshot on its own a sufficient backup strategy? Why or why not?