NFS: "Stale file handle" and hung mounts
The client is holding a reference to something the server no longer recognises, or the server has gone and the mount is waiting for it forever.
What you see
ls returns "Stale file handle", or any command touching the mount hangs and cannot be killed. Load average climbs while the machine does nothing.
What is actually wrong
The export was recreated, the underlying filesystem was remounted, or the server rebooted and its filehandles changed. A hung mount is usually a hard mount with the server unreachable.
Codes and articles
Fixes (3)
Clear the stale handles
ESTALE errors on an otherwise reachable server.
Find what still has the mount open — this is what blocks a clean unmount.
sudo lsof +D /mnt/nfs 2>/dev/null | head -20sudo fuser -vm /mnt/nfs
Stop those processes or move them out of the directory, then unmount and remount.
sudo umount /mnt/nfssudo mount -als /mnt/nfs
If it will not unmount, use a lazy unmount, which detaches the tree immediately and cleans up when the last reference closes.
sudo umount -l /mnt/nfsA lazy unmount is the tool for exactly this. A forced unmount on a hung NFS mount can leave processes in uninterruptible sleep, which nothing short of a reboot resolves.
On the server, check the export has not changed identity — a recreated filesystem gets a new fsid.
sudo exportfs -vsudo cat /etc/exports
Pin the fsid in the export so a server rebuild does not invalidate every client handle.
sudo sed -i 's|\(/srv/share.*\)(|\1(fsid=1,|' /etc/exportssudo exportfs -ra
mount | grep nfs; ls -la /mnt/nfs | headRecover from a hung hard mount, and stop it recurring
Everything touching the path hangs.
Confirm the diagnosis — processes in D state on that mount.
ps -eo pid,stat,wchan:24,comm | awk '$2 ~ /D/'dmesg -T | grep -i 'nfs.*not responding' | tail
Detach it lazily so new commands stop hanging.
sudo umount -l /mnt/nfsUnderstand the trade-off before changing the mount options. A hard mount blocks forever, which protects data — writes are retried until the server returns. A soft mount gives up and returns an error, which can silently corrupt a file being written.
Soft mounts are the usual advice for this fault and they trade a hang for possible data loss. For read-only data that is a fine trade; for anything being written it is not.
Add intr and a timeout where a hard mount is right but responsiveness matters.
sudo sed -i 's|\(nfs.*defaults\)|\1,_netdev,hard,timeo=600,retrans=2|' /etc/fstabsudo mount -a
Use autofs for mounts that are not always needed — it mounts on access and unmounts when idle, which removes the whole class of boot-time hangs.
sudo apt install autofsAlways add _netdev to an NFS entry in fstab, or the machine will hang at boot waiting for a mount before the network exists.
mount | grep nfssystemd-analyze blame | head
Fix a mount that is refused
mount.nfs reports access denied or connection refused.
Check what the server actually exports and to whom.
showmount -e nfsserversudo exportfs -v
Check the client's address matches the export's allowed range — an export for 10.0.0.0/24 refuses a client that has moved to another subnet.
Check the firewall. NFSv4 needs only TCP 2049; NFSv3 needs rpcbind and several other ports.
sudo ss -tlnp | grep 2049rpcinfo -p nfsserver | head
NFSv3's dynamic ports are why it is so often blocked by a firewall while NFSv4 works. Forcing version 4 is frequently the whole fix.
Force the version explicitly to remove the negotiation from the equation.
sudo mount -t nfs -o vers=4.2 nfsserver:/srv/share /mnt/nfsCheck root squashing if files are visible but not writable — root on the client becomes nobody on the server by default.
sudo grep -n squash /etc/exportsid; ls -ln /mnt/nfs | head
sudo touch /mnt/nfs/.writetest && sudo rm /mnt/nfs/.writetest && echo writableRelated faults
Where this stops. This write-up was written and checked by hand. It says what each step changes, how to confirm it worked and how to reverse it, and anything destructive is flagged before you reach it. If it does not match what your machine is doing, search the Support Centre for the exact code or message — and when something needs a person, get in touch.