Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

On my laptop the eject button for the CD/DVD drive is placed in a very unfortunate position and I hit it a dozen times per day and the tray pops out. I found many solutions which seemed to work for other people:

From man eject:

-i on | 1 | off | 0

This option controls locking of the hardware eject button. When enabled, the drive will not be ejected when the button is pressed. This is useful when you are carrying a laptop in a bag or case and don't want it to eject if the button is inadvertently pressed.

This seems to be exactly what I need. eject -i on successfully returns:

CD-Drive may NOT be ejected with device button

However, hitting the device button still ejects the drive. As suggested in another answer invoking

echo 1 > /proc/sys/dev/cdrom/lock

did not help either, lock already contains 1. The information from /proc/sys/dev/cdrom/info suggests that locking is possible:

drive name:            sr0
drive speed:           24
drive # of slots:      1
Can close tray:        1
Can open tray:         1
Can lock tray:         1
Can change speed:      1
Can select disk:       0
Can read multisession: 1
Can read MCN:          1
Reports media changed: 1

The cdctl tool is not in the Debian repository and it does not build on my system.

How do I lock my drive so that hitting the hardware switch on the drive would no pop out the drive?

share|improve this question

marked as duplicate by Marco, slm, Anthon, Karlson, peterph Feb 1 '14 at 16:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

If you mount a CD-ROM, does it lock the drive? Can you see anything different in /proc/sys/dev/cdrom? – Gilles Dec 28 '12 at 23:21
If a filesystem on the CD is mounted the locking with eject works. But not if it's not mounted or without media in drive. The contents of /proc/sys/dev/cdrom don't change. – Marco Dec 29 '12 at 0:20
What is your OS? – slm Jan 2 '13 at 0:30
@slm Debian GNU/Linux unstable with kernel 3.5.0 – Marco Jan 2 '13 at 17:13

I compiled cdctl some time ago for Fedora/CentOS. I've taken that compilation and converted to a .deb file. cdctl is the only application I've found that does a reliable job of locking/unlocking the CD/DVD eject button.

Feel free to give it a try.

Commands to lock and unlock

# locks the tray
% cdctl -o1

# unlocks the tray
% cdctl -o0
share|improve this answer
With the patch I could compile it, but it does not work either. When I press the button the drive pops out. – Marco Jan 2 '13 at 17:11
Something must of changed with the newer kernels, it worked up to for me on Fedora 14. I tried it on my Ubuntu 12.10 system and it disables the ability of the eject command from working but not the drives button on front. I'll take a peak at the cdctl source when I get a chance. – slm Jan 2 '13 at 17:49
Curious, did you recompile on Debian? – slm Jan 2 '13 at 17:50
Yes, see comment under my question. I did not test interference with eject. – Marco Jan 2 '13 at 19:09
Not sure if you saw this Q&A, the issue with cdctl was resolved: unix.stackexchange.com/questions/104791/… – slm Jan 31 '14 at 20:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.