Logical volumes with LVM

Intermediate · 2 min

Pool disks into volume groups, carve flexible logical volumes, grow a mounted filesystem without downtime, and use snapshots and thin pools safely.

Before thisMounting and fstab

Learn Linux TV · 28 min · from 25:25

Logical volumes with LVM

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Learn Linux TVReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • LVM adds a layer between disks and filesystems: physical volumes (PVs) are pooled into a volume group (VG), which is carved into logical volumes (LVs).
  • An LV is a block device like a partition, but it can grow, shrink, move between disks and span several of them without repartitioning.
  • Growing is the everyday win: add space to the VG if needed, then `lvextend -r` grows the LV and the filesystem on it in one step, while mounted.
  • Shrinking needs a filesystem that can shrink, usually unmounted. XFS cannot shrink at all.
  • A classic snapshot is copy-on-write: it stores old versions of changed blocks and becomes invalid if that space fills. Use it briefly, for a consistent backup.
  • A thin pool hands out space as it is written, so volumes can promise more than exists. If the pool fills, writes queue and then fail, which can damage filesystems.
  • Debian's lvm.conf leaves automatic extension of snapshots and thin pools off (threshold 100). Monitor Data% or turn it on.

The partition you sized wrong

A server was installed with a 20 GB /var partition. Two years later the logs and database need 60 GB, and the disk has free space, but it sits after /home. Growing /var means moving partitions on a live system, or a maintenance window and a backup restore.

The Logical Volume Manager exists so that never happens again. It puts a layer between the physical disks and the filesystems, so storage can be handed out, grown and moved like money in an account rather than walls in a building.

Three layers

From the LVM man pages:

  • Physical volume (PV): a disk or partition prepared for LVM with pvcreate. LVM writes a small label and metadata on it and divides it into extents, 4 MiB each by default.
  • Volume group (VG): a pool of extents from one or more PVs, made with vgcreate. This is the account.
  • Logical volume (LV): a block device carved from a VG with lvcreate, appearing as /dev/vg0/var and /dev/mapper/vg0-var. You put a filesystem on it and mount it like a partition.

An LV’s extents do not have to be next to each other, or even on the same disk. That is the whole trick: an LV can grow into any free extent anywhere in the VG.

Building and looking

From lvm(8) and friends, LVM tools 2.03. Not run here, as there is no Linux machine:

pvcreate /dev/sdb /dev/sdc            # mark disks as PVs
vgcreate vg0 /dev/sdb /dev/sdc        # pool them
lvcreate -n data -L 100G vg0          # carve an LV
mkfs.xfs /dev/vg0/data
pvs; vgs; lvs                          # one-line summaries
pvdisplay; vgdisplay; lvdisplay        # the long forms

lsblk from the partitions lesson shows the result as a tree, with each LV of type lvm under the disk it lives on.

Growing online

This is the operation you will do most:

vgs                                   # VFree: is there space in the pool?
lvextend -r -L +20G vg0/var           # grow the LV by 20G and the filesystem with it
lvextend -r -l +100%FREE vg0/var      # or take everything that is free

-r, --resizefs in lvextend(8), resizes the filesystem along with the LV. ext4 and XFS can both grow while mounted, so there is no downtime. If the VG is out of space, add a disk: pvcreate /dev/sdd, then vgextend vg0 /dev/sdd. On a cloud VM, growing the virtual disk and then running pvresize on its PV does the same.

Shrinking is the risky direction. The filesystem must be shrunk before the LV, or the end of it is cut off. lvreduce -r does both in the right order for ext4, unmounted. XFS cannot be shrunk, as the filesystems lesson covered. LVM can also move data off a disk while it is in use, pvmove /dev/sdb, which is how you retire a failing disk from a VG without downtime.

Snapshots

lvcreate -s makes a snapshot: per lvcreate(8), a snapshot LV represents the content of the original LV at the moment it was made. A classic LVM snapshot is copy-on-write. It starts empty. Each time a block on the original is about to change, the old block is copied into the snapshot first. So its size is not a copy of the volume. It is how much change it can absorb.

lvcreate -s -n data-snap -L 10G vg0/data   # snapshot with 10G of change space
mount -o ro /dev/vg0/data-snap /mnt/snap   # back up from a frozen view
umount /mnt/snap; lvremove vg0/data-snap

When the change space fills, the snapshot becomes invalid, and lvs(8) shows the state as I, “invalid snapshot”. Every write to the origin also costs an extra copy while a snapshot exists. Use classic snapshots for minutes or hours, a consistent backup or a safety net during an upgrade, then remove them.

Thin pools

Thin provisioning, per lvmthin(7), separates promised size from used space. You create a thin pool LV, then thin LVs in it with any virtual size, and blocks are taken from the pool only when written. Snapshots of thin LVs are cheap and do not need preallocated space.

The catch is that you can promise more than you have. When the pool’s data space runs out, lvmthin(7) says the default is to queue writes for up to 60 seconds, waiting for someone to extend the pool, and then to return errors, which “can result in file system damage that requires repair”. So a thin pool must be watched. lvs shows Data% and Meta% for the pool.

LVM can extend a pool automatically when it crosses a threshold, through dmeventd. Out of the box it does not. In Debian 13’s lvm2 package (2.03.31), which I downloaded and unpacked on this Mac, /etc/lvm/lvm.conf documents the defaults:

	# Configuration option activation/thin_pool_autoextend_threshold.
	# Auto-extend a thin pool when its usage exceeds this percent.
	# Setting this to 100 disables automatic extension.
	...
	# This configuration option has an automatic default value.
	# thin_pool_autoextend_threshold = 100

The same file sets snapshot_autoextend_threshold = 100 for classic snapshots. Set them to something like 70 with thin_pool_autoextend_percent = 20, as the file’s own example suggests, if the VG has free space to give, and alert on Data% either way.

About the video

The embed is a clip, 25:25 to the end, of Learn Linux TV’s “Linux Logical Volume Manager (LVM) Deep Dive Tutorial”, June 2020. The clip’s chapters are “Viewing LVM info”, “Expanding a filesystem”, “Setting up LVM manually” and “Creating and restoring snapshots”. It skips the first half, which installs Ubuntu Server 18.04 with LVM. The release is old, but these commands have not changed. It does not cover thin pools or the risk of a full pool, which this lesson adds from lvmthin(7). English was judged from the channel and English auto-captions, the content from the chapters. Red Hat’s 2025 livestream in deeper adds pvmove and LVM metadata.

What was run: downloading and unpacking Debian 13’s lvm2 package and reading its lvm.conf on macOS. LVM behaviour is from the LVM tools 2.03 man pages on man7.org, checked 2026-11-28.

Where this fits

LVM makes space flexible. It does not make it survive a dead disk. That is RAID’s job: software RAID with mdadm.

Check yourself

  1. 01The /var LV is full. The VG has 50 GB free. What single command adds 20 GB to /var while it stays mounted?

    `lvextend -r -L +20G vg0/var`. -r resizes the filesystem along with the LV, so both grow online.

  2. 02The VG has no free space left. How do you get more?

    Add a disk or partition as a new PV with pvcreate, then vgextend the VG with it. Its extents are then free for any LV.

  3. 03You take a 5 GB snapshot of a database LV and forget it. Weeks later the snapshot is marked invalid. Why?

    A classic snapshot stores the original version of every block changed on the origin. After 5 GB of changes its space was full and LVM dropped it. Snapshots are for short-lived use, or need to be sized for the change rate.

  4. 04Ten 100 GB thin volumes live in a 500 GB thin pool. What is the risk and what do you watch?

    The pool is overcommitted. If written data reaches 500 GB, writes queue for 60 seconds by default and then fail, which can corrupt filesystems. Watch Data% and Meta% in lvs and enable autoextend or alerting.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark