Shared storage lets several hypervisors see the same VM disks, so you can live migrate VMs without copying disks. NFS is the simplest way to get there. This guide shows how to set up NFS shared storage for KVM hosts with libvirt.
Before you start
- A storage server (or NAS) with fast disks and redundancy (see RAID levels).
- Two or more KVM hosts on a fast, private network (10 Gbit/s recommended for VM disks).
- The same user and group IDs for
qemu/libvirt-qemuon all hosts, or appropriate squash settings.
Export the share on the storage server
sudo apt install -y nfs-kernel-serversudo mkdir -p /srv/vmstoreAdd to /etc/exports, limited to your private hypervisor subnet:
/srv/vmstore 10.10.0.0/24(rw,sync,no_subtree_check,no_root_squash)sudo exportfs -rano_root_squash is commonly needed for hypervisors; only use it on a trusted private network. Firewall NFS so only hypervisors can reach it.
Add the share as a libvirt pool on each host
sudo apt install -y nfs-commonvirsh pool-define-as vmstore netfs --source-host 10.10.0.5 --source-path /srv/vmstore --target /var/lib/libvirt/vmstorevirsh pool-build vmstore && virsh pool-start vmstore && virsh pool-autostart vmstoreUse the same pool name and target path on every host, so VM definitions point to identical paths.
Create VM disks on the share
virsh vol-create-as vmstore web01.qcow2 40G --format qcow2Attach it in virt-install with --disk vol=vmstore/web01.qcow2,bus=virtio,cache=none. cache=none is required for safe live migration on shared storage.
Live migrate
With the disk visible on both hosts, only memory moves:
virsh migrate --live --persistent --undefinesource web01 qemu+ssh://kvm2/systemSee KVM live migration.
Other uses
- Central ISO library for all hosts.
- Backup target for VM dumps; Proxmox users can add NFS under Datacenter → Storage.
Reliability tips
- The NFS server is a single point of failure for all VMs on it. Use redundant hardware, or consider Ceph for no single point of failure.
- Use NFSv4.1+ where possible and a dedicated storage VLAN.
- Monitor latency; slow storage makes every VM slow.
Troubleshooting
- Permission denied creating disks: squash settings or UID mismatch; check ownership on the server.
- VMs freeze when NFS drops: expected with hard mounts; fix the network or storage rather than using soft mounts for VM disks.
- Migration fails with cache warning: set
cache=noneon the disk.
Frequently asked questions
NFS or iSCSI?
NFS is file-level and simple; iSCSI gives block devices and can perform better but needs a cluster-aware setup for sharing.
Is NFS fast enough for databases?
On a fast network with good storage, yes for many workloads; latency-sensitive databases prefer local NVMe.
Can I use a NAS?
Yes, many NAS devices export NFS. Check their performance under random I/O.
