Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Manage logical storage with LVM

By updated

Improve this page

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 a test on AlmaLinux.

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

Terminal window
sudo apt install lvm2

The 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).
Two physical volumes, /dev/sda1 then /dev/sdb added with vgextend, feed the vgdata volume group. The group provides the logical volume lvdata, formatted as XFS and mounted on /data. The snapshot lvdata-snap is created from lvdata, with lvcreate -s, and the space it uses comes from the group. The space that stays free in the group, VFree, is the headroom for lvextend -r.     PV /dev/sda1     disk initialised by pvcreate     PV /dev/sdb     disk added laterVG vgdatapool of space vgcreate  vgextend      LV lvdata     XFS mounted on /data lvcreate VFreeheadroom for lvextend -r     LV lvdata-snap     snapshot lvcreate -s disk or logical volumevolume group and free spaceprovides space or is the starting point
Source · SVG
Esc to close, + and − to zoom, scroll to move around. 100 %

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.

Terminal window
sudo pvcreate /dev/sda1
sudo vgcreate vgdata /dev/sda1
sudo 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:

Terminal window
sudo mkfs.xfs /dev/vgdata/lvdata
sudo mkdir -p /data
sudo mount /dev/vgdata/lvdata /data

For 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).

Terminal window
sudo pvs
sudo vgs
sudo 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.00g

Reading 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):

Terminal window
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.00g

Add 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:

Terminal window
sudo pvcreate /dev/sdb
sudo vgextend vgdata /dev/sdb

The 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:

Terminal window
sudo lvcreate -s -L 512M -n lvdata-snap /dev/vgdata/lvdata
Logical volume "lvdata-snap" created.

The snapshot starts from the original logical volume (/dev/vgdata/lvdata), not from the volume group. The 512 MB requested with -L are taken from the free space of the group. It 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.

Terminal window
sudo lvreduce -r -L 2G /dev/vgdata/lvdata # ext4 only, back up first

To remove the stack, unmount then remove in the reverse order of creation: LV, VG, PV.

Terminal window
sudo umount /data
sudo lvremove /dev/vgdata/lvdata
sudo vgremove vgdata
sudo pvremove /dev/sda1

Going 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.

SymptomProbable causeSolution
Added space invisible after lvextend-r forgottensudo lvextend -r or manual resize2fs/xfs_growfs
lvcreate refuses: not enough spaceVG fullvgs (VFree), add a disk with vgextend
Snapshot gone / volume frozensaturated snapshotrecreate larger, watch lvs (Data%)
Shrinking impossibleXFS volumeXFS 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 check that 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 → lvcreate builds the stack; you format and mount the LV like a partition.
  • pvs / vgs / lvs give the state; VFree shows the headroom for growth.
  • lvextend -r grows volume and file system online, in one command.
  • vgextend adds 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

6 questions
6 min
70% to pass

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

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.