Storing VM disks as LVM logical volumes avoids a filesystem layer and gives fast, predictable block I/O. This guide shows how to set up an LVM storage pool for KVM with libvirt, the same approach many VPS panels use under the hood.
Before you start
- A KVM host with libvirt; see install KVM on Ubuntu.
- A spare disk or partition for VMs (it will be wiped), e.g.
/dev/nvme1n1. - Basic LVM knowledge helps; see Linux LVM basics.
Create the volume group
pvcreate /dev/nvme1n1vgcreate vg_vms /dev/nvme1n1Check with vgs.
Define it as a libvirt pool
virsh pool-define-as vg_vms logical --source-name vg_vms --target /dev/vg_vmsvirsh pool-start vg_vmsvirsh pool-autostart vg_vmsConfirm with virsh pool-info vg_vms.
Create VM disks
virsh vol-create-as vg_vms web01-disk0 40GUse it with virt-install:
virt-install --name web01 --memory 4096 --vcpus 2 --disk vol=vg_vms/web01-disk0,bus=virtio --cdrom /var/lib/libvirt/images/debian-12.iso --os-variant debian12 --network bridge=br0,model=virtio --graphics vnc,listen=127.0.0.1 --noautoconsoleSee create a VM with virt-install for the full workflow.
Thin provisioning with LVM-thin
Plain logical volumes reserve their whole size. LVM-thin allocates space only as written, allowing overprovisioning:
lvcreate --type thin-pool -l 95%FREE -n thinpool vg_vmslvcreate -V 40G --thin -n web02-disk0 vg_vms/thinpoollibvirt's logical pool type does not create thin volumes itself; create them with lvcreate and attach the path /dev/vg_vms/web02-disk0. Monitor thin pool usage closely with lvs: a full thin pool can corrupt VMs. Proxmox and VPS panels manage LVM-thin natively; see Virtualizor LVM-thin.
Resize a VM disk
lvextend -L +20G /dev/vg_vms/web01-disk0Then tell the running VM: virsh blockresize web01 /dev/vg_vms/web01-disk0 60G, and grow the partition and filesystem inside the guest.
Snapshots
lvcreate -s -L 5G -n web01-snap /dev/vg_vms/web01-disk0Classic LVM snapshots slow writes and fail when their space fills, so keep them short-lived (for example during a backup). Thin snapshots are cheaper.
Troubleshooting
- Pool will not start: the volume group name or target path is wrong; check
vgsandvirsh pool-dumpxml. - Thin pool 100% full: extend it immediately with
lvextendand add disks; set autoextend inlvm.conf. - VM sees old size after resize: run
blockresizeor reboot the guest.
Frequently asked questions
LVM or qcow2 files?
LVM is faster and simpler for block I/O; qcow2 is more portable and has internal snapshots. See qcow2 vs raw.
Can I use LVM on RAID?
Yes. Put the physical volume on an mdadm or hardware RAID device for redundancy.
LVM-thin or ZFS?
LVM-thin uses less RAM; ZFS adds checksums and compression. See ZFS for VMs.
