Dirk's Tech Findings

systemd: Mount NFS share on system boot (Debian Linux)

Publication date: 2025-10-12

Issue: Attempting to mount an NFS4 share on boot does not work

My first attempt to mount my NFS4 share on boot (via IPv6 by the way) looked like this in the file "/etc/fstab":

[fe80::19c:5ff:fe72:65c2%vmbr0]:/vault/data /vault/data  nfs4    _netdev,rw,exec,nofail,soft,timeo=200,proto=tcp6

"_netdev" is a mount option that indicates that the mount requires the network to succeed. This "old way" of doing things worked well in the running system but did not mount the share on boot.

Online search revealed that with systemd, there is "x-systemd.requires=network-online.target" to state a dependency on the network. So I tried that option (with and without "_netdev"):

[fe80::19c:5ff:fe72:65c2%vmbr0]:/vault/data /vault/data  nfs4    _netdev,rw,exec,nofail,soft,timeo=200,proto=tcp6,x-systemd.requires=network-online.target

The behavior did not change: the share did not get mounted on boot. The logs indicated that the system attempts to mount the share too early without the network being ready:

journalctl -u vault-data.mount

Oct 12 04:35:58 dh-nas8 systemd[1]: Mounting vault-data.mount - /vault/data...
Oct 12 04:35:58 dh-nas8 mount[1202]: mount.nfs4: Network is unreachable for [fe80::19c:5ff:fe72:65c2%vmbr0]:/vault/data on /vault/data
Oct 12 04:35:58 dh-nas8 systemd[1]: vault-data.mount: Mount process exited, code=exited, status=32/n/a
Oct 12 04:35:58 dh-nas8 systemd[1]: vault-data.mount: Failed with result 'exit-code'.
Oct 12 04:35:58 dh-nas8 systemd[1]: Failed to mount vault-data.mount - /vault/data.

Solution: Use "systemd-networkd-wait-online" with proper configuration

More online search revealed that there is a systemd unit called "systemd-networkd-wait-online" that can be enabled if required. I tried this by enabling the unit with the following command:

systemctl enable systemd-networkd-wait-online

This yielded good news and bad news... The good news: The mount did work on boot since it was no longer attempted before the network was ready. The bad news: Boot took several minutes while waiting for the network to come up - waiting even continued for roughly three minutes more than that.

More online search revealed that "systemd-networkd-wait-online" can be configured as needed. Thus I added by calling

systemctl edit systemd-networkd-wait-online

the following overrides:

[Service]
ExecStart=
ExecStart=/usr/lib/systemd/systemd-networkd-wait-online --interface=vmbr0 -4 -6 -o routable --timeout 60

Note that the line with "ExecStart=" is important. It removes the default "ExecStart". If this is not done, both ExecStart lines are called and we are again waiting some minutes for the timeout. "vmbr0" is the main network interface on the machine, and we wait for up to 60 seconds for IPv4 and IPv6 to become routable using it.

Hint towards the solution

Back to topic list...