Forcefully Unmount Stale NFS Mount When Server Becomes Unreachable


1 views

We've all been there - your NFS server goes down unexpectedly, but the mount point remains visible on the client. Attempting standard unmount commands just hangs indefinitely, leaving you with a zombie mount that blocks access to the directory and potentially causes other issues.

When an NFS server disappears, the client's mount enters a "stale" state. The kernel maintains the mount point but all operations will hang waiting for the server to respond. This is why standard umount commands fail - they're waiting for clean termination that will never come.

Here are the most effective methods to deal with this situation:

Method 1: Lazy Unmount

This is the safest first approach:

umount -l /mnt/myfolder

The -l (lazy) flag detaches the filesystem immediately, cleaning it up once it's no longer busy.

Method 2: Force Unmount

When lazy unmount doesn't work:

umount -f /mnt/myfolder

The -f (force) option attempts to force unmount even when the NFS server is unreachable. This may cause data loss on the server if it comes back online.

Method 3: Combined Approach

For stubborn mounts:

umount -fl /mnt/myfolder

For particularly problematic mounts, you may need to:

  1. Kill processes using the mount:
  2. fuser -km /mnt/myfolder
  3. Then attempt unmount again

Consider adding these NFS mount options to your /etc/fstab:

server:/export /mnt/myfolder nfs soft,timeo=5,retrans=5 0 0

The soft option prevents hangs when the server is unavailable, though may cause data corruption if used with write operations.

For critical mounts, autofs can provide better recovery:

yum install autofs  # or apt-get for Debian
systemctl enable --now autofs

Configure /etc/auto.master and /etc/auto.nfs for automatic mount management.


We've all been there - your NFS server goes down unexpectedly, but the mount point on your client machine remains stubbornly attached. Trying standard unmount commands just leaves you staring at a hanging terminal. Here's how to break free from these "zombie mounts" without rebooting your client.

When an NFS server disappears (hard crash, network failure, etc.), the Linux kernel maintains the mount point in a "stale" state. The default umount command tries to contact the server for a clean unmount, which causes the hang. We need to tell the kernel to skip this communication attempt.

The most reliable solution is using the lazy or force options with umount:

# Lazy unmount (preferred)
sudo umount -l /mnt/myfolder

# Force unmount (if lazy doesn't work)
sudo umount -f /mnt/myfolder

Alternatively, for particularly stubborn cases, you might need to:

# Check all open files on the mount
sudo lsof | grep /mnt/myfolder

# Kill processes using the mount
sudo fuser -km /mnt/myfolder
sudo umount /mnt/myfolder

Consider these mount options in your /etc/fstab to make mounts more resilient:

server:/export /mnt/myfolder nfs 
    rw,soft,timeo=5,retrans=1,retry=0 0 0

Key parameters:

  • soft: Fails operations after retries instead of hanging
  • timeo: Timeout in deciseconds (5 = 0.5 seconds)
  • retrans: Number of retry attempts

If you're using systemd mounts, you may need to:

sudo systemctl stop mnt-myfolder.mount
sudo systemctl reset-failed mnt-myfolder.mount