12

My todler is continuosly pushing the cd/dvd button and trying to destroy the tray. I know it should be possible to let her life harder, disabling the eject button. How to do that? This is ubuntu (shouldn't matter) linux. See also the this related question.

And the same one as this one, but on windows

EDIT: this is Hardy

Davide
  • 675
  • 3
  • 9
  • 22
  • 1
    This reminds me of a video of someone who had a script that continuously ejected and closed the disc drive. There was a string connecting the disk tray to a baby's rocker. And the cd drive just rocked the baby! – Jonno_FTW Nov 18 '09 at 16:14
  • @Jonno_FTW: A similar story comes from the German ubuntuusers-site. Someone created a 'benchmark' to measure how often the drive could open and close in a minute. Needless to say, somebody figured out how to do that via network and had some fun at work. – Bobby Jan 04 '11 at 09:43

6 Answers6

12

At the command line:

eject -i 1

To return to normal:

eject -i 0

Or you can software eject it using:

eject

In all cases, you can add a device name if you have more than one ejectable device.

Apparently, this doesn't work with all versions of eject. If it doesn't with yours, you can bypass eject completely and do it the "hard" way:

echo 1 | sudo tee /proc/sys/dev/cdrom/lock
Dennis
  • 48,917
  • 12
  • 130
  • 149
gorilla
  • 2,300
  • 14
  • 9
  • Thanks, but it doesn't work for my OS: $ eject -i 1 eject: invalid option -- i $ eject --version eject version 2.1.5 by Jeff Tranter (tranter@pobox.com) – Davide Nov 18 '09 at 03:08
  • Grrr, comments don't align code snippet correctly, and cannot be edited! Let me try again: `$ eject -i 1` results in `eject: invalid option -- i` - and you should be able to figure out the version from the other comment – Davide Nov 18 '09 at 03:10
  • Weird. `$ eject -i 1` works fine for me in Karmic. Version 2.1.5. – regan Nov 18 '09 at 03:27
  • 1
    If you want to do it the hard way, then
    sudo echo 1 > /proc/sys/dev/cdrom/lock
    will work with any version of eject, because you're not using eject.
    – gorilla Nov 18 '09 at 14:08
  • @gorilla, you should add that as your own answer.. – quack quixote Nov 18 '09 at 15:28
  • Note that `sudo command > file` won't work, you need something like `echo 1 | sudo tee /proc/sys/dev/cdrom/lock`. – tokland Jan 12 '13 at 11:51
  • Update: According to the page on poweradded.net linked in the other answer, you may have to disable a udev rule for `eject -i` to work. – sleske Jul 11 '13 at 16:31
  • Note: I filed [Debian bug #716715](http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=716715) about the problem with eject and udev. – sleske Jul 11 '13 at 21:00
  • Won't work for me (Gentoo, Lenovo T420s). – Pavel Šimerda Dec 28 '14 at 21:48
5

You might want to try this out...

http://www.poweradded.net/2009/09/cddvd-tray-lockunlock-under-linux.html

baumgart
  • 1,416
  • 9
  • 14
  • This is good, it works pretty well (the code is not robust, but I can improve it myself, if I'll never need) – Davide Dec 04 '09 at 04:54
  • This isn't working in Fedora 19. Using a Thinkpad T410 laptop. – slm Dec 12 '13 at 02:06
  • Didn't work at first in Ubuntu but I didn't see the update to the post (search for "UPDATE1 03.Jan.2013" which had a fix that made the solution linked to, work again so don't miss that comment when giving it a shot. – Björn Sep 13 '14 at 18:03
2

Ubuntu's default automounter doesn't lock the CD/DVD try when it mounts an inserted disc. But if you mount the disc manually (say, with sudo), the tray should lock and stay locked until you dismount the disc.

So this process would accomplish what you want, without disabling other functionality, and you could even script it for quick access:

  1. Insert a disc,
  2. Run sudo umount /media/cdrom, then
  3. Run sudo mount /dev/cdrom /media/cdrom

Obviously, replace those paths and devices with ones your system uses.

quack quixote
  • 42,186
  • 14
  • 105
  • 129
  • Works, but it's inconvenient (actually I did know about that). Thanks for the answer, anyway. – Davide Dec 04 '09 at 04:53
2

A user left a comment on another question. The comment should have been a separate answer. I'm writing his suggestion here, since it might work for somebody (it doesn't in Hardy Haron) and might be more convenient than installing the code from my accepted question.

To lock:

sudo bash -c 'echo 1 > /proc/sys/dev/cdrom/lock'

To unlock:

sudo bash -c 'echo 0 > /proc/sys/dev/cdrom/lock'

Of course small shell scripts, possibly linked from the panel would be used.

Davide
  • 675
  • 3
  • 9
  • 22
1

eject -i 1 only works a single time on Ubuntu 20.04 (focal) -- only mildly useful for those of us who accidentally hit the eject button constantly throughout the day.

Simply adding this command to the cron entry (crontab -e) such that the command runs every minute satisfied my need, although the placement of this button over the Del key will forever remain a mystery. For the record, I was NOT able to get this to disable through the Ubuntu keyboard settings.

* * * * * eject -i 1 

*** EDIT ***

After upgrading to Ubuntu 21.04 (hirsute) this fix stopped working. I tried various permutations of eject, disabling the Keyboard Shortcut and re-enabling with a cryptic keyboard sequence, and the solution of editing the rules in /etc/udev/rules.d/60-cdrom_id.rules -- all to no avail.

The only thing that worked for me is physically disabling the drive in .bashrc upon startup, i.e. adding this line here:

sudo rm /dev/sr0

This is actually not a terrible solution but I am still mystified why all attempts to disable this button on my Das external keyboard have been a failure. Considering that CD-ROM drives are only used on the odd occasion I still have an audio CD to burn, this is probably a decent solution for most.

D-S
  • 11
  • 2
1

You might want to try out cdctl. It's available here: http://cdctl.sourceforge.net/. This switch will accomplish what you want.

       -oS, --lockdoor=S
          Locks the eject button so the disc cannot be manually ejected.  Requires  kernel  ver‐
          sion 2.2.4 or newer.  Set S to 0 to unlock the drive, and to 1 to lock it.

I've used this for the last 10 years on Fedora, RHEL, CentOS but the package is available as a tarball and should be compilable on Ubuntu. NOTE: The package hasn't been updated in a while but it works fine. There's a patch available on gentoo's site that fixes a small issue so that it can be compiled with more recent kernels. The patch is available here:

http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/app-misc/cdctl/files/cdctl-0.15-cdc_ioctls.patch?revision=1.1

Once you've installed it you can use the command to lock the cd tray:

cdctl -o1

To unlock the tray:

cdctl -o0

I've recently repackaged cdctl for use on Debian/Ubuntu 12.10. It's available here, http://www.lamolabs.org/blog/wp-content/uploads/2011/01/cdctl_0.15-1.lamolabs.1_amd64.deb

slm
  • 9,959
  • 10
  • 49
  • 57
  • Doesn't build on the most recent version of Ubuntu for me. Needs this patch from gentoo: http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/app-misc/cdctl/files/cdctl-0.15-cdc_ioctls.patch?revision=1.1&view=markup. Seriously, why bother with a tool that won't take such a simple patch such as this. – dgrant Mar 28 '12 at 04:34
  • Uhh, because it's the only tool I've found that does what I need. Besides the applying of the patch isn't that big a deal, I maintain a built version of this in my yum repository here: http://www.lamolabs.org/yum-repos/Fedora/14/x86_64/cdctl-0.15-1.lamolabs.1.x86_64.rpm. You can't use my rpm directly but you could convert it using the app alien, http://www.addictivetips.com/ubuntu-linux-tips/how-to-convert-rpm-file-to-deb-file-in-linux/. – slm Mar 28 '12 at 04:46