source: chapter07/symlinks.xml@ ac3fb3e9

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 ac3fb3e9 was ac3fb3e9, checked in by Bryan Kadzban <bryan@…>, 17 years ago

Move custom CD symlink and custom NIC name rules files to 70-persistent-*.rules, and add ENV{GENERATED} to the CD symlink rules. Prevents Udev rule_generator stuff from conflicting.

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

  • Property mode set to 100644
File size: 6.6 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 /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>udevtest /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 &gt; /etc/udev/rules.d/70-persistent-cd.rules &lt;&lt; EOF
36<literal>
37# Custom CD-ROM symlinks
38SUBSYSTEM=="block", ENV{ID_MODEL}=="SAMSUNG_CD-ROM_SC-148F", \
39 ENV{ID_REVISION}=="PS05", ENV{GENERATED}="1", SYMLINK+="cdrom"
40SUBSYSTEM=="block", ENV{ID_MODEL}=="PHILIPS_CDD5301", \
41 ENV{ID_SERIAL}=="5VO1306DM00190", ENV{GENERATED}="1", SYMLINK+="cdrom1 dvd"
42</literal>
43EOF</userinput></screen>
44
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==&quot;block&quot; 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 &gt; /etc/udev/rules.d/70-persistent-cd.rules &lt;&lt; EOF
78<literal>
79# Custom CD-ROM symlinks
80SUBSYSTEM=="block", ENV{ID_TYPE}=="cd", \
81 ENV{ID_PATH}=="pci-0000:00:07.1-ide-0:1", \
82 ENV{GENERATED}="1", SYMLINK+="cdrom"
83SUBSYSTEM=="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>
87EOF</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}==&quot;cd&quot; 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>
96
97 </sect2>
98
99 <sect2>
100
101 <title>Dealing with duplicate devices</title>
102
103 <para>As explained in <xref linkend="ch-scripts-udev"/>, the order in
104 which devices with the same function appear in
105 <filename class="directory">/dev</filename> is essentially random.
106 E.g., if you have a USB web camera and a TV tuner, sometimes
107 <filename>/dev/video0</filename> refers to the camera and
108 <filename>/dev/video1</filename> refers to the tuner, and sometimes
109 after a reboot the order changes to the opposite one.
110 For all classes of hardware except sound cards and network cards, this is
111 fixable by creating udev rules for custom persistent symlinks.
112 The case of network cards is covered separately in
113 <xref linkend="ch-scripts-network"/>, and sound card configuration can
114 be found in <ulink url="&blfs-root;">BLFS</ulink>.</para>
115
116 <para>For each of your devices that is likely to have this problem
117 (even if the problem doesn't exist in your current Linux distribution),
118 find the corresponding directory under
119 <filename class="directory">/sys/class</filename> or
120 <filename class="directory">/sys/block</filename>.
121 For video devices, this may be
122 <filename
123 class="directory">/sys/class/video4linux/video<replaceable>X</replaceable></filename>.
124 Figure out the attributes that identify the device uniquely (usually,
125 vendor and product IDs and/or serial numbers work):</para>
126
127<screen role="nodump"><userinput>udevinfo -a -p /sys/class/video4linux/video0</userinput></screen>
128
129 <para>Then write rules that create the symlinks, e.g.:</para>
130
131<screen role="nodump"><userinput>cat &gt; /etc/udev/rules.d/83-duplicate_devs.rules &lt;&lt; EOF
132<literal>
133# Persistent symlinks for webcam and tuner
134KERNEL=="video*", SYSFS{idProduct}=="1910", SYSFS{idVendor}=="0d81", \
135 SYMLINK+="webcam"
136KERNEL=="video*", SYSFS{device}=="0x036f", SYSFS{vendor}=="0x109e", \
137 SYMLINK+="tvtuner"
138</literal>
139EOF</userinput></screen>
140
141 <para>The result is that <filename>/dev/video0</filename> and
142 <filename>/dev/video1</filename> devices still refer randomly to the tuner
143 and the web camera (and thus should never be used directly), but there are
144 symlinks <filename>/dev/tvtuner</filename> and
145 <filename>/dev/webcam</filename> that always point to the correct
146 device.</para>
147
148 <para>More information on writing Udev rules can be found in
149 <filename>/usr/share/doc/udev-&udev-version;/index.html</filename>.</para>
150
151 </sect2>
152
153</sect1>
Note: See TracBrowser for help on using the repository browser.