如何强制卸载 CIFS 连接

发布于 2024-07-05 01:56:08 字数 236 浏览 4 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

灼疼热情 2024-07-12 01:56:08

惰性卸载将为您完成这项工作。

umount -l <mount path>

A lazy unmount will do the job for you.

umount -l <mount path>
云巢 2024-07-12 01:56:08

在 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 命令开始。 它对于分析挂载的状态很有用:

mountpoint /mnt/smb_share

通常它返回是挂载点/不是挂载点

但它甚至可以返回:

  • No such device
  • Transport Endpoint is not connect

对于每一个期望不是挂载点的结果,都有可能被卸载。

您可以尝试通常的方法:

umount /mnt/smb_share

或强制模式:

umount /mnt/smb_share -f

但强制通常没有帮助。 它只是返回同样令人讨厌的设备正忙消息。

那么唯一的选择是使用惰性模式:

umount /mnt/smb_share -l

但是:这不会卸载任何东西。 它只是将挂载“移动”到系统的根目录,如下所示:

# lsof | grep mount | grep cwd
mount.cif  3125             root  cwd   unknown                                          / (stat: No such device)
mount.cif  3150             root  cwd   unknown                                          / (stat: No such device)

甚至在文档中也注明了:

延迟卸载。 从文件层次结构中分离文件系统
现在,尽快清除对此文件系统的所有引用
因为现在不忙了。

现在,如果你不走运,它就会永远留在那里。 即使终止进程也可能无济于事:

kill -9 $pid

但为什么这是一个问题呢? 因为只有在惰性卸载路径被 Linux 内核真正清理干净后,mount /mnt/smb_share 才会起作用。 umount 的文档中甚至提到了这一点。 “lazy”只能用于避免长时间关闭/重新启动:

如果您在不久的将来,系统预计会重新启动
将此选项用于网络文件系统或本地
带有子挂载的文件系统。 推荐的用例
umount -l 是为了防止因关闭而挂起
无法访问的网络共享,正常卸载将因该原因而挂起
到已关闭的服务器或网络分区。 重新安装
共享将是不可能的。

解决方法

使用不同的 SMB 版本

如果您仍然希望惰性卸载路径不再繁忙并被 Linux 内核清理,或者您无法在此刻,那么您可能很幸运,您的 SMB 服务器支持不同的协议版本。 通过这种方式,我们可以使用以下技巧:

假设您按如下方式安装了共享:

mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw

Linux 会自动尝试最大支持 SMB 协议版本。 也许是3.1。 现在,您可以强制使用此版本,但它不会按预期安装:

mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw,vers=3.1

但只需尝试不同的版本:

mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw,vers=3.0

或者可能是 2.1:

mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw,vers=2.1

更改 SMB 服务器的 IP

如果您能够更改 IP地址或添加第二个 IP 到您的 SMB 服务器,您可以使用它来安装同一服务器。

脏:转发流量

假设 SMB 服务器的 IP 地址为 10.0.0.1,并且挂载确实已失效。 然后创建此 iptables 规则:

iptables -t nat -A OUTPUT -d 10.0.0.250 -j DNAT --to-destination 10.0.0.1

现在相应地更改您的挂载规则,以便它通过 IP 10.0.0.250 而不是 10.0.0.1 挂载 samba 服务器,瞧,无需重新启动服务器即可挂载。 很脏,但是有用。 PS 此规则不会在重新启动后继续存在,因此您应该手动挂载 SMB 服务器并保留 /etc/ fstab 像往常一样。

更多调试

如果您想检查 samba 连接本身理论上是否正常工作,您可以尝试通过 SMB3 列出服务器的所有 SMB 共享,如下所示:

smbclient //smb.server -U "smb_user" -m SMB3 -L

或查看与 SMB1 共享的内容:

smbclient //smb.server -U "smb_user" -m NT1 -c ls

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:

mountpoint /mnt/smb_share

Usually it returns is a mountpoint or / is not a mountpoint.

But it can even return:

  • No such device
  • Transport endpoint is not connected
  • <nothing / stale>

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:

# lsof | grep mount | grep cwd
mount.cif  3125             root  cwd   unknown                                          / (stat: No such device)
mount.cif  3150             root  cwd   unknown                                          / (stat: No such device)

It is even noted in the documentation:

Lazy unmount. Detach the filesystem from the file hierarchy
now, and clean up all references to this filesystem as soon
as it is not busy anymore.

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 of umount. "lazy" should only be used to avoid a long shutdown / reboot times:

A system reboot would be expected in near future if you’re
going to use this option for network filesystem or local
filesystem with submounts. The recommended use-case for
umount -l is to prevent hangs on shutdown due to an
unreachable network share where a normal umount will hang due
to a downed server or a network partition. Remounts of the
share will not be possible.

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:

mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw

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:

mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw,vers=3.1

But then simply try a different version:

mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw,vers=3.0

or maybe 2.1:

mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw,vers=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:

iptables -t nat -A OUTPUT -d 10.0.0.250 -j DNAT --to-destination 10.0.0.1

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:

smbclient //smb.server -U "smb_user" -m SMB3 -L

or to view the content of a share with SMB1:

smbclient //smb.server -U "smb_user" -m NT1 -c ls
聊慰 2024-07-12 01:56:08

从侧面解决这个问题:

如果由于文件系统繁忙而无法卸载,那么您的 ssh/terminal 会话是否 cd'd 到挂载目录中,从而使文件系统繁忙?

对我来说,解决方案是 cd 进入我的家,然后 sudo umount 完美地工作。

cd ~
umount /path/to/my/share

我会将其作为评论发布,但我的声誉不足。 希望不要被别人打额头。

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.

cd ~
umount /path/to/my/share

I would post this as a comment, but I have insufficient reputation. Hoping to spare someone else the forehead slap.

快乐很简单 2024-07-12 01:56:08
umount -f -t cifs -l /mnt &

小心&,让umount在后台运行。
umount 将首先分离文件系统,因此您将找不到关于 /mnt 的任何内容。 如果你运行df命令,那么它会强制umount /mnt

umount -f -t cifs -l /mnt &

Be careful of &, let umount run in background.
umount will detach filesystem first, so you will find nothing abount /mnt. If you run df command, then it will umount /mnt forcibly.

遇到 2024-07-12 01:56:08

尝试 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

绝情姑娘 2024-07-12 01:56:08

我在 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 by umount.davfs. To force-unmount my davfs mount, I had to use umount -i -f -l /media/davmount.

雨的味道风的声音 2024-07-12 01:56:08

我遇到这个问题一天了,直到找到真正的解决方案。 不要尝试强制卸载挂起的 smb 共享,而是使用“软”选项挂载共享。 如果进程尝试连接到不可用的共享,它将在一段时间后停止尝试。

soft 使安装变得柔软。 几秒钟后文件系统调用失败。

mount -t smbfs -o soft //username@server/share /users/username/smb/share

stat /users/username/smb/share/file
stat: /users/username/smb/share/file: stat: Operation timed out

可能不是您问题的真正答案,但它是问题的解决方案

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.

soft Make the mount soft. Fail file system calls after a number of seconds.

mount -t smbfs -o soft //username@server/share /users/username/smb/share

stat /users/username/smb/share/file
stat: /users/username/smb/share/file: stat: Operation timed out

May not be a real answer to your question but it is a solution to the problem

稳稳的幸福 2024-07-12 01:56:08

您可以尝试使用 -f 选项来卸载:

umount -f /mnt/fileshare

您是否指定要安装的“-t cifs”选项? 还要确保您没有指定要安装的“硬”选项。

您可能还需要考虑 fusesmb,因为文件系统将在用户空间中运行你可以像任何其他进程一样杀死它。

There's a -f option to umount that you can try:

umount -f /mnt/fileshare

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.

寄居者 2024-07-12 01:56:08

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.

美人骨 2024-07-12 01:56:08

在 RHEL 6 上,这有效:

umount -f -a -t cifs -l 

On RHEL 6 this worked:

umount -f -a -t cifs -l 
小巷里的女流氓 2024-07-12 01:56:08

这对我有用(Ubuntu 13.10 桌面到 Ubuntu 14.04 服务器):-

 sudo umount -f /mnt/my_share

安装

 sudo mount -t cifs -o username=me,password=mine //192.168.0.111/serv_share /mnt/my_share

在 smb.conf 文件中设置并指向 serv_share 的位置。

This works for me (Ubuntu 13.10 Desktop to an Ubuntu 14.04 Server) :-

 sudo umount -f /mnt/my_share

Mounted with

 sudo mount -t cifs -o username=me,password=mine //192.168.0.111/serv_share /mnt/my_share

where serv_share is that set up and pointed to in the smb.conf file.

习ぎ惯性依靠 2024-07-12 01:56:08

我使用延迟卸载:umount -l(这是一个小写的L

延迟卸载。 分离文件系统
现在从文件系统层次结构中,并且
清理所有对的引用
文件系统一旦不忙
不再了。 (需要内核 2.4.11 或
稍后。)

I use lazy unmount: umount -l (that's a lowercase 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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文