Ubuntu 20.04 - How to automount a CIFS share if mounting during boot fails
I'm trying to automatically mount a samba share residing on nas running openmediavault 5.6.12-1 and samba version 4.9.5-Debian on my desktop running Ubuntu 20.04.3.
After following the instructions in the openmediavault forum and the ubuntu community I added the following command to my fstab file:
//192.168.100.12/HomSpace /media/nasMounted cifs credentials=/root/.memoriaCredentials,uid=1000,gid=1000,noperm,rw,vers=3.0 0 0
When I execute sudo mount -a
the share folder is mounted correctly without errors. Unfortunately, after rebooting the PC the folder is not mounted automatically. I haven't found any instructions on the internet suggesting a different and equally practicable way to mount a cifs share folder and without any error in the log I have no idea what I'm doing wrong.
What's wrong with the command that I added to the fstab? How can I automount the cifs share at boot? Thank you in advance.
Solution 1:
Since the share will mount when you issue a sudo mount -a
I suspect there is nothing wrong with your fstab declaration. It does suggest a timing issue. Linux is reading fstab before the network stack is up and operational so when it goes to mount the network share it fails.
2 possibilities are to turn this into a "mount on demand":
[1] Keep your current mount point but add two more options: noauto,user
//192.168.100.12/HomSpace /media/nasMounted cifs credentials=/root/.memoriaCredentials,uid=1000,gid=1000,noperm,rw,vers=3.0,noauto,user 0 0
When you boot your system the share will not mount but it will show up on the side panel of your file manager as a launcher. Click on it and it will go to fstab to see how to mount it then do so.
EDIT: As pointed out below I should have made sure the credentials file was readable by the ordinary user for this method to work. Placing it under one's home directory would be a better choice.
[2] Change your mount point and use a systemd automounter.
Mount point cannot be under your home directory or /media so I would suggest something like /mnt/nasMounted. Then add two options noauto,x-systemd.automount
//192.168.100.12/HomSpace /mnt/nasMounted cifs credentials=/root/.memoriaCredentials,uid=1000,gid=1000,noperm,rw,vers=3.0,noauto,x-systemd.automount 0 0
This works by accessing the /mnt/nasMounted mount point. Either by you directly through the file manager, or by any application, or by any other process. Pretty much anything accessing that mount point will trigger a mount all without your intervention.
Either way after you edit fstab run these two commands to make systemd happy:
sudo systemctl daemon-reload
sudo systemctl restart remote-fs.target