Mount remote smb share on hassio

I missed this when it first came up in May.

If I read this correctly, I think Fantu was originally asking if there’s a way to mount an external device, like a NAS, to HA. We already know HA can offer an SMB share to other devices. It would be great to be able to go the other way.

For example, HA collects some data about my heating and cooling systems and stores them in a file I can analyze later on another device. Right now I have to store those files on my Raspberry Pi running HA (on Hass.io) then move them to my NAS for long-term storage.

It would make more sense for my automations to save directly to the NAS.

I was a little surprised to find that this not built in to HA, or at least an optional add-on.

8 Likes

I’m facing this same issue right now. I need to mount an SMB (an external drive connected to my router) to my hassio and, to my surprise, there seems to be no solution. Any solution in sight?

Thanks!

1 Like

Have you trying that?
Im getting the following when im trying to load a module.

~ $ modprobe cifs
modprobe: can’t change directory to ‘/lib/modules’: No such file or directory
~ $ cd /lib/modules
-bash: cd: /lib/modules: No such file or directory

This is precisely what I’m trying to accomplish. The ultimate goal is to allow recording of camera streams and snapshots of cameras to be saved to and stored on a NAS on my network running smb/cifs . I would greatly appreciate any insight others might be able to contribute towards a solution.

2 Likes

Wow just stumbled here and have this exact need (download streams and I have a recursive auto-delete for older than X days). I just migrated from HA Core install (directly in Ubuntu using pip3 command) onto Hass.io and I cannot get the downloader HA component to work. On my HA Core it obviously works because /etc/fstab has the proper CIFS mapping to my NAS. In Hass.io I still have the issue and tried desperate things like tweaking the homeassistant docker config.v2.json file to add the mount point (docker mount point hack which definitely works)… so far it completely blew up the Hass.io (supervised) install and I had a hard time getting Samba add-in to work again. Had to stop the supervisor service and remove all docker containers and start over — but it didn’t whack the config folder.

I’ll keep messing with fstab and possibly settle on an NFS share — but completely agree with you that access to any parent machine folders or even remote hosts is a must.

I’ll respond to myself as it’s the only workaround I found with the supervised hass.io… basically use HA to run an automation (shell command) to mount NFS — because CIFS would not cut it. Thankfully my QNAP was simple enough to enable permissive NFS access.

Here are things that failed:

  • Using rc.local
  • Using fstab
  • Mounting CIFS in the homeassistant Docker container

This NFS mount worked and it runs after Home Assistant starts:

configuration.yaml

shell_command:
  map_nas_video_folder: mount 192.168.0.100:/_NASVIDEO /mnt/_NASVIDEO

automation.yaml

- alias: Map NFS Drive to HassIO
  id: map_nfs_drive_to_hassio
  initial_state: 'on'
  trigger:
    - platform: homeassistant
      event: start
  action:
    - delay: '00:00:15'
    - service: shell_command.map_nas_video_folder
2 Likes

In hassos from version 3.2 there is cifs kernel support as module:

One year ago I proposed to add it as built-in instead loadable kernel support and add cifs-utils in hassos and/or hassio but was rejected.
For use cifs in hassos (>=3.2) is needed addon that load the cifs kernel module and have cifs-utils, is not possible do an addon that share cifs mount to other container because hassos don’t have possibility to set bind-propagation to shared in addon container.
In case is used other operating system (not hassos) should be possibile mount cifs in it and share it with a bind to container FWIK.
About better cifs support in hassos and/or hassio container if useful / necessary to many people I think it would be necessary to request it again if possible add it (to hassos / hassio developers).

1 Like

A workaround would be to install a folder monitoring app that monitors the /config/mysubfolder share and moves security cam snapshots and vids to a NAS to prevent the hassio drive from filling up.

1 Like

I was looking for a way to mount NAS shares to utilise the PLEX add-on and MotionEye addon in Home Assistant. It seems like these two add-ons are pretty well useless if we cannot mount external storage of some kind.
Did anyone work out how to mount a CIFS path in HA? They seem to point to using /share as a mount point but I have no idea how to make this work.

6 Likes

Ok, so I managed to make this work, having a cifs folder mapped to a HA running supervised under docker.

I logged in HA container using Portainer ssh as root, added the fstab entry pointing to a folder under /mnt (for some reason it wouldn’t let me create a mount in /some_new_folder

Now the problem was that every time I started HA I needed to run mount -a. This issue was fixed by adding a startup automation with a 2 minutes delay that runs a shell_command.

Now I can monitor the network shared folder using command_line sensors and take actions using shell_commands

Will edit this later if needed with more detailed information

Check my post

I am trying to mount an nfs file system that works fine from Ubuntu (also works from MacOS):

/mnt$ ls -la /mnt
total 12
drwxr-xr-x  3 root root 4096 Sep 19 11:56 .
drwxr-xr-x 20 root root 4096 Apr 23 16:05 ..
drwxr-xr-x  2 root root 4096 Sep 19 11:56 test

/mnt$ sudo mount -t nfs 192.168.0.100:/nfs/Public /mnt/test

/mnt$ mount | grep nfs
192.168.0.100:/nfs/Public on /mnt/test type nfs (rw,relatime,vers=3,rsize=65536,wsize=65536,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=192.168.0.100,mountvers=3,mountport=49097,mountproto=udp,local_lock=none,addr=192.168.0.100)

But I cannot get this to work on Home Assistant (HASSIO). From the Home Assistant Terminal:


The exit code from mount is 255.

It is not clear to me what permission it is complaining about. I’m running the terminal as root, and root is the owner of /mnt/test, and there is no permissions required on the NFS server side for that share. I can ping 192.168.0.100 from Home Assistant terminal.

2 Likes

Would love to see this working for the new media browser stuff in 0.115 as I have many GBs of music on a server that I’d like to be able to play through HA.

1 Like

Same problems here…
Capture

Just trying to get nas music folder mounted for the new media browser

Brent

1 Like

I’m on HassIO Supervised (using Docker containers that are tightly controlled by the Supervisor) and the below shell_command works well for me and I call it as a HA startup automation:

shell_command:
  mount_nas_video_folder: mount 192.168.0.99:/_NASVIDEO /mnt/_NASVIDEO

So the goal is to have an NFS share with full permissions. On my QNAP everyone has full access to that share. Check out the key setting for this to work in this screenshot:

2 Likes

I’m pulling my hair here. Using Hassio VM image.

NFS definitely has full access for everyone. It mounts everywhere(tested on Debian server), except HA.
In HA, connecting to docker HA instance, getting Permission denied error, just like @markcocker. I suspect, it’s because /media is mounted from host /mnt/data/supervisor/media. Thought I should get to this /mnt/data/supervisor/media.
When connected to SSH Add-on (SSH & Web Terminal), through web ui, and after getting to HA CLI, and login command. Trying to mount (mount -t nfs …) getting error that I need helper program. It is missing /sbin/mount.cifs.
When connected to SSH Add-on (SSH & Web Terminal), without login command, -

➜  ~ mount -t nfs 192.168.8.18:/export/public /mnt/media
mount: mounting 192.168.8.18:/export/public on /mnt/media failed: Connection refused

I really don’t get how to mount external share… can’t mount it in HA docker container because permission denied, can’t mount in ssh docker because connection refused(can’t imagine how this would help anyways), can’t mount on host because missing mount.cifs.

Might be that docker container somehow blocking ports for NFS?

Another option is to create NFS as volume in docker, but I can’t add this volume to HomeAssistant, as supervisor manages all volumes, and my edit to docker container get lost.

Hello @BloodRave,
If I understand well your post (sorry for my english misundestanding), you have succeeded to mount a folder on a HA contained supervised.
Could you just give us a little more detailed information about the action that you have made on the configuration.yaml and automation.yaml
Thank you very much for your help ! :pray:

I finally got it working!
Basically @Christianb233 message made me carefully redo all @BloodRave steps and keep trying until it got working.

/etc/fstab contents in container HomeAssistant (login as root through Portainer add-on).

192.168.8.18:/public_m3 /mnt/media nfs4 rw,async,hard,intr,noexec 0 0

Make sure you create /mnt/media folder before mounting.
I should point out, that /export/public_m3 and nfs share type did not work for me, although it works everywhere else. This was the last step to get it working, so all other things that I did, might be unnecessary.

My NFS share is on openmediavault, in there I set allowed clients to be * instead of 192.168.8.0/24
Extra options that I set to the NFS share, I set anonuid to be root

subtree_check,insecure,no_root_squash,anonuid=1000,anongid=1000

configuration.yaml

homeassistant:
  media_dirs:
    public_m3: /mnt/media
shell_command:
  mount_nas_media_folder: mount -a

automations.yaml

- id: ha_start_event
  alias: HomeAssistant Start
  trigger:
  - event: start
    platform: homeassistant
  action:
  - delay: 00:02:00
  - service: shell_command.mount_nas_media_folder

While trying to mount from ha container console using command ‘mount -a’, these errors occurred:

  • Permission denied - worst case. Seems I had permission issue with Client config on OMV.
  • Connection refused - next error I had after fixing permission issue. It was due to using nfs instead of nfs4.
  • File directory not found - last error I had. It was due to using /export/public_m3 with nfs4, dropping /export directory fixed it all.

Now writing this comment, checked that I can omit fstab configuration, and mount using shell command

shell_command:
  mount_nas_media_folder: mount -t nfs4 192.168.8.18:/public_m3 /mnt/media

instead of 'mount -a' and fstab combo.

Thanks @BloodRave and @JZhass for commenting your solutions!

9 Likes

I believe our solution here is the only one that exists which is not a great thing because it’s pretty hacky. Maybe it’s a good idea to ask @pvizeli and @balloob to see if they know of any other way of persistently mounting a remote share (NFS and SMB) — and possibly consider enhancing HA to make mounting of remote folders just a bit more user friendly rather than a startup hack. Hoping it’s already somewhere on the product road-map :slight_smile:

Excellent to hear that all is working @insajd! This was indeed challenging when I switched over from a direct PIP install onto the Supervised solution. My reason & purpose for this mount is to dump motion triggered videos from my Ring doorbell and Blink cameras.

Once I enabled NFS4 on my QNAP then mine worked with both NFS (old) and the NFS4 mount type that you have working. Interesting that you can’t get the old NFS to work.

BTW, I also wanted to go the fstab route but changed by mind. I want my hack to be more “portable” and not impact any config files on the container — if possible. After every HassIO (supervised) upgrade, I click a button in Node RED (runs on host Ubuntu) which basically runs docker command asking the container to create a folder and then reboots the HA docker container. Otherwise HA does not start correctly if I’m listing it under allowlist_external_dirs but the folder doesn’t exist — and then I simply have the same startup like you’re doing though it’s just the full mount command rather than an fstab mount all like you do @insajd. This is what I run after every Supervisor upgrade via Node RED:

sudo docker exec -i homeassistant mkdir /mnt/_NASVIDEO && sudo docker container restart homeassistant

3 Likes

Glad I could help!

Somehow I had cifs installed in HA supervised (I am using open media vault with HA installed in docker), but after the upgrade to 115, I was unable to mount cifs share, so I switched to mounting the folder in another rpi and sending the information via mqtt… I am using this for a recording folder also, and have an automation in HA that deletes the content once I get to 100Gb of recordings.

I might try @insajd version because I might use this for other automations.