| 18 | | media players) expect the /dev/cdrom and /dev/dvd symlinks to exist. |
|---|
| 19 | | Also, it may be convenient to put references to those symlinks into |
|---|
| 20 | | <filename>/etc/fstab</filename>. For each of your CD-ROM devices, |
|---|
| 21 | | find the corresponding directory under |
|---|
| | 18 | media players) expect the <filename class="symlink">/dev/cdrom</filename> |
|---|
| | 19 | and <filename class="symlink">/dev/dvd</filename> symlinks to exist, and |
|---|
| | 20 | to point to a CD-ROM or DVD-ROM device. Also, it may be convenient to put |
|---|
| | 21 | references to those symlinks into <filename>/etc/fstab</filename>. Udev |
|---|
| | 22 | comes with a script that will generate rules files to create these symlinks |
|---|
| | 23 | for you, depending on the capabilities of each device, but you need to |
|---|
| | 24 | decide which of two modes of operation you wish to have the script use.</para> |
|---|
| | 25 | |
|---|
| | 26 | <para>First, the script can operate in <quote>by-path</quote> mode, where |
|---|
| | 27 | the rules it creates depend on the physical path to the CD or DVD device. |
|---|
| | 28 | Second, it can operate in <quote>by-id</quote> mode, where the rules it |
|---|
| | 29 | creates depend on identification strings stored in the CD or DVD device |
|---|
| | 30 | itself. The path is determined by Udev's <command>path_id</command> script, |
|---|
| | 31 | and the identification strings are read from the hardware by its |
|---|
| | 32 | <command>ata_id</command> or <command>scsi_id</command> programs, depending |
|---|
| | 33 | on which type of device you have.</para> |
|---|
| | 34 | |
|---|
| | 35 | <para>There are advantages to each approach; the correct approach to use |
|---|
| | 36 | will depend on what kinds of device changes may happen. If you expect the |
|---|
| | 37 | physical path to the device (that is, the ports and/or slots that it plugs |
|---|
| | 38 | into) to change, for example because you plan on moving the drive to a |
|---|
| | 39 | different IDE port or a different USB connector, then you should use the |
|---|
| | 40 | <quote>by-id</quote> mode. On the other hand, if you expect the device's |
|---|
| | 41 | identification to change, for example because it may die, and you would |
|---|
| | 42 | replace it with a different device with the same capabilities and which |
|---|
| | 43 | is plugged into the same connectors, then you should use the |
|---|
| | 44 | <quote>by-path</quote> mode.</para> |
|---|
| | 45 | |
|---|
| | 46 | <para>If either type of change is possible with your drive, then choose a |
|---|
| | 47 | mode based on the type of change you expect to happen more often.</para> |
|---|
| | 48 | |
|---|
| | 49 | <!-- If you use by-id mode, the symlinks will survive even the transition |
|---|
| | 50 | to libata for IDE drives, but that is not for the book. --> |
|---|
| | 51 | |
|---|
| | 52 | <important>External devices (for example, a USB-connected CD drive) should |
|---|
| | 53 | not use by-path persistence, because each time the device is plugged into a |
|---|
| | 54 | new external port, its physical path will change. All externally-connected |
|---|
| | 55 | devices will have this problem if you write Udev rules to recognize them |
|---|
| | 56 | by their physical path; the problem is not limited to CD and DVD drives.</important> |
|---|
| | 57 | |
|---|
| | 58 | <para>If you wish to see the values that the Udev scripts will use, then |
|---|
| | 59 | for the appropriate CD-ROM device, find the corresponding directory under |
|---|
| 45 | | <note> |
|---|
| 46 | | <para>Be aware that Udev does not recognize the backslash for line |
|---|
| 47 | | continuation. The examples in this book work properly because both |
|---|
| 48 | | the backslash and newline are ignored by the shell. This makes the |
|---|
| 49 | | shell send each rule to cat on only one line. (The shell ignores |
|---|
| 50 | | this sequence because the EOF string used in the here-document |
|---|
| 51 | | redirection is not enclosed in either double or single quotes. For |
|---|
| 52 | | more details, see the bash(1) manpage, and search it for "Here |
|---|
| 53 | | Documents".)</para> |
|---|
| 54 | | <para>If modifying Udev rules with an editor, be sure to leave each |
|---|
| 55 | | rule on one physical line.</para> |
|---|
| 56 | | </note> |
|---|
| 57 | | |
|---|
| 58 | | <para>This way, the symlinks will stay correct even if you move the drives |
|---|
| 59 | | to different positions on the IDE bus, but the |
|---|
| 60 | | <filename>/dev/cdrom</filename> symlink won't be created if you replace |
|---|
| 61 | | the old SAMSUNG CD-ROM with a new drive.</para> |
|---|
| 62 | | <!-- The symlinks in the first approach survive even the transition |
|---|
| 63 | | to libata for IDE drives, but that is not for the book. --> |
|---|
| 64 | | |
|---|
| 65 | | <para>The SUBSYSTEM=="block" key is needed in order to avoid |
|---|
| 66 | | matching SCSI generic devices. Without it, in the case with SCSI |
|---|
| 67 | | CD-ROMs, the symlinks will sometimes point to the correct |
|---|
| 68 | | <filename>/dev/srX</filename> devices, and sometimes to |
|---|
| 69 | | <filename>/dev/sgX</filename>, which is wrong.</para> |
|---|
| 70 | | |
|---|
| 71 | | <para>The ENV{GENERATED}="1" key is needed to prevent the Udev |
|---|
| 72 | | 75-cd-aliases-generator.rules file from overriding your custom |
|---|
| 73 | | rules.</para> |
|---|
| 74 | | |
|---|
| 75 | | <para>The second approach yields:</para> |
|---|
| 76 | | |
|---|
| 77 | | <screen role="nodump"><userinput>cat > /etc/udev/rules.d/70-persistent-cd.rules << EOF |
|---|
| 78 | | <literal> |
|---|
| 79 | | # Custom CD-ROM symlinks |
|---|
| 80 | | SUBSYSTEM=="block", ENV{ID_TYPE}=="cd", \ |
|---|
| 81 | | ENV{ID_PATH}=="pci-0000:00:07.1-ide-0:1", \ |
|---|
| 82 | | ENV{GENERATED}="1", SYMLINK+="cdrom" |
|---|
| 83 | | SUBSYSTEM=="block", ENV{ID_TYPE}=="cd", \ |
|---|
| 84 | | ENV{ID_PATH}=="pci-0000:00:07.1-ide-1:1", \ |
|---|
| 85 | | ENV{GENERATED}="1", SYMLINK+="cdrom1 dvd" |
|---|
| 86 | | </literal> |
|---|
| 87 | | EOF</userinput></screen> |
|---|
| 88 | | |
|---|
| 89 | | <para>This way, the symlinks will stay correct even if you replace drives |
|---|
| 90 | | with different models, but place them to the old positions on the IDE |
|---|
| 91 | | bus. The ENV{ID_TYPE}=="cd" key makes sure that the symlink |
|---|
| 92 | | disappears if you put something other than a CD-ROM in that position on |
|---|
| 93 | | the bus.</para> |
|---|
| 94 | | |
|---|
| 95 | | <para>Of course, it is possible to mix the two approaches.</para> |
|---|
| | 80 | <para>Note that it is not necessary to create the rules files or symlinks |
|---|
| | 81 | at this time, because you have bind-mounted the host's |
|---|
| | 82 | <filename class="directory">/dev</filename> directory into the LFS system, |
|---|
| | 83 | and we assume the symlinks exist and are correct on the host. The rules |
|---|
| | 84 | will be created, along with the symlinks, the first time you boot your LFS |
|---|
| | 85 | system.</para> |
|---|