How share folder in QEMU with plan9/virtfs between MacOS host and Linux guest?
Solution 1:
As of July 2021, Plan 9
and virtfs
are not available in QEMU on macOS.
An alternate method to share folders with read-write access from a macOS host to a Linux VM is to use sshfs
.
Read-write access using SSHFS
- Install
sshfs
on Linux VM. - Allow remote login on macOS host:
System Preferences > Sharing > Remote login
. - Mount macOS directory on Linux VM via:
sshfs user@macos_ip:/Users/user/mydir ~/host_mydir
If you cannot use ssh to access the macOS host you can still share the directory with read-only access using QEMU virtual FAT disk images:
Read-only access using a virtual FAT disk image
- Add directory as a disk image via:
Note: VM will not start without fat:rw:
qemu-system-x86_64 \
-machine type=q35,accel=hvf \
-cpu host \
-hda /images/linux.qcow2 \
-drive file=fat:rw:/Users/user/mydir,format=raw,media=disk
- Mount directory in Linux VM via:
Note: directory will not mount without -o ro
# 'ro' is required to mount directory
sudo mount -t auto -o ro /dev/sdb1 /media
This method has some limitations:
- [never] use non-ASCII filenames
- [never] use “-snapshot” together with “:rw:”
- [never] expect it to work when loadvm’ing
- [never] write to the FAT directory on the host system while accessing it with the guest system