source: BOOK/system-config/common/eudev.xml@ 286ecce

clfs-3.0.0-sysvinit sysvinit
Last change on this file since 286ecce was f6721f7, checked in by Chris Staub <chris@…>, 11 years ago

Rewrote Udev page

  • Property mode set to 100644
File size: 14.7 KB
Line 
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-config-eudev">
9 <?dbhtml filename="eudev.html"?>
10
11 <title>Device and Module Handling on a CLFS System</title>
12
13 <indexterm zone="ch-config-eudev">
14 <primary sortas="a-Eudev">Eudev</primary>
15 <secondary>usage</secondary>
16 </indexterm>
17
18 <para>In <xref linkend="chapter-building-system"/>, we installed the Eudev
19 package. Before we go into the details regarding how this works,
20 a brief history of previous methods of handling devices is in
21 order.</para>
22
23 <sect2>
24 <title>History</title>
25
26 <sect3>
27 <title>Static Device Nodes</title>
28
29 <para>Linux systems in general traditionally use a static device creation
30 method, whereby a great many device nodes are created under <filename
31 class="directory">/dev</filename> (sometimes literally thousands of nodes),
32 regardless of whether the corresponding hardware devices actually exist.
33 This is typically done via a <command>MAKEDEV</command> script, which
34 contains a number of calls to the <command>mknod</command> program with the
35 relevant major and minor device numbers for every possible device that
36 might exist in the world.</para>
37
38 </sect3>
39
40 <sect3>
41 <title>Devfs</title>
42
43 <para>In February 2000, a new filesystem called <systemitem
44 class="filesystem">devfs</systemitem> was merged into the 2.3.46 kernel
45 and was made available during the 2.4 series of stable kernels. Although
46 it was present in the kernel source itself, this method of creating devices
47 dynamically never received overwhelming support from the core kernel
48 developers.</para>
49
50 <para>The main problem with the approach adopted by <systemitem
51 class="filesystem">devfs</systemitem> was the way it handled device
52 detection, creation, and naming. The latter issue, that of device node
53 naming, was perhaps the most critical. It is generally accepted that if
54 device names are allowed to be configurable, then the device naming policy
55 should be up to a system administrator, not imposed on them by any
56 particular developer(s). The <systemitem
57 class="filesystem">devfs</systemitem> file system also suffered from race
58 conditions that were inherent in its design and could not be fixed without a
59 substantial revision to the kernel. It was marked deprecated with the
60 release of the 2.6 kernel series, and was removed entirely as of version
61 2.6.18.</para>
62
63 </sect3>
64
65 <sect3>
66 <title>Sysfs</title>
67
68 <para>With the development of the unstable 2.5 kernel tree, later released
69 as the 2.6 series of stable kernels, a new virtual filesystem called
70 <systemitem class="filesystem">sysfs</systemitem> came to be. The job of
71 <systemitem class="filesystem">sysfs</systemitem> is to export a view of
72 the system's hardware configuration to userspace processes. Drivers that
73 have been compiled into the kernel directly register their objects with
74 <systemitem class="filesystem">sysfs</systemitem> as they are detected by
75 the kernel. For drivers compiled as modules, this registration will happen
76 when the module is loaded. Once the <systemitem
77 class="filesystem">sysfs</systemitem> filesystem is mounted (on <filename
78 class="directory">/sys</filename>), data which the built-in drivers
79 registered with <systemitem class="filesystem">sysfs</systemitem> are
80 available to userspace processes. With this
81 userspace-visible representation, the possibility of seeing a userspace
82 replacement for <systemitem class="filesystem">devfs</systemitem> became
83 much more realistic.</para>
84
85 </sect3>
86
87 <sect3>
88 <title>Udev Implementation</title>
89
90<!-- <title>Device Node Creation</title> -->
91
92 <para>When Udev was introduced, the <command>udevd</command> daemon made
93 calls to mknod() to create device nodes in
94 <filename class="directory">/dev</filename> dynamically, based on the
95 information from <systemitem class="filesystem">sysfs</systemitem>, in
96 <filename class="directory">/sys</filename>. For example,
97 <filename>/sys/class/tty/vcs/dev</filename> contains the string
98 <quote>7:0</quote>. This string was used by <command>udevd</command>
99 to create a device node with major number <emphasis>7</emphasis> and
100 minor number <emphasis>0</emphasis>. Using the Udev method
101 only those devices which are detected by the kernel would get device
102 nodes created for them. Because these device nodes were created each time
103 the system boots, they were stored on a
104 <systemitem class="filesystem">tmpfs</systemitem> file system (a virtual
105 file system that resides entirely in system memory). Device nodes do not
106 require much space, so the memory that is used is negligible.</para>
107
108 <para>Linux kernel version 2.6.32 introduced a new virtual file system
109 called <systemitem class="filesystem">devtmpfs</systemitem>, a
110 replacement for <systemitem class="filesystem">devfs</systemitem>.
111 With this approach, a
112 <systemitem class="filesystem">devtmpfs</systemitem> file system is
113 mounted on <filename class="directory">/dev/</filename> when the system
114 is booted, and all needed device nodes are created on this virtual
115 file system. As of version 176, Udev no longer creates device nodes
116 itself, instead relying on
117 <systemitem class="filesystem">devtmpfs</systemitem> to do so.</para>
118
119 <para>Udev also sets appropriate ownership and permissions
120 for the device nodes, and creates extra symlinks as needed (such as
121 <filename class="symlink">/dev/cdrom</filename>). The ownership and
122 permissions of the nodes under the
123 <filename class="directory">/dev</filename> directory are
124 determined by rules specified in the files within the <filename
125 class="directory">/etc/udev/rules.d/</filename> directory. These are
126 numbered in a similar fashion to the CLFS-Bootscripts package. If
127 <command>udevd</command> can't find a rule for the device it is creating,
128 it will default permissions to <emphasis>660</emphasis> and ownership to
129 <emphasis>root:root</emphasis>.</para>
130
131 </sect3>
132
133 <sect3>
134 <title>Systemd and Eudev</title>
135
136 <para>In May 2012, Udev's source was merged with systemd, an alternate
137 <command>init</command> implementation. Some time later, several Gentoo
138 developers took the Udev code from systemd and created a fork called
139 Eudev.</para>
140
141 </sect3>
142
143 </sect2>
144
145 <sect2>
146 <title>Module Loading</title>
147
148 <para>Device drivers compiled as modules may have aliases built into them.
149 Aliases are visible in the output of the <command>modinfo</command>
150 program and are usually related to the bus-specific identifiers of devices
151 supported by a module. For example, the <emphasis>snd-fm801</emphasis>
152 driver supports PCI devices with vendor ID 0x1319 and device ID 0x0801,
153 and has an alias of <quote>pci:v00001319d00000801sv*sd*bc04sc01i*</quote>.
154 For most devices, the bus driver exports the alias of the driver that
155 would handle the device via <systemitem
156 class="filesystem">sysfs</systemitem>. E.g., the
157 <filename>/sys/bus/pci/devices/0000:00:0d.0/modalias</filename> file
158 might contain the string
159 <quote>pci:v00001319d00000801sv00001319sd00001319bc04sc01i00</quote>.
160 The default rules provided by Eudev will cause <command>udevd</command>
161 to call out to <command>/sbin/modprobe</command> with the contents of the
162 <envar>MODALIAS</envar> uevent environment variable (that should be the
163 same as the contents of the <filename>modalias</filename> file in sysfs),
164 thus loading all modules whose aliases match this string after wildcard
165 expansion.</para>
166
167 <para>In this example, this means that, in addition to
168 <emphasis>snd-fm801</emphasis>, the obsolete (and unwanted)
169 <emphasis>forte</emphasis> driver will be loaded if it is
170 available. See below for ways in which the loading of unwanted drivers can
171 be prevented.</para>
172
173 <para>The kernel itself is also able to load modules for network
174 protocols, filesystems and NLS support on demand.</para>
175
176 </sect2>
177
178 <sect2>
179 <title>Handling Hotpluggable/Dynamic Devices</title>
180
181 <para>When you plug in a device, such as a Universal Serial Bus (USB) MP3
182 player, the kernel recognizes that the device is now connected and
183 generates a uevent. This uevent is then handled by
184 <command>udevd</command> as described above.</para>
185
186 </sect2>
187
188 <sect2>
189 <title>Problems with Loading Modules and Creating Devices</title>
190
191 <para>There are a few possible problems when it comes to automatically
192 creating device nodes.</para>
193
194 <sect3>
195 <title>A kernel module is not loaded automatically</title>
196
197 <para>Eudev will only load a module if it has a bus-specific alias and the
198 bus driver properly exports the necessary aliases to <systemitem
199 class="filesystem">sysfs</systemitem>. In other cases, one should
200 arrange module loading by other means. With Linux-&linux-version;, Eudev is
201 known to load properly-written drivers for INPUT, IDE, PCI, USB, SCSI,
202 SERIO and FireWire devices.</para>
203
204 <para>To determine if the device driver you require has the necessary
205 support for Eudev, run <command>modinfo</command> with the module name as
206 the argument. Now try locating the device directory under
207 <filename class="directory">/sys/bus</filename> and check whether there is
208 a <filename>modalias</filename> file there.</para>
209
210 <para>If the <filename>modalias</filename> file exists in <systemitem
211 class="filesystem">sysfs</systemitem>, the driver supports the device and
212 can talk to it directly, but doesn't have the alias, it is a bug in the
213 driver. Load the driver without the help from Eudev and expect the issue
214 to be fixed later.</para>
215
216 <para>If there is no <filename>modalias</filename> file in the relevant
217 directory under <filename class="directory">/sys/bus</filename>, this
218 means that the kernel developers have not yet added modalias support to
219 this bus type. With Linux-&linux-version;, this is the case with ISA
220 busses. Expect this issue to be fixed in later kernel versions.</para>
221
222 <para>Eudev is not intended to load <quote>wrapper</quote> drivers such as
223 <emphasis>snd-pcm-oss</emphasis> and non-hardware drivers such as
224 <emphasis>loop</emphasis> at all.</para>
225
226 </sect3>
227
228 <sect3>
229 <title>A kernel module is not loaded automatically, and Eudev is not
230 intended to load it</title>
231
232 <para>If the <quote>wrapper</quote> module only enhances the functionality
233 provided by some other module (e.g., <emphasis>snd-pcm-oss</emphasis>
234 enhances the functionality of <emphasis>snd-pcm</emphasis> by making the
235 sound cards available to OSS applications), configure
236 <command>modprobe</command> to load the wrapper after Eudev loads the
237 wrapped module. To do this, add an <quote>install</quote> line in
238 <filename>/etc/modprobe.conf</filename>. For example:</para>
239
240<screen role="nodump"><literal>install snd-pcm /sbin/modprobe -i snd-pcm ; \
241 /sbin/modprobe snd-pcm-oss ; true</literal></screen>
242
243 <para>If the module in question is not a wrapper and is useful by itself,
244 configure the <command>S05modules</command> bootscript to load this
245 module on system boot. To do this, add the module name to the
246 <filename>/etc/sysconfig/modules</filename> file on a separate line.
247 This works for wrapper modules too, but is suboptimal in that case.</para>
248
249 </sect3>
250
251 <sect3>
252 <title>Eudev loads some unwanted module</title>
253
254 <para>Either don't build the module, or blacklist it in
255 <filename>/etc/modprobe.conf</filename> file as done with the
256 <emphasis>forte</emphasis> module in the example below:</para>
257
258<screen role="nodump"><literal>blacklist forte</literal></screen>
259
260 <para>Blacklisted modules can still be loaded manually with the
261 explicit <command>modprobe</command> command.</para>
262
263 </sect3>
264
265 <sect3>
266 <title>Eudev creates a device incorrectly, or makes a wrong symlink</title>
267
268 <para>This usually happens if a rule unexpectedly matches a device. For
269 example, a poorly-writen rule can match both a SCSI disk (as desired)
270 and the corresponding SCSI generic device (incorrectly) by vendor.
271 Find the offending rule and make it more specific, with the help of
272 <command>udevadm info</command>.</para>
273
274 </sect3>
275
276 <sect3>
277 <title>Eudev rule works unreliably</title>
278
279 <para>This may be another manifestation of the previous problem. If not,
280 and your rule uses <systemitem class="filesystem">sysfs</systemitem>
281 attributes, it may be a kernel timing issue, to be fixed in later kernels.
282 For now, you can work around it by creating a rule that waits for the used
283 <systemitem class="filesystem">sysfs</systemitem> attribute and appending
284 it to the <filename>/etc/udev/rules.d/10-wait_for_sysfs.rules</filename>
285 file. Please notify the CLFS Development list if you do so and it
286 helps.</para>
287
288 </sect3>
289
290 <sect3>
291 <title>Device naming order changes randomly after rebooting</title>
292
293 <para>This is due to the fact that Eudev, by design, handles uevents and
294 loads modules in parallel, and thus in an unpredictable order. This will
295 never be <quote>fixed</quote>. You should not rely upon the kernel device
296 names being stable. Instead, create your own rules that make symlinks with
297 stable names based on some stable attributes of the device, such as a
298 serial number or the output of various *_id utilities installed by Eudev.
299 See <xref linkend="ch-config-symlinks"/> and
300 <xref linkend="chapter-network"/> for examples.</para>
301
302 </sect3>
303
304 </sect2>
305
306 <sect2>
307 <title>Useful Reading</title>
308
309 <para>Additional helpful documentation is available at the following
310 sites:</para>
311
312 <itemizedlist>
313
314 <listitem>
315 <para remap="verbatim">A Userspace Implementation of <systemitem class="filesystem">devfs</systemitem>
316 <ulink url="http://www.kroah.com/linux/talks/ols_2003_udev_paper/Reprint-Kroah-Hartman-OLS2003.pdf"/></para>
317 </listitem>
318
319 <listitem>
320 <para remap="verbatim">The <systemitem class="filesystem">sysfs</systemitem> Filesystem
321 <ulink url="http://www.kernel.org/pub/linux/kernel/people/mochel/doc/papers/ols-2005/mochel.pdf"/></para>
322 </listitem>
323
324 </itemizedlist>
325
326 </sect2>
327
328</sect1>
Note: See TracBrowser for help on using the repository browser.