Kingsfordweg 151, 1043GR Amsterdam, The Netherlands ● 24/7 support — support@novogara.com
Knowledge base

LVM

LVM sits between your disks and your filesystems and makes the layout changeable. On a machine you cannot easily reinstall, that is worth a great deal.

The three layers

Physical volume (PV)
A disk or partition handed to LVM.
Volume group (VG)
A pool made of one or more PVs.
Logical volume (LV)
A slice of the pool that carries a filesystem. This is what you mount.

pvs, vgs, lvs show each layer. Start there whenever something is confusing.

Growing a filesystem

The everyday use. With free space in the volume group:

lvextend -L +50G /dev/vg0/data

resize2fs /dev/vg0/data — ext4, works mounted

xfs_growfs /data — XFS, also online

Or in one step: lvextend -r -L +50G /dev/vg0/data.

Added a new disk? Bring it in first:

pvcreate /dev/sdc && vgextend vg0 /dev/sdc

Shrinking is the dangerous direction

XFS cannot shrink at all. ext4 can, but only unmounted, and the filesystem must be resized before the volume — the other order destroys data. Back up first and prefer to avoid it: leave space unallocated rather than over-allocating and shrinking later.

Snapshots before every upgrade

This is the feature people underuse:

lvcreate -L 10G -s -n root_before_upgrade /dev/vg0/root

Do the upgrade. If it goes wrong:

lvconvert --merge /dev/vg0/root_before_upgrade — and reboot

If it went well, lvremove the snapshot. Two cautions: a snapshot that fills up is dropped and becomes useless, so size it for the expected churn, and a snapshot is not a backup — it lives on the same disks. See backups.

Leave space free on purpose

Do not allocate the whole volume group at install time. Unallocated space is what makes snapshots and growth possible later. A quarter held back costs nothing and saves a migration.

LVM or ZFS

LVM is simple, universal and does not need much memory. ZFS gives you checksums, cheap snapshots and send/receive replication, at the cost of memory and a little complexity. For a plain machine where you mainly want to resize later, LVM. For storage you care about deeply, ZFS.

Ask us before delivery

The partitioning decision is easiest at install time. Tell us when you order that you want LVM with room left over, and the machine arrives that way instead of being rebuilt later. See ordering a server.


Still stuck? Mail support@novogara.com — an engineer answers, at any hour. Back to the knowledge base