Mount remote smb share on hassio

I’ve tried dozens of different variations in Terminal but I consistently get a “Permission Denied” error. I’m running HA in a VM on my QNAP NAS. Does anyone have instructions for the code that will mount a NAS directory just manually using Terminal? I should be able to figure to figure out the Automation from there but I would like to successfully mount a directory manually to validate that I have it right

Seems it is not possible in the terminal because it runs in a separate container with restricted permissions.
Moreover, you won’t see the directory mounted in the terminal even when it work: the /mnt folder in terminal and HA are different folders.

Just put the configuration into you configuration.yaml:

homeassistant:
  media_dirs:
    media: /media

shell_command:
    mount_media: 'mkdir -p /mnt/media;ln -s /mnt/media /media/;mount -t cifs -o username=.....'

And then run it from /developer-tools/service as shell_command.mount_media.
It should be visible under /media-browser.

It’s a little bit strange, I still got an error:

Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/__init__.py:115
Integration: Shell Command ([documentation](https://www.home-assistant.io/integrations/shell_command), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+shell_command%22))
First occurred: 1:44:05 PM (2 occurrences)
Last logged: 1:44:06 PM

Error running command: `mkdir -p /mnt/nas-media;ln -s /mnt/nas-media /media/;mount -t nfs4 nas.lan:/Multimedia/Music /media/nas-media`, return code: 255

NoneType: None

And this is my command:

shell_command:
  mount_nas_music_folder: mkdir -p /mnt/nas-media;ln -s /mnt/nas-media /media/;mount -t nfs4 nas.lan:/Multimedia/Music /media/nas-media

The shell_command didn’t give a clear log of stdout or stderr, which make it pretty hard to debug the command, sad story…

This is what worked for me. I am running an Ubuntu host server with HA as a KVM VM. I already had a Samba share setup for media. I also had nfs-kernel-server already installed on the host server. When trying to mount the cifs share in HA I was getting an error because the password contained a ) symbol in it. I’m now wondering if the posts recommending using ’ ’ around the mount commands would have resolved that issue. But I have not tested that. I switched to trying to mount it as an NFS share.

NOTE IP Addresses and folder paths have been changed where necessary for security reasons.

To get past the permission denied error for NFS mount command in HA, 1st in HA terminal run the mount command using the -vvvv option to see verbose messages. The network IP address of my HA server is 192.168.1.12. However, the verbose message showed that HA VM was communicating with host server using a client IP address of 172.30.32.2. Next on the server that I’m exporting (sharing) the media folder from, run command:

ls -l /path/to/shared/folder

(using your path) to see user and group of folder owner. Then run the command:

id username

where username was determined from previous ls command. The output of the id command will give you the user id and group id corresponding to the output of the ls command. Then edit the /etc/exports file (as root or sudo) on the server containing the shared media folder adding a line like the one below, adjusted for your environment:


/local/folder/media 192.168.1.12(rw,no_subtree_check,all_squash,anonuid=1001,anonguid=141) 172.30.32.2(rw,no_subtree_check,all_squash,anonuid=1001,anonguid=141)

where:
/local/folder/media is the folder you are sharing
I added both HA network IP Address and the client IP Address used to communicate with host to be safe.
anonuid = the user ID for the folder owner, and anonguid = the group id for folder.
make sure there is not a space between the IP Address and the (.
Save the file then restart nfs service with command:

sudo systemctl restart nfs-kernel-server

Occasionally the service failed to restart for me. I double check the exports file but didn’t see anything wrong. The NFS service restarted on the 2nd try.

In configuration.yaml I have:

homeassistant:
  media_dirs:
    media: "/media"
shell_command:
  make_music_folder: mkdir -p /media/music
  mount_music_nfs_folder: mount -t nfs4 -o rw 192.168.1.10:/local/folder/media /media/music

I used the media folder since it already existed in HA and I wouldn’t have to worry about recreating it after upgrading HA.

After rebooting HA host I was able to go to Developer Tools → Services and run both shell commands. I can now go to the Media tab and browse through all of the folders and files in the mounted share. My next step is to create an automation based on previous posts to run the shell commands upon HA startup.

1 Like

Can somebody please make some small steps to link a windows folder.
I think that we tried all of the above, but just cant get it mount.
We use VirtualBox with homeassistant VDI.

Windows 10 Host?

Here is how I did it.

This solved the problem for me. I’m running HA Supervised and I have a ‘downloads’ folder in my NAS which is mounted in the homeassistant config dir using a cifs entry in fstab.

//192.168.1.100/Public/Downloads    /usr/share/hassio/homeassistant/nas_downloads        cifs    credentials=/root/.smbcredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0

I got “permission denied” error every time I tried to write to the nas_downloads folder, but this setting fixed it. I wonder if this means anyone can access the folder, even without credentials (guest) or permission to do so.

In the 2022.3 relase it will be possible :clap:

What will be, exactly? I see no mention of mounting external NAS devices.

I was just looking for the same thing. :grinning:

ok i agree . This is only beneficial for those who want to mount a NAS to have only access to the DLNA files…

Hello all,

I’ll start off by saying that I only made it through the first 60 or so messages so far, and already feel like I may be over my head. Maybe there’s a better way to accomplish things now?

I’m running HA on an ODROID-N2 blue, so I’m still a little unclear on what exactly my setup is since I didn’t set it up myself. Here is what is reported under my system info

Version	core-2022.3.7
Installation Type	Home Assistant OS
Development	false
Supervisor	true
Docker	true
User	root
Virtual Environment	false
Python Version	3.9.9
Operating System Family	Linux
Operating System Version	5.10.103
CPU Architecture	aarch64

Here is what I have listed in my configuration.yaml:

homeassistant:
  media_dirs:
    media: /media
    synologynas: /media/syno
    
shell_command:
  mount_nas_media_folder2: mkdir -p /media/syno;mount -t cifs -o username=guest,password='PASSWORD',domain=WORKGROUP //192.168.0.109/video /media/syno

I have the PASSWORD in ''s as it contains a ) and I ran into an error due to that. I’m not sure if putting the password in ''s is the solution for that? Still trying to learn the ins and outs of yaml: I tried looking up how to escape special characters but couldn’t find a definitive answer.

Here is the behavior I’ve seen:

The configuration checker yells at me if the media/syno directory doesn’t exist, so I have to manually create it. I do that via ssh to homeassistant. (I don’t know if I should be ssh’ing a level higher? I don’t know how I would even do that. ) Then when I restart HA there aren’t any errors in the logs, but when I go to the media/syno directory (either in the media viewer in HA or via ssh in HA) nothing shows up.

When I go to Developer Tools → Services and run the following:

Shell Command: mount_nas_media_folder2  

Nothing seems to happen, there aren’t any errors or anything. But files still don’t show up in the directory.

I’m still relatively new to HA and trying to find my feet, so I’m sure there are a variety of things I could be doing wrong. Any assistance is sorely needed and would be greatly appreciated.

Ok, I set the logger to debug. Nothing regarding the shell_command showed up after restarting HA, but when I went to Developer Tools->Services and ran it manually I get the following in the log:

2022-04-02 14:27:27 DEBUG (MainThread) [homeassistant.components.shell_command] Stderr of command: `mkdir -p /media/syno;mount -t cifs -o username=guest,password='password',domain=WORKGROUP //192.168.0.109/video /media/syno`, return code: 111:
b'mount: mounting //192.168.0.109/video on /media/syno failed: Not supported\n'
2022-04-02 14:27:27 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `mkdir -p /media/syno;mount -t cifs -o username=guest,password='password',domain=WORKGROUP //192.168.0.109/video /media/syno`, return code: 111
NoneType: None

From searching it seems like return code 111 indicates an issue making a connection. I’ve done as much as I can on the Synology where my drive exists, I enabled the guest account and set the password, gave it read/write access to the directory I’m attempting to mount in HA.

I thought a Samba-Share should be "accessible " for the Samba-User ?, or HA system-user

How do I find out what the HA system-user is? I tried creating a user called homeassistant on the Synology and gave it explicit permissions to everything, and using those credentials still results in a return code 111.

HA’s os is root, HA uses root + you “your-user/login name”, samba is samba-user … what user did you use to mount-on hassio ?

Sorry if this is a really basic question, but does that depend on how I connected to run it? I used putty to connect to the ssh that I configured in the Terminal & SSH Add-on.

I guess you then logged into Ha, with your HA username, so you should have the right “credentials” then “Administrator” in HA, root in terminal/SSH … easiest way is to login through ssh again and type “whoami”

…and this sounds like “greek” to me and “escape special characters” ? … don’t use them if it’s not supported

PS: Have you read/tried any of the examples above ?, on howto Mount … or maybe some other “half” official guide

Ah, TIL, thank you. I know whoami works in a windows command line, didn’t even think to try that.

I think I butchered that. I meant that putting them in ''s would indicate it’s a string, like in SQL. I just tried to replicate and I’m not seeing the error I did before, so there must have been something else going on. At any rate, removing the ''s has the same effect. Shouldn’t one of them return an error for a bad password? I did enable debug but the only mention of homeassistant.components.shell_command in the log is it with a bunch of other components.