Virtiofs with Proxmox
Using virtio fs inside a Virtual Machine with Proxmox.
System.d template
file: /usr/lib/systemd/system/[email protected]
1[Unit]
2Description = start virtio-fs daemon for vm %i fs tank
3After = network.target
4
5[Service]
6Type=simple
7# Another Type: forking
8User=root
9Group=kvm
10
11ExecStart=/usr/lib/kvm/virtiofsd --socket-path=/var/run/vm-%i-vhost-fs.sock -o source=/tank -o cache=always -o xattr
12# -o writeback
13Restart=on-failure
14# Other restart options: always, on-abort, etc
15# The install section is needed to use
16# `systemctl enable` to start on boot
17# For a user service that you want to enable
18# and start automatically, use `default.target`
19# For system level services, use `multi-user.target`
20[Install]
21WantedBy=multi-user.target
Usage
the parameter being passing in 102
is the VM id from proxmox, this become %i
in the systemd
template.
the --now
will start the new service immediately.
1
2systemctl enable virtiofs-tank@ 102 --now
VM Configuration
What needs to be added to your VM configuration is the following line
1args: -chardev socket,id=char0,path=/var/run/vm-102-vhost-fs.sock -device vhost-user-fs-pci,chardev=char0,tag=tank -object memory-backend-memfd,id=mem,size=32048M,share=on -numa node,memdev=mem
Parameter | Description |
---|---|
path | Path to the socket file to be used by the vm |
tag | tag to be used with in the VM in the fstab |
The size
option much exactly match the VM memory
size.
File: /etc/pve/qemu-server/102.conf
1args: -chardev socket,id=char0,path=/var/run/vm-102-vhost-fs.sock -device vhost-user-fs-pci,chardev=char0,tag=tank -object memory-backend-memfd,id=mem,size=32048M,share=on -numa node,memdev=mem
2boot: order=ide2;ide0;net0
3cores: 16
4ide0: zfs-pve:vm-102-disk-1,size=125G
5ide2: none,media=cdrom
6memory: 32048
7name: kube-1
8net0: virtio=62:46:28:94:78:DC,bridge=vmbr0
9numa: 0
10onboot: 1
11ostype: l26
12scsihw: virtio-scsi-pci
13smbios1: uuid=4600c4d6-fa0f-4f1f-ab69-4275b3d2fefb
14sockets: 1
15unused1: zfs-pve:vm-102-disk-0
16vmgenid: 40fc7f94-6645-48ac-ba98-34492335b7e5
Linux Guest
File: /etc/fstab
1tank /tank virtiofs rw 0 0
Windows Guest
Install WinFsp
https://github.com/billziss-gh/winfsp/releases
Install VirtIo
https://github.com/virtio-win/virtio-win-pkg-scripts/blob/master/README.md
Open up devices manager and find Mass Storage Device and update drive from VirtIO eg E:\viofs\w10\amd64
Copy the Virtio folder to the local hard drive, we will need this for the Windows Service we are creating.
I placed mine in C:\VirtIo
sc create VirtioFsSvc binpath="C:\VirtIo\virtiofs.exe -m T" start=auto depend="WinFsp.Launcher/VirtioFsDrv" DisplayName="Virtio FS Service"
TODO
One thing that still needs to be added is create VM hooks to auto start the corresponding systemd service since when a VM is shutdown it disconnects from the socket and the service stops.