Trying to unmount the CDROM gives "...device busy

Trying to unmount the CDROM gives "...device busy". I know that this means that the CDROM directory is being accessed from one of my shells and that I should cd away from there, but which one is it?

This is very annonying when you have a lot of terminal windows open or when the process that originally accessed the CDROM unexpectedly died. What we want to do in this case is to avoid having to close or check all the windows. The elegant (and fast!) way to do it is using the fuser command:
fuser /mnt/cdrom/i386/
   /mnt/cdrom/i386/:     3170  3233  3467
This will show you which processes are associated with reading the CDROM. You can now issue:
ps -ef | grep 3170
ps -ef | grep 3233
to see the names of the applications and the tty number of the terminal they're running in, or, if that fails and you feel confident, you can even do:
kill -9 3170  3233  3467
Now you can unmount the CDROM (valid for other filesystems as well; e.g. floppies)

If you have the lsof command (list open files) that could be useful too, especially in the more tricky case when you have quited every CD directory that has been accessed and still you cannot unmount the CD. Suppose for instance that you changed directory to the mount point of the CD-ROM (something like cd /mnt/cdrom) and launched an application from there (like xmixer &). Now because the initial working directory of xmixer was the CD mount point, this last directory is perceived as being in use by the umount command, and the message will be
umount: /mnt/cdrom: device is busy.
After you have cd-ed away from all CD-ROM directories, instead of wondering why on earth you cannot unmount the CD, just issue:
lsof | grep cdrom
   xmixer    2192 fdonea  cwd    DIR      22,64    6144     79872 /mnt/cdrom
The output line (second line above) clearly shows you the offending application (in this case xmixer). Quit that and you will be able to unmount your CD.

Have a Unix Problem
Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.