Thursday, April 25, 2024
 Popular · Latest · Hot · Upcoming
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 11537  / 1 Year ago, tue, april 4, 2023, 9:15:41

Certain programs look for /dev/dvd by default to find DVDs. When I first boot my computer without a DVD inserted, /dev/dvd exists and points to the correct place (/dev/sr0). However, when I insert a DVD, /dev/dvd disappears. I'd like it to stick around so I don't have to navigate to /dev/sr0 in programs that are looking for DVDs. How do I ensure that the /dev/dvd symlink exists and points to the right place?



It looks like I can add something to /etc/udev/rules.d/70-persistent-cd.rules. This site gives a couple of examples, but the 70-persistent-cd.rules file says "add the ENV{GENERATED}=1 flag to your own rules", which isn't part of the examples. The man 7 udev page is impenetrable to me, and I'm not convinced the linked page gives 100% of the information I need.



So, what can I do on a modern, Ubuntu 12.04 (or later) system to make /dev/dvd always exist and point to the right device?



EDIT: Is it as simple as adding ENV{GENERATED}=1 to the rules in the linked page, something like this:



SUBSYSTEM=="block", KERNEL=="sr0", SYMLINK+="dvd", GROUP="cdrom", ENV{GENERATED}=1


Is that the right information for modern Ubuntu? What is ENV{GENERATED} doing there, when it wasn't generated, but hand-written?


More From » 12.04

 Answers
7

This tutorial explain very nice how to do what you want:





According to it, there are two approaches to creating symlinks. The first one is to use the model name and the serial number:



SUBSYSTEM=="block", ENV{ID_MODEL}=="...", ENV{ID_SERIAL}=="...", ENV{GENERATED}="1", SYMLINK+="dvd"


This way, the symlink will stay correct even if you move the drive to different positions on the IDE bus, but the /dev/dvd symlink won't be created if you replace the drive.



The second one is based on the location of the device on the bus:



SUBSYSTEM=="block", ENV{ID_TYPE}=="...", ENV{ID_PATH}=="pci-...", ENV{GENERATED}="1", SYMLINK+="dvd"


This way, the symlink will stay correct even if you replace drives with different models, but place them to the same positions on the IDE bus. The ENV{ID_TYPE} key makes sure that the symlink disappears if you put something other than a DVD in that position on the bus.



You can find the values for ID_MODEL, ID_SERIAL, ID_TYPE and ID_PATH using the following command (the udevtest command as in tutorial doesn't work - anymore ? - in Ubuntu):



udevadm info --query=all --name=sr0


The SUBSYSTEM=="block" key is needed in order to avoid matching SCSI generic devices. Without it, in the case with SCSI DVD, the symlink will sometimes point to the correct /dev/sr0 devices, and sometimes to /dev/sg0, which is wrong.



The ENV{GENERATED}="1" key is needed to prevent the udev 75-cd-aliases-generator.rules file from overriding your custom rules.


[#38989] Tuesday, April 4, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
taigysel

Total Points: 33
Total Questions: 136
Total Answers: 114

Location: Singapore
Member since Wed, Jan 13, 2021
3 Years ago
;