Monday, 18 August 2014

Can't safely remove USB drive. Device busy!

We have seen cases where we are not allowed to safely remove or eject USB drive because of the fact that some process is using resources on the drive. The easy way to get out of this is to kill the process which is doing this. For example if the problem is the result of stalled file copying (say, using nautilus) then killall nautilus should do the trick. However it happens that sometimes it is not possible to figure out which process is accessing the USB drive. So how do we find the rogue process(es)?

fuser to the rescue!

fuser -k -15 -m  /dev/sdb1

The above command will kill all the processes accessing your device! Replace /dev/sdb1 with the device file corresponding to your USB device.

Now try ejecting/ safely removing. It will mostly work!