Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sck opened this issue Jun 21, 2020 · 10 comments
Closed

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

sck opened this issue Jun 21, 2020 · 10 comments
Labels
enhancement New feature or request

Comments

@sck
Copy link

sck commented 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)

@sickcodes
Copy link
Owner

You can use the

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

@sickcodes
Copy link
Owner

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

@sickcodes sickcodes added the enhancement New feature or request label Jul 4, 2020
@sck
Copy link
Author

sck commented 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 #53 :)

@sickcodes
Copy link
Owner

Thanks for this btw, just used it myself!

@mmausler
Copy link

mmausler commented Dec 11, 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

@coppercash
Copy link

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.

@sickcodes
Copy link
Owner

Working to implement the solutions mentioned in this issue now!

@sickcodes
Copy link
Owner

sickcodes commented 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

@gombosg
Copy link

gombosg commented Jan 4, 2022

@sickcodes actually this (#52 (comment)) is very important to get sharing work both ways. Can I create a PR to add a link to the docs?

@manang
Copy link

manang commented 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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants