1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
---|
3 | "http://www.oasis-open.org/docbook/xml/4.5/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 /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
|
---|
22 | <filename class="directory">/sys</filename> (e.g., this can be
|
---|
23 | <filename class="directory">/sys/block/hdd</filename>) and
|
---|
24 | run a command similar to the following:</para>
|
---|
25 |
|
---|
26 | <screen role="nodump"><userinput>udevadm test /sys/block/hdd</userinput></screen>
|
---|
27 |
|
---|
28 | <para>Look at the lines containing the output of various *_id programs.</para>
|
---|
29 |
|
---|
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>
|
---|
34 |
|
---|
35 | <screen role="nodump"><userinput>cat >/etc/udev/rules.d/82-cdrom.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", SYMLINK+="cdrom"
|
---|
40 | SUBSYSTEM=="block", ENV{ID_MODEL}=="PHILIPS_CDD5301", \
|
---|
41 | ENV{ID_SERIAL}=="5VO1306DM00190", SYMLINK+="cdrom1 dvd"
|
---|
42 | </literal>
|
---|
43 | EOF</userinput></screen>
|
---|
44 |
|
---|
45 | <note>
|
---|
46 | <para>Although the examples in this book work properly, be aware
|
---|
47 | that Udev does not recognize the backslash for line continuation.
|
---|
48 | If modifying Udev rules with an editor, be sure to leave each rule
|
---|
49 | on one physical line.</para>
|
---|
50 | </note>
|
---|
51 |
|
---|
52 | <para>This way, the symlinks will stay correct even if you move the drives
|
---|
53 | to different positions on the IDE bus, but the
|
---|
54 | <filename>/dev/cdrom</filename> symlink won't be created if you replace
|
---|
55 | the old SAMSUNG CD-ROM with a new drive.</para>
|
---|
56 | <!-- The symlinks in the first approach survive even the transition
|
---|
57 | to libata for IDE drives, but that is not for the book. -->
|
---|
58 |
|
---|
59 | <para>The SUBSYSTEM=="block" key is needed in order to avoid
|
---|
60 | matching SCSI generic devices. Without it, in the case with SCSI
|
---|
61 | CD-ROMs, the symlinks will sometimes point to the correct
|
---|
62 | <filename>/dev/srX</filename> devices, and sometimes to
|
---|
63 | <filename>/dev/sgX</filename>, which is wrong.</para>
|
---|
64 |
|
---|
65 | <para>The second approach yields:</para>
|
---|
66 |
|
---|
67 | <screen role="nodump"><userinput>cat >/etc/udev/rules.d/82-cdrom.rules << EOF
|
---|
68 | <literal>
|
---|
69 | # Custom CD-ROM symlinks
|
---|
70 | SUBSYSTEM=="block", ENV{ID_TYPE}=="cd", \
|
---|
71 | ENV{ID_PATH}=="pci-0000:00:07.1-ide-0:1", SYMLINK+="cdrom"
|
---|
72 | SUBSYSTEM=="block", ENV{ID_TYPE}=="cd", \
|
---|
73 | ENV{ID_PATH}=="pci-0000:00:07.1-ide-1:1", SYMLINK+="cdrom1 dvd"
|
---|
74 | </literal>
|
---|
75 | EOF</userinput></screen>
|
---|
76 |
|
---|
77 | <para>This way, the symlinks will stay correct even if you replace drives
|
---|
78 | with different models, but place them to the old positions on the IDE
|
---|
79 | bus. The ENV{ID_TYPE}=="cd" key makes sure that the symlink
|
---|
80 | disappears if you put something other than a CD-ROM in that position on
|
---|
81 | the bus.</para>
|
---|
82 |
|
---|
83 | <para>Of course, it is possible to mix the two approaches.</para>
|
---|
84 |
|
---|
85 | </sect2>
|
---|
86 |
|
---|
87 | <sect2>
|
---|
88 |
|
---|
89 | <title>Dealing with duplicate devices</title>
|
---|
90 |
|
---|
91 | <para>As explained in <xref linkend="ch-scripts-udev"/>, the order in
|
---|
92 | which devices with the same function appear in
|
---|
93 | <filename class="directory">/dev</filename> is essentially random.
|
---|
94 | E.g., if you have a USB web camera and a TV tuner, sometimes
|
---|
95 | <filename>/dev/video0</filename> refers to the camera and
|
---|
96 | <filename>/dev/video1</filename> refers to the tuner, and sometimes
|
---|
97 | after a reboot the order changes to the opposite one.
|
---|
98 | For all classes of hardware except sound cards and network cards, this is
|
---|
99 | fixable by creating udev rules for custom persistent symlinks.
|
---|
100 | The case of network cards is covered separately in
|
---|
101 | <xref linkend="ch-scripts-network"/>, and sound card configuration can
|
---|
102 | be found in <ulink url="&cblfs-root;">CBLFS</ulink>.</para>
|
---|
103 |
|
---|
104 | <para>For each of your devices that is likely to have this problem
|
---|
105 | (even if the problem doesn't exist in your current Linux distribution),
|
---|
106 | find the corresponding directory under
|
---|
107 | <filename class="directory">/sys/class</filename> or
|
---|
108 | <filename class="directory">/sys/block</filename>.
|
---|
109 | For video devices, this may be
|
---|
110 | <filename
|
---|
111 | class="directory">/sys/class/video4linux/video<replaceable>X</replaceable></filename>.
|
---|
112 | Figure out the attributes that identify the device uniquely (usually,
|
---|
113 | vendor and product IDs and/or serial numbers work):</para>
|
---|
114 |
|
---|
115 | <screen role="nodump"><userinput>udevadm info -a -p /sys/class/video4linux/video0</userinput></screen>
|
---|
116 |
|
---|
117 | <para>Then write rules that create the symlinks, e.g.:</para>
|
---|
118 |
|
---|
119 | <screen role="nodump"><userinput>cat >/etc/udev/rules.d/83-duplicate_devs.rules << EOF
|
---|
120 | <literal>
|
---|
121 | # Persistent symlinks for webcam and tuner
|
---|
122 | KERNEL=="video*", SYSFS{idProduct}=="1910", SYSFS{idVendor}=="0d81", \
|
---|
123 | SYMLINK+="webcam"
|
---|
124 | KERNEL=="video*", SYSFS{device}=="0x036f", SYSFS{vendor}=="0x109e", \
|
---|
125 | SYMLINK+="tvtuner"
|
---|
126 | </literal>
|
---|
127 | EOF</userinput></screen>
|
---|
128 |
|
---|
129 | <para>The result is that <filename>/dev/video0</filename> and
|
---|
130 | <filename>/dev/video1</filename> devices still refer randomly to the tuner
|
---|
131 | and the web camera (and thus should never be used directly), but there are
|
---|
132 | symlinks <filename>/dev/tvtuner</filename> and
|
---|
133 | <filename>/dev/webcam</filename> that always point to the correct
|
---|
134 | device.</para>
|
---|
135 |
|
---|
136 | <para>More information on writing Udev rules can be found in
|
---|
137 | <filename>/usr/share/doc/udev-&udev-version;/index.html</filename>.</para>
|
---|
138 |
|
---|
139 | </sect2>
|
---|
140 |
|
---|
141 | </sect1>
|
---|