VirtioFS host folder into VM with fstab automount
GOAL
Share a host folder from UGOS Pro into a Linux VM using virtiofs, and have it mounted via /etc/fstab without breaking boot. We also use bindfs inside the VM so your VM user has correct read/write permissions, and files created inside the VM map correctly to UGOS's user and "admin" group (GID 10).
WARNING
This guide was written for UGOS Pro only, and was last tested with the version 1.13.x
1. On the UGOS host: add virtiofs to the VM
SSH into the UGOS host and become root:
bashssh root@<ugos-host>- or ssh <username>@<ugos-host> then:
bashsudo -i # if sudo exists, otherwise use whatever UGOS provides for rootFind your VM name in libvirt:
bashvirsh list --allNOTE
The Name will be in the format of a UUID, e.g. "f229f5ce-b904-4027-a50b-ba24b1d8e2ea"
Dump the VM XML to a temp file:
bashvirsh dumpxml <vm-name> > /tmp/vm-config.xmlEdit
/tmp/vm-config.xmland add shared memory backing at top level (as a direct child of<domain>, not inside<devices>):xml<memoryBacking> <access mode='shared'/> <source type='memfd'/> </memoryBacking>Place it anywhere before
<devices>, as long as it’s a sibling of<memory>,<vcpu>,<devices>, etc.In the same XML file, inside the
<devices>section, add afilesystemblock:NOTE
Modify the
/volume1/projectspath below to the full path of your shared folder. You can rename the 'tag' in the<target dir=...>field too; remember this tag for later.xml<devices> ... <filesystem type='mount' accessmode='passthrough'> <driver type='virtiofs'/> <source dir='/volume1/projects'/> <target dir='projects-fs'/> </filesystem> ... </devices>- Replace
/volume1/projectswith the host path you want to mount. - The
<target dir='projects-fs'/>string is the tag the VM will mount. Remember this tag exactly (case‑sensitive).
- Replace
Redefine the VM from the modified XML:
bashvirsh define /tmp/vm-config.xmlRestart the VM so the new config is applied:
bashvirsh shutdown <vm-name> virsh start <vm-name>
2. Inside the VM: Install bindfs and create mount points
Because UGOS forces passthrough access mode for virtiofs, the mount will show up owned by root:root with strict permissions. We use bindfs to remap this safely for your normal user without modifying the host.
Log into the VM (console or SSH).
Install
bindfs(Debian/Ubuntu example):bashsudo apt update sudo apt install bindfsCreate two mount points (one raw/hidden, and one for your user):
bashsudo mkdir -p /mnt/.projects-raw sudo mkdir -p /mnt/projectsprojects-fsmust exactly match the<target dir='...'/>tag in the VM XML.- If this works and
/mnt/projectsshows the host files, proceed to edit/etc/fstabfor automount, otherwise fix the issue before continuing.
3. Configure fstab with virtiofs and bindfs
We will mount the raw virtiofs share to the hidden folder, then use bindfs to present it to the final folder with the correct user permissions.
Edit
/etc/fstabin the VM:bashsudo nano /etc/fstabAdd these two lines. (Assume your VM user's UID is
1000, and UGOS expects files to be created with group "admin", which is GID10):NOTE
It works best if the USERNAME inside your VM matches the USERNAME in UGOS that you want to have ownership of the files created inside this folder.
NOTE
If you don't know the UID of your VM user, run this command:
id $USER. The admin GID of 10 is required by UGOS, please don't change that.fstab# 1. Mount raw virtiofs to a hidden staging folder projects-fs /mnt/.projects-raw virtiofs nofail,x-systemd.automount,x-systemd.device-timeout=10 0 0 # 2. Use bindfs to remap ownership and permissions to your user bindfs#/mnt/.projects-raw /mnt/projects fuse force-user=1000,force-group=1000,create-as-user,create-for-group=10,chown-ignore,chgrp-ignore,perms=0770,nofail,x-systemd.requires=/mnt/.projects-raw 0 0What these flags do:
x-systemd.automount: Defers mounting until first access so it doesn't break VM boot timing.force-user=1000,force-group=1000,perms=0770: Makes/mnt/projectscompletely readable/writable by your VM user (UID/GID 1000).create-as-user,create-for-group=10: Ensures files created by your VM user map correctly to your host user and the UGOSadmingroup (GID 10).chown-ignore,chgrp-ignore: Prevents permission errors when the VM OS attempts to change ownership on the FUSE mount.
Reload systemd units so the new fstab is recognized:
bashsudo systemctl daemon-reload
4. Verify automount works
Trigger the automount by accessing the raw folder, then mount the bindfs layer:
- (Alternatively, just reboot the VM).
bashls /mnt/.projects-raw sudo mount /mnt/projectsVerify ownership:
bashls -ld /mnt/projects- It should now show
drwxrwx--- youruser yourgroup ... /mnt/projects.
- It should now show
Optional: confirm with
mount:bashmount | grep projects-fs- or:
bashmount | grep /mnt/projects- You should see a line showing
projects-fsmounted on/mnt/projectswith typevirtiofs.
Test file creation:
As your non-root user, create a file:
bashtouch /mnt/projects/test-file.txt- If you check this file on the UGOS host via SSH (
ls -l /volume1/projects/test-file.txt), it will correctly show as owned by your UGOS user and theadmingroup.
- If you check this file on the UGOS host via SSH (
5. Common gotchas to double‑check
- The tag in fstab (
projects-fs) must exactly match the<target dir='...'/>tag in the VM XML. - If you ever edit the VM via the UGOS GUI, you may lose the
<filesystem>block. If the mount suddenly fails, re‑add the XML block and restart the VM.
Credit
This guide was created by Drauku