57

Is it possible to use "Filesystem Passthrough" virtual hardware option inside virt-manager to share a folder on my Linux host with my Windows guest? I found some tutorials for how to do this with a Linux guest, but when I try this with my Windows guest I receive the following error message when attempting to start the VM:

Error starting domain: Unable to read from monitor: Connection reset by peer

Traceback (most recent call last):   File "/usr/share/virt-manager/virtManager/asyncjob.py", line 100, in cb_wrapper
    callback(asyncjob, *args, **kwargs)   File "/usr/share/virt-manager/virtManager/asyncjob.py", line 122, in tmpcb
    callback(*args, **kwargs)   File "/usr/share/virt-manager/virtManager/domain.py", line 1210, in startup
    self._backend.create()   File "/usr/lib64/python2.7/site-packages/libvirt.py", line 698, in create
    if ret == -1: raise libvirtError ('virDomainCreate() failed', dom=self)
libvirtError: Unable to read from monitor: Connection reset by peer

I tried sourcing some documentation but all I could find was the official page linking to a FAQ and "some screenshots".

1

10 Answers 10

29

I don't believe this is possible using Windows guests. I usually setup a Samba server on the Linux KVM host and then share a folder out using that to my KVM guests.

Filesystem Passthrough

The documentation on sharing a KVM host's directory with the KVM guests (Linux) is available here on the virt-manager website. The page is titled: Example Sharing Host files with the Guest.

Setting up Samba

The linux-kvm website also contains directions for setting up Samba. That documentation is available here, titled: Tip: How you can share files on your Linux Host with a Windows Guest using Samba.

4
  • thumbs up for the "setting up samba" part. It is the safer approach
    – pqnet
    Commented Aug 7, 2014 at 0:46
  • 2
    @pqnet: could you please qualify how and why it's safer? Commented Jan 15, 2016 at 23:33
  • 5
    @0xC0000022L because it does not depend on the virtualizator being able to trick effectively the guest operating system, which may break if the operating system change. Samba is a network protocol, thus the guest operating system has less expectation on what it can and it cannot do on it.
    – pqnet
    Commented Jan 16, 2016 at 16:56
  • 3
    This doesn't do windows guests Commented Apr 24, 2020 at 18:15
19

Default file managers of both Gnome and KDE desktop environtment can easily access windows shared resources using SMB protocol.
You don't need to install a samba server on Linux host machine because Windows O.S. already comes with built-in samba communication protocols.

Let's say your guest O.S. is "Windows XP" for instance, choose the folder you want to share or just create one for that purpose, e.g. "hostshare" and right click on it -> "properties" -> "sharing" Tab -> select: "Share this folder on the network" and "Allow network user to change my files".

At this point be sure that windows' firewall gives access to shared file and printer resources. Go to "start Menu" -> "settings" -> "Control Panel" -> "windows firewall" -> "Exceptions" Tab -> select: -> "File and Printer Sharing".

Make sure that the Linux host machine can be seen from Windows guest V.M. through the network. So, from windows' command line type: ping 10.0.0.12 where in this case (as an example) "10.0.0.12" is the host IP address; you have to change it to your own. If you do not have echo's responses you'll have to get into troubleshooting that.
And do the same thing from Linux command line: ping -c3 192.168.122.216, where these numbers (as an example) belong to the virt-IP address assigned to the guest V.M.; you must change it to your own.

To get Windows IP address run this command: ipconfig

To get Linux IP address running this commands may help you:

$ ifconfig
$ ip a
$ ip r
$ hostname -I
$ hostname -i

From Linux host machine open "Nautilus" and go to "File" -> "Connect to Server" -> Into "Server Address" box type: smb://192.168.122.216 -> "Connect".
Nautilus window will open with the browseable resources of your windows built-in Samba server. You'll be able to see and access the "hostshare" windows folder's content. That's all!

2
  • 1
    The solution of Andy worked for me, debian host and windows guest. Note that I have the spice-guest-tools installed with a special network driver from redhat. In addition, I had to remove the password protection via smb Here at that link I found how to remove the password pureinfotech.com/setup-network-file-sharing-windows-10 Commented May 9, 2019 at 15:58
  • I must add that it might be a good solution or not, depending on the goal. You might want, for instance, to keep a directory shared in the host with multiple guests to save space and keep guest's storage usage low, and in that case a samba server would be a better solution.
    – Ágatha
    Commented Nov 27, 2021 at 0:36
13

You can now use virtio-fs to achieve efficient sharing of a host-exported filesystem on a guest. It's efficient as it relies on shared memory between host and guest, rather than some networking-based workaround.

Minimum pre-reqs (at time of writing)

  • Host:
    • Kernel 5.4, QEMU 5.0 and libvirt 6.2 and
    • a shared-memory mechanism for the guest's RAM allocation, such as hugepage or file-backed memory.
  • Guest:
    • Linux: kernel 5.4
    • Windows: WinFSP (Windows Filesystem Proxy)

I have successfully deployed it on an Ubuntu 20.10 server hosting a 20.04 guest (this combination meets the minimum pre-reqs above), with RAM backed by hugepage.

Some how-to's

In-depth background presentation

  • "virtio-fs: A Shared File System for Virtual Machines" by Stefan Hajnoczi, Fosdem20 (PDF / full presentation)
2
  • This would be an ideal solution, but I could not get this to run on Windows XP. v2.4 requires the KERNEL32.dll!AcquireSRWLockExclusive API that doesn't exist. v2.2 crashes immediately on startup.
    – simonzack
    Commented Aug 16, 2022 at 10:03
  • That WinFSP link seemed pretty useful but only part of the picture. This blog post takes it further with full instructions for Linux virt manager and Windows guest (although I haven't tried it myself) - blog.sergeantbiggs.net/posts/…
    – icc97
    Commented Jun 12, 2023 at 15:54
11

For a quick and dirty copy, you can also use libguestfs.

Example:

virt-copy-in -a windows10.qcow2 /tmp/data.zip /

This copies the file /tmp/data.zip from your host to the root C:\ directory in the Windows guest image windows10.qcow2.

Do this while the VM is off.

2
  • This was the simplest for me for a couple of files. This is similar to this post Shared Folder in QEMU Between Linux Host and Windows Guest which has more explanation. It seems that virt-copy-in does a combination of guestmount and then guestunmount.
    – icc97
    Commented Jun 12, 2023 at 15:39
  • To find that .qcow2 file, I looked in the GUI Virtual Machine details | SATA Disk 1 | Source path. Mine was /var/lib/libvirt/images/win10.qcow2. I also needed to use sudo so my command was sudo virt-copy-in -a /var/lib/libvirt/images/win10.qcow2 ~/.bashrc / which would copy my .vimrc file to the Windows `C:` root.
    – icc97
    Commented Jun 12, 2023 at 15:48
6

I believe @slm has provided the best answer. HOWEVER, there is another use-case. This alternative is a bit of a hack, though.

Rough guide. Do not consider these definitive commands:

  1. create an image file (ms-dos floppy or ISO-9660 CD)
  2. format the image with a filesystem, e.g. mkfs.msdos
  3. copy and manipulate files on image as needed, such as with mcopy, et al
  4. mount image on Guest VM cd-rom or floppy drive

It's not ideal, but it can work if your Guest VM won't allow network protocol connections between dom0 and Guest (such as during a closed VPN session).

More info here:

https://stackoverflow.com/q/11202706/3407600

4

A read only share is possible (Windows guest has R/W, and Linux host can read only), since Linux host can mount NTFS on loopback device, suppose you use 'raw' type storage for the Windows guest:

Assume you have Win.img as the raw image, it is emulated as a disk.

  • Step 1: Find the offset of your file system (since it is a disk) using fdisk:
$ fdisk -lu Win.img

Disk Win.img: 16.3 GB, 16252928000 bytes
255 heads, 63 sectors/track, 1975 cylinders, total 31744000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x3a793a79

    Device Boot      Start         End      Blocks   Id  System
    Win.img   *          63    31712309    15856123+   7  HPFS/NTFS/exFAT

Now, calculate the offset = 63 x 512 = 32256

  • Step 2: mount it
mount Win.img /mntpoint -o ro,loop,offset=32256

CAUTION

You can mount it RW, and thus Linux can write to it, but your file system will be corrupted! Because both your Linux and Windows are accessing the file system AT THE SAME TIME! They may allocate the same free blocks to write the files they want to write!

Linux read is not stable, in rare cases

With this method the file system is safe, and mostly OK to have stable read. However, as I said, they access the file system at the same time, and thus When windows tries to write something, Linux may not be informed, and thus read something corrupted. However, if you use it carefully, the read should be very stable.

2
  • 4
    How reliable is this? Data can be in caches. Writes will not be atomic with respect to reads on other system. Commented Jan 31, 2015 at 23:52
  • Robin Hsu, that's very quality information about mounting something in non conventional way. Many thanks for that. To ctrl-alt-delor. Well we can always
    – falero80s
    Commented Feb 18, 2021 at 9:11
3

A quick way to let a guest read (but not write to) a file or folder structure is to mount a folder as a cd-rom. This takes a few seconds, and works for both Windows and Linux guests.

  1. mkisofs -o cdrom.iso -R --joliet-long /your/folder/with/your/files

  2. Mount 'cd-rom.iso' in a cd-drive in the virtual machine using virsh-manager (or command-line).

mikisofs creates a cd-rom image containing your folder, including its files and sub-folders. The options -R --joliet-long allow long filenames (up to 146 unicode characters), and posix extensions. If you don't use this, then names may (usually will) be truncated.

If you have deeply nested directories, or even longer filenames, try --iso-level 4, instead of -R, but read the man page for caveats.

Edit: 0xsheepdog has posted the same general method. Thanks to AdminBee for pointing this out. This answer, however, provides essential details, and further, Sheepdog's method needs two extra steps.

2
  • 2
    Welcome to the site, and thank you for your contribution. Please note that this method was already explained in the answer by 0xSheepdog. You may want to edit your post to make it more distinct.
    – AdminBee
    Commented Jul 5, 2021 at 11:51
  • To whoever downvoted. Fine, but why? This is the only answer that actually tells you how to create an iso image. I simply ignore answers that don't bother to give detail, and I would think others do too.
    – freeB
    Commented Jul 7, 2021 at 21:56
3

now we can use spice tools. install spice-webdavd on windows guest

update 2022

now virtiofs based local file sharing is preferred over DAV based approach or other network based approach. vfio has much better performance. same as spice one, it requires windoes guest to install a driver.

1

using ssh.

host: fedora linux

systemctl start sshd

guest: windows 7

winscp

0

I use Dokany+Win-SSHFS to mount remote folders over ssh. Let them to play the catch-up game, not the other way around <evil grin>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .