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

Add support for mounting a shared folder between the host and guest via virtiofs (v2) #93

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

nathanchance
Copy link
Member

virtiofs, available in QEMU 5.2 or newer and Linux guests 5.4 or newer,
is a more modern way to pass local folders along to QEMU, as it takes
advantage of the fact that the folders are on the same machine as the
hypervisor.

To use virtiofs, we first need to find and run virtiofsd, which has two
different implementations: a C implementation included with QEMU up until
8.0 (available on most distros) and a standalone Rust implementation
available on GitLab (not packaged on many distros but easy to build and
install). Once we find it, we run it in the background and connect to it
using some QEMU parameters, which were shamelessly taken from the
official virtiofs website:

https://virtio-fs.gitlab.io/howto-qemu.html

To use it within the guest (you can use a different path than
/mnt/shared but mount -t virtio shared must be used):

  # mkdir /mnt/shared
  # mount -t virtiofs shared /mnt/shared
  # echo "$(uname -a)" >/mnt/shared/foo

On the host:

  $ cat shared/foo
  Linux (none) 6.1.0-rc8-next-20221207 #2 SMP PREEMPT Wed Dec  7 14:56:03 MST 2022 aarch64 GNU/Linux

This does require guest kernel support (CONFIG_VIRTIO_FS=y), otherwise it will
not work inside the guest; the script warns when there is a possibility this
configuration is not set so the user is not surprised by the following error:

  / # mount -t virtiofs shared /mnt/shared
  mount: mounting shared on /mnt/shared failed: No such device

Closes: #81
Link: https://gitlab.com/virtio-fs/virtiofsd

This will come in handy in trying to warn people when they are missing
configurations needed for certain features.

Signed-off-by: Nathan Chancellor <[email protected]>
…rtiofs

virtiofs, available in QEMU 5.2 or newer and Linux guests 5.4 or newer,
is a more modern way to pass local folders along to QEMU, as it takes
advantage of the fact that the folders are on the same machine as the
hypervisor.

To use virtiofs, we first need to find and run virtiofsd, which has two
different implementations: a C implementation included with QEMU up until
8.0 (available on most distros) and a standalone Rust implementation
available on GitLab (not packaged on many distros but easy to build and
install). Once we find it, we run it in the background and connect to it
using some QEMU parameters, which were shamelessly taken from the
official virtiofs website:

https://virtio-fs.gitlab.io/howto-qemu.html

To use it within the guest (you can use a different path than
/mnt/shared but 'mount -t virtio shared' must be used):

  # mkdir /mnt/shared
  # mount -t virtiofs shared /mnt/shared
  # echo "$(uname -a)" >/mnt/shared/foo

On the host:

  $ cat shared/foo
  Linux (none) 6.1.0-rc8-next-20221207 ClangBuiltLinux#2 SMP PREEMPT Wed Dec  7 14:56:03 MST 2022 aarch64 GNU/Linux

This does require guest kernel support (CONFIG_VIRTIO_FS=y), otherwise
it will not work inside the guest:

  / # mount -t virtiofs shared /mnt/shared
  mount: mounting shared on /mnt/shared failed: No such device

Closes: ClangBuiltLinux#81
Link: https://gitlab.com/virtio-fs/virtiofsd
Signed-off-by: Nathan Chancellor <[email protected]>
…mentations of virtiofsd

In at least virtiofsd 1.6.1 (the Rust implementation), the '-o' options
warn that they are deprecated and the '--help' text agrees:

  [2023-07-19T19:32:50Z WARN  virtiofsd] Use of deprecated option format '-o': Please specify options without it (e.g., '--cache auto' instead of '-o cache=auto')

  -o <compat-options>...
          Options in a format compatible with the legacy implementation [deprecated]

To defend against a release removing the deprecated option and breaking
the invocation, maintain two sets of arguments depending on what
implementation is being used. This allows us to drop support for the C
implementation once the Rust one is more widely available in
distributions.

Signed-off-by: Nathan Chancellor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

automate fs share between host+guest
1 participant