Share directories from host->guest via qemu:-virtfs, osx:mount_p9 #43

Closed
opened 2025-12-28 23:22:28 +01:00 by adam · 10 comments
Owner

Originally created by @sck on GitHub (Jun 21, 2020).

I was looking into getting NFS working but then I came across this much more convenient way: in the qemu command-line options add:

-virtfs local,path=<path>,mount_tag=<volume name>,security_model=passthrough,id=<id>

(<id> can be the same as <volume name>)

and then in OSX:

10.14# mount_9p # Will automount all the volumes added via -virtfs
10.15# mount_9p <volume name> # Since Catalina the volumes to be mounted need to be named

I think mount_9p was added in Mojave (10.14)

Originally created by @sck on GitHub (Jun 21, 2020). I was looking into getting NFS working but then I came across this much more convenient way: in the qemu command-line options add: ``` -virtfs local,path=<path>,mount_tag=<volume name>,security_model=passthrough,id=<id> ``` (`<id>` can be the same as `<volume name>`) and then in OSX: ``` 10.14# mount_9p # Will automount all the volumes added via -virtfs ``` ``` 10.15# mount_9p <volume name> # Since Catalina the volumes to be mounted need to be named ``` I think mount_9p was added in Mojave (10.14)
adam added the enhancement label 2025-12-28 23:22:28 +01:00
adam closed this issue 2025-12-28 23:22:28 +01:00
Author
Owner

@sickcodes commented on GitHub (Jun 21, 2020):

You can use the

-e EXTRA=“-somearg” to add qemu args

@sickcodes commented on GitHub (Jun 21, 2020): You can use the `-e EXTRA=“-somearg”` to add qemu args
Author
Owner

@sickcodes commented on GitHub (Jul 4, 2020):

This is great btw, can I add this to the repo?

@sickcodes commented on GitHub (Jul 4, 2020): This is great btw, can I add this to the repo?
Author
Owner

@sck commented on GitHub (Jul 4, 2020):

Yeah, this is why I documented it here... I thought NFS is much too complicated to use inside docker, with the required kernel support and all, mount_9p is straightforward. Makes creating build servers much easier, along with the automatic booting from the macos disk https://github.com/sickcodes/Docker-OSX/issues/53 :)

@sck commented on GitHub (Jul 4, 2020): Yeah, this is why I documented it here... I thought NFS is much too complicated to use inside docker, with the required kernel support and all, mount_9p is straightforward. Makes creating build servers much easier, along with the automatic booting from the macos disk https://github.com/sickcodes/Docker-OSX/issues/53 :)
Author
Owner

@sickcodes commented on GitHub (Jul 21, 2020):

Thanks for this btw, just used it myself!

@sickcodes commented on GitHub (Jul 21, 2020): Thanks for this btw, just used it myself!
Author
Owner

@mmausler commented on GitHub (Dec 12, 2020):

For anyone else trying to set up a share directory between guest and host, here is what ended up working for me. I had to add my host directory as a docker volume, then reference the docker volume path in the virtfs command options.

docker run \
--device /dev/kvm \
--device /dev/snd \
-p 50922:10022 \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v /mnt/your_host_local_folder_here:/mnt/hostshare \
-e "DISPLAY=${DISPLAY:-:0.0}" \
-e EXTRA="-virtfs local,path=/mnt/hostshare,mount_tag=hostshare,security_model=passthrough,id=hostshare" \
yourimage

Since the virtfs passthrough uses host permissions on all files in the share directory, you can change the OS X user to the same ID as your host user ID and read/write should work as expected. This post was helpful in that regard
https://www.inteller.net/notes/change-user-id-on-snow-leopard

@mmausler commented on GitHub (Dec 12, 2020): For anyone else trying to set up a share directory between guest and host, here is what ended up working for me. I had to add my host directory as a docker volume, then reference the docker volume path in the virtfs command options. ``` docker run \ --device /dev/kvm \ --device /dev/snd \ -p 50922:10022 \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -v /mnt/your_host_local_folder_here:/mnt/hostshare \ -e "DISPLAY=${DISPLAY:-:0.0}" \ -e EXTRA="-virtfs local,path=/mnt/hostshare,mount_tag=hostshare,security_model=passthrough,id=hostshare" \ yourimage ``` Since the virtfs passthrough uses host permissions on all files in the share directory, you can change the OS X user to the same ID as your host user ID and read/write should work as expected. This post was helpful in that regard https://www.inteller.net/notes/change-user-id-on-snow-leopard
Author
Owner

@coppercash commented on GitHub (Dec 28, 2020):

I tried mount_9p several months ago.
But the performance was disappointing.
I put my source files (an iOS project) on the shared drive, and tried to build from there.
It was obviously much slower than on a native drive.
Even worse, it crashed at some middle point in the building process.
I couldn't find more relative information on the Internet and stopped trying.
I hope it was just my case.
Because directory sharing is so convenient and wanted.

@coppercash commented on GitHub (Dec 28, 2020): I tried `mount_9p` several months ago. But the performance was disappointing. I put my source files (an iOS project) on the shared drive, and tried to build from there. It was obviously much slower than on a native drive. Even worse, it crashed at some middle point in the building process. I couldn't find more relative information on the Internet and stopped trying. I hope it was just my case. Because directory sharing is so convenient and wanted.
Author
Owner

@sickcodes commented on GitHub (Mar 10, 2021):

Working to implement the solutions mentioned in this issue now!

@sickcodes commented on GitHub (Mar 10, 2021): Working to implement the solutions mentioned in this issue now!
Author
Owner

@sickcodes commented on GitHub (Mar 11, 2021):

stat mac_hdd_ng.img
SHARE=/home/user/test/1px/

docker run -it \
    --device /dev/kvm \
    -p 50922:10022 \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -e "DISPLAY=${DISPLAY:-:0.0}" \
    -v "${PWD}/mac_hdd_ng.img:/home/arch/OSX-KVM/mac_hdd_ng.img" \
    -v "${SHARE}:/mnt/hostshare" \
    -e OSX_COMMANDS="echo alpine | sudo -S mount_9p hostshare && /bin/bash" \
    -e EXTRA="-virtfs local,path=/mnt/hostshare,mount_tag=hostshare,security_model=passthrough,id=hostshare" \
    sickcodes/docker-osx:auto

@sickcodes commented on GitHub (Mar 11, 2021): ```bash stat mac_hdd_ng.img SHARE=/home/user/test/1px/ docker run -it \ --device /dev/kvm \ -p 50922:10022 \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -e "DISPLAY=${DISPLAY:-:0.0}" \ -v "${PWD}/mac_hdd_ng.img:/home/arch/OSX-KVM/mac_hdd_ng.img" \ -v "${SHARE}:/mnt/hostshare" \ -e OSX_COMMANDS="echo alpine | sudo -S mount_9p hostshare && /bin/bash" \ -e EXTRA="-virtfs local,path=/mnt/hostshare,mount_tag=hostshare,security_model=passthrough,id=hostshare" \ sickcodes/docker-osx:auto ```
Author
Owner

@gombosg commented on GitHub (Jan 4, 2022):

@sickcodes actually this (https://github.com/sickcodes/Docker-OSX/issues/52#issuecomment-743473409) is very important to get sharing work both ways. Can I create a PR to add a link to the docs?

@gombosg commented on GitHub (Jan 4, 2022): @sickcodes actually this (https://github.com/sickcodes/Docker-OSX/issues/52#issuecomment-743473409) is very important to get sharing work both ways. Can I create a PR to add a link to the docs?
Author
Owner

@manang commented on GitHub (Apr 13, 2022):

I tried to change the uuid of the user from 501 to 1001 (it is the uuid of my user on my host vm). I'm not able to write on the shared disk.
do you know how I can solve it?
Thanks

@manang commented on GitHub (Apr 13, 2022): I tried to change the uuid of the user from 501 to 1001 (it is the uuid of my user on my host vm). I'm not able to write on the shared disk. do you know how I can solve it? Thanks
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Docker-OSX#43