I was frustrated with the fact that I didn’t have sufficient knowledge to get 9p working on Windows, but what I did know was how to mount file images as drives in QEMU/KVM…
Then it dawned upon me, if I made a disk image that could be mounted as a loop device to transfer files from the host to the Windows guest when it literally acts as a emulated drive… I found a way to make temporary “virtual flash drives” for those of us unable to build a internal QEMU network with VLANs and Samba shares, and those unable to get 9p working on Windows…
I started with a zeroed out .img file:
dd if=/dev/zero of=(name).img bs=1M seek=4096
to make a 4GB virtual flash disk inside a IMG file.
Next, I used losetup
to mount the image to a loop device:
losetup -L /dev/loop0 (name).img
Then I used GNOME Disk utility (a GUI I was familiar with) to modify the loop device and make partitions and a MBR inside it.
Click on the loop device, then click the hamburger menu and click “Format Disk”. I selected MBR and let it format.
Then it was as simple as adding a NTFS partition and mounting it. I added the files destined for the guest, and unmounted the partition, then detached the loop device. If you wanted to make a read-only HDD, format it FAT32 instead.
Taking that file into QEMU, It’s as simple as reading the .img file as a SATA disk. Boot the VM, and your files will appear in your VM as a “virtual flash disk.” It’s read-write unless you explicitly say it’s read only in the virt-manager config for the drive. Word of caution though, only FAT32 and Virtio work for a read only HDD QEMU config.
HOWEVER. Only one OS can mount the img file at a time. If 2 try at once, you lose ALL the data in the img file. This is why this is more of a “temporary virtual flask drive” than a “permanent virtual flash drive.”
That’s why there’s a checklist you must follow before proceeding to either boot the VM or to mount the loop device:
Before you start the VM:
- Did you unmount the partition in the loop device?
- Did you unmount the loop device?
- Do you pledge to not use Windows’ Disk Management tools?
Before you start mounting the loop device:
- Did you shut down your VM?
- Is QEMU still running?
- Did you fully shut down QEMU? (closing virt-manager by clicking X DOES NOT exit virt-manager or QEMU!)
Failure to follow these precautions will result in the loss of all your data in the “virtual flash drive” according to these instructions.
If you’re in a pinch, and you don’t want to hassle with a virtual network inside QEMU or 9p, this is a solution I found to work well enough for a temporary file transfer between VM and host. It may not be necessary for Duel Booting, but for those of us that use qcow2 images for the Guest OS, this seems to be a better solution if you want to just not hassle with network topography and unpredictable 9p mounts on OSes without fstab.