Difference between revisions of "Script for locking optical drive"

From ThinkWiki
Jump to: navigation, search
(←Created page with 'On some model ThinkPads it is rather easy to accidentally eject the optical drive (CD/DVD drive). The below two scripts will disable the eject button to prevent acciden...')
 
m
 
Line 38: Line 38:
  
 
[[Category:Scripts]]
 
[[Category:Scripts]]
[[Category:Bluetooth]]
 

Latest revision as of 11:51, 10 December 2015

On some model ThinkPads it is rather easy to accidentally eject the optical drive (CD/DVD drive). The below two scripts will disable the eject button to prevent accidental ejection. The tray can still be ejected afterwards by either right clicking in a graphical file manager on the CD icon and choosing eject, or from the commandline with the 'eject' command.

Note: These scripts are only for modern Linux distributions utilizing systemd.

Create a file as root named: /etc/systemd/system/cdrom-lock-on-boot.service with the following contents;

[Unit]
Description=CD-ROM lock on boot

[Service]
Type=simple
ExecStart=/usr/bin/eject -i on /dev/sr0

[Install]
WantedBy=multi-user.target

In addition, also create this file: /etc/systemd/system/cdrom-lock-on-resume.service with the following contents;

[Unit]
Description=CD-ROM lock on resume
After=suspend.target

[Service]
Type=simple
ExecStart=/usr/bin/eject -i on /dev/sr0

[Install]

Now we need to enable the scripts as follows;

systemctl enable cdrom-lock-on-boot.service
systemctl enable cdrom-lock-on-resume.service

Now after a reboot, or suspend/resume cycle the eject button will be locked. Alternatively we can lock it immediately with the following command;

/usr/bin/eject -i on /dev/sr0