source: BOOK/system-config/common/eudev.xml @ 87c0d57

clfs-3.0.0-sysvinitsysvinit
Last change on this file since 87c0d57 was 87c0d57, checked in by William Harrington <kb0iic@…>, 10 years ago

Add &linux-version2; entity to the required parts of the book that need the full kernel version rather than just the &linux-version; entity. I.E. 3.14.8 instead of 3.14

  • Property mode set to 100644
File size: 15.2 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
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>
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>, 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>
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
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
61      release of the 2.6 kernel series, and was removed entirely as of version
62      2.6.18.</para>
63
64    </sect3>
65
66    <sect3>
67      <title>Sysfs</title>
68
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
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
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>
85
86    </sect3>
87
88    <sect3>
89      <title>Udev Implementation</title>
90
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
96      information from <systemitem class="filesystem">sysfs</systemitem>, in
97      <filename class="directory">/sys</filename>. For example,
98      <filename>/sys/class/tty/vcs/dev</filename> contains the string
99      <quote>7:0</quote>. This string was used by <command>udev</command>
100      to create a device node with major number <emphasis>7</emphasis> and
101      minor number <emphasis>0</emphasis>.</para>
102
103      <para>Linux kernel version 2.6.32 introduced a new virtual file system
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
110      <systemitem class="filesystem">devtmpfs</systemitem> to do so.</para>
111
112    </sect3>
113
114    <sect3>
115      <title>Systemd and Eudev</title>
116
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>
125    </sect3>
126
127  </sect2>
128
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>
153    and be left at the defaults defined by the kernel, as described above. <!-- For
154    more details about writing Udev rules, see
155    <command>man 7 udev</command>. --></para>
156
157  </sect2>
158
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>
189
190  </sect2>
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
201      <para>Eudev will only load a module if it has a bus-specific alias and the
202      bus driver properly exports the necessary aliases to <systemitem
203      class="filesystem">sysfs</systemitem>. In other cases, one should
204      arrange module loading by other means. With
205      Linux-&linux-version;-&linux-version2;, Eudev is known to load
206      properly-written drivers for INPUT, IDE, PCI, USB, SCSI, SERIO and
207      FireWire devices.</para>
208
209      <para>To determine if the device driver you require has the necessary
210      support for Eudev, run <command>modinfo</command> with the module name as
211      the argument.  Now try locating the device directory under
212      <filename class="directory">/sys/bus</filename> and check whether there is
213      a <filename>modalias</filename> file there.</para>
214
215      <para>If the <filename>modalias</filename> file exists in <systemitem
216      class="filesystem">sysfs</systemitem>, the driver supports the device and
217      can talk to it directly, but doesn't have the alias, it is a bug in the
218      driver. Load the driver without the help from Eudev and expect the issue
219      to be fixed later.</para>
220
221      <para>If there is no <filename>modalias</filename> file in the relevant
222      directory under <filename class="directory">/sys/bus</filename>, this
223      means that the kernel developers have not yet added modalias support to
224      this bus type. With Linux-&linux-version;-&linux-version2;, this is the
225      case with ISA busses. Expect this issue to be fixed in later kernel
226      versions.</para>
227
228      <para>Eudev is not intended to load <quote>wrapper</quote> drivers such as
229      <emphasis>snd-pcm-oss</emphasis> and non-hardware drivers such as
230      <emphasis>loop</emphasis> at all.</para>
231
232    </sect3>
233
234    <sect3>
235      <title>A kernel module is not loaded automatically, and Eudev is not
236      intended to load it</title>
237
238      <para>If the <quote>wrapper</quote> module only enhances the functionality
239      provided by some other module (e.g., <emphasis>snd-pcm-oss</emphasis>
240      enhances the functionality of <emphasis>snd-pcm</emphasis> by making the
241      sound cards available to OSS applications), configure
242      <command>modprobe</command> to load the wrapper after Eudev loads the
243      wrapped module. To do this, add an <quote>install</quote> line to a file
244      in <filename>/etc/modprobe.d</filename>. For example:</para>
245
246<screen role="nodump"><literal>install snd-pcm /sbin/modprobe -i snd-pcm ; \
247    /sbin/modprobe snd-pcm-oss ; true</literal></screen>
248
249      <para>If the module in question is not a wrapper and is useful by itself,
250      configure the <command>S05modules</command> bootscript to load this
251      module on system boot. To do this, add the module name to the
252      <filename>/etc/sysconfig/modules</filename> file on a separate line.
253      This works for wrapper modules too, but is suboptimal in that case.</para>
254
255    </sect3>
256
257    <sect3>
258      <title>Eudev loads some unwanted module</title>
259
260      <para>Either don't build the module, or blacklist it in
261      <filename>/etc/modprobe.d</filename> file as done with the
262      <emphasis>forte</emphasis> module in the example below:</para>
263
264<screen role="nodump"><literal>blacklist forte</literal></screen>
265
266      <para>Blacklisted modules can still be loaded manually with the
267      explicit <command>modprobe</command> command.</para>
268
269    </sect3>
270
271    <sect3>
272      <title>Eudev makes a wrong symlink</title>
273
274      <para>This usually happens if a rule unexpectedly matches a device. For
275      example, a poorly-written rule can match both a SCSI disk (as desired)
276      and the corresponding SCSI generic device (incorrectly) by vendor.
277      Find the offending rule and make it more specific, with the help of
278      <command>udevadm info</command>.</para>
279
280    </sect3>
281
282    <sect3>
283      <title>Eudev rule works unreliably</title>
284
285      <para>This may be another manifestation of the previous problem. If not,
286      and your rule uses <systemitem class="filesystem">sysfs</systemitem>
287      attributes, it may be a kernel timing issue, to be fixed in later kernels.
288      For now, you can work around it by creating a rule that waits for the used
289      <systemitem class="filesystem">sysfs</systemitem> attribute and appending
290      it to the <filename>/etc/udev/rules.d/10-wait_for_sysfs.rules</filename>
291      file. Please notify the CLFS Development list if you do so and it
292      helps.</para>
293
294    </sect3>
295
296    <sect3>
297      <title>Device naming order changes randomly after rebooting</title>
298
299      <para>This is due to the fact that Eudev, by design, handles uevents and
300      loads modules in parallel, and thus in an unpredictable order. This will
301      never be <quote>fixed</quote>. You should not rely upon the kernel device
302      names being stable. Instead, create your own rules that make symlinks with
303      stable names based on some stable attributes of the device, such as a
304      serial number or the output of various *_id utilities installed by Eudev.
305      See <xref linkend="ch-config-symlinks"/> and
306      <xref linkend="chapter-network"/> for examples.</para>
307
308    </sect3>
309
310  </sect2>
311
312  <sect2>
313    <title>Useful Reading</title>
314
315    <para>Additional helpful documentation is available at the following
316    sites:</para>
317
318    <itemizedlist>
319
320      <listitem>
321        <para remap="verbatim">A Userspace Implementation of <systemitem class="filesystem">devfs</systemitem>
322        <ulink url="http://www.kroah.com/linux/talks/ols_2003_udev_paper/Reprint-Kroah-Hartman-OLS2003.pdf"/></para>
323      </listitem>
324
325      <listitem>
326        <para remap="verbatim">The <systemitem class="filesystem">sysfs</systemitem> Filesystem
327        <ulink url="http://www.kernel.org/pub/linux/kernel/people/mochel/doc/papers/ols-2005/mochel.pdf"/></para>
328      </listitem>
329
330    </itemizedlist>
331
332  </sect2>
333
334</sect1>
Note: See TracBrowser for help on using the repository browser.