skip to content

LVM

Linux's logical volume manager: physical volumes, volume groups and logical volumes, online resizing, snapshots and thin provisioning, and spreading a filesystem across disks. Interviewers ask because add space to a full disk without downtime is routine work that requires the whole LVM stack in your head.

on this pageshow

questions

17

On a Linux server with two blank disks, explain LVM's three layers — physical volume, volume group and logical volume — and give the commands, in order, that turn those disks into a mounted filesystem.

level: juniorimportance: must knowfreq 78%

answer

  1. three layers, bottom to top
  2. disk gets labelled, then pooled
  3. the pool is chopped into extents
  4. pvcreate, vgcreate, lvcreate, mkfs
  5. filesystem sits on /dev/vg/lv

basics

~20 s

LVM stacks three layers: pvcreate initialises each disk as a physical volume, vgcreate pools those PVs into a volume group, and lvcreate carves logical volumes out of the pool. Then you mkfs and mount the LV like any block device.

solid answer

~40 s

LVM inserts a virtualisation layer between disks and filesystems. A **physical volume** is a block device — a whole disk or a partition — that `pvcreate` has labelled for LVM use. A **volume group** is a pool built from one or more PVs; `vgcreate vg0 /dev/sdb /dev/sdc` merges both disks' capacity into one address space, chopped into fixed-size physical extents. A **logical volume** is a slice of that pool: `lvcreate -L 200G -n data vg0` hands you `/dev/vg0/data`, a normal block device that may be backed by extents from either disk. From there it is ordinary storage — `mkfs.ext4 /dev/vg0/data`, then mount it. The payoff is that the filesystem is no longer welded to one physical disk, so capacity can be added to the pool later without moving data.

code

bash · 7 lines
bash
pvcreate /dev/sdb /dev/sdc
vgcreate vg0 /dev/sdb /dev/sdc
lvcreate -L 200G -n data vg0
mkfs.ext4 /dev/vg0/data
mkdir -p /srv/data
mount /dev/vg0/data /srv/data
lvs vg0

go deeper

for a junior

Be able to name the three layers in order and give the command for each: pvcreate, vgcreate, lvcreate, then mkfs and mount. Say plainly that the filesystem goes on the logical volume, not on the group.

for a middle

Explain what pvcreate actually writes to the disk, that the VG is divided into fixed-size extents, and why an LV can be larger than any single member disk.

for a senior

Show that you treat the VG as the capacity pool you manage: leaving headroom unallocated, knowing which PV backs which extents via lvdisplay -m, and reading pvs/vgs/lvs to orient yourself on a machine you have never seen.

for a principal

Own the convention: whether hosts get one VG or several, how much of the pool stays unallocated as insurance, and when a workload should skip LVM entirely because its storage is already virtualised beneath you.

## Why the layer exists Without LVM, a filesystem lives on a partition, and a partition is a fixed range of sectors on one disk. If it fills up, your options are ugly: back up, repartition, restore. LVM breaks that binding by putting a pool in the middle. Disks feed the pool; filesystems are served out of the pool; the two no longer have to line up. ## Layer 1 — the physical volume (PV) A PV is any block device you have handed to LVM with `pvcreate`. It can be a whole disk (`/dev/sdb`), a partition (`/dev/sdb1`), a multipath device, or a RAID array exposed by a controller. `pvcreate` does not reformat the device. It writes a small LVM label (by default in the second 512-byte sector) plus a metadata area holding a text description of the volume group this PV belongs to. That is why LVM metadata is self-describing: plug the disks into another machine and the configuration comes with them. ## Layer 2 — the volume group (VG) `vgcreate vg0 /dev/sdb /dev/sdc` creates a named pool from those PVs. The VG's total capacity is the sum of its PVs, and it is divided into equal-sized **physical extents** (PEs) — 4 MiB each by default. The extent is LVM's unit of allocation: everything above this layer is bookkeeping about which extents belong to which logical volume. The VG is also the boundary of allocation. A logical volume can only take extents from PVs inside its own VG; it can never straddle two VGs. ## Layer 3 — the logical volume (LV) `lvcreate` allocates extents from the VG and presents them as a block device: ```bash lvcreate -L 200G -n data vg0 # by size lvcreate -l 100%FREE -n data vg0 # all remaining extents ``` The result appears as `/dev/vg0/data` (and `/dev/mapper/vg0-data`). Because the extents may come from more than one PV, a 200 GiB LV can exist on a VG made of two 150 GiB disks — something a partition could never do. By default the layout is *linear*: extents are taken from one PV until it is exhausted, then from the next. It is concatenation, not RAID; LVM by itself adds no redundancy. ## Putting a filesystem on it An LV is an ordinary block device, so the rest is unremarkable: ```bash pvcreate /dev/sdb /dev/sdc vgcreate vg0 /dev/sdb /dev/sdc lvcreate -L 200G -n data vg0 mkfs.ext4 /dev/vg0/data mkdir -p /srv/data mount /dev/vg0/data /srv/data ``` The filesystem has no idea LVM is underneath. It sees a device with a size, and reads and writes sectors; device-mapper translates each of those sectors to a location on a real disk. ## Checking your work Each layer has a reporting command, and they are the first thing to reach for on an unfamiliar machine: - `pvs` — one line per physical volume: which VG it belongs to, its size (`PSize`) and how much of it is unallocated (`PFree`). - `vgs` — one line per volume group: number of PVs and LVs, total size (`VSize`) and free space (`VFree`). - `lvs` — one line per logical volume: its VG, size (`LSize`) and an attribute string such as `-wi-ao----`, where the `a` means active and the `o` means currently open (mounted). The verbose forms `pvdisplay`, `vgdisplay` and `lvdisplay` print the same information in paragraph form; `lvdisplay -m` additionally shows the segment map — which PV's extents actually back each part of the LV. ## The order matters, and only in one direction You cannot skip a rung. There is no way to create an LV without a VG, and no way to add a disk to a VG without `pvcreate` first. Conversely, tearing down runs in reverse: unmount, `lvremove`, `vgremove`, `pvremove`. The payoff for all this ceremony is that the pool is now the unit you manage. Space that is free in the VG can be handed to whichever filesystem needs it, and a new disk becomes usable capacity for every LV in the group rather than a new mount point somebody has to find a use for.

  • How would you find out how much unallocated space is left before creating another logical volume?
    `vgs` shows a `VFree` column — the extents in the volume group that no LV has claimed. `vgdisplay vg0` prints the same figure as "Free PE / Size" along with the extent count. `pvs` breaks it down per disk via `PFree`, which matters when you care *which* device the free space is on.
  • What is the difference between lvcreate -L and lvcreate -l?
    `-L` takes a human size such as `200G` and LVM converts it to extents, rounding up to a whole extent. `-l` takes the extent count directly, or a percentage expression such as `100%FREE`, `50%VG` or `100%PVS`. `-l 100%FREE` is the usual way to consume exactly the remaining space without doing arithmetic.
  • Can a single logical volume span two volume groups?
    No. The volume group is the allocation boundary: an LV is built only from extents belonging to PVs inside its own VG. If you need capacity from another disk, you add that disk to the same VG as a new PV rather than trying to bridge two groups.

Think of the PVs as sacks of flour, the VG as one big bin you empty them into, and the LVs as loaves you bake from the bin — the loaf no longer corresponds to any particular sack.

saying these in an interview costs you the question

  • Thinks LVM by itself gives redundancy like RAID
  • Says you run mkfs on the volume group
  • Believes an LV cannot span more than one disk
  • Skips pvcreate and passes a raw disk to vgcreate
  • Calls the volume group a filesystem

context

open as a page

On a Linux host using LVM, you run `lvextend -L +50G /dev/vg0/data` and it reports success, yet `df -h` still shows the old size for the mounted filesystem. Why, and what do you run to make the filesystem use the new space?

level: juniorimportance: must knowfreq 76%

basics

~20 s

An LVM logical volume and the filesystem on it are separate layers. lvextend grew only the block device, so the filesystem still records its old size. Run resize2fs (ext4) or xfs_growfs (XFS) afterwards, or pass lvextend -r to do both.

open as a page

A team asks you to shrink an LVM logical volume holding a 500 GB filesystem down to 200 GB so the freed extents can go to another volume. What do you check first, and what is the correct order of operations?

level: middleimportance: must knowfreq 61%

basics

~20 s

Check the filesystem type first. XFS cannot shrink at all, so the only route is back up, recreate a smaller volume and restore. On ext4, unmount, shrink the filesystem with resize2fs, and only then reduce the volume with lvreduce — never the other way round.

open as a page

You run `lvcreate -s -L 5G -n db-snap vg0/db` on a Linux host. What has LVM created, and what happens on disk the first time a block of the origin volume is overwritten afterwards?

level: middleimportance: must knowfreq 62%

basics

~20 s

LVM allocated a 5 GiB copy-on-write area and a snapshot device; no data was copied. The first overwrite of a chunk on the origin makes device-mapper read the old chunk, write it into the copy-on-write area, record the exception, then apply the new write.

open as a page

A nightly job snapshots a busy Linux volume so a backup can stream from it. This morning `lvs` shows the snapshot at 100% Data% with an `I` in its attribute string, and the backup that ran from it is unusable. What happened, and how do you size and monitor the snapshot so it does not recur?

level: seniorimportance: must knowfreq 55%

basics

~20 s

The origin changed more than the snapshot's copy-on-write area could hold, so LVM marked the snapshot invalid and reads from it now fail. Size the COW area for the origin's write volume during the snapshot's lifetime, monitor Data%, and enable snapshot autoextend with lvm2-monitor running.

open as a page

A colleague says the nightly LVM snapshot of the server's data volume is the backup. Why is an LVM snapshot sitting in the same volume group not a backup, and what is it actually good for?

level: juniorimportance: should knowfreq 48%

basics

~20 s

An LVM snapshot stores only the blocks that changed since it was taken and reads everything else from the origin volume, on the same disks in the same volume group. Lose the origin or the disks and the snapshot is worthless. It is a stable point-in-time source to copy from, not a copy.

open as a page

When creating an LVM logical volume with lvcreate, what is the difference between the default linear layout and a striped one requested with -i, and when does striping actually buy you anything?

level: middleimportance: should knowfreq 42%

basics

~20 s

A linear LV concatenates extents, filling one physical volume before using the next, so one request hits one disk. A striped LV created with lvcreate -i alternates fixed-size chunks across several PVs, so a large sequential transfer is served by all of them in parallel.

open as a page

In LVM on Linux, what is a physical extent (PE), what extent size does vgcreate use by default, and what does that choice actually affect?

level: middleimportance: should knowfreq 52%

basics

~20 s

A physical extent is LVM's fixed-size unit of allocation — 4 MiB by default in LVM2, set per volume group at vgcreate time and shared by every PV in it. Logical volume sizes are always rounded up to a whole number of extents.

open as a page

An LVM volume group on a Linux server has no free extents left. In one case the storage team presents a brand-new disk as /dev/sdc; in another they enlarge the existing disk that the volume group already sits on. What do you run in each case to get that capacity into an existing logical volume?

level: middleimportance: should knowfreq 54%

basics

~20 s

A new disk is initialised with pvcreate and joined to the group with vgextend. A disk enlarged in place needs a device rescan and then pvresize on the existing physical volume. In both cases lvextend -r is what finally moves the space into a volume.

open as a page

How does a thin snapshot of an LVM thin logical volume differ from a classic `lvcreate -s -L` snapshot in the way it stores data, and why can you keep dozens of thin snapshots but not dozens of classic ones?

level: middleimportance: should knowfreq 45%

basics

~20 s

A classic LVM snapshot owns a fixed copy-on-write area and preserves old chunks by copying them into it. A thin snapshot just shares block references in the thin pool: a write allocates a new pool block, nothing is copied, and the cost does not grow with the number of snapshots.

open as a page

You are adding a new data disk to a Linux server for LVM. Should you run pvcreate on the whole disk (/dev/sdb) or on a partition (/dev/sdb1), and what does each choice cost you?

level: seniorimportance: should knowfreq 38%

basics

~20 s

Both work. A whole-disk PV is simpler and self-aligning but leaves no partition table, so other tools and humans can mistake the disk for blank. A partitioned PV advertises its use through the Linux LVM type code and lets the disk be shared, at the cost of an extra layer to manage.

open as a page

On a Linux server, /dev/sdb is one of three physical volumes in an LVM volume group serving live databases, and it has started logging SMART errors and I/O timeouts. How do you get the data off that disk and remove it from the volume group without downtime?

level: seniorimportance: should knowfreq 45%

basics

~20 s

Confirm the remaining physical volumes hold enough free extents, then run pvmove /dev/sdb to relocate its extents onto them while the volumes stay online. Finish with vgreduce to drop the disk from the group and pvremove to clear its LVM label.

open as a page

Before a risky package upgrade you snapshot the Linux server's root-adjacent data volume with `lvcreate -s`. The upgrade goes badly and you want to roll back. What does `lvconvert --merge vg0/snap` do, and why might the rollback not take effect the moment the command returns?

level: seniorimportance: should knowfreq 40%

basics

~20 s

lvconvert --merge schedules the snapshot's preserved contents to be written back over the origin, reverting it to the snapshot's point in time and deleting the snapshot when finished. If the origin is open — mounted or in use — the merge is deferred until the volume is next deactivated and reactivated.

open as a page

An LVM thin pool created with `lvcreate -L 200G -T vg0/pool` backs thin volumes whose virtual sizes total 800G. What happens to those volumes when the pool's data space — or its metadata space — actually runs out, and how do you keep that from happening?

level: seniorimportance: should knowfreq 42%

basics

~20 s

Once the pool has no free blocks, any write needing a new allocation fails or hangs, filesystems on the thin volumes go read-only or corrupt, and metadata exhaustion is worse — the pool goes read-only and needs offline repair. Prevent it with Data%/Meta% alerting, autoextend, and volume group headroom.

open as a page

An LVM logical volume appears on Linux as /dev/vg0/data, /dev/mapper/vg0-data and /dev/dm-2. What is each of those three paths, and how does device-mapper name a volume whose VG or LV name contains a dash?

level: middleimportance: nice to knowfreq 30%

basics

~20 s

/dev/dm-2 is the real device-mapper device node, whose number is assigned at activation and is not stable. /dev/mapper/vg0-data and /dev/vg0/data are udev-created symlinks to it. Dashes inside a VG or LV name are doubled in the /dev/mapper form.

open as a page

You take an LVM snapshot of a mounted, actively written filesystem on a Linux host. What consistency does the resulting snapshot actually give you, and what does running `fsfreeze -f` on the mount point immediately before the snapshot add?

level: seniorimportance: nice to knowfreq 33%

basics

~20 s

The snapshot is crash-consistent: it looks exactly like the volume would after a power cut, so a journalling filesystem mounts it after replaying its journal, but anything still buffered above the block layer is missing. fsfreeze -f flushes and quiesces the filesystem first, giving a cleanly-shut-down image instead.

open as a page

When you standardise LVM provisioning across a fleet of Linux servers, how do you decide how much of each volume group to allocate to logical volumes up front rather than leaving extents unallocated?

level: principalimportance: nice to knowfreq 31%

basics

~20 s

Allocate lean and grow on demand. LVM growth is online and cheap, while shrinking is offline at best and impossible on XFS, so unallocated extents are the reversible position. Free extents also give operations like pvmove somewhere to relocate data.

open as a page