Now you might have thought that unmounting a cdrom was a really easy thing to do but don't be fooled, it can be really tricky to get your system to let go of the disk. An errant process grabs hold of the disk, locks the drive and no amount of pleading with it will make it give it back. Unfortunatly this some times leads people to reboot their system, reset it (using the reset button) or even poke something in the emergency release hole. None of which are generally necessary when you have a little know how.

First off you need to know why you can't get the drive to open. I am going to assume that the drive isn't physically broken in which case you may well have to use the emergency release. I have never seen a drive break to the point where the tray won't eject. I have seen trays that seem to be on their way out but the drive is so old by that point anyway that it is replaced before it totally gives up. Generally speaking the drive won't eject because the disk is still being accessed by some process which is why a reboot or reset works to free the drive.

Unmounting the Drive

The Simple Method

First try to just unmount the drive using

someone@comptuer:/$ umount /mnt/cdrom

where /mnt/cdrom is the mount location of your cdrom drive. Of course you could have mounted it anywhere but this is the standard place. If you get a reply like this

umount: /mnt/cdrom: device is busy

then it means something is still using the drive. What that something is is what we have to find out.

The first thing to try is the "fuser" command which will give you a list of the process numbers (ids) of all the processes that are using the cdrom. The command is used like this

fuser /mnt/cdrom

and responds thusly

/mnt/cdrom: 123 456

the numbers 123 and 456 are the process numbers which you can use to look up the process using ps and grep like this

ps -A -f | grep 123

The result of this will look something like this but yours will differ

xyz      123  3203  0 14:19 ?        00:00:20 xmms

The process name is the last part of the line and we can see that the process is xmms (a media player). Find that applicaiton on one of your desktops and close it then do the same for the other process that was listed by fuser. If the process doesn't have a window that you can close you will have to kill it from the console. This can be done using

kill -9 456

Which is a little brutal but quite effective. If you know a better way to stop the application it is probably safer to use that.

An Alternative

If the fuser command doesn't return any process numbers but you still can't eject the drive it is worth trying the "lsof" command which lists open files.

lsof | grep cdrom

You have to run this command through grep because even a lightly loaded system will have perhaps a hundred files open. This command will directly give you the name of the application that has a file open on the device and conveniently the PID (process id) aswell which you can use to kill the process.

Getting Rough With the Drive

Forcing the Issue

It is possible, but not recommended, to force the system to unmount the drive using

umount -f /mnt/cdrom

At best you are going to get a few applications complaining or crashing but it could easily cause a kernel panic as well due to it suddenly having a highly corrupt filesystem. Use at your peril.


Another thing to try if none of the above have worked is

cdrecord -eject

Apparently cdrecord doesn't care about the locked state of the drive and will just issue the eject command. Again this is not generally a good thing to do as there are processes accessing the drive. Having said that if you can't kill the process this might be the only way to go.