6

I am trying to share files between Linux host and Windows guest and I came across the link:

Use virt-manager to share files between Linux host and Windows guest?

As suggested in the third answer, I followed the steps:

  1. Find the offset of your file system (since it is a disk) using fdisk:

    $ fdisk -lu Win.img
    
  2. Mount the image using command:

    mount Win.img /mntpoint -o ro,loop,offset=32256
    

Here,this seems to be promising approach. I am able to see the files of Windows guest VM on Linux host. However, I am not able to see any changes on host side if I make changes on guest unless I remount the image again.

Is there anyway to refresh that memory so I can see changes on host side too?

4
  • 4
    Mounting the some file-system on two different systems is dangerous. You can create write inconsistencies, and read problems, like what you are getting. Commented Jan 31, 2015 at 23:47
  • 1
    I would go with the samba answers. Or use virtual-box, as it has a simple file-sharing tool. Commented Jan 31, 2015 at 23:53
  • What user-mode virtualisation system are you using? Commented Jan 31, 2015 at 23:59
  • I have KVM installed on Ubuntu host and using virt-manager to manage Virtual Machines. Commented Feb 9, 2015 at 6:05

5 Answers 5

4

For file share from linux to Windows or vice-versa you can just use WinScp on Windows and try to copy the file to either systems.

3

No, reading the images is not reliable when the disk is in use by the guest.

If you shut the guest down it'll work fine (because no changes will be made).

If you want live access to the files, you have to ask windows nicely, EG: smbmount or share a linux filesystem to the guest using samba. The latter avoids windows file-locking problems which is convenient for things like logfiles.

3

you can simply use OpenSSH for this. In windows guest install WinSCP to remotely access to your Linux server. you can find info about configuring OpenSSH here https://help.ubuntu.com/community/SSH/OpenSSH/Configuring and can download WinSCP from here: http://winscp.net/eng/download.php

0
2

The reason why this is in principle unreliable is caching - likely both in the host kernel and by the guest (both the VM and the OS). In the first case, the host kernel caches the writes and doesn't realize that the data in the VM image file mounted somewhere has changed.

In the latter case, tha VM (me it KVM or something else) will likely cache the writes into the image and only perform the write (i.e. giving the data to the host kernel, which by far doesn't mean the data will get written to the underlying medium, by the way) at a more convenient time. This can be alleviated by requesting the VM to make the writes immediately (for QEMU/KVM see the cache option for the -drive argument in the qemu(1) man page). On top of that, the quest OS does some form of caching as well, so it may take a while before the data hits the Guest/VM boundary at all.

That said, sharing data is usually done via network - your options are numerous. For Windows the obvious option is CIFS/SMB, since that has native guest support. All you need to do is to figure out the approipriate Samba configuration on the host. If you happen to be using QEMU/KVM, it can even do some basic samba sharing for you - see -net user,smb=... (source same as above). You may also set up FTP or WebDAV on your host, although the latter might get a bit trickier than Samba. SSH/SFTP is another option.

Specific to QEMU(/KVM) is the virtual fat, which allows you to export an existing directory - subject to restrictions, be sure to read the "What you should never do" paragraph - as a FAT file system to the guest.

2
  • Thank you very much for the suggestion. I tried to change the caching policy to "no caching" and tried with the command: mount /var/lib/libvirt/images/VM3_Windows7.img /Windows7_VM_files -o ro,loop,offset=105906176. As before, I'm not able to see from the host new files or file changes made by the guest unless I remount the image. So is the caching policy that I have set (cache = none) enough? or if there is any other option related to caching that should also be changed? In my application, I need only to read data in one direction (guest to host) and no write. Thank you, Commented Feb 3, 2015 at 1:17
  • I don't think using the images is the way to go at all - too many uncertainties and things to fiddle with. Either set up Samba/FTP or, if you are using QEMU/KVM and the restrictions imposed by the virtual FAT are ok for you, use that. Neither of those are that complicated. Commented Feb 3, 2015 at 8:14
0

Mounting an image ro is non-destructive; this setup might help you:

sudo losetup -f image_name
dev=$(sudo losetup -j image_name|sed 's/:.*//')
sudo kpartx -av $dev

Partitions will show up under /dev/mapper, for example: loop0p1.

mount -t fs -o ro /dev/mapper/loop0p1 /mnt

To delete, kpartx -d $dev. The losetup code may not be necessary depending on the distro. Use straight kpartx -av image_name ; kpartx -d image_name on Ubuntu.

For the best outcome: use libguestfs. There is a cli shell guestfish part of libguestfs-tools on Ubuntu.

1
  • Hi, I tried to use libguestfs APIs from my host (Linux) to read guest files (Windows VM). I need to do this continuously on just a few files in case they change. Using guestfs_cat(), I am able to read the files of the guest VM from the host, but I cannot read a modified file without doing guestfs_shutdown(), guestfs_close() and then relaunching the image. A modified file seems not to be visible until the shutdown/relaunch combination. Now I'm trying rsync, will that work? I only need to read, and the amount of data is relatively small, about 50 MByte. Commented Feb 7, 2015 at 0:33

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.