LVM explained: physical volumes, volume groups and logical volumes
LVM puts a flexible layer between disks and filesystems, so you can grow volumes, add disks and take snapshots without repartitioning.
With plain partitions, a filesystem is stuck with the size of its partition and lives on exactly one disk. The Logical Volume Manager (LVM) removes both limits. RHEL, Rocky and AlmaLinux install onto LVM by default, and the Ubuntu Server installer offers it, so you will meet it on most servers.
The three layers
- Physical volume (PV): a disk or partition prepared for LVM with
pvcreate. Example:/dev/sdb. - Volume group (VG): a pool made from one or more PVs. Its capacity is the sum of its disks. Example:
datavg. - Logical volume (LV): a slice of a VG that behaves like a partition. You put a filesystem on it. Example:
/dev/datavg/www, also visible as/dev/mapper/datavg-www.
Space is handed out in fixed-size chunks called extents. An LV can use extents from any PV in its group, which is why it can grow beyond one disk.
disks: /dev/sdb /dev/sdc
| |
PVs: pvcreate pvcreate
\_______ _______/
VG: datavg (pool)
________|________
LVs: www db
FS: ext4 xfs
mount: /var/www /var/lib/db
Seeing what you have
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
sudo pvs # physical volumes and which VG they belong to
sudo vgs # volume groups, total size and VFree (unallocated space)
sudo lvs # logical volumes and their sizes
lsblk # the whole tree from disk to mount point
VFree in vgs is the most useful number: it is the space you can still give to logical volumes without adding a disk.
Building a volume group from scratch
Warning: pvcreate overwrites the start of the device. Check with lsblk -f and sudo wipefs /dev/sdb that the disk is empty and not in use.
Check before you run this
- Formats or repartitions a disk and erases its data.
- Runs with administrator rights. Make sure you understand every line.
sudo pvcreate /dev/sdb
sudo vgcreate datavg /dev/sdb
sudo lvcreate --name www --size 20G datavg
sudo mkfs.ext4 /dev/datavg/www
sudo mkdir -p /var/www
sudo mount /dev/datavg/www /var/www
To use all remaining space instead of a fixed size: lvcreate --name www -l 100%FREE datavg. Add the mount to /etc/fstab as usual; for LVs, the /dev/mapper/datavg-www path is stable, and a UUID works too.
Growing: the main reason to use LVM
Growing a volume is safe to do online, while the filesystem is mounted and in use. lvextend with --resizefs (-r) grows the LV and then the ext4 or XFS filesystem in one step:
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
sudo lvextend --size +10G --resizefs datavg/www
# or give it all free space in the VG
sudo lvextend -l +100%FREE --resizefs datavg/www
When the VG has no free space left, add a disk to it first:
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
sudo pvcreate /dev/sdc
sudo vgextend datavg /dev/sdc
If the underlying disk itself grew (common for virtual disks), tell LVM about the new size with pvresize. When the PV is a partition, the partition has to be enlarged first, for example with growpart or parted:
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
sudo pvresize /dev/sdb # PV on a whole disk
Shrinking is different
Shrinking is risky and often impossible online. XFS cannot be shrunk at all. ext4 can only be shrunk while unmounted, after a filesystem check. If you must do it, make a backup first and use lvreduce --resizefs, which shrinks the filesystem before the volume. Never run lvreduce without --resizefs on a volume that holds data.
Snapshots and thin provisioning
LVM can take a snapshot of an LV: a frozen view you can back up while the original keeps changing. Classic snapshots need free space in the VG to store the changes and become invalid if that space fills up, so they are meant to be short-lived. Thin pools let you create volumes larger than the physical space and allocate it only when data is written; they need monitoring so the pool never runs full.
Good habits
- Leave some free space in the VG instead of giving everything to one LV on day one. Growing later is easy; shrinking is not.
- Use names that say what the volume is for (
datavg/postgres, notvg0/lv3). - Before any change, look at
vgsandlvs, and use--test(-t) to see what a command would do without writing metadata.
Official documentation
See also
- 0102 Proxmox VE storage types: local, LVM-thin, ZFS, NFS and Ceph Proxmox VE stores disks, ISOs, templates and backups in storage pools defined in /etc/pve/storage.cfg. Learn the main storage types, what local and… Intermediate · Concept · Linux Article Disks, LVM & filesystems · Storage 15 Oct 2026
- 0168 Server health check script: disk, memory and failed units A dependency-free bash script that checks disk and inode usage, available memory, load, failed systemd units and pending reboots, and exits non-zero… Intermediate · Reference · Linux Script Disks, LVM & filesystems · Services & systemd 15 Oct 2026
- 0169 Add a new disk: partition, format and mount it by UUID Find a new disk with lsblk, partition it with parted, create an ext4 or XFS filesystem and mount it permanently through /etc/fstab… Intermediate · How-to · Linux Article Disks, LVM & filesystems 15 Oct 2026
- 0171 Extend an LVM logical volume and filesystem online (safe script) A bash script that grows the LVM volume behind a mount point, checks the filesystem type and free space first, and runs… Advanced · How-to · Linux Script Disks, LVM & filesystems 15 Oct 2026
- 0172 Fix: No space left on device Writes fail because a filesystem is full, out of inodes, or holding space for deleted files that are still open. Find which… Beginner · Fix · Linux Article Disks, LVM & filesystems 15 Oct 2026
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- commitpedia-admin +4,084 chars