umount - device is busy

Published on 2010-01-12.

Have you ever tried to unmount a partition only to get the message "device is busy"? Well, there's a reason for that and here's what you can do.

When you receive the message "device is busy" it's because some program or programs are using the device.

# umount /media/cdrom/
umount: /media/cdrom: device is busy

You need to find out what programs are accessing the device, and you can do that using the lsof command:

# lsof /media/cdrom/
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF      NODE NAME
bash     3279 knl   cwd    DIR   0,19     8192 805939346 /media/cdrom/pdf (/dev/cdrom)
xpdf.bin 3337 knl   cwd    DIR   0,19     8192 805939346 /media/cdrom/pdf (/dev/cdrom)
xpdf.bin 3337 knl    4r    REG   0,19  2114081   1760652 /media/cdrom/pdf/Emacs_Tutorial.pdf (/dev/cdrom)

In this case it shows that the bash and xpdf are using the device, and that xpdf has opened a file called Emacs_Tutorial.pdf in the pdf directory.

You need to close these applications and exit the device in order to unmount it.

Sometimes a mounted device can freeze up, and it gets impossible to unmount it using the umount command. Then you still get the "device is busy" message even though no program is using the device. When you have made sure that all applications accessing the device has been terminated you can use the -l option to umount and force an unmount.

# umount -l /media/cdrom/

The -l option stands for "Lazy unmount" and it detach the filesystem from the file hierarchy immediately, and then clean up all references to the filesystem as soon as it is not busy anymore.

Using lsof on the device name rather than mountpoint can sometimes provide more information. If your cdrom drive is /dev/sdb1 you can use # lsof /dev/sdb1 rather than # lsof /media/cdrom/