[TUTORIAL] Proxmox 8.4 - VIRTIOFS (virtiofs) - Shared Host folder for Linux and/or Windows Guest VMs

slipperyduck

Member
Feb 3, 2021
3
0
21
50
USING VIRTIO-FS ON PROXMOX TO GUESTS

Since Proxmox 8.4 you can now user VIRTIOFS to share HOST directories with Guest VMs and its stable.
Lets run though how to do this. I couldn't find a tutorial or guide online anywhere, so I made one myself.
Hope this helps someone out there.

Option 1 - Create shared folder for Linux Guests
Option 2 - Create shared folder for Windows Guests

OPTION 1 - LINUX GUEST

On Proxmox go to your shell(console) and create a folder that you want to share.
eg: mkdir /mnt/linuxguest

In my case I am using ZFS so I will create a new Dataset on my ZFS pool, set the attributes and share that instead.
My ZFS Poolname is hyper1, here are my commands to create the new dataset and set the attributes for Linux systems:

Code:
zfs create hyper1/hypershare
** note you can list the default attributes (which are inherited from the pool itself) with the command:
** zfs get all hyper1/hypershare

Now I will set xattr (enables extended attributes), acltype (so we can set file/folder permissions), atime (timestamp when a file is accessed)
and sync options.
**Note sync disabled essentially disables write cache through the ZIL and writes directly - AKA Direct IO - this helps with speed but is
a bit more risky i.e. powerloss can incur dataloss (the thing that ZFS helps to prevent essentially), in my case this data is not mission critical
and I prefer the performance.

Code:
zfs set xattr=sa hyper1/hypershare
zfs set acltype=posixacl hyper1/hypershare
zfs set sync=disabled hyper1/hypershare
zfs set atime=off hyper1/hypershare
zfs set mountpoint=/hyper1/hypershare hyper1/hypershare
**NOTE mountpoint is generally automatically added when you create the dataset, but I list it here just in case it doesnt get set.

Now that this is all set and created, we go to the PROXMOX WEBUI
Navigate to: [Datacenter] --> [Directory Mappings] this is near the bottom of that panel and NOT storage where you can set directories (to avoid confusion)

At the top click the [Add] button
Give your share Name (Also known as a TAG - which is how you refer to it inside the Guest) and set the path my eg:
Name: HYPERSHARE Path: /hyper1/hypershare
and click [Create]

NOW CLICK ON YOUR GUEST --> [Hardware] The click [Add] the dropdown at the bottom will have Virtiofs, click on that to add it.
You can then click on the Directory ID and select your newly create Directory(TAG) and tick needed Attribute boxes
as appropriate to your setup, mine i tick all three, then click [Add]

Now last thing to do quickly is install the extended ACL tools on proxmox, go to the SHELL(CONSOLE) and install it with:

Code:
apt install acl

by default root already has all permissions to the created dataset folder, but if you use Linux guests responsibly
then you will be using a non-root user, so I now want to add the first user created which numerically is user 1000.
So I will run the following command to make sure this user has all the permissions needed to workin in this folder:

Code:
setfacl -R -m u:1000:rwx /hyper1/hypershare
**Note this applies to a NON-ZFS Dataset folder or simple folder share too.

Fire up your guest and login. Mine is a Debian 12 guest and I'm loggin in with my non-root user.
VirtioFS is built in to the Debian 12 kernel, so no need to install additional software.
** Note if you do not have sudo installed (Debian), login as root on your console, do an: apt install sudo
** then add your user to the sudo group with: adduser myusername sudo
** then logout and login with your user, where you will now be able to run commands with sudo

You need to create a folder that will map and mount to this share, first create a folder eg:

Code:
sudo mkdir /mnt/hypershare
Next we will mount the proxmox virtiofs share to this folder with mount -t virtiofs TAG /mountpoint, so mine would be:

Code:
sudo mount -t virtiofs HYPERSHARE /mnt/hypershare
Now this just mounts it in userspace, so to make sure it mounts at boot up time of the VM edit the fstab and add it with:

Code:
sudo nano /etc/fstab
at the bottom add your mount with your own TAG and mountpoint, but my example is:

Code:
HYPERSHARE /mnt/hypershare virtiofs defaults,nofail 0 0
**Note the nofail option set - so if the VIRTIOFS on the host is not available for whatever reason this doesnt halt your guest
or prevent bootup completion.

Thats it you should now use this storage as you see fit, mount it with multiple guests for a nice shared storage that doesnt
rely on a network service, very handy indeed.


OPTION 2 - WINDOWS GUEST

I recommend creating an entirely different shared folder for Windows Guest. Windows Permission structure is not the same
as a Linux one and Windows is Case Insensitive too.
This can pose a problem if you have ext4 format as the default format options for ext4 is casefold off.

Credit to original work by: Daniel on StackExchange
https://unix.stackexchange.com/ques...lesystem-option-of-the-root-partition-if-i-on

I have modified Daniels method since a Default Proxmox formatted disk Uses EXT4 formatted LVM instead of a raw device, luckily Tune2fs supports using logical devices with the -l flag. So I below is the way we can do this.

First we need to create a script that turns on the option to use casefold with ext4 on our LVM root partition at boot, make it executable and then update initramfs to include this script at boot.

I use nano to edit, so here is the file I create with nano:

nano /usr/share/initramfs-tools/scripts/local-premount/ext4_casefold
Code:
#
# ext4_casefold
#
# initrd script to add the casefold option to the root filesystem
#

DEVICE=/dev/mapper/pve-root

prereqs()
{
    . /usr/share/initramfs-tools/hook-functions
    copy_exec /usr/sbin/tune2fs usr/sbin/tune2fs
}

case $1 in
# get pre-requisites
prereqs)
        prereqs
        exit 0
        ;;
esac

echo "Adding casefold option to $DEVICE"
sleep 5
/usr/sbin/tune2fs -O casefold -l $DEVICE
echo "If everything went well, we added the casefold option to $DEVICE"
sleep 5

Now add the executable attribute to your file with:
Code:
chmod a+x /usr/share/initramfs-tools/scripts/local-premount/ext4_casefold

Now update the boot environment:
Code:
update-initramfs -u

Once it completes the boot environment update you can reboot.

To test if it has worked open a PROXMOX shell make a directory and set the -F (the attribute that sets something to case-insensitive):
Code:
mkdir myfolder
chattr +F myfolder

If you get the error "chattr: Operation not supported while setting flags" that means casefolding is not enabled.
Otherwise your chattr command will just work.

If you want to test, go into your folder create a file with a name with upper and lowercase characters and do the same with all lowercase, if you end up with two files, then your folder is still case-sensitive, if only one file is listed then case-insensitivity is enabled and working.

for example:

Code:
cd myfolder
root@pve:~/myfolder# touch Welcome
root@pve:~/myfolder# ls -l
total 0
-rw-r--r-- 1 root root 0 Jun 17 10:05 Welcome
root@pve:~/myfolder# touch welcome
root@pve:~/myfolder# ls -l
total 0
-rw-r--r-- 1 root root 0 Jun 17 10:05 Welcome
root@pve:~/myfolder#

However, in my case where I use ZFS I have a pool that was built for Linux, some attributes that are inherited such as case-sensitivity
become read-only, so I will have to create a new dataset for Windows Guests with the appropriate options set explicitly at creation:

Code:
zfs create -o casesensitivity=insensitive -o normalization=formD hyper1/winshare

zfs set xattr=sa hyper1/winshare
zfs set acltype=posixacl hyper1/winshare
zfs set atime=off hyper1/winshare
zfs set relatime=off hyper1/winshare
zfs set sync=disabled hyper1/winshare

NOW CLICK ON YOUR GUEST --> [Hardware] The click [Add] the dropdown at the bottom will have Virtiofs, click on that to add it.
You can then click on the Directory ID and select your newly create Directory(TAG)
tick ONLY XATTR SUPPORT AND ALLOW DIRECT IO, then click [Add]

On Windows you will need to install the virtiofs driver, just mount that virtio iso image that you used to setup windows again.
Then open the CD/DVD Drive in exporer and re-run virtio-win-gt-x64.msi again if needed.
you will also need to download WINFSP you can it from https://winfsp.dev/rel/

Make sure to install WINFSP with CORE & DEVELOPER options

The last thing is then to start the VirtioFS Service in windows and a Z: drive will automatically be mapped to your
Host drive

Either go to settings and search for services or run services.msc
look for VirtIO-FS Service - double click it and set to automatic, then click start

thats it - all up and running.

You can repeat the WINFSP across multiple Windows machine, again for a handy non-network based shared filestore
for all your Windows guests.
 
Last edited: