2

I have a debian server where I need to auto-mount a Samba share during startup.

I did the following:

  1. Added the following line to /etc/fstab:

//192.168.1.1/FRITZ.NAS/WD-1600BEVExternal-01/share /srv/nas cifs credentials=/home/rlommers/.smbcredentials,rw,uid=rlommers,gid=rlommers 0 0

  1. This works with a sudo mount --all
  2. However, I would like this mount to be mounted automatically at boot time, and that doesn't happen.

Any clue on this issue? So the mount works fine, but it's not mounted automatically during boot of the server.

4

You are hiting a known systemd "feature"; on top of it, the system might be trying to mount the remote SAMBA share before networking is operational.

Modify your fstab to to add to the mounting options ,noauto,x-systemd.automount,_netdev

//192.168.1.1/FRITZ.NAS/WD-1600BEVExternal-01/share /srv/nas   cifs    credentials=/home/rlommers/.smbcredentials,rw,uid=rlommers,gid=rlommers,noauto,x-systemd.automount,_netdev      0       0

For the explanation, corrected to the new syntax by myself - Cute systemd trick of the day: auto-mounting remote shares

If you have remote drives – cifs, nfs, whatever – in /etc/fstab with typical options, then you’ll probably find that the system will sit there and wait for the network to come up on boot, then mount them, before boot completes. That’s not terrible, but it’s not awesome either.
...
to make it super awesome, add two options: noauto and x-systemd.automount.
Then what happens is the share gets mounted as soon as something tries to access it…but not before.
So boot runs as fast as possible, and as soon as you actually try to access the share, it gets mounted. Thanks, systemd!

Also from Arch Wiki to explain this feature - fstab

Automount with systemd

Remote filesystem

The same applies to remote filesystem mounts. If you want them to be mounted only upon access, you will need to use the noauto,x-systemd.automount parameters. In addition, you can use the x-systemd.device-timeout= option to specify how long systemd should wait for the filesystem to show up. Also, the _netdev option ensures systemd understands that the mount is network dependent and order it after the network is online.

noauto,x-systemd.automount,x-systemd.device-timeout=30,_netdev

Warning: Be sure to test the fstab before rebooting with a sudo mount -o remount -a and sudo mount -o rw,remount /srv/nas as a erronous fstab can give you problems upon boot.

See also, related, CIFS randomly losing connection to Windows share

  • 1
    I would add nofail so the system boots even if network share can't be mounted. – svin83 Sep 16 '18 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.