LVM (Logical Volume Manager) decouples logical volumes from physical disks: you grow a volume online, add a disk on the fly or take a snapshot, without reformatting anything. This guide is the entry point of the LVM path: it shows how to build the PV/VG/LV stack, inspect it and grow a volume online with lvextend -r (the number one use case in production). Advanced operations (thin provisioning, snapshots, disk migration) are covered in dedicated guides, presented before the troubleshooting section. For beginner to intermediate administrators, on Debian/Ubuntu and RHEL. All outputs come from an AlmaLinux test.
What you will learn
- Understand the PV / VG / LV model
- Build the stack with
pvcreate,vgcreate,lvcreate - Grow a logical volume online with
lvextend -r - Create and use a snapshot
Prerequisites
- A free disk or LVM-type partition
- The
lvm2package:
sudo apt install lvm2sudo dnf install lvm2The PV / VG / LV model
LVM stacks three layers. Understanding this stacking is understanding LVM:
- PV (Physical Volume): a disk or a partition initialised for LVM (
pvcreate). - VG (Volume Group): a pool of space that aggregates one or more PVs (
vgcreate). - LV (Logical Volume): a slice carved out of the VG, which you format and mount like a partition (
lvcreate).
The benefit: an LV is no longer tied to a specific disk. When the VG runs short of space, you add a disk to it; when an LV fills up, you grow it by drawing from the VG. Without reformatting, without unmounting.
Build the LVM stack
Let us start from a 10 GB /dev/sda1 partition dedicated to LVM. You initialise the PV, create the VG, then a 4 GB LV.
sudo pvcreate /dev/sda1sudo vgcreate vgdata /dev/sda1sudo lvcreate -L 4G -n lvdata vgdata Physical volume "/dev/sda1" successfully created. Volume group "vgdata" successfully created Logical volume "lvdata" created.The logical volume is reachable under two equivalent paths: /dev/vgdata/lvdata and /dev/mapper/vgdata-lvdata. Format and mount it like any volume:
sudo mkfs.xfs /dev/vgdata/lvdatasudo mkdir -p /datasudo mount /dev/vgdata/lvdata /dataFor persistence, add the entry to /etc/fstab (by UUID through blkid, see the mount guide). LVM's /dev/mapper/... paths are stable, but the UUID remains the safest convention.
Inspect the state: pvs, vgs, lvs
Three concise commands give a summary view of each layer. They are the ones to know day to day (the pvdisplay, vgdisplay, lvdisplay variants go into more detail).
sudo pvssudo vgssudo lvs PV VG Fmt Attr PSize PFree /dev/sda1 vgdata lvm2 a-- <10.00g <6.00g
VG #PV #LV #SN Attr VSize VFree vgdata 1 1 0 wz--n- <10.00g <6.00g
LV VG Attr LSize Pool Origin Data% ... lvdata vgdata -wi-ao---- 4.00gReading the essentials: the vgdata VG totals 10 GB of which 6 GB are free (VFree), and the lvdata LV uses 4 GB. These 6 free GB are the headroom available to grow.
Grow a volume online: lvextend -r
This is LVM's reason for being. When /data fills up, you extend the logical volume and its file system in a single command, without unmounting, thanks to the -r option (resize filesystem):
sudo lvextend -r -L +2G /dev/vgdata/lvdata Size of logical volume vgdata/lvdata changed from 4.00 GiB (1024 extents) to 6.00 GiB (1536 extents). Extending file system xfs to 6.00 GiB on vgdata/lvdata... data blocks changed from 1048576 to 1572864 Logical volume vgdata/lvdata successfully resized.LVM detects the file system (here XFS) and runs xfs_growfs automatically.
Do not worry if your output is much longer than the one above: lvextend -r is very verbose. On AlmaLinux 10 with lvm2 2.03.36, it produces 21 lines, including the File system xfs found on … mounted at … line, the command it is about to run (xfs_growfs /dev/vgdata/lvdata) and the full geometry returned by it. The student comparing with the guide's block believes they made a mistake: they did not.
lvs confirms the new size:
LV VG Attr LSize Pool ... lvdata vgdata -wi-ao---- 6.00gAdd a disk to a Volume Group
When the whole VG runs short of space, add a new disk to it. You initialise the PV, then aggregate it with vgextend:
sudo pvcreate /dev/sdbsudo vgextend vgdata /dev/sdbThe VG now has the sum of both disks, and lvextend -r can draw from it. That is how storage is extended beyond the size of a single disk, without migration.
Snapshots: back up or test without risk
A snapshot is an instant copy of an LV at a moment T. Ideal before a risky update or to back up a database online:
sudo lvcreate -s -L 512M -n lvdata-snap /dev/vgdata/lvdata Logical volume "lvdata-snap" created.The snapshot only stores the blocks modified since its creation (copy-on-write), hence its small initial size. You can also use it to roll back after a failed operation (lvconvert --merge), and a full snapshot becomes invalid. Consistent backup, rollback and sizing are detailed in the dedicated LVM snapshots guide.
Shrink and remove
Shrinking an LV is trickier: you must shrink the file system first, then the volume. And XFS does not shrink: only ext4 allows it.
sudo lvreduce -r -L 2G /dev/vgdata/lvdata # ext4 only, back up firstTo remove the stack, unmount then remove in the reverse order of creation: LV, VG, PV.
sudo umount /datasudo lvremove /dev/vgdata/lvdatasudo vgremove vgdatasudo pvremove /dev/sda1Going further with LVM: thin provisioning, snapshots, pvmove
Once the stack is in place and resizing is mastered, three operations cover most of everyday LVM work. Each one has its dedicated guide, with real outputs and traps to avoid.
Thin provisioning allocates
space on demand and lets you overcommit storage without wasting it.
LVM snapshots go deeper into online
backup and rollback with lvconvert --merge. Finally,
pvmove moves data from one disk to another
so you can retire it without downtime.
Troubleshooting
LVM failures can almost always be read in vgs and lvs: exhausted free space, a full snapshot or a file system that did not follow the volume. The table starts from the observed symptom.
| Symptom | Probable cause | Solution |
|---|---|---|
Added space invisible after lvextend | -r forgotten | sudo lvextend -r or manual resize2fs/xfs_growfs |
lvcreate refuses: not enough space | VG full | vgs (VFree), add a disk with vgextend |
| Snapshot gone / volume frozen | saturated snapshot | recreate larger, watch lvs (Data%) |
| Shrinking impossible | XFS volume | XFS does not shrink: back up, recreate, restore |
Put it into practice
The lab scenario is the one you will live in production: a volume filling up that must be grown without downtime. You extend a logical volume with lvextend, grow the XFS file system, then write the mount into /etc/fstab by UUID to prove it survives the reboot.
Once this guided lab is mastered, test yourself under exam conditions: partitions, LVM and swap to complete without hints, against the clock, on RHEL or Ubuntu.
Key points
- LVM stacks PV → VG → LV: the logical volume is no longer tied to a specific disk.
pvcreate→vgcreate→lvcreatebuilds the stack; you format and mount the LV like a partition.pvs/vgs/lvsgive the state;VFreeshows the headroom for growth.lvextend -rgrows volume and file system online, in one command.vgextendadds a disk to the pool to go beyond the size of a single disk.- Snapshots (
lvcreate -s) back up online; watch how full they are.
Knowledge check
Check that the essentials of this guide are acquired. The questions only cover what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: LVM snapshots: back up online and roll back
A new full quiz with random questions
Work again only on the questions you missed
FAQ: frequently asked questions about LVM
The questions below cover those that come up most often about LVM: its principle, growing a volume and the place of snapshots.
lvextend with the -r option (alias --resizefs), which grows the logical volume and the file system in a single command:lvextend -L +10G -r /dev/vg_data/lv_app
The operation is done online, without unmounting or service interruption. It is LVM's number one use case in production (and an RHCSA exam objective). Then check with df -h that the space is available.- PV (Physical Volume): a disk or a partition initialised for LVM with
pvcreate. - VG (Volume Group): a pool that aggregates one or more PVs (
vgcreate). It is the reservoir of space. - LV (Logical Volume): a volume carved out of the VG (
lvcreate), which you format and mount like a partition.
e2fsck -f), shrink the file system (resize2fs) then the volume (lvreduce), in that order, otherwise you lose data. With XFS, it is impossible in practice: XFS only grows, its experimental shrinking (xfs_growfs -D) being limited to the free space of the last allocation group. Always back up before a shrink, and prefer growing another volume rather than shrinking.lvcreate -s (snapshot), reserving space for the writes made after it is taken:lvcreate -s -L 1G -n snap_app /dev/vg_data/lv_app
The snapshot freezes the state of the volume at a moment T, ideal for a consistent backup of a database or to test a risky operation and roll back. Size the space according to the expected writes, and remove the snapshot (lvremove) once the task is finished: a saturated snapshot becomes invalid.