In virt-manager, navigate to Memory and enable the option Enable shared memory.
In virt-manager, use Add Hardware > Filesystem, change the driver to virtiofs, and configure the given options. Alternatively, attach the below XML:
<filesystem type="mount" accessmode="passthrough">
<driver type="virtiofs"/>
<source dir="HOST_DIRECTORY_PATH"/>
<target dir="GUEST_MOUNT_NAME"/>
<address type="pci" domain="0x0000" bus="0x01" slot="0x00" function="0x0"/>
</filesystem>where HOST_DIRECTORY_PATH is the directory on the host to passthrough, e.g. /home/virtio-shared, and GUEST_MOUNT_NAME is the drive name that will appear in the guest.
If guest is linux -- Drivers should come with the kernel, if not, install virtiofs or the relevant package for your distro. Then, simply mount GUEST_MOUNT_NAME with type virtiofs with:
sudo mount -t virtiofs GUEST_MOUNT_NAME /mount/point/pathThat's all there is to do. Have a blast.
If guest is windows -- drivers need to be attached to the system somehow. There are two files you will need to download, either on the host or guest, depending on which option you decide to follow. WinFSP can be downloaded from the WinFSP github and the virtio windows guest tools installer can be downloaded from RedHat. Select the most recent version and download the virtio-win-guest-tools.exe file.
- Option 1 -- Bundle both into an iso. The steps to do this are as follows:
First, make a tmpdir and copy all the files to it. Then, make the tmpdir into an iso (see mkisofs(8) for documentation and this StackOverflow answer for flags):
ISOWRITE=$(mktemp -d)
cp "/path/to/virtio-win-guest-tools.exe" "$ISOWRITE"
cp "/path/to/winfsp.msi" "$ISOWRITE"
mkisofs -v -J -V "SharedFolderGuestTools" -o shared-folder-guest-tools.iso "$ISOWRITE"Attach this iso to the guest in virt-manager.
This may seem like a more convoluted method, but for me personally, it is much easier to bundle a single iso and attach it any time I fire up a new Windows vm.
-
Option 2 -- Enable spice USB passthrough or similar. Pause the guest, mount a USB to the host, copy these files to that USB, unmount it, then physically disconnect it. Then, unpause the guest, and plug the USB back in. It should be passed through automatically to the guest. Mount it and there should be your files.
-
Option 3 -- Requires an internet connection in the guest. Download these two files directly in the guest. This might be the easiest, but I often prefer to not let my testbed windows VMs access the internet.
| Method | Requires host internet? | Requires guest internet? |
|---|---|---|
| 1 | Yes* | No |
| 2 | Yes* | No |
| 3 | No | Yes |
*Just get the files onto the host somehow. Download directly, or transfer from another computer.
Once these files somehow are accessible in the guest, via whatever method you choose, follow the following steps:
- Boot into the guest.
- Run the WinFSP installer (
winfsp-[vers].msi) and the virtio driver installer (virtio-win-[vers]/virtio-win-guest-tools.exe). - Reboot the guest.
- When logged back in, open Device Manager (
devmgmt.msc), and under System Devices, open the properties panel for theVirtIO FS Devicedevice. Verify that the device is "functioning properly" and that the driver is correctly installed and loaded. - Open Services (
services.msc), and findVirtIO-FS Service. Right-click and select "Start" to start the service. - If you wish to automatically start this service at boot, right-click and select "Properties" and set "Startup type" to
Automatic. - The folder should now show up as a new drive, at label
Z:\, in File Explorer.