Use QEMU's 9pfs to Share Directores on macOS with Linux Guest
Contents
The previous post Run Ubuntu in QEMU on macOS (Apple Silicon) instructed us how to run Ubuntu in QEMU on macOS. Under some scenarios, we want to share directories on macOS with the Ubuntu guest for the sake of data exchange. This post is a guide to do so.
Add the following options to the command
qemu-system-aarch64.1 2 3 4 5-virtfs local,path=/some/path/on/macos,mount_tag=some_mount_tag,security_model=mapped ## Example: ## Share /tmp/virtfs on macOS with Ubuntu guest and name the mount_tag virtfs. # -virtfs local,path=/tmp/virtfs,mount_tag=virtfs,security_model=mappedAfter booting the virtual machine, execute the following command to mount the path.
1 2 3 4 5 6sudo mount -t 9p -o trans=virtio,msize=524288 some_mount_tag /some/mount/point/on/linux ## Example: ## On Ubuntu # mkdir /tmp/virtfs # sudo mount -t 9p -o trans=virtio,msize=524288 virtfs /tmp/virtfsIf the step
2is executed successfully, we can use the commandmountto check whether the 9pfs is mounted successfully.1 2 3 4 5 6 7 8 9 10# Example: # We should see the virtfs is mounted on /tmp/virtfs with type 9p. $ mount sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) udev on /dev type devtmpfs (rw,nosuid,relatime,size=1928632k,nr_inodes=482158,mode=755,inode64) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) ... virtfs on /tmp/virtfs type 9p (rw,relatime,sync,dirsync,access=client,msize=512000,trans=virtio)(Optional) We can modify
/etc/fstabto persist the mount point by adding the following line to/etc/fstab.1 2 3 4some_mount_tag /some/mount/point/on/linux 9p _netdev,trans=virtio,msize=524288 0 0 ## Example: # virtfs /tmp/virtfs 9p _netdev,trans=virtio,msize=524288 0 0
References
Author Adonis Ling
LastMod 2023-06-27 (edd3392)