Sharing Files between the Linux Host and a Windows VM using virtiofs

I often transfer files between my Windows virtual machine (VM) and my Linux host. Up until now I used a Samba server on the Linux host, with the Windows guest connected via a network bridge. That worked great and never gave me any problems.

Recently I tried out the new virtio-fs shared file system that allows you to share a folder on the Linux host with a Windows or Linux guest. Before you rush and follow my tutorial below, check out the “Performance” and “Conclusion” sections at the end. Here is my tutorial:

virtiofs Tutorial for Windows Guest

The tutorial is divided into four sections:

  • Host-side configuration using Virtual Machine Manager (virt-manager)
  • WinFSP FUSE software installation in Windows guest
  • Virtiofs device driver installation in Windows guest
  • Virtiofs service activation in Windows guest

The entire process takes about 10-15 minutes.

Host-side configuration using Virtual Machine Manager (virt-manager)

  1. Open the Virtual Machine Manager (virt-manager) and select your Windows VM.
  2. Click “Open”, then click the info symbol.
  3. Select “Memory” and tick the “Enable shared memory” box:
Enable shared memory!
  1. Click “Add Hardware” and select “Filesystem”:
Select “Filesystem”

Make sure the selected “driver” is “virtiofs“.

Then fill in the fields as follows:

Source path: Path to the folder on your Linux host you wish to share with the Windows guest.

Target path: Descriptive name under Windows – Microsoft Windows will mount the source folder as a drive using this name. See example below.

[] Export filesystem as readonly mount: You can choose to share your host folder as “read-only” by ticking the box.

Specify “Source path” on Linux host and “Target path” on Windows guest

In my example above, I shared my Dropbox folder residing on my Linux host to the Windows VM. Windows will create a drive letter with the descriptive name “Dropbox” that will be functionally equivalent to a local folder under Windows.

WinFSP FUSE software installation in Windows guest

  1. Boot the Windows VM.
  2. Once Windows has started, download the latest stable release of the WinFsp FUSE software for Windows. For more information on the WinFsp software, see winfsp.dev.
  3. Run the WinFsp installer and leave the default options as is. This will install the “Core”.
WinFsp installer default options – leave as is

Virtiofs device driver installation in Windows guest

  1. Now we need to install the virtiofs PCI device driver. You have two options, and I’m showing you both:
  1. Option 1: Installing the virtiofs driver from the virtio-win drivers ISO. Here we will install only the specific virtiofs device driver.
  1. If you haven’t got it already, download the virtio-win ISO using the following download links:
    Stable virtio-win ISO
    Latest virtio-win ISO
    Make sure you have enough disk space (~600 MB). As of this writing, the stable and latest driver ISOs are the same: virtio-win-0.1.240.iso.
  2. Double-click on the downloaded virtio-win-…iso file to mount it in Windows as a DVD drive (usually drive D:).
  3. Right-click the Windows Start button and select “Device Manager”.
In the Device Manager, open “Other devices” to see the “Mass Storage Controller” with the missing driver
  1. Open the “Other devices” tab.
  1. Right-click the “Mass Storage Controller” entry (the one with the yellow triangle) and select “Update driver”.
  2. Click “Browse my computer for drivers”.
Under “Update driver” select “Browse my computer for drivers”
  1. Select the drive where the virtio-win ISO is mounted.
    Make sure to tick “[] Include subfolders“.
Select the drive letter (usually D:) of the mounted virtio-win ISO image
Select the virtio-win-…iso image
  1. Click “OK” and let Windows search and install the appropriate driver. The “Mass Storage Controller” entry will disappear.
  1. Option 2: Installing the virtiofs driver using the virtio-win-guest-tools.exe installer. This will automatically install about everything but the kitchen sink.
  1. Download the stable version of the virtio-win-guest-tools.exe installer from fedorapeople.org. The installer includes the virtiofs and other Windows drivers. For more options, see here.
    (Note: The tool is also available on the virtio-win-…iso image from option 1.)
  2. Run the virtio-win-guest-tools.exe installer.
virtio-win installer for Microsoft Windows
You can leave as is, or deselect drivers you do not wish to install

Make sure “Viofs” is selected! Unless you run multiple VMs and know what you are doing, you can deselect the “Balloon” driver as memory ballooning may be problematic. You can mark the drivers as “install when needed”, like I did below (note the yellow “1”s on the drive icons):

virtio-win guest tools
Selectively install the drivers you need
  1. When done with the selection, click “Next”. You will be asked to agree to the terms and conditions. After a few more clicks the installer should do its work. Note that virtio-win-guest-tools.exe will also install the Spice guest agent and driver. See Virtio-win guest tools installer for more information.
  1. Either of the two options will install the virtiofs driver. The Device Manager should now show the “VirtIO FS Device” under “System devices”. If not, reboot the Windows VM.
VirtIO FS Device in Device Manager
“VirtIO FS Device” under “System devices” in Device Manager

Virtiofs service activation in Windows guest

  1. In the Windows search bar, type “services”. Select the “Services” App and choose “Run as administrator”.
Type “services” in the search box and choose “Run as administrator”

This opens the Services App below.

  1. Scroll down and select the “VirtIO-FS Service“:
Microsoft Services App
Scroll down to the “VirtIO-FS Service” entry
  1. Right-click on the VirtIO-FS Service and select “Properties” to open the following window:
Enable WinFsp service
For startup type, select “Automatic”, then click “Start” and “OK” at the bottom
  1. For startup type, use the pull-down menu to select “Automatic”.
  2. The virtio-win-guest-tools (option 2 in the previous section) should have already started the VirtIO-FS service. If not, click “Start” to start the VirtIO-FS service.
    For more information on the virtiofs driver, see here.
  3. Open the Windows file explorer. If all went well, you should now see the shared host folder mounted as a drive, by default letter Z. In the example above, the host folder appears under “My PC” as “Dropbox (Z:)”.
    As with most Microsoft Windows issues, if it doesn’t work, close the Windows and reboot.

For reference, there is another good tutorial over at Debugpoint.com: “Share Folder Between Windows Guest and Linux Host in KVM using virtiofs“.

Performance

The first thing I wanted to see is how well (or not so well) virtiofs performs versus the old and proven file sharing method using a Samba server on the host. Here are some bullet points of my Samba setup for sharing a Linux host folder to the Windows VM:

  • Bridged network using the virtio interface in the Windows guest. A bridged network is so much faster compared to the default routed network. Caveat: Bridging is only available on wired connections, not on wireless networks.
    Just to get an idea of the performance, the network speed between the VM and the host using a network bridge should be somewhere around 10 Gbit.
  • Samba server on the Linux host.
  • Network folder mounted on Windows.
  • The shared folder is an ext4 partition residing on a LVM logical volume. Every partition on my PC – including the NTFS partitions of my Windows guest, uses LVM. The sole exception is the UEFI boot partition.
  • All copy/move transactions were performed on partitions residing on NVME drives. The Windows guest partitions reside on a 1 TB NVME drive whereas the Linux host folders are on another 500 GB NVME drive.

The shared folder on the Linux host is a Dropbox folder that syncs to the cloud using the proprietary Dropbox application. The Dropbox application only runs on the Linux host.

I created a 2 GB random character file using the following command:

head -c 2G /dev/urandom > sample.txt

On the Linux host I timed the cp and mv commands copying/moving the sample.txt file between different host folders/partitions as well as between the host ext4 file system and the mounted guest NTFS partition. The guest NTFS partition was mounted using the ntfs-3g FUSE driver (not to be confused with the ntfs3 kernel driver). See screenshot below:

Transfer times measured for copying or moving files on the Linux host – note that the /mnt/vmvg-workdrive is a NTFS partition on LVM mounted using the NTFS-3G driver

As you can see, it takes less than 2 seconds to copy or move a 2Gbyte file between different ext4 partitions on the host. However, copying or moving the same 2GByte from the ext4 host partition to a mounted NTFS partition took more than 14 seconds (using the NTFS-3G driver). Because of potential file corruption using the new NTFS3 kernel driver, I now avoid using the kernel driver and did not use it for this test.

The above results are for reference only, to get an idea on how fast a file can be copied or moved from one place to another on the Linux host. The following screenshot is taken within the Windows guest and shows the time it took to copy the 2GB file from the Windows VM to the Linux host using the virtiofs shared file system:

virtiofs file copying speed
Using Robocopy to copy the 2GB sample.txt file from the Windows guest to the Linux host shared folder using the virtiofs driver

Robocopy measures 18 seconds for copying the 2GB file from Windows to the Linux folder. Not exactly earth-shattering.

The screenshot below shows the same file copy command, but this time the file is copied to the Samba share folder on the Linux host using the smb protocol over the bridged network interface:

Samba (smb) file copying speed over bridged network
Copying the 2GB sample.txt file from the Windows guest to the Linux host shared folder using the smb network protocol

With smb (Samba server) the Robocopy took only 2 seconds for copying the 2GB file from Windows to the Linux folder. That’s nine times as fast as using virtiofs!

Below is a graph taken during a copy action using the virtiofs driver:

virtiofs copy speed
Graph showing the transfer speed for copying a file using virtiofs

Notice the speed of only 105 MB/s using virtiofs. Next is a graph showing the file transfer speed using the smb network protocol (Samba):

Copy speed over smb network (bridged)
Graph showing the transfer speed for copying a file using smb over a bridged network connection

Using a Samba server on the Linux host and a bridged network connection to the guest, the copy speed rises to 955 MB/s. Again, nine times as fast as using virtiofs.

For the speed test in a Windows VM, Samba is the winner!

Update: I did the sample.txt file copy/move test from a Linux guest to the Linux host using virtiofs. This is a lot faster than under Windows! Below are the results:

virtiofs file copying speed
Copying a 2GB sample.txt file from a Linux guest to the Linux host using the virtiofs driver

The file was copied in 3 seconds, the move command took 3.4 seconds. The file transfer speed from/to a Linux guest is significantly higher than from/to a Windows guest.

Conclusion

Virtiofs is an easy way to share files between your host and your Windows VM. It also works with more than one VM, sharing data between multiple VMs and the host. Likewise you can share multiple folders/partitions on your host to your VMs.

Though Samba is no rocket science, virtiofs is easier to implement. If you do not transfer large files or large amounts of data, then virtiofs is perfectly adequate and there is no need to install a Samba server on your host.

Virtiofs was primarily developed to share files between the host and multiple containers running Linux. After you configured the shared folder on the host side (see tutorial above), all you need to do to enable virtiofs in a Linux VM or container is the following shell command:

mount -t virtiofs shared_host_folder /mnt/host

To automatically mount a host share in a Linux guest on boot, add the following line to your /etc/fstab file (change as appropriate):

shared_host_folder /mnt/host virtiofs rw,relatime 0 0

So yes, virtiofs is easy to configure, even more so in Linux. But with a Windows guest and a bridged network, Samba is a lot faster.

There are other concerns that make virtiofs less ideal. Aside from slow speed (which is also mentioned by others), users reported memory leaks and other issues/bugs. While Samba isn’t perfect either, it has been quite reliable over the many years I used it.

By design, virtiofs should have some advantages, once performance has improved and the bugs are ironed out. Since I often copy large files or a large volume of data from the Windows guest to the host, I need a fast copy speed between the two. That makes virtiofs currently unsuitable for me.

With regard to Linux guests, virtiofs is far easier to configure and much more performant. As always, YMMV.

Author: Heiko Sieger

The day has 24 hours. If that isn't enough, I also use the night.

Leave a Reply

Your email address will not be published. Required fields are marked *

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