wiki/gofurther/virtiofs.md

70 lines
2.0 KiB
Markdown
Raw Normal View History

2022-08-13 00:16:19 +00:00
---
title: Share a host directory with a guest using virtiofs
description:
published: true
2023-01-24 16:49:39 +00:00
date: 2023-01-24T16:49:37.566Z
2022-08-13 00:16:19 +00:00
tags:
editor: markdown
dateCreated: 2022-08-13T00:16:17.437Z
---
2023-01-24 16:27:18 +00:00
# Sharing a directory
2022-08-13 00:16:19 +00:00
2023-01-24 16:27:18 +00:00
> *As of January 2023, virtio-fs is only available for virtual machines managed by the system libvirt instance (`qemu:///system`)*
{.is-info}
2022-08-13 00:16:19 +00:00
2023-01-24 16:49:39 +00:00
> *As of January 2023, virtio-fs does not feature a read-only mode. Do not share a host directory with an untrusted guest*.
2023-01-24 16:27:18 +00:00
{.is-warning}
2023-01-24 16:49:39 +00:00
[Virtio-fs](https://virtio-fs.gitlab.io/), shorts for virtio shared filesystem, allows you to share a directory located on the host with a guest.
It is designed to be fast and optimized for local usage, when the host and the guest are located on the same physical machine.
2023-01-24 16:27:18 +00:00
## The guest
### Edit XML configuration
* Memory backing needs to be added to the XML definition:
2022-08-13 00:16:19 +00:00
```
<domain type="kvm">
[...]
<memoryBacking>
<source type="memfb"/>
<access mode="shared/>"
</memoryBacking>
[...]
2023-01-24 16:27:18 +00:00
</domain>
2022-08-13 00:16:19 +00:00
```
2023-01-24 16:27:18 +00:00
* A filesystem device has to be added.
2022-08-13 00:16:19 +00:00
```
<domain type="kvm">
[...]
<devices>
[...]
<filesystem type="mount" accessmode="passthrough">
<driver type="virtiofs"/>
2023-01-24 16:27:18 +00:00
<source dir="/mnt/"> # The host directory to be shared with the guest
<target dir="share"/> # Contrary to what the name implies, this is the tag used inside the guest
2022-08-13 00:16:19 +00:00
</filesystem>
[...]
</devices>
[...]
</domain>
2023-01-24 16:27:18 +00:00
```
### Mount the folder inside the guest
* Inside the guest VM, mount the folder using the following commmand to mount the `/mnt` host directory on the guest, using also the `/mnt` point:
`# mount -t virtiofs share /mnt/`
## Resources
* Official website: https://virtio-fs.gitlab.io/index.html#status
* In the context of a Windows guest: https://github.com/virtio-win/kvm-guest-drivers-windows/wiki/VirtIO-FS:-Shared-file-system
2023-01-24 16:49:39 +00:00
* https://wiki.archlinux.org/title/Libvirt#Sharing_data_between_host_and_guest
2023-01-24 16:27:18 +00:00