- Timestamp:
- 02/17/2007 11:30:52 PM (17 years ago)
- Branches:
- 10.0, 10.0-rc1, 10.1, 10.1-rc1, 11.0, 11.0-rc1, 11.0-rc2, 11.0-rc3, 11.1, 11.1-rc1, 11.2, 11.2-rc1, 11.3, 11.3-rc1, 12.0, 12.0-rc1, 12.1, 12.1-rc1, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 7.0, 7.1, 7.2, 7.3, 7.4, 7.5, 7.5-systemd, 7.6, 7.6-systemd, 7.7, 7.7-systemd, 7.8, 7.8-systemd, 7.9, 7.9-systemd, 8.0, 8.1, 8.2, 8.3, 8.4, 9.0, 9.1, arm, bdubbs/gcc13, ml-11.0, multilib, renodr/libudev-from-systemd, s6-init, trunk, xry111/arm64, xry111/arm64-12.0, xry111/clfs-ng, xry111/lfs-next, xry111/loongarch, xry111/loongarch-12.0, xry111/loongarch-12.1, xry111/mips64el, xry111/pip3, xry111/rust-wip-20221008, xry111/update-glibc
- Children:
- 80640a49
- Parents:
- aeb956f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
chapter07/symlinks.xml
raeb956f r84dbfdac 16 16 17 17 <para>Some software that you may want to install later (e.g., various 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 22 60 <filename class="directory">/sys</filename> (e.g., this can be 23 61 <filename class="directory">/sys/block/hdd</filename>) and 24 62 run a command similar to the following:</para> 25 63 26 <screen role="nodump"><userinput>udevtest / block/hdd</userinput></screen>64 <screen role="nodump"><userinput>udevtest /sys/block/hdd</userinput></screen> 27 65 28 <para>Look at the lines containing the output of various *_id programs.</para> 66 <para>Look at the lines containing the output of various *_id programs. 67 The <quote>by-id</quote> mode will use the ID_SERIAL value if it exists and 68 is not empty, otherwise it will use a combination of ID_MODEL and 69 ID_REVISION. The <quote>by-path</quote> mode will use the ID_PATH value.</para> 29 70 30 <para>There are two approaches to creating symlinks. The first one is to 31 use the model name and the serial number, the second one is based on the 32 location of the device on the bus. If you are going to use the first 33 approach, create a file similar to the following:</para> 71 <para>If you choose the <quote>by-path</quote> mode, then the rules files 72 installed by default with Udev will work. If you choose the <quote>by-id</quote> 73 mode, then you will have to modify the 74 <filename>/etc/udev/rules.d/75-cd-aliases-generator.rules</filename> file, 75 as follows:</para> 34 76 35 <screen role="nodump"><userinput>cat > /etc/udev/rules.d/70-persistent-cd.rules << EOF 36 <literal> 37 # Custom CD-ROM symlinks 38 SUBSYSTEM=="block", ENV{ID_MODEL}=="SAMSUNG_CD-ROM_SC-148F", \ 39 ENV{ID_REVISION}=="PS05", ENV{GENERATED}="1", SYMLINK+="cdrom" 40 SUBSYSTEM=="block", ENV{ID_MODEL}=="PHILIPS_CDD5301", \ 41 ENV{ID_SERIAL}=="5VO1306DM00190", ENV{GENERATED}="1", SYMLINK+="cdrom1 dvd" 42 </literal> 43 EOF</userinput></screen> 77 <screen><userinput>sed -i -e 's/write_cd_aliases/& by-id/' \ 78 /etc/udev/rules.d/75-cd-aliases-generator.rules</userinput></screen> 44 79 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> 96 86 97 87 </sect2>
Note:
See TracChangeset
for help on using the changeset viewer.