A small systemd service I used for mounting NFS shares from a host on the local network using systemd and NetworkManager-dispatch on Arch Linux.
Systemd has support for automounting NFS shares using the x-systemd-automount option. However, if the server is not found on the attached network, then the booting system will hang until systemd gives up trying to mount the missing shares. For wireless hosts, this is not acceptable.
With NetworkManager-dispatcher enabled, systemd will activate any scripts contained in /etc/NetworkManager/dispatcher.d. This
is where 10-AutoMountNFS is installed. This script calls the AutoMountNFS systemd service which itself calls the
automountnfs
script that does the actual mounting. The automountnfs
script checks for my nfs server, if it is found,
then it attempts to mount the nfs shares. If it is not found, then it attempts to umount any mounted shares. Simple.
Additionally, AutoMountNFS uses systemd timers to run every minute. If the NFS host cannot be reached, then the NFS mounts are unmounted.
Clone
makekpg -c
pacman -U <compiled package>
Make sure NetworkManager-dispatcher is enabled:
systemctl enable NetworkManager-dispatcher
Enable and start AutoMountNFS
systemctl enable AutoMountNFS.timer systemctl start AutoMountNFS.timer
Check
/var/run/automountnfs
for output.