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.
For development and building using the justfile targets:
- just - Command runner
- aurutils - Required for
just build-and-ship
target - pre-commit - For code quality checks
Clone the repository
Using justfile (recommended):
# Setup development environment just setup # Build package locally just build # Build and ship to alvaone repository (requires aurutils) just build-and-ship
Manual build:
updpkgsums && makepkg -f
Install the package:
# Using justfile just install # Or manually sudo pacman -U automountnfs-*.pkg.tar.xz
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.