Linux VPS

Share host folders with KVM VMs using virtiofs

Use virtiofs to share a host directory with KVM guests at near-local speed: requirements, enabling shared memory, adding a filesystem device in libvirt, mounting in Linux and Windows, and security notes.

IntermediateKVM hosts2 min read

Sometimes a VM needs files from the host: source code in a dev lab, media for a server, or shared data between VMs on one host. virtiofs is a shared filesystem designed for VMs that is much faster and more POSIX-compliant than older 9p sharing or NFS over a virtual network.

Before you start

  • A KVM host with recent libvirt and QEMU, and the virtiofsd daemon (packaged as virtiofsd on many distributions).
  • A Linux guest with kernel 5.4 or newer, or Windows with virtio-win drivers and WinFsp.
  • For sharing between hosts, use NFS or Ceph instead; see NFS shared storage.

Enable shared memory for the VM

virtiofs requires the VM's memory to be shareable with the daemon. In the VM XML (virsh edit vmname):

<memoryBacking>
  <source type='memfd'/>
  <access mode='shared'/>
</memoryBacking>

Add the filesystem device

<filesystem type='mount' accessmode='passthrough'>
  <driver type='virtiofs'/>
  <source dir='/srv/shared/projects'/>
  <target dir='projects'/>
</filesystem>

target dir is a tag, not a path. Shut down and start the VM. virt-manager can add this under Add Hardware → Filesystem with driver virtiofs.

Mount in a Linux guest

sudo mkdir -p /mnt/projects && sudo mount -t virtiofs projects /mnt/projects

Persist it in /etc/fstab:

projects  /mnt/projects  virtiofs  defaults,nofail  0  0

Windows guests

  1. Install virtio-win drivers (including the virtiofs driver) and WinFsp.
  2. Start the VirtIO-FS service; the share appears as a drive letter.

See Windows VMs on KVM for virtio-win.

Security notes

  • The guest can read and write the shared directory with the daemon's permissions; share only what is needed.
  • Do not share sensitive host paths (like / or /etc).
  • For untrusted guests, prefer network file sharing with authentication or no sharing at all.

Limitations

  • Live migration of VMs using virtiofs has limited support depending on versions.
  • Shared memory backing prevents some memory features such as ballooning in certain setups.

Troubleshooting

  • VM fails to start, "virtiofs requires shared memory": add the memoryBacking block.
  • "virtiofsd not found": install the package or set the binary path in the driver element.
  • Permission denied in guest: host directory ownership or SELinux label; check with ls -Z.

Frequently asked questions

virtiofs or 9p?

virtiofs is faster and more compatible; 9p is older and simpler.

Can two VMs share the same folder?

Yes, each with its own virtiofs device, but concurrent writes need application-level care.

Does Proxmox support virtiofs?

Recent Proxmox versions offer virtiofs directory mappings for VMs.

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.