[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>
|
---|
| 153 | and be left at the defaults defined by the kernel, as described above. For
|
---|
| 154 | more details about writing Udev rules, see
|
---|
| 155 | <ulink url="/usr/share/doc/systemd-&systemd-version;/udev.html" />.</para>
|
---|
| 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
|
---|
[82fc053] | 204 | arrange module loading by other means. With Linux-&linux-version;, Eudev is
|
---|
[806d0c2] | 205 | known to load properly-written drivers for INPUT, IDE, PCI, USB, SCSI,
|
---|
| 206 | SERIO and FireWire devices.</para>
|
---|
| 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
|
---|
| 223 | this bus type. With Linux-&linux-version;, this is the case with ISA
|
---|
| 224 | busses. Expect this issue to be fixed in later kernel versions.</para>
|
---|
| 225 |
|
---|
[82fc053] | 226 | <para>Eudev is not intended to load <quote>wrapper</quote> drivers such as
|
---|
[806d0c2] | 227 | <emphasis>snd-pcm-oss</emphasis> and non-hardware drivers such as
|
---|
| 228 | <emphasis>loop</emphasis> at all.</para>
|
---|
| 229 |
|
---|
| 230 | </sect3>
|
---|
| 231 |
|
---|
| 232 | <sect3>
|
---|
[82fc053] | 233 | <title>A kernel module is not loaded automatically, and Eudev is not
|
---|
[806d0c2] | 234 | intended to load it</title>
|
---|
| 235 |
|
---|
| 236 | <para>If the <quote>wrapper</quote> module only enhances the functionality
|
---|
| 237 | provided by some other module (e.g., <emphasis>snd-pcm-oss</emphasis>
|
---|
| 238 | enhances the functionality of <emphasis>snd-pcm</emphasis> by making the
|
---|
| 239 | sound cards available to OSS applications), configure
|
---|
[82fc053] | 240 | <command>modprobe</command> to load the wrapper after Eudev loads the
|
---|
[bbf3c21] | 241 | wrapped module. To do this, add an <quote>install</quote> line to a file
|
---|
| 242 | in <filename>/etc/modprobe.d</filename>. For example:</para>
|
---|
[806d0c2] | 243 |
|
---|
| 244 | <screen role="nodump"><literal>install snd-pcm /sbin/modprobe -i snd-pcm ; \
|
---|
| 245 | /sbin/modprobe snd-pcm-oss ; true</literal></screen>
|
---|
| 246 |
|
---|
[82fc053] | 247 | <para>If the module in question is not a wrapper and is useful by itself,
|
---|
| 248 | configure the <command>S05modules</command> bootscript to load this
|
---|
| 249 | module on system boot. To do this, add the module name to the
|
---|
| 250 | <filename>/etc/sysconfig/modules</filename> file on a separate line.
|
---|
| 251 | This works for wrapper modules too, but is suboptimal in that case.</para>
|
---|
| 252 |
|
---|
[806d0c2] | 253 | </sect3>
|
---|
| 254 |
|
---|
| 255 | <sect3>
|
---|
[82fc053] | 256 | <title>Eudev loads some unwanted module</title>
|
---|
[806d0c2] | 257 |
|
---|
| 258 | <para>Either don't build the module, or blacklist it in
|
---|
[bbf3c21] | 259 | <filename>/etc/modprobe.d</filename> file as done with the
|
---|
[806d0c2] | 260 | <emphasis>forte</emphasis> module in the example below:</para>
|
---|
| 261 |
|
---|
| 262 | <screen role="nodump"><literal>blacklist forte</literal></screen>
|
---|
| 263 |
|
---|
| 264 | <para>Blacklisted modules can still be loaded manually with the
|
---|
| 265 | explicit <command>modprobe</command> command.</para>
|
---|
| 266 |
|
---|
| 267 | </sect3>
|
---|
| 268 |
|
---|
| 269 | <sect3>
|
---|
[bbf3c21] | 270 | <title>Eudev makes a wrong symlink</title>
|
---|
[806d0c2] | 271 |
|
---|
| 272 | <para>This usually happens if a rule unexpectedly matches a device. For
|
---|
| 273 | example, a poorly-writen rule can match both a SCSI disk (as desired)
|
---|
| 274 | and the corresponding SCSI generic device (incorrectly) by vendor.
|
---|
| 275 | Find the offending rule and make it more specific, with the help of
|
---|
| 276 | <command>udevadm info</command>.</para>
|
---|
| 277 |
|
---|
| 278 | </sect3>
|
---|
| 279 |
|
---|
| 280 | <sect3>
|
---|
[82fc053] | 281 | <title>Eudev rule works unreliably</title>
|
---|
[806d0c2] | 282 |
|
---|
| 283 | <para>This may be another manifestation of the previous problem. If not,
|
---|
| 284 | and your rule uses <systemitem class="filesystem">sysfs</systemitem>
|
---|
| 285 | attributes, it may be a kernel timing issue, to be fixed in later kernels.
|
---|
| 286 | For now, you can work around it by creating a rule that waits for the used
|
---|
| 287 | <systemitem class="filesystem">sysfs</systemitem> attribute and appending
|
---|
| 288 | it to the <filename>/etc/udev/rules.d/10-wait_for_sysfs.rules</filename>
|
---|
| 289 | file. Please notify the CLFS Development list if you do so and it
|
---|
| 290 | helps.</para>
|
---|
| 291 |
|
---|
| 292 | </sect3>
|
---|
| 293 |
|
---|
| 294 | <sect3>
|
---|
| 295 | <title>Device naming order changes randomly after rebooting</title>
|
---|
| 296 |
|
---|
[82fc053] | 297 | <para>This is due to the fact that Eudev, by design, handles uevents and
|
---|
[806d0c2] | 298 | loads modules in parallel, and thus in an unpredictable order. This will
|
---|
| 299 | never be <quote>fixed</quote>. You should not rely upon the kernel device
|
---|
| 300 | names being stable. Instead, create your own rules that make symlinks with
|
---|
| 301 | stable names based on some stable attributes of the device, such as a
|
---|
[82fc053] | 302 | serial number or the output of various *_id utilities installed by Eudev.
|
---|
[775d9a7] | 303 | See <xref linkend="ch-config-symlinks"/> and
|
---|
[806d0c2] | 304 | <xref linkend="chapter-network"/> for examples.</para>
|
---|
| 305 |
|
---|
| 306 | </sect3>
|
---|
| 307 |
|
---|
| 308 | </sect2>
|
---|
| 309 |
|
---|
| 310 | <sect2>
|
---|
| 311 | <title>Useful Reading</title>
|
---|
| 312 |
|
---|
| 313 | <para>Additional helpful documentation is available at the following
|
---|
| 314 | sites:</para>
|
---|
| 315 |
|
---|
| 316 | <itemizedlist>
|
---|
| 317 |
|
---|
| 318 | <listitem>
|
---|
| 319 | <para remap="verbatim">A Userspace Implementation of <systemitem class="filesystem">devfs</systemitem>
|
---|
| 320 | <ulink url="http://www.kroah.com/linux/talks/ols_2003_udev_paper/Reprint-Kroah-Hartman-OLS2003.pdf"/></para>
|
---|
| 321 | </listitem>
|
---|
| 322 |
|
---|
| 323 | <listitem>
|
---|
| 324 | <para remap="verbatim">The <systemitem class="filesystem">sysfs</systemitem> Filesystem
|
---|
| 325 | <ulink url="http://www.kernel.org/pub/linux/kernel/people/mochel/doc/papers/ols-2005/mochel.pdf"/></para>
|
---|
| 326 | </listitem>
|
---|
| 327 |
|
---|
| 328 | </itemizedlist>
|
---|
| 329 |
|
---|
| 330 | </sect2>
|
---|
| 331 |
|
---|
| 332 | </sect1>
|
---|