unable to mount samba share on boot (ubuntu 15.10)
I am following MountWindowsSharesPermanently to mount a samba share on boot
As said in wiki, I added these lines to /etc/fstab
:
# auto-mounting the samba share 'Seagates' on raspberry pi
//192.168.2.2/Seagates /home/edward/samba/raspberry cifs uid=1000,gid=1000,credentials=/home/edward/.smbcredentials,iocharset=utf8,sec=ntlm 0 0
and after that, since it is a password protected share, I added login credentials in ~/.smbcredentials
and rebooted
The mount is failing with these errors, taken from journalctl | grep samba
:
Nov 10 22:39:27 flippingbits systemd[1]: Mounting /home/edward/samba/raspberry...
Nov 10 22:39:33 flippingbits systemd[1]: home-edward-samba-raspberry.mount: Mount process exited, code=exited status=32
Nov 10 22:39:33 flippingbits systemd[1]: Failed to mount /home/edward/samba/raspberry.
Nov 10 22:39:33 flippingbits systemd[1]: home-edward-samba-raspberry.mount: Unit entered failed state.
Nov 10 22:39:58 flippingbits smbd[2613]: pam_unix(samba:session): session closed for user nobody
However if I mount using sudo mount -a
after boot, it works.
NOTE: On the same page (here) they have showed a work around to add username=guest
to solve this problem. But I cant do it because I am mounting it as another user which is written in ~/.smbcredentials
I am on Ubuntu 15.10
The Ubuntu Wiki I have mentioned in question is bit outdated and does not works properly with systemd
. systemd was first introduced in Ubuntu 15.04
The problem can be anything, by the time /etc/fstab
is read the network would not be up OR by the time /etc/fstab
is read samba
services would not be ready OR it can be anything, I didn't read logs much.
But basically the method shown in wiki does not work.
After roaming on web, I finally found the solution and it is to add x-systemd.automount,x-systemd.device-timeout=3,
before the rest of the options in fstab
file
This:
//192.168.2.2/Seagates /home/edward/samba/raspberry cifs uid=1000,gid=1000,credentials=/home/edward/.smbcredentials,iocharset=utf8,sec=ntlm 0 0
will become
//192.168.2.2/Seagates /home/edward/samba/raspberry cifs x-systemd.automount,x-systemd.device-timeout=3,uid=1000,gid=1000,credentials=/home/edward/.smbcredentials,iocharset=utf8,sec=ntlm 0 0
What happens is if the drive is not mounted on first try, systemd will wait before it gives up trying to automount. This also does not affect/increase the boot time since systemd does not wait for this to complete and keeps loading rest of the system.