KVM folder sharing between Linux host and Windows guest

Questions about virtualization software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
satimis
Level 3
Level 3
Posts: 111
Joined: Tue Apr 30, 2013 10:43 pm

KVM folder sharing between Linux host and Windows guest

Post by satimis »

Hi all,

Please advise how to share Host folder to Windows guest

KVM
Host - Linuxmint
Guests:
Ubuntu
Debian
Windows 10

I have no problem sharing ~/Home/KVM_Share folder to Ubuntu and Debian guests. But I can't share the same folder to Windows 10 guest. Please advise how to do it. I don't expect running Samba and SSH to share files.

SPICE is not good for sharing large size file.

Please advise. Thanks in advance

Regards
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
jamiebiswas
Level 1
Level 1
Posts: 1
Joined: Thu Feb 03, 2022 4:53 am

Re: KVM folder sharing between Linux host and Windows guest

Post by jamiebiswas »

I am writing down all the things related to KVM folder -

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

Default file managers of both Gnome and KDE desktop environment 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". Basically, I have also wanted to use this Linux host for the best hrms software in Kolkata and all the related things.

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 wherein 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!

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.

Hope this will help you proeprly.
Locked

Return to “Virtual Machines”