Linux 强制卸载 NFS 挂载目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 16:23:34  来源:igfitidea点击:

Force unmount of NFS-mounted directory

linuxmountnfsumountnfsclient

提问by Lorin Hochstein

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:

我在已挂起的 Linux 机器上有一个挂载 NFS 的目录。我试图强制卸载,但它似乎不起作用:

$ 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:

如果我输入“ mount”,该目录似乎不再挂载,但如果我输入“ ”,它会挂起ls /mnt/data,如果我尝试删除挂载点,我会得到:

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

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

除了重启机器还有什么我可以做的吗?

采纳答案by tessein

You might try a lazy unmount:

您可以尝试延迟卸载:

umount -l

回答by Ryan Ahearn

Try running

尝试跑步

lsof | grep /mnt/data

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

这应该列出任何正在访问 /mnt/data 的进程,这些进程会阻止它被卸载。

回答by Daniel Papasian

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

如果 NFS 服务器消失并且您无法将其重新联机,我使用的一个技巧是使用 NFS 服务器的 IP(在本例中为 192.0.2.55)向接口添加别名。

Linux

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:

其中 192.0.2.55 是消失的 NFS 服务器的 IP。然后您应该能够 ping 地址,并且您还应该能够卸载文件系统(使用 unmount -f)。然后您应该销毁别名接口,以便您不再将流量路由到旧的 NFS 服务器:

ifconfig eth0:fakenfs down

FreeBSD and similar operating systems

FreeBSD 和类似的操作系统

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!

man ifconfig(8) 了解更多!

回答by Daniel Papasian

Your NFS server disappeared.

您的 NFS 服务器消失了。

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

理想情况下,您最好的选择是 NFS 服务器返回。

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

如果没有,“umount -f”应该可以解决问题。它并不总是有效,但通常会有效。

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.

如果您碰巧知道哪些进程正在使用 NFS 文件系统,您可以尝试杀死这些进程,然后卸载可能会起作用。

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.

另外,不要软安装 NFS 驱动器。您使用硬安装来保证它们有效。如果你正在写,这是必要的。

回答by Dave

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

在这里找不到有效的答案;但在 linux 上你可以运行“umount.nfs4 /volume -f”,它肯定会卸载它。

回答by Daniel N.

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

我遇到了同样的问题,而且都umount /path -f没有umount.nfs /path -f,都没有 ,也没有 ,都 fuser -km /path不起作用

finally I found a simple solution >.<

最后我找到了一个简单的解决方案>.<

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

sudo /etc/init.d/nfs-common restart,然后让我们做简单的umount;-)