无法卸载_Linux系统无法卸载文件系统该怎么办

简介

前些日子,有个开发找我,说他的一个Linux环境,想卸载其中的一个文件系统,可是执行umount命令,一直显示文件系统忙,无法卸载,问我怎么办。

af749f595f36f304e6204c8ec136620d.png

问题复盘

1.先创建测试文件系统/fstest

[root@192 ~]# df -ThFilesystem              Type      Size  Used Avail Use% Mounted ondevtmpfs                devtmpfs  475M     0  475M   0% /devtmpfs                   tmpfs     487M     0  487M   0% /dev/shmtmpfs                   tmpfs     487M   45M  442M  10% /runtmpfs                   tmpfs     487M     0  487M   0% /sys/fs/cgroup/dev/mapper/centos-root xfs        39G   23G   16G  59% //dev/sda1               xfs      1014M  160M  855M  16% /boot/dev/mapper/centos-home xfs        19G  3.3G   16G  18% /hometmpfs                   tmpfs      98M     0   98M   0% /run/user/1000overlay                 overlay    39G   23G   16G  59% /var/lib/docker/overlay2/d228823ce6403d522417b3e69eda58a89e36db8f3dde5e1be623040becbc3682/merged/dev/mapper/vg1-lv01    xfs      1014M   33M  982M   4% /fstest

2.创建测试目录和业务脚本

[root@192 log]# mkdir -p /fstest/log[root@192 fstest]# cat test.sh#!/bin/bashwhile truedoecho `date` >> /fstest/log/test.logsleep 10done

3.将脚本放在后台运行

[root@192 fstest]# nohup ./test.sh > test.sh.log &[1] 54652[root@192 fstest]# nohup: ignoring input and redirecting stderr to stdout[root@192 fstest]# lltotal 4drwxr-xr-x 2 root root 22 Sep  5 10:03 log-rwxr-xr-x 1 root root 77 Sep  5 10:04 test.sh-rw-r--r-- 1 root root  0 Sep  5 10:12 test.sh.log

4.模拟卸载/fstest文件系统

[root@192 ~]# umount /fstestumount: /fstest: target is busy.        (In some cases useful info about processes that use         the device is found by lsof(8) or fuser(1))

卸载文件系统报错了,文件系统繁忙,无法卸载,这是因为有应用程序在读写/fstest文件的文件,所以在这里必须要找出是谁在访问/fstest文件

5.找出访问指定文件系统的应用进程

[root@192 ~]# fuser -u -m /fstest/fstest:             54652c(root) 54913c(root)

在这里使用fuser已经找出正在使用/fstest的用户进程ID了,剩下的就是可以通过ps -ef找出什么进程了。

[root@192 ~]# ps -ef|egrep -i "54652|55159"root      54652  52239  0 10:12 pts/1    00:00:00 /bin/bash ./test.shroot      55216  54652  0 10:20 pts/1    00:00:00 sleep 10root      55226  52239  0 10:20 pts/1    00:00:00 grep -E --color=auto -i 54652|55159

在杀掉进程之前,需要看看此进程是否会影响业务,如果不影响业务,就可以直接杀掉

[root@192 ~]# kill -9 54652[root@192 ~]# ps -ef|egrep -i "54652|55159"root      55377  52239  0 10:22 pts/1    00:00:00 grep -E --color=auto -i 54652|55159[1]+  Killed                  nohup ./test.sh > test.sh.log  (wd: /fstest)(wd now: ~)

杀掉进程之后,就可以正常的卸载文件了

[root@192 ~]# umount /fstest/[root@192 ~]# [root@192 ~]# df -ThFilesystem              Type      Size  Used Avail Use% Mounted ondevtmpfs                devtmpfs  475M     0  475M   0% /devtmpfs                   tmpfs     487M     0  487M   0% /dev/shmtmpfs                   tmpfs     487M   45M  442M  10% /runtmpfs                   tmpfs     487M     0  487M   0% /sys/fs/cgroup/dev/mapper/centos-root xfs        39G   23G   16G  59% //dev/sda1               xfs      1014M  160M  855M  16% /boot/dev/mapper/centos-home xfs        19G  3.3G   16G  18% /hometmpfs                   tmpfs      98M     0   98M   0% /run/user/1000overlay                 overlay    39G   23G   16G  59% /var/lib/docker/overlay2/d228823ce6403d522417b3e69eda58a89e36db8f3dde5e1be623040becbc3682/merged

文件系统已经正常卸载了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值