37

Server A used to be a NFS server. Server B was mounting an export of that. Everything was fine. Then A died. Just switched off. Gone. Vanished.

However that folder is still mounted on B. I obviously can't cd into it or anything. However umount /mnt/myfolder just hangs and won't umount. Is there anyway to umount it without restarting B?

Both client and server are Linux machines.

Kalle Richter
  • 259
  • 6
  • 17
Amandasaurus
  • 30,211
  • 62
  • 184
  • 246
  • 1
    http://askubuntu.com/questions/292043/how-to-unmount-nfs-when-server-is-gone | https://superuser.com/questions/973273/force-unmount-nfs-partition | http://unix.stackexchange.com/questions/97834/nfs-unable-to-umount-nfs-share-when-server-offline – Ciro Santilli OurBigBook.com Mar 18 '17 at 07:27

10 Answers10

55

Assuming Linux:

umount -f -l /mnt/myfolder

Will sort of fix the problem:

-f Force unmount (in case of an unreachable NFS system). (Requires kernel 2.1.116 or later.)

-l Lazy unmount. Detach the filesystem from the filesystem hierarchy now, and cleanup all references to the filesystem as soon as it is not busy anymore. (Requires kernel 2.4.11 or later.)

-f also exists on Solaris and AIX.

Douglas Leeder
  • 2,725
  • 18
  • 15
  • 1
    I had the same issue, googled and came here. Yes - the lazy flag really helped me here... -f on it's own wasn't doing it... – wawawawa Jul 15 '10 at 17:27
  • yes, must have "-l" "-f" option SAME TIME. – liuyang1 Jun 27 '15 at 12:27
  • 2
    Also, I sometimes had better success by specifying the remote address rather than the local path for umount, eg. `umount -f -l nfsserver:/export/thefolder`. – oliver Jan 11 '17 at 16:55
  • It seems to me only "-l" without "-f" option could prevent the hang – PT Huynh Jan 10 '20 at 01:37
19

Elaborating upon the hint given by David Pashley,

unless "umount -l" solves your problem, you can set up a fake server with the same address as the one that has gone away - but you don't actually have to set up a new sever or anything. The easiest way out of the blocking/hung umount situation is to set up a local alias IP interface, as follows:

ifconfig eth0:nfstmp 11.22.33.44 netmask 255.255.255.255
umount -l /mnt/deadnfsmount    # -l or -f or whichever that gets the job done
ifconfig eth0:nfstmp down

(obviously 11.22.33.44 being the (former) IP address of the (now dead) NFS server)

conny
  • 2,259
  • 2
  • 16
  • 14
8

It might be wise to add the intr option to any /etc/fstab entries that might end up hanging or crashing. If you don't use the soft or intr options, then when the server hosting the NFS files goes down, the server on which the files are mounted (the client) may hang when booting up.

According to man 5 nfs:

soft / hard
Determines the recovery behavior of the NFS client after an NFS request times out. If neither option is specified (or if the hard option is specified), NFS requests are retried indefinitely. If the soft option is specified, then the NFS client fails an NFS request after retrans retransmissions have been sent, causing the NFS client to return an error to the calling application.

... and then it goes on to say intr is preferred over soft, but it has the similar effect of preventing hanging.

Kalle Richter
  • 259
  • 6
  • 17
s g
  • 581
  • 3
  • 7
  • 17
  • 5
    Note that with newer versions of nfs, intr is deprecated or has no operation - in which case soft should be used. – Paul Mar 17 '17 at 17:30
3

umount -f /mnt/myfolder should solve this. See the umount manpage.

sebix
  • 4,175
  • 2
  • 25
  • 45
pauska
  • 19,532
  • 4
  • 55
  • 75
  • 2
    This doesn't quite do it with NFS and a dead server. You need the lazy flag too (or the trick with adding an IfAlias). lsof and fuser all hang and umount -f says "device busy". – wawawawa Jul 15 '10 at 17:28
1

I've never managed to get umount -f to work. A useful trick is to set up another server mounting the same export, give it the same IP address as the old server. Your NFS client should think everything is back as normal and processes will unblock. You can then unmount the mount point normally and remove the IP address from the temporary NFS server.

sebix
  • 4,175
  • 2
  • 25
  • 45
David Pashley
  • 23,151
  • 2
  • 41
  • 71
1

Just as an aside, using automount will handle unmounting NFS shares when they become unavaliable, which avoids getting stuck in this situatuion in future.

Coops
  • 5,967
  • 1
  • 31
  • 52
1

For Solaris, restarting the NFS client will resolve the "hard mount spiral of death". The command for Solaris 10 is "svcadm restart network/nfs/client" Haven't tried this on a Linux box lately (because those all mount with the "intr" flag so they rarely have this problem), but it probably will also fix the problem.

John Grant
  • 11
  • 2
0

I just noticed that forcing unmounts on kernel 3.2.0 hangs with NFSv4 mounts. NFSv3 unmounts work fine.

$ mount [...] -o nfsvers=3
slm
  • 7,355
  • 16
  • 54
  • 72
0

just an OS X-specific follow-up, since mount commands are mostly *nix agnostic: the -l (lazy) flag doesn't exist in OS X, however, the -f (force) flag does, and proved to be sufficient. Also, the system-generated mount points are in /Volumes (/Volumes/myserversexport)

niels
  • 181
  • 4
0

I've met this same problem. Since the NFS server got removed, I can not umount the nfs from client. I tried the following trick, see if it could be helpful. Since the original NFS server is gone, I create a new server with same IP and exports. Then I try umount -f /mnt/nfs_part. I finally could umount the nfs now.

Lan
  • 1