linux如何卸载光驱显示busy,关于linux卸载设备时的busy问题处理

常常我们对某个设备读写后,要卸载掉该设备,然后常常在这个时候会出现以下头疼的提示,这通常是因为有进程在对该设备进行读写操作,而该进程还在活跃状态

比如我将设备/dev/sde1 挂载在usb ,并且进入该目录,然后打开一个新的tty并且卸载该目录设备,就会有如下提示

umount: /mnt/lst/usb: device is busy.         (In some cases useful info about processes that use

the device is found by lsof(8) or fuser(1))

如果是有经验的人,会想到刚刚是否有开了别的程序,比如用winscp访问了该文件夹,又或者某个用户正在改设备挂载的目录下而没有退出等等。退出相应设备挂载目录后,就可以正常卸载了。这样比较安全。然后有时候确实不知道是什么进程占用了,那该怎么办呢。这时候要用到一个linux下的工具叫fuser

root@moyue-virtual-machine:/mnt/lst# fuser --help

fuser: Invalid option --help

Usage: fuser [-fMuv] [-a|-s] [-4|-6] [-c|-m|-n SPACE] [-k [-i] [-SIGNAL]] NAME...

fuser -l

fuser -V

Show which processes use the named files, sockets, or filesystems.

-a,--all              display unused files too

-i,--interactive      ask before killing (ignored without -k)

-k,--kill             kill processes accessing the named file

-l,--list-signals     list available signal names

-m,--mount            show all processes using the named filesystems or block device

-M,--ismountpoint     fulfill request only if NAME is a mount point

-n,--namespace SPACE  search in this name space (file, udp, or tcp)

-s,--silent           silent operation

-SIGNAL               send this signal instead of SIGKILL

-u,--user             display user IDs

-v,--verbose          verbose output

-w,--writeonly        kill only processes with write access

-V,--version          display version information

-4,--ipv4             search IPv4 sockets only

-6,--ipv6             search IPv6 sockets only

-                     reset options

udp/tcp names: [local_port][,[rmt_host][,[rmt_port]]]

从帮助文档可以看出来,我们可以使用-m 参数来查看设备的占用情况

root@moyue-virtual-machine:/mnt/lst# fuser -mu usb

/mnt/lst/usb:        10926c(root)

可以看出该,有一个root用户占用了该设备,进程ID为10926,如果直接杀掉进程也是可以的,但是不是很安全,毕竟害怕数据丢失。

root@moyue-virtual-machine:/mnt/lst# ps xa | grep 10926

10926 pts/1    Ss+    0:00 bash

可以看出这是一个bash进程,应该知道cd命令为bash内置程序

查找出来并且退出该目录就可以正常卸载了。

如果真的找不到了,又要卸载设备,最好先执行下sync命令。然后再杀死那个进程,其实直接用fuser -k也可以杀进程,并且如果希望杀掉进程前询问你的话可以加个-i参数,如下

root@moyue-virtual-machine:/mnt/lst# fuser -ki usb /mnt/lst/usb:        10926c Kill process 10926 ? (y/N) y 然后再去卸载就会发现可以正常卸载设备了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值