Today I discovered systemd.automount (5) and let me tell you: it’s yet another reason to love systemd, don’t be a naysayer.

I mean, it’s just a kind of MAGIC!

You only need to add something like this to your /etc/fstab

nas:/data /srv/data nfs nofail,x-systemd.automount,x-systemd.requires=network-online.target,x-systemd.device-timeout=10s 0 0

… and after reloading the systemd daemon, as you do when one changes fstab, then merely start the mount point:

root@machine:~# systemctl start srv-data

root@machine:~# ls -laF /srv/data/
total 28
drwxr-xr-x.   5 root root   60 nov 17 18:09 ./
drwxr-xr-x.   3 root root 4096 jan  4 10:00 ../
drwxr-xr-x. 258 root root 8192 nov 17 18:08 somedir/
drwxr-xr-x. 277 root root 8192 nov 17 17:55 anotherdir/
drwxr-xr-x.   3 root root   29 nov 17 18:09 whateverdir/