A recommended way to move data between host and gest? (QEMU)
I'm struggling with setting up a way to move data from my host (with QEMU) to a Windows 7 virtual machine. To do so I'm trying to follow the wiki options in order, but I'm pretty lost and failing to use any of these. So first of all, does any body recommend a particular way (for newbies)?
I wonder if I have a conceptual issue here. Regarding options to "mount a partition inside a raw disk image", I do follow the steps on the loop module and set my disk image as a loopback device (ej. sudo losetup -f -P boxy.img). My first unused loop device is /dev/loop0, and I check that /dev/loop0p0 is created.
I'm confused about the next step. I mount that loopback device on a new directory (ej. sudo mount /dev/loop0p0 ~/new) and init the virtual machine. I was expecting to see a qemu folder in network folders but it isn't (does not this step set the new folder as shared folder for the disk image?).
I don't really know if this last step "mount the disk image with udisksctl" in the wiki is a requirement or not. As far as I understand, the loopback device has already been settled. Even if I run it (ej. udisksctl loop-setup -r -f boxy.img ) I cannot see the qemu folder when I boot the machine. What am I missing?
EDIT Thank you for all your replies. I'm starting trying the method with SMB. I haven't the samba service running in my system and it could be the problem, I will try to fix this first.
EDIT2: After playing a little with SMB this solution works just fine. In the case this post comes to the help of anybody in the future, I will write down the commands I use.
First, the SMB configuration file /etc/samba/smb.conf must include a definition of shared folder. Mine is very basic, and looks like:
[myshare]
path = /home/user/shared_folder
valid users = user
read only = no
After following the first steps in the Wiki (ej. setting the samba user) I start smb and check it with smbclient -L //127.0.0.1/home/user/shared_folder -U user. It works fine. So now I run QEMU with:
qemu-system-x86_64 boxy.img -m 4G -net nic -net user,smb=/home/xiao_ou/VB
An in fact can access to shared_folder from \\10.0.2.4\qemu. It still surprises me how easy it was.
Edited 25 Apr 2019. We only hold this version.
About this post
- Posted
- Archived
- Edited
- Score
- 44 · 100% up
- Kind
- Text
- ID
- bfppd2
24 comments
I typically use the network rather than a pass through mount. If you're using virtio on your NIC, it is incredibly fast.
In M$ guests, I use WinSCP (one could use SMB)
In Linux, you can use SSHFS or NFS.
Edit: Protip, there is a package called virtio-win that has Windows drivers for all the virtio devices. Totally worth it:
https://aur.archlinux.org/packages/virtio-win/
Same here, I've found WinSCP to be a much simpler solution than fiddling with a mount or with samba.
Windows 10 has OpenSSH built-in as well.
Yep, the Virtio NIC's might say 1GBit but they aren't actually hardware limited. I can easily get full hardware speed over NFS between host and guest OOTB.
Hehe, fun fact - the Intel? Realtek? one that is also in libvirt also doesn't limit to 1G :P
Try the samba way. It's simpler.
I tried this exact command, but it does not work either, even with netbios enabled and the firewall disabled in the Windows machine. I can only see the typical "USER-PC" directory in network folders, not a qemu directory.
Make suure you have samba installed. Mount your whole home directory to test (
/home/username). Then in windows go to\\10.0.2.4which i think is the default mountin point of samba with qemu.First, about the recommendation, I usually use losetup, as you are trying to use. I find it easier and faster. But there are some limitations. The vm must be turned off, and its easier when your vm is raw rather than qcow (although it seems to be possible for qcow disks). I should also note that if you know how to deal with networking, it can be a nice way too, but usually takes a little more time to set up.
About your specific issue, you seem to have created the loop device right. You just seem to don’t know what to do with it. The idea is to use the loop device as any other disk in your host machine. For example, if you plug a usb, it will probably be named /dev/sdb. If you want write or read files from usb, you can mount it, for example:
And then you can access /mnt and it will have your usb files.
The idea is the same for the loop device. When you use loosetup command from the wiki, you are creating a device for every partition on your vm disk. You can then mount these loop devices and operate on them, as if they were another drive plugged to your pc. But this all needs to happen while the vm is turned off. Actualy there is a warning in the wiki page you linked saying: “ You must make sure to unmount the partitions before running the virtual machine again. Otherwise, data corruption is very likely to occur”. So I hope you haven’t lost data.
Also, udiskctl is not needed. It seems to be just another way to mount the vm disk, I personally never used it.
Edit: spelling
you've probably seen all the replies already, but SSH is the easiest way to go, for both windows and linux guests (some extra software required for windows).
QEMU exposes the host at a specific IP address inside the guest (check the wiki), so just enable sshd on the host and ssh to that address.
I installed FreeSSHD in my Windows 7 machine as SSH server. When I initiate it with:
I check that the server is running. When I run
ssh guest_user@localhost -p10022, I'm asked for a key (which is none) and then for guest_user@localhost password, and is this step where I'm stacked here. I have disabled authentication in FreeSSHD, but I still fail to authenticate, a password is set, and is not the user's.EDIT I just noticed that no matter how many times I disable authentication in FreeSSHD, It will return to "allowed". In any case, I have not set any password
are you trying to ssh into the guest, or out of it? The solution I described allows you to SSH out of the guest into the host. (which allows you bidirectional data transfer either way)
The way I achieved this was by configuring Samba on the Linux host with the desired shares and setting it to only listen on the virbr0 interface (so I do not expose the shares to whatever network I'm connected to). Then, on the guests, I can access these shares from \\192.168.122.1 (network mode for the VM is NAT)
One important thing to note is that if you're using the MACVTAP driver to connect your VM to the same network as the host, the host will not be able to communicate with the VM via said network and vice versa.
I'm using a macvtap device due to my wireless connection. In order to has communication between host and guest, I created an isolated network, did some iptables rules then everything went OK.
Sshfs
You need to tweak Windows 10 to work with Samba. Dumb down to 56-bit encryption and something else I can't remember. This isn't QEMU specific. Windows 10 broke backwards compatibility with current versions of Samba.
The guest is Windows 7. I noticed that samba service is not running in my system, I will try to fix this. In any case, Is this step necessary also for Windows 7 or just Windows 10?
As memory serves, you'll need to make some adjustments to Windows 7 as well. You'll find tons of people who had working Linux/Samba setups that upgraded beyond XP, and ran into the same sorts of issues. Follow their solutions.
Also, if your virtual environment networking is using NAT, you're going to have trouble. I always choose to bridge, and allow the VM to pull DHCP from the same place as the host. That way they're all on the same subnet.
Can you pass data through ssh? Via scp?
I come to try this option by installing FreeSSHD in the guest, but no luck. The server runs in Windows but when I try to ssh I get a connection refused error.
You could also use syncthing of you end up sticking with user mode networking. I've found it to be overall easier since I already use it for other purposes.
RDP allows pushing a virtual folder through the link, works without further setup if you have RDP on the guest.