Mounting Network shares with fstab
Auto Mounting a Network SMB or CIFS Drive
As always, backup your working fstab first:sudo cp /etc/fstab /etc/fstab.bak
The following is a way to automatically mount a network share without the risk of it blocking you computer from booting. This is useful for non-critical drives such as media or backups. Review the params before saving your fstab file, you may need to adjust some!
In this example we will mount the SMB share photos to the local directory /mnt/photos.
sudo mkdir /mnt/photos
Add the mount as a new line to /etc/fstab
sudo findmnt --verify --verbose
Tell the system to re-load the fstab changes with:
systemctl daemon-reload
Because the example here sets noauto, you cannot mount them with the "mount -a" command
Usually the network shares will mount automatically once you try and access the local directories. Sometimes this takes a few minutes the first time. You can speed this up with the following command:
sudo systemctl restart local-fs.target
Explanation of line #2:
nofail - Don't fail booting if there's an issue with this drive
mount -a is called
x-systemd.automount - Automatically mount the drive when you attempt to access it using the local directory
username=,password= - Your SMB user and password go here. Leave these off if there isn't one.
uid=1000,gid=1000
cat /etc/passwd and finding your user. The two numbers shows are the uid and gid in that same order.
dir_mode=0777,file_mode=0666
Notes:
You may have a different preference about the noauto param preventing mounting a boot time. If you absolutely need your drive to mount first thing and it should hold up booting until it has mounted, you can remove that option. If you want booting to fail entirely if the drive is not available, you can also remove the nofail param.