qemus / qemu-docker

QEMU in a Docker container.
MIT License
485 stars 58 forks source link

[Question]: How can I share a folder from my host system with a guest virtual machine running in QEMU ? #590

Open DartSteven opened 2 months ago

DartSteven commented 2 months ago

Is your question not already answered in the FAQ?

Is this a general question and not a technical issue?

Question

Hi,

I would like to share a folder from my host system with a guest virtual machine running in QEMU. I’ve been trying to find the right way to do this, but I haven’t been able to get it to work. Could you please provide a step-by-step guide on how to properly share a host folder with a guest VM?

Specifically, I tried using the following command:

volumes:

Could you please guide me on how to correctly set up folder sharing between the host and the guest? Any help would be greatly appreciated!

Thank you!

EagAnarchy commented 1 month ago

could you tell how you are trying to achieve this? (Network sharing or just sharing offline?)

DartSteven commented 1 month ago

could you tell how you are trying to achieve this? (Network sharing or just sharing offline?)

Sure! My idea is to use your fantastic project to run “Roon-Server.” You can check it out here: https://roon.app/. More specifically, the image to download is this one: https://download.roonlabs.net/builds/roonbox-linuxx64-nuc4-usb-factoryreset.img.gz. It is listed in this guide, section 3 “Download”: https://help.roonlabs.com/portal/en/kb/articles/rock-install-guide#3_Download.

In short, this is audio software for listening to music. My music is stored on a partition on my host, and the backup folder (which the application interacts with for regular backups) is also on a partition on my host. I would like to be able to pass these two directories (for example, /media/lvm/data/Music and /media/lvm/backup) to the virtual machine.

fizzyduck commented 1 month ago

Might there be some way to use QEMU's 9pfs to achieve this?

DartSteven commented 1 month ago

Might there be some way to use QEMU's 9pfs to achieve this?

yes but how? i tried but always nothing comes from host to guest

fizzyduck commented 1 month ago

The way I am doing this is:

  1. Ensure that your guest has 9pfs support compiled in or available as a kernel module
  2. Add a volume in docker-compose.yml so that qemu will have access to your host's FS via a bind mount:
    volumes:
      - /mnt/shared:/mnt/shared
  3. Add an ARGUMENT parameter to the environment section of docker-compose.yml:
    environment:
       ARGUMENTS: "-fsdev local,id=fsdev0,path=/mnt/shared,security_model=none -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=host_share"
  4. Boot the guest and then attempt to mount the shared location:
    mount -t 9p -o trans=virtio host_share /mnt/guest_mountpoint

    I have just tested this and it appears to work as expected.

fizzyduck commented 1 month ago

What would be good is to put this in the main readme ;)