Sunday, November 9, 2008

A killer umount script

I was just plain sick of the dreaded "Device is busy" message while unmounting the CD drive so I thought I'd do something about it.


if [ $# -gt 0 ]; then

PROC=$(fuser -m $1)

for var in $PROC; do
sudo kill -9 $var


sudo umount $1 || echo "Failed to unmount $1"

I saved the file as kumount (lets call it - Killer umount) in /bin.
Make it executable.

chmod a+x /bin/kumount

Now just test it.
I plugged in my audio player, started playing some music in Audacious. Ran the command

kumount /dev/sdc1

... and bang! Audacious got killed and the device unmounted.
Of course, this has many downsides.. Especially when you're copying stuff to a device but I'm sure nobody would kill-unmount devices when they're actually in use ;-)