umount: device is busy

Posted on 12.01.2010 by Kim N. Lesmer.
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 with the lsof command:

# lsof /media/cdrom/
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 programs 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 programs 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. You still get the "device is busy" message eventhough no program is using the device.

When you have made sure, that all programs accessing the device has been terminated, you can use the fuser command to force an unmount and possible killing any frozen processes.

# fuser -uz /media/cdrom/

The -z option kills the process involved. Sometimes you need to run the command more than once.

On Debian the fuser program comes with the psmisc package, and you can install that using:

# apt-get install psmisc

psmisc provides some utilities that use the proc filesystem.

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/