source: BOOK/system-config/common/eudev.xml@ 3a08b23

sysvinit
Last change on this file since 3a08b23 was 7349750, checked in by William Harrington <kb0iic@…>, 10 years ago

Correction to previous commit, we want &linux-version2; entity where it is required. Do not use &linux-version; and &linux-version2; entities together. We just want Linux-3.14.10 where required, rather than LInux-3.14. And surely we do not want LInux-3.14-3.14.10.

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