I have a shared folder on windows and I usually mount it like this
mkdir /media/somedir
sudo mount -t cifs //servername/sharename /media/somedir
The problem is that once I restart the machine the mounted shared folder is no longer their and I have to run the above commands again. I wonder if there is a way to automount it when trying to access this directory? I've checked with @Gilles commenting to his answer found here and as shown in the below screenshot, he said it can be done by editing the file but it's not recommended and he said may be there is a way to automount it when trying to access the directory and he suggested me to ask a question as someone may be able help. Any advice?
vers=3.0
in your options, because by default CIFS doesn't always try the latest SMB protocol versions. This resulted in some headaches at one of the places that employs me, until I dug into this a bit. – Thomas Ward Mar 15 '18 at 17:23/etc/fstab
is world-readable. usingusername=
andpassword=
works but puts the login & password in plain text in a file readable by anyone. usecredentials=/path/to/file
instead, as in @AyushGoyal's answer, to put the login & password in a separate file (that can be owned by root:root, and readable only by root...i.e. mode 600). Seeman mount.cifs
for details. – cas Mar 16 '18 at 00:57nofail
should take care of this. I had the same problem with an external HDD on my Pi and adding this stopped from failing to boot when it was umplugged. Just try it out. If it fails, you can comment out that line from the fstab in the emergency console and reboot normally again. – piegames Mar 16 '18 at 07:53noauto
andnofail
both solve that particular problem. they can be used by themselves or together.noauto
prevents the fs from being auto-mounted at boot (can only be manually mounted from the command line - e.g. withmount /media/somedir
(the rest of the details come from the /etc/fsstab file).nofail
stops systemd from caring if the automount fails. – cas Mar 16 '18 at 07:53