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
Important notes to read before proceeding
- When you see an item surrounded by < > do not include the < > in your file. For example if your server is MyServer, then /mnt/<server> would become /mnt/MyServer
- If you have spaces in the name, then you need a \ before the space. For example /mnt/My Files should be /mnt/My\ Files
- If you are migrating from using fstab, you were used to replacing spaces with \040. This will not work with autofs. Just a plain \ before the space is all that’s needed.
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>/
You may have to add an additional parameter to your /etc/auto.smb.shares
, namely vers=3.0
to enforce the usage of SMB version 3 especially if you have connection issues with Windows 10.
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:
username=<username>
password=<password>
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
created
last reply
- 19
replies
- 7.2k
views
- 7
users
- 10
likes
- 7
links