How to share a host folder with a KVM guest machine

How to share a host folder with a KVM guest machine

Accessing host storage directly from a KVM guest is useful in many cases, for example when that storage is on separate/dedicated hardware or the storage is or grows large over time and it would be inefficient to hoard large volume of data inside the virtual machine itself.

KVM has the ability to share storage (folders) directly with guest machines, albeit built-in support is readily available only with Linux-based guests, Windows requiring additional software to be used.

With Cockpit, sharing a folder from the host is a simple procedure. Navigate in the Virtual Machines section (this is normally a separate module that needs to be installed manually), select the target machine and click the Add Shared Directory button at the bottom of the page – note that the guest machine has to be powered off when doing this.

In the popup fill in the full directory path from the host and an easily identifiable name (tag) for this shared directory which will be used in the guest. Save and power on the guest machine.

With the guest up and running, mount the shared directory:

mount -t virtiofs shared-dir-tag /targetdironguest

When all works as expected the mounting can be transferred to a permanent location, like fstab, a cron job run at boot or a startup script.

Leave a Reply