Share Folder Between Windows Guest and Linux Host in KVM using virtiofs

5 min


In this guide, you will learn how to share a folder between Windows guest, running under a Linux host – such as Fedora, Ubuntu or Linux Mint using KVM.

The virt-manager application (with libvirt) and packages provide a flexible set of tools to manage virtual machines in Linux. It is free and open-source and used for KVM virtual machines and other hypervisors.

In the prior article, I explained how to share folders between a Linux guest and a Linux host. However, when you are trying to create a shared folder using Windows Guest and Linux host, it’s a little difficult and complex process. Because both the operating system works differently and a lot of configuration is needed.

Follow the below instructions as mentioned to share the folder between Windows guest and Linux host.

A note about virtiofs

The sharing files and folders are powered by the libvirt shared file system called virtiofs. It provides all the features and parameters to access the directory tree on the host machine. Since most of the virt-manager virtual machine configurations are translated to XML, the share files/folders can also be specified by the XML file.

Note: If you are looking for file sharing using KVM between two Linux machines (guest and host), read this article.

Share folder between Windows guest and Linux host using KVM

The following instructions assume that you have installed Windows in virt-manager in any Linux host. If not, you can read this complete guide on how to install Windows in Linux.

Set up a mount tag in virt-manager

  • First, make sure your guest virtual machine is powered off. From the virt-manager GUI, select the virtual machine and click on Open to pull up the console settings.
Open the console settings
Open the console settings
  • Click on the icon which says show virtual hardware details in the toolbar. And then click on Memory on the left panel.
  • Select the option “Enable shared memory“. Click Apply.
  • Make sure the XML shows “access mode=shared” as below in the XML tab.
  <memoryBacking>
    <source type="memfd"/>
    <access mode="shared"/>
  </memoryBacking>
Enable shared memory
Enable shared memory
  • Click “Add hardware” at the bottom.
  • Select File system from the left panel in the add new hardware window.
  • Then select Driver=virtiofs in the details tab. Click on browse > browse local and select the host path from your Linux system.
  • In the target path, mention any name you want. It’s just a file tag which will be used during mount. This name in the target path will be mounted as Drive in Windows – My PC in Explorer.
  • I have added “linux_pictures” as the target mount tag.
  • So, if I want to access the Pictures folder (/home/debugpoint/Pictures), sample settings could be the following:
  • Click Finish.
Add a file system mount for windows
Add a file system mount for windows

The XML settings are below for the above configuration. You can find it in the XML tab.

<filesystem type="mount" accessmode="passthrough">
  <driver type="virtiofs"/>
  <source dir="/home/debugpoint/Pictures"/>
  <target dir="linux_pictures"/>
  <address type="pci" domain="0x0000" bus="0x05" slot="0x00" function="0x0"/>
</filesystem>

In the main virt-manager window, right-click on the Windows virtual machine and click Run to start the virtual machine. Make sure to click on the “show the graphical console” (monitor icon in the toolbar) – if the VM is not showing.

Set up WinFSP – FUSE for Windows

Make sure Windows virtual machine (guest) is running.

  • First, we need to set up the WinFSP or Windows File System Proxy – FUSE for Windows. This enables you to mount any UNIX-like filesystem without any difficulties.
  • Open the below page in the WinFSP GitHub from the guest Windows machine.
  • Download the WinFSP .msi installer.
  • Install the package on Windows virtual machine. Make sure to select “Core” while installing the package. Finish the installation.
WinFSP set up
WinFSP set up

Create VirtIO-FS as a service

  • Download the virtio-win-guest-tools.exe from the below path by going inside stable-virtio folder.
Download guest tools
  • Install the package on Windows virtual machine.
Virtio-Win-driver installation
Virtio-Win-driver installation
  • After installation is complete, reboot Windows virtual machine.
  • After reboot, open the “Device Manager” by searching in the start menu.
  • Navigate to System devices and look for “VirtIO FS Device”. It should be recognized and driver should be signed by Red Hat.
  • Note: (optional) If you see an exclamation mark i.e. driver is not detected, then follow the instructions here on how to download ISO file, mount it and manually detect the driver.
Make sure the Virt IO driver is signed and installed
Make sure the Virt IO driver is signed and installed
  • Open the start menu and search for “Services”.
  • Scroll down to find out the “VirtIO-FS Service”. Right-click and hit Start to start the service.
  • Alternatively, you can run the below command from PowerShell/command prompt as admin to start the service.
sc create VirtioFsSvc binpath="C:\Program Files\Virtio-Win\VioFS\virtiofs.exe" start=auto depend="WinFsp.Launcher/VirtioFsDrv" DisplayName="Virtio FS Service"
sc start VirtioFsSvc
Start the Virt IO Service
Start the Virt IO Service
  • After the service start, open Explorer, and you should see the mount tag which you have created in the first step above, which should be mapped as Z drive. See below.
  • You can now access the entire Linux folder with modified permission as per your need.
The mount tag is mapped as Z drive in windows
The mount tag is mapped as Z drive in Windows

Here is a side-by-side comparison of the same folder accessed in Linux Mint and Windows guest.

Access and share folder in Windows guest and Linux host
Access and share folder in Windows guest and Linux host

Conclusion

I hope you can now able to share a folder between Windows guest and Linux host system. The above method is tested in Linux Mint for this article. It should work for Ubuntu, Fedora as well.

If the above method works, drop a comment below for the benefit of others.

References


Arindam

Creator and author of debugpoint.com. Connect with me via Telegram, 𝕏 (Twitter), or send us an email.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

35 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments