linux卸载设备忙_如何强制Linux卸载文件系统,报告“设备正忙”

linux卸载设备忙

Linux may report "device is busy" when we try to umount a filesystem. This behavior is reasonable as it can help us avoid data loss by disallowing unmouting a filesystem when it is being used. But for situations when we are sure there is something wrong happened or we care not data lost such as a NFS mounting failed because that the NFS server is dead and will never be back. Under these kinds of situations, how do we force Linux to unmount a filesystem?

当我们尝试卸载文件系统时, Linux可能会报告“设备正忙”。 此行为是合理的,因为它可以通过禁止在使用文件系统时对其进行更改来帮助我们避免数据丢失。 但是在某些情况下,如果我们确定发生了某些错误,或者我们不关心数据丢失(例如NFS挂载失败)是因为NFS服务器已死并且永远不会退回,那么这种情况就不会发生。 在这种情况下,我们如何强制Linux卸载文件系统?

First, why "device is busy"? The reason is that there are likely programs/kernel threads accessing partition or open files. Knowing the reason, we can find the solutions.

首先,为什么“设备忙”? 原因是可能有程序/内核线程访问分区或打开的文件。 知道原因之后,我们可以找到解决方案。

选项0:如果要重新安装,请尝试重新安装文件系统 (Option 0: Try to remount the filesystem if what you want is remounting)

Here this option is not to really do unmounting a filesystem. But it is a useful technique. It is common that the reason we want to unmount a filesystem is that we find that there are problems with the mounting temporarily and we want to unmount and re-mount it. For these situations, you may first try

在这里,此选项不是真正卸载文件系统。 但这是一种有用的技术。 通常,我们要卸载文件系统的原因是,我们发现临时挂载存在问题,并且我们想卸载并重新挂载它。 对于这些情况,您可以先尝试

# mount -o remount /your/mount/point

The "-o remount" option will make Linux try to remount the filesystem. If the remounting can succeed, it avoids the problems of disrupting or killing processes.

“ -o remount”选项将使Linux尝试重新安装文件系统。 如果重新安装能够成功,则可以避免破坏或终止进程的问题。

选项1:强制卸载 (Option 1: Force unmount)

There are options of umount to detach a busy device immediately even if the device is busy.

umount选项可以立即分离繁忙的设备,即使该设备繁忙也是如此。

-f, --force
  Force an unmount (in case of an unreachable NFS system).
  (Requires kernel 2.1.116 or later.)

The -f option is for unreachable NFS system. Please be aware that programs may not expect a force or lazy unmounting and these options may disrupt running processes using the filesystem, cause data loss or corrupt files opened.

-f选项用于不可访问的NFS系统。 请注意,程序可能不会强制卸载或延迟卸载,并且这些选项可能会中断使用文件系统的运行进程,导致数据丢失或打开的文件损坏。

选项2:使用文件系统杀死进程,然后将其卸载 (Option 2: Kill the processes using the filesystem and then unmount it)

If the reason is that processes are using the filesystem, we can kill the processes using the filesystem and then it will be fine to unmount it. Here, we introduce 2 common methods with 2 common tools.

如果原因是进程正在使用文件系统,则我们可以使用文件系统杀死进程,然后卸载它就可以了。 在这里,我们介绍2种常用方法和2种常用工具。

方法1:使用lsof (Method 1: use lsof)

The following command finds out the processes accessing the partition/filesystem. You need to run the following command as root. Here, we use the mount point /mnt/data as an example.

以下命令找出访问分区/文件系统的进程。 您需要以超级用户身份运行以下命令。 在这里,我们以挂载点/ mnt / data为例。

# lsof | grep '/mnt/data'

It will output lines like

它将输出像

bash  17622  user1 cwd   DIR    253,2  4096  2 /mnt/data

If you are sure that it is safe to kill the process, you may kill them by kill or kill -9. After the processes are killed, the filesystem will be able to be unmounted.

如果确定杀死该进程是安全的,则可以通过killkill -9杀死它们。 在进程被杀死之后,文件系统将能够被卸载。

方法2:使用fuser (Method 2: use fuser)

You can find out the processes using a filesystem (e.g. /mnt/data) by

您可以通过以下方式使用文件系统(例如/ mnt / data)找出进程

# fuser /mnt/data

fuser can also help you kill all processes using a filesystem at the same time by

fuser还可以帮助您同时杀死使用文件系统的所有进程

# fuser -k /mnt/data

or

要么

# fuser -k -9 /mnt/data

Then you can continue to umount the filesystem.

然后,您可以继续卸载文件系统。

Lastly, if all above options and methods failed for you, you may try the final method reboot or SysRq or hardware resetting to reboot you Linux.

最后,如果上述所有选项和方法都对您失败,则可以尝试reboot最终方法或reboot SysRq硬件,以重新启动Linux。

翻译自: https://www.systutorials.com/force-linux-unmount-filesystem-reporting-device-busy/

linux卸载设备忙

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值