Linux VPS

Set up NFS shared storage for KVM hosts

Export an NFS share from a storage server, mount it on KVM hosts, add it as a libvirt storage pool for VM disks, ISOs and backups, and tune it for live migration and reliability.

IntermediateKVM hosts2 min read

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-qemu on all hosts, or appropriate squash settings.

Export the share on the storage server

sudo apt install -y nfs-kernel-server
sudo mkdir -p /srv/vmstore

Add 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 -ra

no_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-common
virsh pool-define-as vmstore netfs --source-host 10.10.0.5 --source-path /srv/vmstore --target /var/lib/libvirt/vmstore
virsh pool-build vmstore && virsh pool-start vmstore && virsh pool-autostart vmstore

Use 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 qcow2

Attach 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/system

See 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=none on 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.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.