163

I have an NFS-mounted directory on a Linux machine that has hung. I've tried to force an unmount, but it doesn't seem to work:

$ umount -f /mnt/data
$ umount2: Device or resource busy
$ umount: /mnt/data: device is busy

If I type "mount", it appears that the directory is no longer mounted, but it hangs if I do "ls /mnt/data", and if I try to remove the mountpoint, I get:

$ rmdir /mnt/data
rmdir: /mnt/data: Device or resource busy

Is there anything I can do other than reboot the machine?

RzR
  • 2,889
  • 26
  • 25
Lorin Hochstein
  • 51,296
  • 30
  • 96
  • 131
  • 3
    I agree, whoever voted to close this seriously confused. This problem has plagued me for years, and the answer below, umount -l, for Linux, is the first solution I've found that worked. – Lizardx Oct 14 '15 at 23:41
  • 1
    ok, but you could find it on Super User. although I don't see why the question was not moved instead of closed. – deeenes Oct 20 '15 at 15:30
  • For umount `--force` will try harder to unmount and `-v` or `-vvv` even will reveal more what is the problem with mount. So try: `umount -vvv --force /badmount` – gaoithe Dec 04 '15 at 11:54
  • 5
    @deeenes Because this question was asked in Sept. 2008, and Super User wasn't launched until July 2009 ;-) – Martin Tournoij Mar 15 '16 at 00:39
  • @Carpetsmoker but it was marked as off-topic in 2013 – hintss Apr 03 '16 at 23:57

6 Answers6

254

You might try a lazy unmount:

umount -l
Tim Cooper
  • 144,163
  • 35
  • 302
  • 261
tessein
  • 2,965
  • 1
  • 16
  • 5
  • 3
    This is not implemented everywhere. I don't have it on FreeBSD, for instance. – Daniel Papasian Jun 03 '09 at 20:23
  • 28
    @Daniel: sure, but it *is* a Linux question (tagged as such even), and Linux does have it. – Jürgen A. Erhard Jul 04 '11 at 13:05
  • This made things worse for me, as I was still not able to suspend my machine. The solution with the eth0 alias and umount -f worked. – Florian Feb 15 '12 at 08:27
  • 5
    I tried this command on Ubuntu and it didnt work. – Kieran Andrews Nov 07 '12 at 23:59
  • 1
    This worked for me (Slackware 14.0). I had a CIFS mount, not NFS, that was hanging everything (including `lsof`). I caused the problem by breaking out of a backup script that I'm writing. The script mounts and unmounts the directory, but something about breaking out of `rsync` messed up my mount. I didn't know about the lazy unmount. It may have been the NAS device causing all the trouble. After successfully unmounting, it turned out that I had to reboot the device before I could mount it again. – paddy Mar 12 '14 at 02:27
  • 10
    @KieranAndrews and anyone else on Ubuntu, try `fusermount -uz /path/to/file`. Worked a charm for me! :) – Matt Fletcher Jun 23 '14 at 09:04
  • after months of not needing this command, a google search brought me back to this question, and thus this answer, and I noticed I already upvoted it. I wish I could upvote it again, because it worked and saved me once again. – Titi Aug 25 '16 at 23:46
78

If the NFS server disappeared and you can't get it back online, one trick that I use is to add an alias to the interface with the IP of the NFS server (in this example, 192.0.2.55).

Linux

The command for that is something roughly like:

ifconfig eth0:fakenfs 192.0.2.55 netmask 255.255.255.255

Where 192.0.2.55 is the IP of the NFS server that went away. You should then be able to ping the address, and you should also be able to unmount the filesystem (use unmount -f). You should then destroy the aliased interface so you no longer route traffic to the old NFS server to yourself with:

ifconfig eth0:fakenfs down

FreeBSD and similar operating systems

The command would be something like:

ifconfig em0 alias 192.0.2.55 netmask 255.255.255.255

And then to remove it:

ifconfig em0 delete 192.0.2.55

man ifconfig(8) for more!

Mike
  • 20,721
  • 13
  • 66
  • 79
Daniel Papasian
  • 15,567
  • 6
  • 27
  • 32
  • 5
    A combination of `ifconfig eth0:fakenfs ...' and `umount -f -l /my/mount/dir' solved the problem for me. – pts Jan 16 '10 at 15:41
  • 1
    me too, the unmount problem prevent me from suspend my laptop, so this solution is really useful. I have made my own script to automatize too. – albfan Nov 18 '11 at 08:03
  • So for removing an alias from Linux, would it be `ifconfig eth0:fakenfs delete`? Or am I looking for something else? Like `ifconfig eth0 delete 192.0.2.55`? – Ehtesh Choudhury Apr 24 '13 at 19:53
  • 2
    @Shurane Under Linux, removing an alias with `ifconfig eth0:fakenfs down` should do the trick. – Sven May 07 '13 at 09:17
  • I got my nfs server back up, but I couldn't unmount the share until I pinged the server, and I didn't have to do the alias stuff. I'm not sure why this worked, but I'll leave this here in case it helps someone else. – Techwolf Jul 23 '13 at 07:03
  • 1
    thanks, brilliant work around! in my case the nfs server was back online and still could not umount it, this did the trick, cheers – nmirceac Mar 14 '15 at 11:52
20

Try running

lsof | grep /mnt/data

That should list any process that is accessing /mnt/data that would prevent it from being unmounted.

Ryan Ahearn
  • 7,636
  • 6
  • 47
  • 56
  • 1
    Definitely helpful, though didn't completely save me. But helpful. – James T Snell Mar 06 '14 at 18:34
  • 2
    When lsof hangs forever, try "lsof -b" (there is an lsof bug realated to NFS, see e.g. https://bugzilla.redhat.com/show_bug.cgi?id=962755 ). – dr0i Aug 10 '15 at 12:39
11

I had the same problem, and neither umount /path -f, neither umount.nfs /path -f, neither fuser -km /path, works

finally I found a simple solution >.<

sudo /etc/init.d/nfs-common restart, then lets do the simple umount ;-)

Ricardo Alvaro Lohmann
  • 25,061
  • 6
  • 80
  • 80
Daniel N.
  • 135
  • 1
  • 9
4

Couldn't find a working answer here; but on linux you can run "umount.nfs4 /volume -f" and it definitely unmounts it.

Dave
  • 364
  • 3
  • 9
  • 4
    Isn't umount.nfs4 a subcommand for umount? In other words, `umount -f /some/mountpoint` is the same as `umount.nfs4 /some/mountpoint -f`. – Ville Jul 15 '13 at 16:32
  • 1
    Interesting. At my side (after NFS-Server vanished): `umount` calls `umount.nfs`, hangs forever (regardless of option). `umount.nfs4 /mnt -f` takes quite long, but completes. `umount.nfs4 /mnt -l` completes immediately (perhaps because it does not wait for processes). – Tino Jan 14 '15 at 22:19
4

Your NFS server disappeared.

Ideally your best bet is if the NFS server comes back.

If not, the "umount -f" should have done the trick. It doesn't ALWAYS work, but it often will.

If you happen to know what processes are USING the NFS filesystem, you could try killing those processes and then maybe an unmount would work.

Finally, I'd guess you need to reboot.

Also, DON'T soft-mount your NFS drives. You use hard-mounts to guarantee that they worked. That's necessary if you're doing writes.

  • Soft vs hard mounting seems to be a matter of use cases. Yes, a soft mount would cause files currently being written to be broken if the NFS server goes down for some reason, and might thus not be suitable system critical directories, but for a drive with non-critical files like music and movies it would work just fine. – zrajm Jan 31 '14 at 21:26