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>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
|
---|
60 | <filename class="directory">/sys</filename> (e.g., this can be
|
---|
61 | <filename class="directory">/sys/block/hdd</filename>) and
|
---|
62 | run a command similar to the following:</para>
|
---|
63 |
|
---|
64 | <screen role="nodump"><userinput>udevtest /sys/block/hdd</userinput></screen>
|
---|
65 |
|
---|
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>
|
---|
70 |
|
---|
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>
|
---|
76 |
|
---|
77 | <screen><userinput>sed -i -e 's/write_cd_aliases/& by-id/' \
|
---|
78 | /etc/udev/rules.d/75-cd-aliases-generator.rules</userinput></screen>
|
---|
79 |
|
---|
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>
|
---|
86 |
|
---|
87 | </sect2>
|
---|
88 |
|
---|
89 | <sect2>
|
---|
90 |
|
---|
91 | <title>Dealing with duplicate devices</title>
|
---|
92 |
|
---|
93 | <para>As explained in <xref linkend="ch-scripts-udev"/>, the order in
|
---|
94 | which devices with the same function appear in
|
---|
95 | <filename class="directory">/dev</filename> is essentially random.
|
---|
96 | E.g., if you have a USB web camera and a TV tuner, sometimes
|
---|
97 | <filename>/dev/video0</filename> refers to the camera and
|
---|
98 | <filename>/dev/video1</filename> refers to the tuner, and sometimes
|
---|
99 | after a reboot the order changes to the opposite one.
|
---|
100 | For all classes of hardware except sound cards and network cards, this is
|
---|
101 | fixable by creating udev rules for custom persistent symlinks.
|
---|
102 | The case of network cards is covered separately in
|
---|
103 | <xref linkend="ch-scripts-network"/>, and sound card configuration can
|
---|
104 | be found in <ulink url="&blfs-root;">BLFS</ulink>.</para>
|
---|
105 |
|
---|
106 | <para>For each of your devices that is likely to have this problem
|
---|
107 | (even if the problem doesn't exist in your current Linux distribution),
|
---|
108 | find the corresponding directory under
|
---|
109 | <filename class="directory">/sys/class</filename> or
|
---|
110 | <filename class="directory">/sys/block</filename>.
|
---|
111 | For video devices, this may be
|
---|
112 | <filename
|
---|
113 | class="directory">/sys/class/video4linux/video<replaceable>X</replaceable></filename>.
|
---|
114 | Figure out the attributes that identify the device uniquely (usually,
|
---|
115 | vendor and product IDs and/or serial numbers work):</para>
|
---|
116 |
|
---|
117 | <screen role="nodump"><userinput>udevinfo -a -p /sys/class/video4linux/video0</userinput></screen>
|
---|
118 |
|
---|
119 | <para>Then write rules that create the symlinks, e.g.:</para>
|
---|
120 |
|
---|
121 | <screen role="nodump"><userinput>cat > /etc/udev/rules.d/83-duplicate_devs.rules << EOF
|
---|
122 | <literal>
|
---|
123 | # Persistent symlinks for webcam and tuner
|
---|
124 | KERNEL=="video*", SYSFS{idProduct}=="1910", SYSFS{idVendor}=="0d81", \
|
---|
125 | SYMLINK+="webcam"
|
---|
126 | KERNEL=="video*", SYSFS{device}=="0x036f", SYSFS{vendor}=="0x109e", \
|
---|
127 | SYMLINK+="tvtuner"
|
---|
128 | </literal>
|
---|
129 | EOF</userinput></screen>
|
---|
130 |
|
---|
131 | <para>The result is that <filename>/dev/video0</filename> and
|
---|
132 | <filename>/dev/video1</filename> devices still refer randomly to the tuner
|
---|
133 | and the web camera (and thus should never be used directly), but there are
|
---|
134 | symlinks <filename>/dev/tvtuner</filename> and
|
---|
135 | <filename>/dev/webcam</filename> that always point to the correct
|
---|
136 | device.</para>
|
---|
137 |
|
---|
138 | <para>More information on writing Udev rules can be found in
|
---|
139 | <filename>/usr/share/doc/udev-&udev-version;/index.html</filename>.</para>
|
---|
140 |
|
---|
141 | </sect2>
|
---|
142 |
|
---|
143 | </sect1>
|
---|