source: chapter07/symlinks.xml@ 651719a

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
Last change on this file since 651719a was 651719a, checked in by Bryan Kadzban <bryan@…>, 17 years ago

Add a note about CD symlinks possibly not matching the host. Fixes the rest of #1963.

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@7927 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

  • Property mode set to 100644
File size: 8.2 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
3 "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
4 <!ENTITY % general-entities SYSTEM "../general.ent">
5 %general-entities;
6]>
7
8<sect1 id="ch-scripts-symlinks">
9 <?dbhtml filename="symlinks.html"?>
10
11 <title>Creating Custom Symlinks to Devices</title>
12
13 <sect2>
14
15 <title>CD-ROM symlinks</title>
16
17 <para>Some software that you may want to install later (e.g., various
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><para>External devices (for example, a USB-connected CD drive)
53 should not use by-path persistence, because each time the device is plugged
54 into a new external port, its physical path will change. All
55 externally-connected devices will have this problem if you write Udev rules
56 to recognize them by their physical path; the problem is not limited to CD
57 and DVD drives.</para></important>
58
59 <para>If you wish to see the values that the Udev scripts will use, then
60 for the appropriate CD-ROM device, find the corresponding directory under
61 <filename class="directory">/sys</filename> (e.g., this can be
62 <filename class="directory">/sys/block/hdd</filename>) and
63 run a command similar to the following:</para>
64
65<screen role="nodump"><userinput>udevtest /sys/block/hdd</userinput></screen>
66
67 <para>Look at the lines containing the output of various *_id programs.
68 The <quote>by-id</quote> mode will use the ID_SERIAL value if it exists and
69 is not empty, otherwise it will use a combination of ID_MODEL and
70 ID_REVISION. The <quote>by-path</quote> mode will use the ID_PATH value.</para>
71
72 <para>If you choose the <quote>by-path</quote> mode, then the rules files
73 installed by default with Udev will work. If you choose the <quote>by-id</quote>
74 mode, then you will have to modify the
75 <filename>/etc/udev/rules.d/75-cd-aliases-generator.rules</filename> file,
76 as follows:</para>
77
78<screen><userinput>sed -i -e 's/write_cd_aliases/&amp; by-id/' \
79 /etc/udev/rules.d/75-cd-aliases-generator.rules</userinput></screen>
80
81 <para>Note that it is not necessary to create the rules files or symlinks
82 at this time, because you have bind-mounted the host's
83 <filename class="directory">/dev</filename> directory into the LFS system,
84 and we assume the symlinks exist on the host. The rules and symlinks will
85 be created the first time you boot your LFS system.</para>
86
87 <para>However, if you have multiple CD-ROM devices, then the symlinks
88 generated at that time may point to different devices than they point to on
89 your host, because devices are not discovered in a predictable order. The
90 assignments created when you first boot the LFS system will be stable, so
91 this is only an issue if you need the symlinks on both systems to point to
92 the same device. If you need that, then inspect (and possibly edit) the
93 generated <filename>/etc/udev/rules.d/70-persistent-cd.rules</filename>
94 file after booting, to make sure the assigned symlinks match what you need.</para>
95
96 </sect2>
97
98 <sect2>
99
100 <title>Dealing with duplicate devices</title>
101
102 <para>As explained in <xref linkend="ch-scripts-udev"/>, the order in
103 which devices with the same function appear in
104 <filename class="directory">/dev</filename> is essentially random.
105 E.g., if you have a USB web camera and a TV tuner, sometimes
106 <filename>/dev/video0</filename> refers to the camera and
107 <filename>/dev/video1</filename> refers to the tuner, and sometimes
108 after a reboot the order changes to the opposite one.
109 For all classes of hardware except sound cards and network cards, this is
110 fixable by creating udev rules for custom persistent symlinks.
111 The case of network cards is covered separately in
112 <xref linkend="ch-scripts-network"/>, and sound card configuration can
113 be found in <ulink url="&blfs-root;">BLFS</ulink>.</para>
114
115 <para>For each of your devices that is likely to have this problem
116 (even if the problem doesn't exist in your current Linux distribution),
117 find the corresponding directory under
118 <filename class="directory">/sys/class</filename> or
119 <filename class="directory">/sys/block</filename>.
120 For video devices, this may be
121 <filename
122 class="directory">/sys/class/video4linux/video<replaceable>X</replaceable></filename>.
123 Figure out the attributes that identify the device uniquely (usually,
124 vendor and product IDs and/or serial numbers work):</para>
125
126<screen role="nodump"><userinput>udevinfo -a -p /sys/class/video4linux/video0</userinput></screen>
127
128 <para>Then write rules that create the symlinks, e.g.:</para>
129
130<screen role="nodump"><userinput>cat &gt; /etc/udev/rules.d/83-duplicate_devs.rules &lt;&lt; EOF
131<literal>
132# Persistent symlinks for webcam and tuner
133KERNEL=="video*", ATTRS{idProduct}=="1910", ATTRS{idVendor}=="0d81", \
134 SYMLINK+="webcam"
135KERNEL=="video*", ATTRS{device}=="0x036f", ATTRS{vendor}=="0x109e", \
136 SYMLINK+="tvtuner"
137</literal>
138EOF</userinput></screen>
139
140 <note>
141 <para>Be aware that Udev does not recognize the backslash for line
142 continuation. This example works properly because both the backslash
143 and newline are ignored by the shell. This makes the shell send each
144 rule to cat on only one line. (The shell ignores this sequence because
145 the EOF string used in the here-document redirection is not enclosed in
146 either double or single quotes. For more details, see the bash(1)
147 manpage, and search it for "Here Documents".)</para>
148 <para>If modifying Udev rules with an editor, be sure to leave each
149 rule on one physical line.</para>
150 </note>
151
152 <para>The result is that <filename>/dev/video0</filename> and
153 <filename>/dev/video1</filename> devices still refer randomly to the tuner
154 and the web camera (and thus should never be used directly), but there are
155 symlinks <filename>/dev/tvtuner</filename> and
156 <filename>/dev/webcam</filename> that always point to the correct
157 device.</para>
158
159 <para>More information on writing Udev rules can be found in
160 <filename>/usr/share/doc/udev-&udev-version;/index.html</filename>.</para>
161
162 </sect2>
163
164</sect1>
Note: See TracBrowser for help on using the repository browser.