Force unmount of NFS-mounted directory [closed]
Asked Answered
C

6

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?

Crinoline answered 2/9, 2008 at 19:4 Comment(5)
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.Visceral
ok, but you could find it on Super User. although I don't see why the question was not moved instead of closed.Flammable
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 /badmountChronicles
@Flammable Because this question was asked in Sept. 2008, and Super User wasn't launched until July 2009 ;-)Graveyard
@Carpetsmoker but it was marked as off-topic in 2013Dzoba
N
254

You might try a lazy unmount:

umount -l
Needlewoman answered 2/9, 2008 at 19:5 Comment(6)
@Daniel: sure, but it is a Linux question (tagged as such even), and Linux does have it.Lamdin
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.Lowpressure
I tried this command on Ubuntu and it didnt work.Hals
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.Judaea
@KieranAndrews and anyone else on Ubuntu, try fusermount -uz /path/to/file. Worked a charm for me! :)Merla
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.Mulkey
C
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!

Corbel answered 15/9, 2008 at 15:56 Comment(6)
A combination of ifconfig eth0:fakenfs ...' and umount -f -l /my/mount/dir' solved the problem for me.Ellord
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.Wilkie
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?Hochman
@Shurane Under Linux, removing an alias with ifconfig eth0:fakenfs down should do the trick.Photosynthesis
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.Chantey
thanks, brilliant work around! in my case the nfs server was back online and still could not umount it, this did the trick, cheersSegura
F
20

Try running

lsof | grep /mnt/data

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

Fulsome answered 2/9, 2008 at 19:12 Comment(2)
Definitely helpful, though didn't completely save me. But helpful.Banian
When lsof hangs forever, try "lsof -b" (there is an lsof bug realated to NFS, see e.g. bugzilla.redhat.com/show_bug.cgi?id=962755 ).Saponaceous
A
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 ;-)

Afterglow answered 27/12, 2012 at 2:41 Comment(2)
Worked for me with umount -f -l ...Carrick
On ubuntu server 14.04 i had to sudo service nfs-kernel-server restart, but your answer definitly got me to the right track, thanks!Tether
S
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.

Supremacist answered 15/9, 2008 at 16:6 Comment(1)
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.Unlearn
B
4

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

Buchbinder answered 31/8, 2012 at 7:55 Comment(2)
Isn't umount.nfs4 a subcommand for umount? In other words, umount -f /some/mountpoint is the same as umount.nfs4 /some/mountpoint -f.Helsa
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).Gilda

© 2022 - 2024 — McMap. All rights reserved.