[HOW-TO] Mounting network shares with autofs (alternative to fstab)


This how-to describes how to mount your network shares via autofs. Autofs should be as performant as fstab based mounting but has the advantage that your shares are mounted on demand which also should give you more reliability in case of network interuptions.

First install the autofs package

sudo apt-get install autofs

If you already have mounted your shares already via fstab comment out that line in fstab and reboot.

For this how-to we are going to use a directory for each server, if you want to replicate your existing folder structure that can also be done.

autofs will create any mountpoints required, so you do not need to create them

For SMB shares

sudo nano /etc/auto.master

and add to the end of the file:

 /- /etc/auto.smb.shares --timeout 15 browse

Next you need to create a map to the share:

sudo nano /etc/auto.smb.shares

and add

/mnt/<server1>/<share1> -fstype=cifs,rw,credentials=/home/osmc/.smbcredentials,iocharset=utf8,uid=osmc,gid=osmc ://<IP of server1>/<share1>/
/mnt/<server2>/<share2> -fstype=cifs,rw,credentials=/home/osmc/.smbcredentials,iocharset=utf8,uid=osmc,gid=osmc ://<IP of server2>/<share2>/

We suggest the usage of a “credentials” file for security reasons.

This is what a credentials file should look like. (a good name for the file would be .smbcredentials) Create this file in the osmc home, so using nano:

nano ~/.smbcredentials

And add:


If you don’t want to use a credentials file use this instead:

/mnt/<server1>/<share1> -fstype=cifs,rw,username=<username>,password=<password>,iocharset=utf8,uid=osmc,gid=osmc ://<IP of server1>/<share1>/
/mnt/<server2>/<share2> -fstype=cifs,rw,username=<username>,password=<password>,iocharset=utf8,uid=osmc,gid=osmc ://<IP of server2>/<share2>/

For NFS:

As with smb, edit auto.master

sudo nano /etc/auto.master

and add

 /- /etc/auto.nfs.shares --timeout 15 browse

to the end of the file.

And for the map file we will be mounting several shares from 2 servers:

sudo nano /etc/auto.nfs.shares

and add:

/mnt/<server1>/<share1> <IP of server1>:</path/to/share1>
/mnt/<server2>/<share2> <IP of server2>:</path/to/share2>

If you’d like, you can always just mount them directly under /mnt (or anywhere else):

/mnt/<share1> <IP of server1>:</path/to/share1>
/mnt/<share2> <IP of server2>:</path/to/share2>

Testing the config:
After you have made the changes restart autofs:

sudo systemctl restart autofs

To test if your mounts works execute:

ls -lah /mnt/<server1>/<share1>

you should see the files from your network share. If it didn’t work run

sudo systemctl stop autofs
sudo automount -f -v -d

to debug what’s wrong.

To exit if running automount, just do a CTRL-C. To restart the service once everything is working, either reboot or:

sudo systemctl start autofs

Remount fstab shares on Vero 4k when connection is interrupted?
OSMC samba network
Reminder od how to auto mount on OSMC Forum please
Remount fstab shares on Vero 4k when connection is interrupted?
Adding Repos
Vero 4K+ freezes randomly
Vero4K: want to use as PVR / view OTA broadcasting
Slow seeking and overall slow performance
Vero 4K+ not turning on
Raspberry & Mycloud NAS failures
Can't seem to get autofs working
Adding Repos