如何强制卸载 CIFS 连接
我在 Linux 计算机上安装了 CIFS 共享。 CIFS 服务器已关闭,或者互联网连接已关闭,并且任何接触 CIFS 安装的内容现在都需要几分钟才能超时,并且在等待期间无法杀死。 我什至无法在我的主目录中运行 ls,因为有一个符号链接指向 CIFS 安装内部,并且 ls 尝试跟随它来决定它应该是什么颜色。 如果我尝试卸载它(即使使用 -fl),卸载进程会像 ls 一样挂起。 甚至 sudo Kill -9 也无法杀死它。 如何强制卸载内核?
I have a CIFS share mounted on a Linux machine. The CIFS server is down, or the internet connection is down, and anything that touches the CIFS mount now takes several minutes to timeout, and is unkillable while you wait. I can't even run ls in my home directory because there is a symlink pointing inside the CIFS mount and ls tries to follow it to decide what color it should be. If I try to umount it (even with -fl), the umount process hangs just like ls does. Not even sudo kill -9 can kill it. How can I force the kernel to unmount?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
惰性卸载将为您完成这项工作。
A lazy unmount will do the job for you.
在 RHEL 6 上,这也对我有用:
umount -f -a -t cifs -l FOLDER_NAME
On RHEL 6 this worked for me also:
umount -f -a -t cifs -l FOLDER_NAME
关于卸载死 cifs 挂载,我经历了非常不同的结果,并发现了一些暂时绕过该问题的技巧。
让我们从
mountpoint
命令开始。 它对于分析挂载的状态很有用:通常它返回
是挂载点
或/不是挂载点
。但它甚至可以返回:
对于每一个期望
不是挂载点
的结果,都有可能被卸载。您可以尝试通常的方法:
umount /mnt/smb_share
或强制模式:
umount /mnt/smb_share -f
但强制通常没有帮助。 它只是返回同样令人讨厌的
设备正忙
消息。那么唯一的选择是使用惰性模式:
umount /mnt/smb_share -l
但是:这不会卸载任何东西。 它只是将挂载“移动”到系统的根目录,如下所示:
甚至在文档中也注明了:
现在,如果你不走运,它就会永远留在那里。 即使终止进程也可能无济于事:
kill -9 $pid
但为什么这是一个问题呢? 因为只有在惰性卸载路径被 Linux 内核真正清理干净后,
mount /mnt/smb_share
才会起作用。 umount 的文档中甚至提到了这一点。 “lazy”只能用于避免长时间关闭/重新启动:解决方法
使用不同的 SMB 版本
如果您仍然希望惰性卸载路径不再繁忙并被 Linux 内核清理,或者您无法在此刻,那么您可能很幸运,您的 SMB 服务器支持不同的协议版本。 通过这种方式,我们可以使用以下技巧:
假设您按如下方式安装了共享:
Linux 会自动尝试最大支持 SMB 协议版本。 也许是3.1。 现在,您可以强制使用此版本,但它不会按预期安装:
但只需尝试不同的版本:
或者可能是 2.1:
更改 SMB 服务器的 IP
如果您能够更改 IP地址或添加第二个 IP 到您的 SMB 服务器,您可以使用它来安装同一服务器。
脏:转发流量
假设 SMB 服务器的 IP 地址为 10.0.0.1,并且挂载确实已失效。 然后创建此
iptables
规则:现在相应地更改您的挂载规则,以便它通过 IP 10.0.0.250 而不是 10.0.0.1 挂载 samba 服务器,瞧,无需重新启动服务器即可挂载。 很脏,但是有用。 PS 此规则不会在重新启动后继续存在,因此您应该手动挂载 SMB 服务器并保留
/etc/ fstab 像往常一样。
更多调试
如果您想检查 samba 连接本身理论上是否正常工作,您可以尝试通过 SMB3 列出服务器的所有 SMB 共享,如下所示:
或查看与 SMB1 共享的内容:
I experienced very different results regarding unmounting a dead cifs mount and found several tricks to bypass the problem temporarily.
Let's start with the
mountpoint
command. It can be useful to analyze the status of a mount:Usually it returns
is a mountpoint
or/ is not a mountpoint
.But it can even return:
For every result expect of
is not a mountpoint
there is a chance of unmounting.You could try the usual way:
umount /mnt/smb_share
or force mode:
umount /mnt/smb_share -f
But often the force does not help. It simply returns the same nasty
device is busy
message.Then the only option is to use the lazy mode:
umount /mnt/smb_share -l
BUT: This does not unmount anything. It only "moves" the mount to the root of the system, which can be seen as follows:
It is even noted in the documentation:
Now if you are unlucky, it will stay there forever. Even killing the process probably does not help:
kill -9 $pid
But why is this a problem? Because
mount /mnt/smb_share
does not work until the lazy unmounted path is really cleaned up by the Linux Kernel. And this is even mentioned in the documentation ofumount
. "lazy" should only be used to avoid a long shutdown / reboot times:Workarounds
Use a different SMB version
If you still have hopes that the lazy unmounted path will ever be not busy anymore and cleaned up by the Linux Kernel or you can't reboot at the moment, then you are maybe lucky and your SMB server supports different protocol versions. By that we can use the following trick:
Lets say you mounted your share as follows:
By that Linux automatically tries the maximum support SMB protocol version. Maybe 3.1. Now, you can force this version and it won't mount as expected:
But then simply try a different version:
or maybe 2.1:
Change the IP of the SMB server
If you are able to change the IP address or add a second IP to your SMB server, you can use this to mount the same server.
Dirty: Forward the traffic
Lets say the SMB server has the IP address 10.0.0.1 and the mount is really dead. Then create this
iptables
rule:Now change your mount rule accordingly, so it mounts the samba server through IP 10.0.0.250 instead of 10.0.0.1 and voila, its mounted without server reboot. Dirty, but it works. PS This rule does not survive a reboot, so you should mount the SMB server manually and leave the
/etc/fstab
as usual.More debugging
If you want to check if samba connection itself is theoretically working, you could try to list all SMB shares of the server through SMB3 as follows:
or to view the content of a share with SMB1:
从侧面解决这个问题:
如果由于文件系统繁忙而无法卸载,那么您的 ssh/terminal 会话是否 cd'd 到挂载目录中,从而使文件系统繁忙?
对我来说,解决方案是 cd 进入我的家,然后 sudo umount 完美地工作。
我会将其作为评论发布,但我的声誉不足。 希望不要被别人打额头。
Approaching this problem sideways:
If you can't unmount because the filesystem is busy, is your ssh/terminal session cd'd into the mount directory, therefore making the filesystem busy?
For me, the solution was to cd into my home, then sudo umount worked flawlessly.
I would post this as a comment, but I have insufficient reputation. Hoping to spare someone else the forehead slap.
小心
&
,让umount
在后台运行。umount
将首先分离文件系统,因此您将找不到关于/mnt
的任何内容。 如果你运行df
命令,那么它会强制umount /mnt
。Be careful of
&
, letumount
run in background.umount
will detach filesystem first, so you will find nothing abount/mnt
. If you rundf
command, then it willumount /mnt
forcibly.尝试 umount -f /mnt/share。 使用 NFS 工作正常,从未尝试过使用 cifs。
另外,看看 autofs,它只会在访问时挂载共享,并在之后卸载它。
www.howtoforge.net 有一个很好的教程
Try umount -f /mnt/share. Works OK with NFS, never tried with cifs.
Also, take a look at autofs, it will mount the share only when accessed, and will unmount it afterworlds.
There is a good tutorial at www.howtoforge.net
我在 davfs 上遇到了非常类似的问题。 在
umount.davfs
的手册页中,我发现-f -l -n -r -v
选项被umount.davfs
忽略>。 要强制卸载我的 davfs 挂载,我必须使用 umount -i -f -l /media/davmount 。I had a very similar problem with davfs. In the man page of
umount.davfs
, I found that the-f -l -n -r -v
options are ignored byumount.davfs
. To force-unmount my davfs mount, I had to useumount -i -f -l /media/davmount
.我遇到这个问题一天了,直到找到真正的解决方案。 不要尝试强制卸载挂起的 smb 共享,而是使用“软”选项挂载共享。 如果进程尝试连接到不可用的共享,它将在一段时间后停止尝试。
可能不是您问题的真正答案,但它是问题的解决方案
I had this issue for a day until I found the real resolution. Instead of trying to force unmount an smb share that is hung, mount the share with the "soft" option. If a process attempts to connect to the share that is not available it will stop trying after a certain amount of time.
May not be a real answer to your question but it is a solution to the problem
您可以尝试使用 -f 选项来卸载:
您是否指定要安装的“-t cifs”选项? 还要确保您没有指定要安装的“硬”选项。
您可能还需要考虑 fusesmb,因为文件系统将在用户空间中运行你可以像任何其他进程一样杀死它。
There's a -f option to umount that you can try:
Are you specifying the '-t cifs' option to mount? Also make sure you're not specifying the 'hard' option to mount.
You may also want to consider fusesmb, since the filesystem will be running in userspace you can kill it just like any other process.
umount -a -t cifs -l
在 CentOS 6.3 上对我来说就像一个魅力。 它让我免去了服务器重启的麻烦。
umount -a -t cifs -l
worked like a charm for me on CentOS 6.3. It saved me a server reboot.
在 RHEL 6 上,这有效:
On RHEL 6 this worked:
这对我有用(Ubuntu 13.10 桌面到 Ubuntu 14.04 服务器):-
安装
在 smb.conf 文件中设置并指向 serv_share 的位置。
This works for me (Ubuntu 13.10 Desktop to an Ubuntu 14.04 Server) :-
Mounted with
where serv_share is that set up and pointed to in the smb.conf file.
我使用延迟卸载:
umount -l
(这是一个小写的L
)I use lazy unmount:
umount -l
(that's a lowercaseL
)