linux下使用umount卸载磁盘时提示 target is busy 处理

- linux系统管理

有个按量付费的硬盘,使用完毕后打算取消挂载并销毁硬盘。但是 umount 的时候报错 umount: /data05: target is busy. 这里记录下处理方法。


取消挂载报错

确认当前情况

[root@imzcy ~]# df -hT /dev/vde
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/vde       xfs   2.6T  892G  1.7T  35% /data05
[root@imzcy ~]# 

取消挂载时报如下错误。

[root@imzcy ~]# umount /dev/vde
umount: /data05: target is busy.
[root@imzcy ~]# 




排查占用情况

使用 lsof 命令过滤指定挂载目录,可以看到占用情况。

[root@imzcy ~]# lsof |grep /data05
screen    27638        root  cwd       DIR             253,64          49 2147789901 /data05/qp
bash      31845        root  cwd       DIR             253,64          49 2147789901 /data05/qp
[root@imzcy ~]# 




处理占用

第一个 screen 的直接连接到这个会话里,确认无用直接 exit 退出关闭这个会话即可。

[root@imzcy ~]# screen -r 27638
[screen is terminating]
[root@imzcy ~]# 

关闭 screen 会话后,再次查看就只剩一个了。

[root@imzcy ~]# lsof |grep /data05
bash      31845        root  cwd       DIR             253,64          49 2147789901 /data05/qp
[root@imzcy ~]# 


查看 pid 为 31845 的进程,可以看出这是一个交互式 bash shell(/usr/bin/bash), TTY(终端)是 pts/8,该进程属于 root 用户,启动时间为 07:04,应该是我早上连的。

[root@imzcy ~]# ps -ef |grep 31845 |grep -v grep
root     31845 31844  0 07:04 pts/8    00:00:00 /usr/bin/bash
[root@imzcy ~]# 

没啥用,直接kill掉进程即可。

[root@imzcy ~]# kill 31845
[root@imzcy ~]# lsof |grep /data05
bash      31845        root  cwd       DIR             253,64          49 2147789901 /data05/qp
[root@imzcy ~]# 
[root@imzcy ~]# kill -9 31845
[root@imzcy ~]# lsof |grep /data05
[root@imzcy ~]# 




再次尝试卸载磁盘成功

[root@imzcy ~]# umount /dev/vde
[root@imzcy ~]#