How to configure VirtIO FS for Proxmox VE
Create /var/lib/vz/snippets/exec-cmds with the following contents:
#!/bin/bashVMID="$1"ACTION="$2"SLEPT=""vmpid() {cat "/var/run/qemu-server/$VMID.pid"}if_action() {if [[ "$ACTION" == "$1" ]]; thenshifteval "$@"fi}sleep_once() {if [[ -z "$SLEPT" ]]; thensleep 1sSLEPT=1fi}exec_virtiofsd() {echo "Needs virtiofsd for directory $1"/usr/lib/kvm/virtiofsd --socket-path=/run/qemu-server/$VMID-${1/\//}.virtiofsd -o source=$1 -o cache=always --daemonize > /dev/null 2>&1 &}exec_cmds() {while read CMD ARG1 ARG2 REST; docase "$CMD" in"#virtiofsd")if_action pre-start exec_virtiofsd "$ARG1";;esacdone}exec_cmds < "/etc/pve/qemu-server/$1.conf"exit 0
Add a comment to the top of the config to each VM that needs it under /etc/pve/qemu-server/<VMID>.conf. It denotes the directory from the local machine to share.
#virtiofsd /media
args: -chardev socket,id=char0,path=/run/qemu-server/101-media.virtiofsd -device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=/media -object memory-backend-file,id=mem,size=4G,mem-path=/dev/shm,share=on -numa node,memdev=mem# path=/run/qemu-server/101-media.virtiofsd -- '101' should be changed to match the VMID and 'media' should be changed to match the shared directory name without slashes.# size=4G -- should be changed to be equal to the VM's RAM size# tag=/media -- this is used by the VM to mount the correct virtiofs share
Once your VM is booted up, you can test the directory mount with:
mkdir /mnt/tmpmount -t virtiofs /media /mnt/tmp