Changeset 81fd230 for chapter07/udev.xml
- Timestamp:
- 02/19/2005 10:16:42 PM (19 years ago)
- Branches:
- 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.1, 6.1.1, 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
- Children:
- 3d31fc4
- Parents:
- 2f9131f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
chapter07/udev.xml
r2f9131f r81fd230 12 12 <secondary>usage</secondary></indexterm> 13 13 14 15 <para>See testing</para> 14 <para>In <xref linkend="chapter-building-system"/>, we installed the Udev 15 package. Before we go into the details regarding how this works, 16 a brief history of previous methods of handling devices is in 17 order.</para> 18 19 <para>Linux systems in general traditionally use a static device 20 creation method, whereby a great many device nodes are created under 21 <filename class="directory">/dev</filename> (sometimes literally 22 thousands of nodes), regardless of whether the corresponding hardware 23 devices actually exist. This is typically done via a 24 <command>MAKEDEV</command> script, which contains a number of 25 calls to the <command>mknod</command> program with the relevant major and minor device 26 numbers for every possible device that might exist in the world. Using 27 the udev method, only those devices which are detected by the kernel 28 get device nodes created for them. Because these device nodes will be 29 created each time the system boots, they will be stored on a 30 <systemitem class="filesystem">ramfs</systemitem> (a file system that 31 resides entirely in memory and does not take up any disk space). 32 Device nodes do not require much disk space, so the memory that is 33 used in negligable.</para> 34 35 <sect2> 36 <title>History</title> 37 38 <para>In February 2000, a new filesystem called <systemitem 39 class="filesystem">devfs</systemitem> was merged into the 2.3.46 40 kernel and was made available during the 2.4 series of 41 stable kernels. Although it was present in the kernel source itself, 42 this method of creating devices dynamically never received 43 overwhelming support from the core kernel developers.</para> 44 45 <para>The main problem with the approach adopted by <systemitem 46 class="filesystem">devfs</systemitem> was the way it handled 47 device detection, creation, and naming. The latter issue, that of 48 device node naming, was perhaps the most critical. It is generally 49 accepted that if device names are allowed to be configurable, then 50 the device naming policy should be up to a system administrator, not 51 imposed on them by any particular developer(s). The <systemitem 52 class="filesystem">devfs</systemitem> file system also suffers from race 53 conditions that are inherent in its design and cannot be fixed 54 without a substantial revision to the kernel. It has also been marked 55 as deprecated due to a lack of recent maintenance.</para> 56 57 <para>With the development of the unstable 2.5 kernel tree, later 58 released as the 2.6 series of stable kernels, a new virtual filesystem 59 called <systemitem class="filesystem">sysfs</systemitem> came to be. 60 The job of <systemitem class="filesystem">sysfs</systemitem> is to 61 export a view of the system's structure to userspace processes. With 62 this userspace visible representation, the possibility of seeing a 63 userspace replacement for <systemitem 64 class="filesystem">devfs</systemitem> became much more 65 realistic.</para> 66 </sect2> 67 68 <sect2> 69 <title>Udev Implementation</title> 70 71 <para>The <systemitem class="filesystem">sysfs</systemitem> filesystem 72 was mentioned briefly above. One may wonder how <systemitem 73 class="filesystem">sysfs</systemitem> knows about the devices present 74 on a system and what device numbers should be used. Drivers that 75 have been compiled into the kernel directly register their objects 76 with <systemitem class="filesystem">sysfs</systemitem> as they are 77 detected by the kernel. For drivers compiled as modules, this will 78 happen when the module is loaded. Once the <systemitem 79 class="filesystem">sysfs</systemitem> filesystem is mounted (on 80 <filename class="directory">/sys</filename>), the data which the 81 built-in drivers registered with <systemitem 82 class="filesystem">sysfs</systemitem> are available to userspace 83 processes and to <command>udev</command> for device node creation.</para> 84 85 <para>The <command>S10udev</command> initscript takes care of creating 86 these device nodes when Linux is booted. This script starts with 87 registering <command>/sbin/udev</command> as a hotplug event handler. 88 Hotplug events (discussed below) should not be generated during this 89 stage, but <command>udev</command> is registered just in case they do 90 occur. The <command>udevstart</command> program then walks through 91 the <systemitem class="filesystem">/sys</systemitem> filesystem and 92 creates devices under <filename class="directory">/dev</filename> that 93 match the descriptions. For example, 94 <filename>/sys/class/tty/vcs/dev</filename> contains the string 95 <quote>7:0</quote> This string is used by <command>udevstart</command> 96 to create <filename>/dev/vcs</filename> with major number 97 <emphasis>7</emphasis> and minor <emphasis>0</emphasis>. The 98 permissions of each and every device that <command>udevstart</command> 99 creates are set using files from the <filename 100 class="directory">/etc/udev.d/permissions.d/</filename> directory. 101 These are numbered in a similar fashion to the LFS bootscripts. If 102 <command>udev</command> cannot find a permissions file for the device 103 it is creating, it will default permissions to 104 <emphasis>600</emphasis> and ownership to 105 <emphasis>root:root</emphasis>. The names of the nodes created under 106 the <filename class="directory">/dev</filename> directory are 107 configured according to the rules specified in the files within the 108 <filename class="directory">/etc/udev/rules.d/</filename> 109 directory.</para> 110 111 <para>Once the above stage is complete, all devices that were already 112 present and have compiled-in drivers will be available for use. What 113 about those devices that have modular drivers?</para> 114 115 <para>Earlier, we mentioned the concept of a <quote>hotplug event 116 handler.</quote> When a new device connection is detected by the 117 kernel, the kernel will generate a hotplug event and look at the file 118 <filename>/proc/sys/kernel/hotplug</filename> to find out the 119 userspace program that handles the device's connection. The 120 <command>udev</command> initscript registered <command>udev</command> 121 as this handler. When these hotplug events are generated, the kernel 122 will tell <command>udev</command> to check the <filename 123 class="directory">/sys</filename> filesystem for the information 124 pertaining to this new device and create the <filename 125 class="directory">/dev</filename> entry for it.</para> 126 127 <para>This brings us to one problem that exists with 128 <command>udev</command>, and likewise with <systemitem 129 class="filesystem">devfs</systemitem> before it. It is commonly 130 referred to as the <quote>chicken and egg</quote> problem. Most Linux 131 distrubtions handle loading modules via entries in 132 <filename>/etc/modules.conf</filename>. Access to a device node causes 133 the appropriate kernel module to load. With <command>udev</command>, 134 this method will not work because the device node does not exist until 135 the module is loaded. To solve this, the 136 <command>S05modules</command> bootscript was added to the 137 lfs-bootscripts package, along with the 138 <filename>/etc/sysconfig/modules</filename> file. By 139 adding module 140 names to the <filename>modules</filename> file, these modules will be 141 loaded when the computer is starting up. This allows 142 <command>udev</command> to detect the devices and create the 143 appropriate device nodes.</para> 144 145 <para>Note that on slower machines or for drivers that create a lot 146 of device nodes, the process of creating devices may take a few 147 seconds to complete. This means that some device nodes may not be 148 immediately accessible.</para> 149 </sect2> 150 151 <sect2> 152 <title>Handling Hotpluggable/Dynamic Devices</title> 153 154 <para>When you plug in a device, such a Universal Serial Bus (USB) MP3 player, the kernel 155 recognizes that the device is now connected and generates a hotplug 156 event. If the driver is already loaded (either because it was compiled 157 into the kernel or because it was loaded via the 158 <command>S05modules</command> bootscript), <command>udev</command> will 159 be called upon to create the relevant device node(s) according to the 160 <systemitem class="filesystem">sysfs</systemitem> data available in 161 <filename class="directory">/sys</filename>. If the driver for the 162 just plugged in device is available as a module but currently unloaded, 163 then attaching the device to the system will only cause the kernel's 164 bus driver to generate a hotplug event that notifies userspace of the 165 new device connection and it not being attached to a driver. In 166 effect, nothing happens and the device itself is not usable 167 yet.</para> 168 169 <para>If building a system that has a lot of drivers compiled as 170 modules rather than directly built into the kernel, using the 171 <command>S05modules</command> may not be practical. The Hotplug 172 package (see <ulink url="http://linux-hotplug.sourceforge.net/"/>) can 173 be beneficial in these cases. When the Hotplug package is installed, 174 it will respond to the aforementioned kernel's bus driver hotplug 175 events. The Hotplug package will load the appropriate module and make 176 this device available by creating the device node(s) for it.</para> 177 </sect2> 178 179 <sect2> 180 <title>Problems with Creating Devices</title> 181 182 <para>There are a few known problems when it comes to automatically creating 183 devices nodes:</para> 184 185 <para>1) A kernel driver may not export its data to <systemitem 186 class="filesystem">sysfs</systemitem>.</para> 187 188 <para>This is most common with third party drivers from outside the 189 kernel tree. These drivers will not end up having their device nodes 190 created. Use the 191 <filename>/etc/sysconfig/createfiles</filename> configuration file to 192 manually create the devices. Consult the 193 <filename>devices.txt</filename> file inside the kernel documentation 194 or the documentation for that driver to find the proper major/minor 195 numbers.</para> 196 197 <para>2) A non-hardware device is required. This is most common with 198 the Advanced Linux Sound Architecture (ALSA) project's Open Sound 199 System (OSS) compatibility module. These types of devices can be 200 handled in one of two ways:</para> 201 202 <itemizedlist> 203 204 <listitem><para>Adding the module names to 205 <filename>/etc/sysconfig/modules</filename></para></listitem> 206 <listitem><para>Using an 207 <quote>install</quote> line in 208 <filename>/etc/modprobe.conf</filename>. This tells the 209 <command>modprobe</command> command <quote>when loading this module, 210 also load this other module, at the same time.</quote> For example:</para> 211 212 <screen><userinput>install snd-pcm modprobe -i snd-pcm ; modprobe \ 213 snd-pcm-oss ; true</userinput></screen> 214 215 <para>This will cause the system to load both the 216 <emphasis>snd-pcm</emphasis> and <emphasis>snd-pcm-oss</emphasis> 217 modules when any request is made to load the driver 218 <emphasis>snd-pcm</emphasis>.</para></listitem> 219 </itemizedlist> 220 </sect2> 221 222 <sect2> 223 <title>Useful Reading</title> 224 225 <para>Additional helpful documentation is available at the following 226 sites:</para> 227 228 <itemizedlist> 229 <listitem><para remap="verbatim">A Userspace Implementation of devfs 230 <ulink url="http://www.kroah.com/linux/talks/ols_2003_udev_paper/Reprint-Kroah-Hartman-OLS2003.pdf"><phrase 231 condition="pdf">http://www.kroah.com/linux/talks/ols_2003_udev_paper/ 232 Reprint-Kroah-Hartman-OLS2003.pdf</phrase></ulink></para></listitem> 233 234 <listitem><para remap="verbatim">udev FAQ 235 <ulink url="http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev-FAQ"/></para></listitem> 236 237 <listitem><para remap="verbatim">The Linux Kernel Driver Model 238 <ulink url="http://public.planetmirror.com/pub/lca/2003/proceedings/papers/Patrick_Mochel/Patrick_Mochel.pdf"><phrase 239 condition="pdf">http://public.planetmirror.com/pub/lca/2003/proceedings/papers/ 240 Patrick_Mochel/Patrick_Mochel.pdf</phrase></ulink></para></listitem> 241 </itemizedlist> 242 </sect2> 16 243 17 244 </sect1>
Note:
See TracChangeset
for help on using the changeset viewer.