Automount & dismount external NAS


#1

This process has worked in my setup to automount and dismount and external NAS.

Prerequisite is installing cifs-utils.

If you’re using wifi, I also check the box “make this connection available for all users” in network manager.

Obviously, you’ll add your specific credentials in place of the generic names in the following.

sudo mkdir -p /media/nas/yourfilename

sudo chmod 777 /media/nas/yourfilename

sudo chown yourusername:yourusername /media/nas/yourfilename

sudo systemctl enable NetworkManager-wait-online.service

sudo chmod u+s /sbin/mount.cifs

sudo pluma /etc/fstab

In fstab, you’ll add the following line to the end of the file.

//yournasaddress/nameofnasfilename /media/nas/nameofnasfilename cifs domain=yourdomainname,username=yourusername,password=yourpassword,x-systemd.automount,_netdev,users,uid=1000,gid=1000,rw,guest,vers=1.0 0 0 

*Note that you may experiment whether you need “vers=1.0” or not. Sometimes not, other times it could be “vers=2.0” etc.

Additionally, there doesn’t appear to be much difference between using a seperate credential file for you personal login data and just placing it directly in fstab. Both can be accessed, but only by root. Neither are encrypted.

GM


#2

First off, thanks for writing a tutorial. As someone who fought with getting a NAS to automount a while ago, I’m sure there are people who’ll appreciate the help. :slight_smile:

That said, I’ll offer a different set of advice, for people who just want a “simple” NAS setup.
Before that though, a few notes…

  • /media is really intended for “system-managed” mounts. “Real” mounts are best based in /mnt, where you don’t run the risk of gnome / systemd people suddenly deciding to break all your stuff.

  • You don’t need to chown the mountpoint, unless you actually have a multi-user system.

  • NetworkManager-wait-online.service is terrible, and you don’t actually need it.

  • chmod’ing something +s is a really bad idea unless you know what you’re doing, and you don’t need THAT either.

  • “vers=1.0” guarantees that you’ll get the worst possible performance out of the NAS. “2.0” is better, but still not very good.
    Unless your NAS is very old, and the manufacturer doesn’t care about supporting it, you should be using 3.0, i.e. SMB3.

For the way I have things set up, the only fstab details you need are:
//nas/share /mnt/nas cifs vers=3.0,guest,username=nobody,noperm,user,noauto,x-systemd.automount 0 0

The “vers=3.0” is only needed if you’re on a pre-4.13 kernel. It’s the default for anything newer than that, because it’s 2x to 10x faster than SMB1/2.

“guest” means “guest on the NAS”, so you don’t have to mess around with passwords etc.

“noperm” means “don’t try to use this machine’s permissions on the NAS”. (You not having that is why you need those six “extra” arguments in your fstab, but that’s why this is the “simple” scenario rather than your more complex permissioned one). :slight_smile:

“user” means non-root users can mount it. You missed that, and that’s why you have dangerous things like setuid’ing a binary for no reason.

“noauto” means what it says, and is why you don’t need to quadruple your boot time thanks to NetworkManager, and also means you don’t need “_netdev” to stop systemd locking the machine up if the NAS is offline.

So, that’s the simple version. Hopefully it’ll save someone having to work it all out themselves.


#4

External mounts, and expecially automounts should be mounted in /media. Internal/non-auto mounts can be mounted to /mnt.

Correct, chown of the mountpoint on a single user machine is not needed.

Correct, NetworkManager-wait-online.service is also not needed.

Correct, chmod u+s is not needed. That has been changed to chmod 754.

vers=1.0 is a necessity in my scenario. I’m not sure quite why, because the drive is a recent USB 3.0 drive and I’m running the most recent LTS kernel 4.15.

//nas/share /mnt/nas cifs vers=3.0,guest,username=nobody,noperm,user,noauto,x-systemd.automount 0 0…this is a good fstab entry for a local mount, newer hardware.

The rest of your detail is very good.


#5

An alternative to my OP… the following guarantees consistant automount/dismount of external NAS.

sudo mkdir -p /media/nas/yourfilename
sudo chmod 777 /media/nas/yourfilename
sudo chmod 754 /sbin/mount.cifs
sudo systemctl enable NetworkManager-wait-online.service       

In fstab, enter the following, or follow arQon’s advice for guest access…

//yournasaddress/nameofnasfilename /media/nas/nameofnasfilename cifs domain=yourdomainname,x-systemd.automount,_netdev,users,uid=1000,gid=1000,rw,guest,vers=1.0 0 0

Based on age of your hardware, you may need to experiment with vers=1, vers=2 or vers=3.