OPINIONATED OMARCHY
TROUBLESHOOTING CORPUS
790
RECORDS
790
AUDITED
0
UNCHECKED
2388
SOURCES
LIVE
network high common DISPUTE

Stop an NFS share in fstab from hanging boot and shutdown

archomarchyendeavouroscachyosmanjarodesktoplaptop
CORRECTED An auditor found the fix wrong or incomplete and rewrote it.
AUDIT NOTE

The diagnosis is accurate: hard is the NFS default and does retry indefinitely, and the record correctly notes that retrans does not bound a hard mount and that soft trades hangs for EIO. The fstab line and options are valid. The activation step is the weak part: systemctl restart remote-fs.target is an unreliable way to pick up a newly generated automount unit (targets carry no processes and mounts are only Wanted by them), so users following this often see nothing happen and conclude the fstab entry is wrong. Start the generated automount unit by name.

The cause above was not rewritten and may still contain the error described. The fix below is the corrected version.
RISK

soft NFS mounts can cause silent data corruption. The man page recommends them only when client responsiveness matters more than data integrity. Never use soft for a share you write to.

Symptom

With an NFS share in /etc/fstab, boot stalls for minutes on A start job is running for /mnt/nas whenever the server is off or you are away from that network, and shutdown hangs on A stop job is running for /mnt/nas. Once the server disappears mid-session, any process touching the mount becomes unkillable in D state and df hangs.

Cause

NFS mounts default to hard, meaning NFS requests are retried indefinitely rather than failing. That is the primary cause of NFS-related hangs. In fstab a network filesystem is also pulled into remote-fs.target as a hard requirement, so systemd blocks boot waiting for it and blocks shutdown trying to unmount a server that is already unreachable.

Fix

fstab line as written is correct:


nas.local:/export/media  /mnt/nas  nfs4  noauto,nofail,_netdev,x-systemd.automount,x-systemd.idle-timeout=600,x-systemd.mount-timeout=10,timeo=100,retrans=2  0 0

Activate it by starting the generated unit explicitly rather than restarting the target:


sudo systemctl daemon-reload
systemd-escape -p --suffix=automount /mnt/nas     # -> mnt-nas.automount
sudo systemctl start mnt-nas.automount
systemctl status mnt-nas.automount --no-pager
ls /mnt/nas          # triggers the mount on first access

To clear a mount that is already wedged (lazy detach is the part that works when the server is gone):


sudo umount -l /mnt/nas

Only add soft if you accept that the client returns EIO after retrans retransmissions instead of retrying forever. That risks silent data loss on writes, so keep hard for anything you write to.

Verify

systemctl list-units 'mnt-nas.*' shows an .automount unit active and the .mount unit inactive until first access. Power the server off, then reboot: boot reaches the greeter without stalling, and systemctl poweroff completes without a stop job.

Sources

nfs-mount-hangs-boot-and-shutdown