How to use virtio-fs
In the context of virtualization, it is always convenient to be able to share a directory from the host with the guest.
virtio-fs, also known as vhost-user-fs is a virtual device defined by the VIRTIO specification which allows any VMM to perform filesystem sharing.
Pre-requisites
The daemon
This virtual device relies on the vhost-user protocol, which assumes the backend (device emulation) is handled by a dedicated process running on the host. This daemon is called virtiofsd and needs to be present on the host.
Build virtiofsd
git clone https://gitlab.com/virtio-fs/virtiofsd
pushd virtiofsd
cargo build --release
sudo setcap cap_sys_admin+epi target/release/virtiofsd
Create shared directory
mkdir /tmp/shared_dir
Run virtiofsd
./virtiofsd \
-d \
--socket-path=/tmp/virtiofs \
--shared-dir=/tmp/shared_dir \
--cache=never
The cache=never
option should be the default when using virtiofsd
with the cloud-hypervisor VMM. This prevents from using the guest page cache, which reduces the memory footprint of the guest. When running multiple virtual machines on the same host, this will let the host deal with page cache, which will increase the density of virtual machines which can be launched.
The cache=always
option will allow for the guest page cache to be used, which will increase the memory footprint of the guest. This option should be used only for specific use cases where a single VM is going to be running on a host.
Kernel support
Modern Linux kernels starting (at least v5.10) have support for virtio-fs. Use of older kernels, with additional patches, are not supported.