13.2. Managing LVM
LVM turns fixed partitions into a pool. Disks or partitions become physical volumes (PVs); a volume group (VG) aggregates their space into 4 MiB extents; and logical volumes (LVs) are mappings of extents onto new block devices. A logical volume is created, resized, renamed, and deleted without repartitioning anything, and snapshots and thin provisioning are properties of the mapping, not of the filesystem above it. Chapter 14 builds on this section for every later resize and migration; here the volumes themselves are the subject.
13.2.1. Physical Volumes, Volume Groups, and Logical Volumes
Figure 13.3. The practice group's object model with its measured
sizes: two 2 GiB PVs pool into vgdata (3.99 GiB after metadata and
extent rounding), which holds two linear volumes, a snapshot, and a thin
pool with a thin volume. Extents are conceptual, not to scale.
pvcreate writes an LVM label and a metadata area at the start of each
device; vgcreate claims the PVs for a group. The reporting side of
LVM comes in short and long forms:
| Command | Shows |
|---|---|
pvs, vgs, lvs |
One line per PV, VG, or LV, with selectable columns |
pvdisplay, vgdisplay, lvdisplay |
Full detail for one object each |
In the root shell, turn the first two practice disks into physical volumes:
# pvcreate /dev/vdb /dev/vdc
Physical volume "/dev/vdb" successfully created.
Physical volume "/dev/vdc" successfully created.
Read the new objects back with the short report, asking for the columns that matter:
# pvs -o pv_name,pv_uuid,vg_name,pv_size
PV PV UUID VG PSize
/dev/vdb XDOJX8-YsOK-POOE-cenS-lTWs-9CMB-j0gkdp 2.00g
/dev/vdc gMGxFP-B5AB-MXHS-ZiFp-8c4m-f16V-nAF1Jh 2.00g
Each PV already has a UUID - the identifier Section 13.1.3 said to
record - and no volume group yet, so the VG column is empty. The long
form shows what was actually written:
# pvdisplay /dev/vdb
"/dev/vdb" is a new physical volume of "2.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdb
VG Name
PV Size 2.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID XDOJX8-YsOK-POOE-cenS-lTWs-9CMB-j0gkdp
PE is a physical extent, the 4 MiB allocation unit the volume group
will carve the PV into; until a VG claims the PV, its size is recorded
but no extent grid exists. Now claim both PVs for a group:
# vgcreate vgdata /dev/vdb /dev/vdc
Volume group "vgdata" successfully created
# vgs -o vg_name,vg_uuid,vg_size,vg_free,pv_count,lv_count
VG VG UUID VSize VFree #PV #LV
vgdata Sn1wfF-2m0A-PdZ8-dlyC-bkfY-qV6m-lbrJCh 3.99g 3.99g 2 0
Two 2 GiB disks pooled into 3.99 GiB, not 4 GiB: each PV gives up a
small metadata area, and extents round capacity to multiples of the
4 MiB extent size. vgdisplay shows the arithmetic:
# vgdisplay vgdata
--- Volume group ---
VG Name vgdata
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 3.99 GiB
PE Size 4.00 MiB
Total PE 1022
Alloc PE / Size 0 / 0
Free PE / Size 1022 / 3.99 GiB
VG UUID Sn1wfF-2m0A-PdZ8-dlyC-bkfY-qV6m-lbrJCh
1022 extents of 4.00 MiB - the group's whole capacity, all free. The
metadata areas live on both PVs, so one surviving PV is enough to
describe the group. A group is also resizable by design: PVs join
with vgextend and leave with vgreduce or pvmove, which is how
Chapter 14 migrates extents onto new disks
without downtime.
13.2.2. Creating and Activating Logical Volumes
A logical volume is a chosen number of the group's extents, mapped into
a new block device. lvcreate is the tool; the options used across
this chapter are:
| Option | Description |
|---|---|
-L, --size SIZE |
Exact size, such as -L 1G; allocated immediately from free extents |
-n, --name NAME |
Volume name; the device appears as /dev/vgdata/NAME |
-s, --snapshot |
Create a snapshot of an existing origin volume (Section 13.2.4) |
--thinpool NAME |
Create a thin pool (with -L) rather than a linear volume |
-V, --virtualsize SIZE |
Virtual size of a thin volume, with --thin to consume from a pool |
Create the first volume, 1 GiB of the group's 3.99 GiB:
# lvcreate -L 1G -n lvdata vgdata
Logical volume "lvdata" created.
# lvs -o lv_name,vg_name,lv_uuid,lv_size,lv_attr vgdata
LV VG LV UUID LSize Attr
lvdata vgdata BBdEld-bRgB-Lxce-3u2A-SHwI-0Nws-l8FcM0 1.00g -wi-a-----
The Attr string is the volume's state in ten characters; the ones
this chapter reads are the first (type: - for a plain linear volume)
and the fifth (state: a for active). The device node exists twice
over - /dev/vgdata/lvdata is the convenient path,
/dev/mapper/vgdata-lvdata the device-mapper node it points to, with
dashes substituting for the slash in the mapper name. The long form:
# lvdisplay /dev/vgdata/lvdata
--- Logical volume ---
LV Path /dev/vgdata/lvdata
LV Name lvdata
VG Name vgdata
LV UUID BBdEld-bRgB-Lxce-3u2A-SHwI-0Nws-l8FcM0
LV Write Access read/write
LV Creation host, time layers, 2026-11-20 11:12:04 +0000
LV Status available
# open 0
LV Size 1.00 GiB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0
256 logical extents of 4 MiB make up the 1 GiB. Now make the volume
useful exactly as Chapter 11 Section 11.3
treated a plain partition: create an ext4 filesystem on it, mount it,
and hand the mounted root to john. The mkfs.ext4 invocation is the
same one Chapter 12 Section 12.2 examined; -q
quietens the creation report and -L sets the label:
# mkfs.ext4 -q -L handbook-lvm /dev/vgdata/lvdata
Silent - the filesystem was created on the logical volume, not on a partition, and the volume's contents before this moment are gone. Create the mount point and give it to john before mounting:
# mkdir -p /srv/lvm
# chown john:john /srv/lvm
# mount /dev/vgdata/lvdata /srv/lvm
# chown john:john /srv/lvm
Each step is silent. The second chown is the one that matters for
use: mounting a freshly made filesystem puts a root-owned filesystem
root on the mount point, so the ownership is set again after the mount,
covering the filesystem's root directory rather than the empty
placeholder beneath it. Confirm the mount and write a file as john:
# findmnt /srv/lvm
TARGET SOURCE FSTYPE OPTIONS
/srv/lvm /dev/mapper/vgdata-lvdata ext4 rw,relatime
findmnt reports the device-mapper name for the source - the same
volume addressed through /dev/mapper. Still as john, in /srv/lvm:
$ printf "%s\n" "linear volume payload" > readme.txt
Silent; the redirection writes the file rather than printing to the
terminal (Chapter 3 Section 3.2.2 covered >).
Read it back:
$ cat readme.txt
linear volume payload
Back in the root shell, one capacity check:
# df -h /srv/lvm
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vgdata-lvdata 974M 284K 906M 1% /srv/lvm
A "1 GiB" volume carries a 974 MiB filesystem: the 1.00 GiB of extents, less ext4's own metadata and block-allocation overhead - usable space is always smaller than the device it comes from.
Create a second, smaller linear volume the same way; the snapshot exercise in Section 13.2.4 will use it as its origin:
# lvcreate -L 512M -n snapdemo vgdata
Logical volume "snapdemo" created.
Both volumes so far landed on extents no data had ever touched, so
lvcreate reported only the creation. The command does look first:
extents a volume group hands out carry whatever bytes were on the
member disk before the PV existed, and when lvcreate finds an old
filesystem signature where the new volume would sit it stops and asks
Wipe it? [y/n]: - answering y erases the old signature and creates
the volume, while n aborts with Aborting. Failed to wipe start of
new LV. Disks reused after earlier filesystems, or space an earlier
volume group's volumes once occupied, are where that prompt normally
appears; wiping the device with wipefs before pvcreate
(Chapter 11 Section 11.1.2's signature rules)
keeps it away. Make the filesystem - this time with a label long enough
that mke2fs warns about it:
# mkfs.ext4 -q -L handbook-snapdemo /dev/vgdata/snapdemo
Warning: label too long; will be truncated to 'handbook-snapdem'
The filesystem was created; the warning, which mke2fs prints on the
error stream, notes that ext4 labels are limited to 16 characters
(Chapter 12 Section 12.2.1 noted the limit), and
handbook-snapdemo is 17. The label is stored truncated; nothing else
changes. Set up the mount point, mount the volume, and hand the root to
john - the same four silent steps as before:
# mkdir -p /srv/snapdemo
# chown john:john /srv/snapdemo
# mount /dev/vgdata/snapdemo /srv/snapdemo
# chown john:john /srv/snapdemo
As john, in /srv/snapdemo, put a known file on the new volume:
$ printf "%s\n" "version one" > plan.txt
Silent. The file will be the snapshot exercise's before-and-after marker.
Activation deserves its own look. A logical volume the kernel has
mapped is active - the fifth Attr character is a - and an
inactive volume is metadata on disk with no device node that works.
Activation normally just happens: at boot, LVM's udev rules scan
devices as they appear and activate volume groups, so neither
/etc/fstab nor any other file needs to request it. The manual
control is vgchange with -a y to activate a group's volumes and
-a n to deactivate them, one group or all groups at a time. Neither
is needed anywhere in this chapter's working path; the demonstration
waits until the group holds every kind of volume this chapter builds,
at the end of Section 13.2.4, and Section 13.5.2 rehearses the same
steps as part of boot integration. Growing a volume afterwards -
lvextend, then the filesystem - is Chapter 14
Section 14.2's procedure and is not repeated here.
13.2.3. Linear Volumes, Thin Provisioning, and Capacity Monitoring
The two volumes so far are linear: every extent was allocated at
creation time, whether used or not, and df inside the filesystem
reported the truth about both. A thin pool allocates differently -
on write. The pool holds the real space; thin volumes carved from it
present a virtual size that may exceed it.
| Property | Linear volume | Thin pool and thin volumes |
|---|---|---|
| Space allocated | Full size, at creation | Only blocks actually written |
df inside the filesystem |
Real capacity | Virtual capacity - not the pool's limit |
| What exhaustion hits | The filesystem (ENOSPC) |
The pool; the kernel discards I/O or invalidates, per policy |
| Monitoring | df |
lvs Data% and Meta% on the pool |
Create a 1 GiB pool inside vgdata:
# lvcreate -L 1G --thinpool thinpool vgdata
Thin pool volume with chunk size 64.00 KiB can address at most <15.88 TiB of data.
Logical volume "thinpool" created.
The pool is internally two devices - a data area and a metadata area - and the chunk size is the unit of copy-on-write allocation within it. The reported 15.88 TiB ceiling is the addressing limit implied by that chunk size, far above anything this pool will hold; it is information, not a problem. Carve a thin volume from it, half a gibibyte virtual:
# lvcreate -V 512M --thin -n thinvol vgdata/thinpool
Logical volume "thinvol" created.
-V gives the virtual size and --thin names the pool to consume.
Make a filesystem and mount it, with the same silent setup steps as
before:
# mkfs.ext4 -q -L handbook-thin /dev/vgdata/thinvol
# mkdir -p /srv/thin
# chown john:john /srv/thin
# mount /dev/vgdata/thinvol /srv/thin
# chown john:john /srv/thin
As john, in /srv/thin:
$ printf "%s\n" "thin payload" > readme.txt
$ cat readme.txt
thin payload
Now the capacity question. df reports the virtual size:
# df -h /srv/thin
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vgdata-thinvol 488M 156K 452M 1% /srv/thin
That 488 MiB is a promise the pool has not yet been asked to keep. The
real numbers live in lvs on the pool:
# lvs -o lv_name,vg_name,lv_size,data_percent,metadata_percent,lv_attr vgdata
LV VG LSize Data% Meta% Attr
lvdata vgdata 1.00g -wi-ao----
snapdemo vgdata 512.00m -wi-ao----
thinpool vgdata 1.00g 2.02 11.23 twi-aotz--
thinvol vgdata 512.00m 4.04 Vwi-aotz--
Three things to read here. The pool's Data% is 2.02 - about 21 MiB of
its 1 GiB is actually holding written blocks, most of that the ext4
metadata just created. Meta% is 11.23: the pool's metadata device,
which tracks which virtual blocks map to which pool chunks, is filling
faster than the data area, and both percentages must be watched. The
attribute strings start with t (thin pool) and V (thin volume, the
capital marking a volume whose size is virtual), and the o in
twi-aotz-- shows the pool is open - mounted through its thin volume.
The group-level view confirms what the pool really cost:
# vgs -o vg_name,vg_size,vg_free vgdata
VG VSize VFree
vgdata 3.99g 1.48g
3.99 GiB total, 1.48 GiB still free: 1 GiB went to lvdata, half a
gibibyte to snapdemo, and the full 1 GiB to the pool - the thin
volume itself cost nothing.
The point of thin provisioning is that the sum of virtual sizes may exceed the pool. Try it deliberately:
# lvcreate -V 2G --thin -n thinlarge vgdata/thinpool
WARNING: Sum of all thin volume sizes (2.50 GiB) exceeds the size of thin pool vgdata/thinpool and the amount of free space in volume group (1.48 GiB).
WARNING: You have not turned on protection against thin pools running out of space.
WARNING: Set activation/thin_pool_autoextend_threshold below 100 to trigger automatic extension of thin pools before they get full.
Logical volume "thinlarge" created.
LVM allows the overprovisioned volume - 2.50 GiB of virtual volumes on
a 1 GiB pool with only 1.48 GiB of spare room behind it - but it says
plainly that nothing stops the pool from filling. The protection it
names is real: setting thin_pool_autoextend_threshold below 100 in
LVM's activation profile tells LVM to grow the pool from the group's
free extents before it reaches that percentage. Check the damage with
the same monitoring columns:
# lvs -o lv_name,lv_size,data_percent,metadata_percent vgdata/thinpool vgdata/thinlarge
LV LSize Data% Meta%
thinlarge 2.00g 0.00
thinpool 1.00g 2.22 11.33
thinlarge shows Data% 0.00 because nothing has been written to it -
the pool's real usage barely moved. Remove it before it can become a
trap:
# lvremove -f vgdata/thinlarge
Logical volume "thinlarge" successfully removed.
-f answers the removal confirmation without pausing for it; the
plain form asks first. What the exercise established is the operating
rule for thin pools: Data% and Meta% are the capacity truth, df
inside a thin volume is the user's view, and a pool without
autoextension and without monitoring will eventually fill. An
exhausted pool queues writes or returns errors, depending on its
error-if-no-space policy, and one that ran out of metadata may need
the thin-provisioning-tools checks before it can be activated again -
lvmthin(7) documents both behaviors. The monitoring habit is the same
one Chapter 11 Section 11.5.2 built for plain
filesystems; the next section shows what a capacity percentage left to
reach 100.00 looks like.
13.2.4. Snapshots, Consistency, and Snapshot Exhaustion
A snapshot is a second mapping of an origin volume, created instantly by sharing the origin's extents. It stays readable as the origin was using copy-on-write: the first time the origin overwrites a block, the old contents are copied aside into the snapshot's reserved area (its COW space), and the snapshot reads the old copy from then on. Nothing is copied at creation; the COW area only fills as the origin changes. Two consequences follow, and this section demonstrates both: a snapshot of a quiesced origin is a consistent point in time, and a snapshot whose COW area fills is destroyed, not paused.
Consistency first. The origin /srv/snapdemo holds john's plan.txt
with "version one". Freeze the filesystem so nothing is mid-write -
fsfreeze flushes it and blocks further writes at the VFS layer:
# fsfreeze -f /srv/snapdemo
Silent; any writer to /srv/snapdemo would now block until the thaw.
While the origin is frozen, create the snapshot - 128 MiB of COW space,
named for its origin:
# lvcreate -L 128M -s -n snapdemo-snap vgdata/snapdemo
Logical volume "snapdemo-snap" created.
-s makes a snapshot, -L sizes its COW area, and the origin is
named as the source. Thaw the filesystem:
# fsfreeze -u /srv/snapdemo
Silent; blocked writers resume. Now change the origin. As john, in
/srv/snapdemo:
$ printf "%s\n" "version two" > plan.txt
Silent - and on disk, lvcreate's copy-on-write moved the old blocks into the snapshot's COW area before this write landed. Mount the snapshot read-only and compare. In the root shell:
# mkdir -p /srv/snapdemo-snap
# mount -o ro /dev/vgdata/snapdemo-snap /srv/snapdemo-snap
Both silent. Read the file through the snapshot:
# cat /srv/snapdemo-snap/plan.txt
version one
The snapshot shows the frozen moment. As john, on the live origin in
/srv/snapdemo:
$ cat plan.txt
version two
One origin, two views. The monitoring columns put numbers on the mechanism:
# lvs -o lv_name,lv_size,data_percent,lv_attr vgdata/snapdemo vgdata/snapdemo-snap
LV LSize Data% Attr
snapdemo 512.00m owi-aos---
snapdemo-snap 128.00m 0.05 swi-aos---
The origin's attribute now begins with o - it is an origin, opened
by its snapshot - and the snapshot's begins with s. The snapshot's
Data% is 0.05: of its 128 MiB COW area, a fraction of a percent
holds the copied-aside blocks of plan.txt. Unmount the snapshot view
when finished with it:
# umount /srv/snapdemo-snap
Silent. The snapshot stays in place; the next step writes heavily to the origin to see what happens when its COW area cannot keep up.
Now the failure mode, induced on purpose. The snapshot's COW area holds a copy of every block the origin has changed since creation, and 128 MiB of that is far less than the origin can rewrite. dd is the tool for writing a measured amount of raw data, and its options recur through this chapter, including the header-destroying write in Section 13.4.3:
| Option | Description |
|---|---|
if=FILE, of=FILE |
Read from FILE, write to FILE - devices included |
bs=SIZE |
Block size; dd reads and writes that much at a time |
count=N |
Copy N blocks in all |
status=none |
Suppress the automatic progress summary |
conv=fsync |
Flush the output physically before exiting |
As john, in /srv/snapdemo:
$ dd if=/dev/urandom of=fill.bin bs=1M count=200 status=none
bs=1M count=200 writes 200 MiB of random data in 1 MiB pieces, and
status=none suppresses dd's final transfer summary, so the command is
silent. Flush it to disk in the root shell:
# sync
Also silent; sync returns once dirty pages are written back. Look at
the monitoring column now:
# lvs -o lv_name,lv_size,data_percent,lv_attr vgdata/snapdemo vgdata/snapdemo-snap
LV LSize Data% Attr
snapdemo 512.00m owi-aos---
snapdemo-snap 128.00m 100.00 swi-I-s---
The COW area is at Data% 100.00, and the snapshot's fifth attribute
character has changed from a to I: the kernel has invalidated the
snapshot. There is no grace period and no read-only fallback - the
mapping stops answering. Try to mount what is left:
# mount -o ro /dev/vgdata/snapdemo-snap /srv/snapdemo-snap
mount: /srv/snapdemo-snap: can't read superblock on /dev/mapper/vgdata-snapdemo--snap.
dmesg(1) may have more information after failed mount system call.
The mount fails; the device returns errors to any reader. The origin is
unharmed - the write pressure fell entirely on the snapshot - but the
snapshot itself is gone as a usable object, and lvremove is the only
cleanup:
# lvremove -f vgdata/snapdemo-snap
Logical volume "snapdemo-snap" successfully removed.
Figure 13.4. Copy-on-write and exhaustion, with the practice run's
measured values: a 128 MiB snapshot of a 512 MiB origin reached
Data% 100.00 after 200 MiB of writes and was invalidated. The
consistency boundary comes from freezing the origin first.
The operational rules that follow: size a snapshot's COW area against
the writes the origin will absorb during the snapshot's lifetime, watch
its Data% in the same monitoring pass as a thin pool's, remove
snapshots when their purpose is served instead of leaving them to age,
and treat a frozen or quiesced origin - fsfreeze here, or an
application-level checkpoint - as the consistency boundary that makes
the snapshot worth taking. Chapter 15
Section 15.2.2 uses exactly this boundary to back up running services.
Close the LVM section by exercising activation across the whole group, which now holds one of everything. Unmount the three practice filesystems, each command silent:
# umount /srv/thin
# umount /srv/lvm
# umount /srv/snapdemo
Deactivate the entire group:
# vgchange -an vgdata
0 logical volume(s) in volume group "vgdata" now active
The count is the volumes remaining active: zero. Look at the attributes with the group idle:
# lvs -o lv_name,lv_attr vgdata
LV Attr
lvdata -wi-------
snapdemo -wi-------
thinpool twi---tz--
thinvol Vwi---tz--
Every volume's fifth character is now -: the metadata is on disk,
the kernel mappings are gone, and no application can reach the data.
Activate again:
# vgchange -ay vgdata
4 logical volume(s) in volume group "vgdata" now active
# lvs -o lv_name,lv_attr vgdata
LV Attr
lvdata -wi-a-----
snapdemo -wi-a-----
thinpool twi-aotz--
thinvol Vwi-a-tz--
All four volumes are active again - the type characters (- for
linear, t for the pool, V for the thin volume) ride through the
cycle unchanged; only the activation bit flipped. This
deactivate/reactivate pair is the
manual equivalent of the boot-time activation LVM performs
automatically, which is why Section 13.5.2 returns to these exact
commands when rehearsing the boot sequence. The filesystems stay
unmounted for now; the RAID section takes over the practice disks
without disturbing vgdata.