Linux取消挂载相关
取消挂载(target is busy)问题原因
[root@icoolkj ~]# umount /data
umount: /data: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
报错的原因通常是由于待卸载磁盘正在使用,导致无法直接卸载,需要将当前使用数据盘的进程杀掉,才能卸载。如果贸然强行删除,可能会导致数据丢失或设备损坏。需要使用fuser命令查找和删除占用的程序。
Linux系统使用Fuser命令安装
[root@icoolkj ~]# fuser -m /data
-bash: fuser: command not found
## 安装
[root@icoolkj ~]# sudo yum -y install psmisc
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
* base: mirrors.bfsu.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/2): extras/7/x86_64/primary_db | 250 kB 00:00:00
(2/2): updates/7/x86_64/primary_db | 24 MB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package psmisc.x86_64 0:22.20-17.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================================================================================================
Package Arch Version Repository Size
=======================================================================================================================================================
Installing:
psmisc x86_64 22.20-17.el7 base 141 k
Transaction Summary
=======================================================================================================================================================
Install 1 Package
Total download size: 141 k
Installed size: 475 k
Downloading packages:
psmisc-22.20-17.el7.x86_64.rpm | 141 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : psmisc-22.20-17.el7.x86_64 1/1
Verifying : psmisc-22.20-17.el7.x86_64 1/1
Installed:
psmisc.x86_64 0:22.20-17.el7
Complete!
[root@icoolkj ~]#
Linux系统使用Fuser命令查询
## fuser命令查找
[root@icoolkj ~]# fuser -m -v /data/
USER PID ACCESS COMMAND
/data: root kernel mount /data
root 2652 F.c.. fdfs_trackerd
root 26031 F.c.. fdfs_storaged
[root@icoolkj ~]#
Linux系统停止FDFS相关服务,并使用Fuser命令查询
## 停止 fdfs相关服务
[root@icoolkj ~]# service fdfs_trackerd stop
Stopping fdfs_trackerd (via systemctl): [ OK ]
[root@icoolkj ~]# service fdfs_storaged stop
Stopping fdfs_storaged (via systemctl): [ OK ]
[root@icoolkj ~]#
[root@icoolkj ~]# fuser -m -v /data/
USER PID ACCESS COMMAND
/data: root kernel mount /data
[root@icoolkj ~]#
fuser 常用场景
fuser通常被用在诊断系统的“resource busy”问题,通常是在你希望umount指定的挂载点得时候遇到。 如果你希望kill所有正在使用某一指定的file, file system or sockets的进程的时候,你可以使用-k option。
1 |
|
这时fuser会向所以正在使用/path/to/your/filename的进程发送SIGKILL。如果你希望在发送之前得到提示,可以使用-i 选项。
1 |
|
Linux取消挂载
[root@icoolkj ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 99G 59G 36G 63% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 612K 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/vdb1 100G 1.1G 98.9G 1% /data
[root@icoolkj ~]#
[root@icoolkj ~]# umount /data
[root@icoolkj ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 99G 59G 36G 63% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 612K 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
tmpfs 1.6G 0 1.6G 0% /run/user/0
[root@icoolkj ~]#