Linux  ·  high  ·  Storage, filesystems & NFS

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

Stale file handleESTALEnfs: server not respondingstill tryingmount.nfs: access denied

Fixes (3)

Clear the stale handles
Root shell on the client20 minutesmedium riskreversible

ESTALE errors on an otherwise reachable server.

  1. Find what still has the mount open — this is what blocks a clean unmount.

    Shell
    sudo lsof +D /mnt/nfs 2>/dev/null | head -20sudo fuser -vm /mnt/nfs
  2. Stop those processes or move them out of the directory, then unmount and remount.

    Shell
    sudo umount /mnt/nfssudo mount -als /mnt/nfs
  3. If it will not unmount, use a lazy unmount, which detaches the tree immediately and cleans up when the last reference closes.

    Shell
    sudo umount -l /mnt/nfs

    A 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.

  4. On the server, check the export has not changed identity — a recreated filesystem gets a new fsid.

    Shell
    sudo exportfs -vsudo cat /etc/exports
  5. Pin the fsid in the export so a server rebuild does not invalidate every client handle.

    Shell
    sudo sed -i 's|\(/srv/share.*\)(|\1(fsid=1,|' /etc/exportssudo exportfs -ra
Confirm it workedThe mount lists normally and files open.
Shell
mount | grep nfs; ls -la /mnt/nfs | head
If you need to undo itRestore /etc/exports from a copy and run exportfs -ra.
Recover from a hung hard mount, and stop it recurring
Root shell on the client30 minutesmedium riskreversible

Everything touching the path hangs.

  1. Confirm the diagnosis — processes in D state on that mount.

    Shell
    ps -eo pid,stat,wchan:24,comm | awk '$2 ~ /D/'dmesg -T | grep -i 'nfs.*not responding' | tail
  2. Detach it lazily so new commands stop hanging.

    Shell
    sudo umount -l /mnt/nfs
  3. Understand 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.

  4. Add intr and a timeout where a hard mount is right but responsiveness matters.

    Shell
    sudo sed -i 's|\(nfs.*defaults\)|\1,_netdev,hard,timeo=600,retrans=2|' /etc/fstabsudo mount -a
  5. 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.

    Shell
    sudo apt install autofs
  6. Always add _netdev to an NFS entry in fstab, or the machine will hang at boot waiting for a mount before the network exists.

Confirm it workedThe mount recovers when the server returns, and a boot with the server unavailable still completes.
Shell
mount | grep nfssystemd-analyze blame | head
If you need to undo itRestore the original fstab line.
Fix a mount that is refused
Both ends25 minuteslow riskreversible

mount.nfs reports access denied or connection refused.

  1. Check what the server actually exports and to whom.

    Shell
    showmount -e nfsserversudo exportfs -v
  2. 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.

  3. Check the firewall. NFSv4 needs only TCP 2049; NFSv3 needs rpcbind and several other ports.

    Shell
    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.

  4. Force the version explicitly to remove the negotiation from the equation.

    Shell
    sudo mount -t nfs -o vers=4.2 nfsserver:/srv/share /mnt/nfs
  5. Check root squashing if files are visible but not writable — root on the client becomes nobody on the server by default.

    Shell
    sudo grep -n squash /etc/exportsid; ls -ln /mnt/nfs | head
Confirm it workedThe mount succeeds and a test file can be created and removed.
Shell
sudo touch /mnt/nfs/.writetest && sudo rm /mnt/nfs/.writetest && echo writable
If you need to undo itNothing persistent changed unless fstab was edited.

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.