Prerequisites
- A Linux VM with a spare, unused disk (or the ability to attach one — a second virtual disk in VirtualBox/VMware/cloud console works fine)
- Root access
- lvm2 package installed (preinstalled on most server distros)
What You'll Learn
- Create physical volumes, volume groups, and logical volumes from raw block devices
- Extend a mounted logical volume and its filesystem live, without unmounting
- Explain the PV → VG → LV relationship and why LVM decouples storage from partitions
- Recognize the recovery options when a volume group loses a physical volume
Theory
Traditional partitioning ties a filesystem directly to a fixed-size slice of one physical disk — growing it later means the free space has to be physically adjacent, and spanning multiple disks isn't possible at all. LVM inserts an abstraction layer with three levels:
| Layer | What it is |
|---|---|
| Physical Volume (PV) | A raw disk or partition, initialized for LVM to use |
| Volume Group (VG) | A storage pool combining one or more PVs into a single space |
| Logical Volume (LV) | A virtual "partition" carved from a VG, formatted with a filesystem |
Because an LV draws from the VG's pooled space rather than a fixed disk region, you can grow an LV by simply adding more PVs to its VG — the filesystem doesn't need to know or care which physical disk the extra space actually came from.
Architecture
Two physical disks pooled into one volume group, carved into two independently-sized logical volumes
Hands-On Lab
Assumes a spare disk attached as /dev/sdb — confirm with lsblk first and substitute the real device name.
# 1. Create the physical volume
sudo pvcreate /dev/sdb
sudo pvs # confirm it's recognized
# 2. Create a volume group from it
sudo vgcreate vg_data /dev/sdb
sudo vgs
# 3. Create a 5G logical volume inside the volume group
sudo lvcreate -L 5G -n lv_web vg_data
sudo lvs
# 4. Format and mount it
sudo mkfs.ext4 /dev/vg_data/lv_web
sudo mkdir -p /mnt/web
sudo mount /dev/vg_data/lv_web /mnt/web
df -h /mnt/web
# 5. Extend it live — grow the LV by 2G, then grow the filesystem to match
sudo lvextend -L +2G /dev/vg_data/lv_web
sudo resize2fs /dev/vg_data/lv_web # ext4; use 'sudo xfs_growfs /mnt/web' for XFS
df -h /mnt/web # confirm the new size is visible, still mountedBest Practices
Leave free space in the volume group
Don't allocate 100% of a VG's capacity to LVs immediately — keeping some free PE (physical extents) unallocated lets you extend an LV instantly later without adding a new disk.Snapshot before risky changes
lvcreate -L 1G -s -n lv_web_snap /dev/vg_data/lv_web creates a point-in-time snapshot you can roll back to — take one before a risky in-place upgrade or migration.Common Mistakes
Extending the LV but forgetting to grow the filesystem
lvextend resizes the block device, not the filesystem sitting on it — the extra space is invisible to df until you also run resize2fs (ext4) or xfs_growfs (XFS, note: takes a mount point, not a device path).Trying to shrink an XFS filesystem
XFS supports growing but has no shrink operation at all — if you need a smaller filesystem, the only path is backup → recreate smaller → restore. Plan XFS logical volume sizes conservatively for this reason; ext4 does support shrinking (offline, unmounted).Troubleshooting
"Insufficient free extents" on lvextend: the volume group itself is out of free space — check with vgs (the VFree column) and either add another physical volume with vgextend or free space from another LV first.
A physical volume fails/disappears from a VG: if the VG has no redundancy (a single PV, or PVs without an LVM RAID setup), data on that PV is lost — LVM alone provides no redundancy by default. vgreduce --removemissing vg_datacan bring the VG back online minus the failed PV's extents, but any LV data that lived there is gone; this is why LVM is not a substitute for RAID or backups.
Interview Questions
Cheat Sheet
Disk & Storage
df -hShow disk space usage for all mounted filesystemslsblkList block devices and their mount pointsmount /dev/sdb1 /mntMount a device to a directoryfdisk -lList partition tables on all disksvgs / lvs / pvsList LVM volume groups / logical volumes / physical volumesFrequently Asked Questions
Summary
LVM pools one or more physical volumes into a volume group, then carves logical volumes from that pool — decoupling filesystem size from any single disk's physical boundaries. Extending storage live is a two-step process (grow the LV, then grow the filesystem), and LVM alone provides no redundancy, so pair it with RAID or backups for anything that matters.