强制Umount NFS终极手法

本文介绍了解决设备占用导致无法卸载的问题,通过使用fuser命令检查并杀死占用设备的进程,以及使用umount命令的-l参数进行懒卸载,最终成功卸载设备。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 当Umount一个目录时,提示device is busy,umount加参数f,是强制执行umount,但是许多时候均不会成功。 
原理上要想umount,首先要kill正在使用这个目录的进程。*假设无法卸载的设备为/dev/sdb1 
1)运行下面命令看一下哪个用户哪个进程占用着此设备 
fuser -m -v /dev/sdb1

2)运行下面命令杀掉占用此设备的进程 
fuser -m -v -k /dev/sdb1 
或者fuser -m -v -k -i  /dev/sdb1(每杀掉一下进程会让你确认) 
3)再umount

*杀掉所有以任何形式访问文件系统 /dev/sdb1的进程: 
$fuser -km /dev/sdb1 
这个办法是一个比较粗鲁的办法,通常适用于在测试等非正式环境。比较正规的要配合ps等命令,查出使用的用户、进程、命令等,然后做出综合判断,必要时先通知(signal或口头等)用户,确认安全时才可以强制kill此进程。 
但有时fuser执行时,仍然会有报错,其实umount强制退出,可以考虑用参数l(Lazy),这个参数是比f(Force)更强大的终极命令。 

今天即使用了一下参数l,确实很强大!


Man Umount 查看f和l的参数说明如下: 
-f     Force  unmount.  This  allows  an  NFS-mounted  filesystem  to be unmounted if the NFS server is unreachable. Note: when using umount -f on an NFS filesystem, the 
              filesystem must be mounted using either the soft, or intr options (see nfs(5).  This option  will  not  force  unmount  a  <A1><AE>busy<A1><AF>  filesystem  (use  -l 
  instead). 
              (Requires kernel 2.1.116 or later.)

       -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. This option 
              allows a <A1><AE>busy<A1><AF> filesystem to be unmounted.  (Requires kernel 2.4.11 or later.) 
本次操作过程如下: 
[root@FUHOST /]# umount /home/swebapp/apache-tomcat-5.5.17/webapps/upload/ 
umount: /home/swebapp/apache-tomcat-5.5.17/webapps/upload: device is busy 
umount: /home/swebapp/apache-tomcat-5.5.17/webapps/upload: device is busy

[root@FJ-WEB-02 sbin]# umount -f /home/swebapp/apache-tomcat-5.5.17/webapps/upload/ 
umount2: 设备或资源忙 
umount: /home/swebapp/apache-tomcat-5.5.17/webapps/upload: device is busy 
umount2: 设备或资源忙 
umount: /home/swebapp/apache-tomcat-5.5.17/webapps/upload: device is busy

[root@FJ-WEB-02 sbin]# fuser -km  /home/swebapp/apache-tomcat-5.5.17/webapps/upload/ 
/home/swebapp/apache-tomcat-5.5.17/webapps/upload/: 输入/输出错误

[root@FJ-WEB-02 sbin]# fuser -um  /home/swebapp/apache-tomcat-5.5.17/webapps/upload/ 
/home/swebapp/apache-tomcat-5.5.17/webapps/upload/: 输入/输出错误

[root@FJ-WEB-02 upload]# umount -l /home/swebapp/apache-tomcat-5.5.17/webapps/upload/


http://tonnyxs.blog.163.com/blog/static/27937985201102202028695/

### 解决 `umount.nfs` 设备忙的问题 当尝试卸载 NFS 挂载点时遇到设备忙的错误,通常是因为有进程正在访问该挂载点下的文件或目录。以下是几种解决方案: #### 方法一:查找并终止占用资源的进程 可以通过 `fuser` 或者 `lsof` 命令来找出哪些进程占用了挂载点。 ```bash # 查找占用 /mnt 的进程 fuser -m /mnt # 或者使用 lsof 来查看打开文件的情况 lsof +D /mnt ``` 找到这些进程之后可以选择结束它们: ```bash # 终止所有占用 /mnt 的进程 (需谨慎操作) sudo fuser -km /mnt ``` 这种方法适用于知道具体是什么原因造成繁忙,并且能够安全地中止那些进程的情况下[^1]。 #### 方法二:强制懒惰卸载 (`-l`) 如果不想立即停止可能依赖于这个路径的应用程序,则可以考虑采用懒惰方式卸载(`-l`)选项。这会让内核在实际不再有人使用的时候自动完成卸载过程。 ```bash # 对指定位置执行懒惰卸载 umount -l /mnt ``` 此命令不会等待所有的引用被释放就返回成功状态,而是让系统继续运行直到自然地断开连接为止[^4]。 #### 方法三:循环尝试卸载 对于某些特殊情况,比如存在残留的网络问题或者其他异常情况,可以编写一个小脚本来不断重试卸载动作直至成功。 ```bash sh -c 'while true; do umount -lf /out && break || sleep 5; done' ``` 这段 shell 脚本会在每次失败后暂停五秒钟再重复尝试,直到最终顺利完成卸载工作[^5]。 以上三种方法可以根据实际情况灵活选用,建议先从最温和的方法开始测试,即先检查是否有活动进程阻止正常卸载,然后再决定是否采取更激进的方式处理这个问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值