Running inside QEMU sharing host file system with HassOS

I am running HassOS inside QEMU.
I want to share some paths from the host with Hass. I’ve configured QEMU to share the path:

    <filesystem type='mount' accessmode='passthrough'> 
      <source dir='/media/videos'/> 
      <target dir='host_videos'/> 
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> 

Then I am sshing into HassOS and trying to mount the path:

mount -t virtiofs host_videos /root/media/videos
This gives me the response:

mount: mounting host_videos on /root/media/videos failed: Invalid argument

Running it in verbose mode gives no additional output.

Can anyone spot what I am doing wrong?

Umm… I’ve had this on my list of things to investigate, so your question got me looking into this some.
I haven’t had success yet, but thought I would mention at a high level what I have come across…

Some people have posted solutions using 9p as a filesystem driver instead of virtiofs, but it looks like 9p is now considered old (and best I can tell hassOS doesn’t support it anyway).

Having said that, virtiofs requires a virtiofsd (daemon) running on the host as well as some sort of memory sharing that has to be enabled between guest and host (I think this is for passing file information between guest and host). I use Ubuntu QEMU/KVM, and the virtiofsd is not available until 22.0.4. My “sandbox” system is only running 20.04 so I can’t test this out. Another thing, I believe you have to tell qemu in the XML which “driver” to use so you also need a line like: <driver type='virtiofs' queue='1024'/>. The other thing I haven’t verified is whether hassOS actually supports virtio filesystem, but what playing around I’ve done, it seems to.

Thanks for your reply.
I’ve had another play with this and done a bit more reading.
It appears that the guest OS needs to have version 5.4 of the linux kernel in order to support virtiofs. It seems that HassOS only has version 5.15.

However - it looks like it has been upgraded to 6.1 (5 days ago) so it looks like it will work in the next release :crossed_fingers:

any success ?

Success! I just gave it a try, and functionally, it works better than I expected. The HA container can mount the filesystem too which is what I didn’t expect.

A few details…

  • I recently upgraded by Ubuntu Desktop to 22.04 and this contains the updates needed to run the virtiofs daemon which is needed here.
  • I use virt-manager to manage my VM. With the VM shutdown make the following changes:
    • For the VM… Memory-> tick the “Enable Shared memory”
    • Add New Hardware->Filesystem.
      • Driver: virtoifs,
      • Source path: <local Host directory you want to pass-thru>. Example:/home/tommy/mount4hass
      • Target path: myshare_label
  • Startup the VM

If you don’t use virt-manager, here are the relevant XML entries that virt-manager produced:

<domain type=blah blah>
    <source type='memfd'/>
    <access mode='shared'/>
    <filesystem type='mount' accessmode='passthrough'>
      <driver type='virtiofs'/>
      <binary path='/usr/lib/qemu/virtiofsd'/>
      <source dir='/home/tommy/mount4hass'/>
      <target dir='myshare_label'/>
      <alias name='fs0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
  • Go inside the HA container (from HAOS shell docker exec -it homeassistant /bin/bash):
    • Create a subdirectory under /media. I used mkdir /media/my_passthru
    • mount it: mount -t virtiofs myshare_label /media/my_passthru

From my Ubuntu Desktop I put a jpeg file in /home/tommy/mount4hass/my_pict.jpg
In the HA UI->Media->Local Media->my_passthru I see the my_pict.jpg file and clicking on it it does display the image.

As a note: If you are using Samba share, the /media/my_passthru/ is shown but it will not show the my_pict.jpg file under it.

To make this more permanent, you could create an entry in /etc/fstab, but my guess is this will get blown away each time you upgrade homeassistant. Instead you should be able to execute a shell command at HA startup that executes the mount command (I haven’t tried this).