/[gentoo]/xml/htdocs/doc/en/udev-guide.xml
Gentoo

Contents of /xml/htdocs/doc/en/udev-guide.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.34 - (show annotations) (download) (as text)
Wed Nov 29 15:48:57 2006 UTC (11 years ago) by nightmorph
Branch: MAIN
Changes since 1.33: +3 -3 lines
File MIME type: application/xml
revert previous change

1 <?xml version='1.0' encoding="UTF-8"?>
2 <!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
3
4 <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/udev-guide.xml,v 1.32 2006/11/27 00:08:22 nightmorph Exp $ -->
5
6 <guide link="/doc/en/udev-guide.xml">
7 <title>Gentoo udev Guide</title>
8
9 <author title="Author">
10 <mail link="swift@gentoo.org">Sven Vermeulen</mail>
11 </author>
12 <author title="Contributor">
13 <mail link="greg_g@gentoo.org">Gregorio Guidi</mail>
14 </author>
15
16 <abstract>
17 This document explains what udev is and how you can use udev to fit your needs.
18 </abstract>
19
20 <license/>
21
22 <version>0.25</version>
23 <date>2006-11-26</date>
24
25 <chapter>
26 <title>What is udev?</title>
27 <section>
28 <title>The /dev Directory</title>
29 <body>
30
31 <p>
32 When Linux-users talk about the hardware on their system in the vicinity of
33 people who believe Linux is some sort of virus or brand of coffee, the use of
34 "slash dev slash foo" will return a strange look for sure. But for the fortunate
35 user (and that includes you) using <path>/dev/hda1</path> is just a fast way of
36 explaining that we are talking about the primary master IDE, first partition. Or
37 aren't we?
38 </p>
39
40 <p>
41 We all know what a device file is. Some even know why device files have special
42 numbers when we take a closer look at them when we issue <c>ls -l</c> in
43 <path>/dev</path>. But what we always take for granted is that the primary
44 master IDE disk is referred to as <path>/dev/hda</path>. You might not see it
45 this way, but this is a flaw by design.
46 </p>
47
48 <p>
49 Think about hotpluggable devices like USB, IEEE1394, hot-swappable PCI, ... What
50 is the first device? And for how long? What will the other devices be named when
51 the first one disappears? How will that affect ongoing transactions? Wouldn't it
52 be fun that a printing job is suddenly moved from your supernew laserprinter to
53 your almost-dead matrix printer because your mom decided to pull the plug of the
54 laserprinter which happened to be the first printer?
55 </p>
56
57 <p>
58 Enter <e>udev</e>. The goals of the udev project are both interesting and
59 needed:
60 </p>
61
62 <ul>
63 <li>Runs in userspace</li>
64 <li>Dynamically creates/removes device files</li>
65 <li>Provides consistent naming</li>
66 <li>Provides a user-space API</li>
67 </ul>
68
69 <p>
70 To provide these features, udev is developed in three separate projects:
71 <e>namedev</e>, <e>libsysfs</e> and, of course, <e>udev</e>.
72 </p>
73
74 </body>
75 </section>
76 <section>
77 <title>namedev</title>
78 <body>
79
80 <p>
81 Namedev allows you to define the device naming separately from the udev program.
82 This allows for flexible naming policies and naming schemes developed by
83 separate entities. This device naming subsystem provides a standard interface
84 that udev can use.
85 </p>
86
87 <p>
88 Currently only a single naming scheme is provided by namedev; the one provided
89 by LANANA, used by the majority of Linux systems currently and therefore very
90 suitable for the majority of Linux users.
91 </p>
92
93 <p>
94 Namedev uses a 5-step procedure to find out the name of a given device. If the
95 device name is found in one of the given steps, that name is used. The steps
96 are:
97 </p>
98
99 <ul>
100 <li>label or serial number</li>
101 <li>bus device number</li>
102 <li>bus topology</li>
103 <li>statically given name</li>
104 <li>kernel provided name</li>
105 </ul>
106
107 <p>
108 The <e>label or serial number</e> step checks if the device has a unique
109 identifier. For instance USB devices have a unique USB serial number; SCSI
110 devices have a unique UUID. If namedev finds a match between this unique number
111 and a given configuration file, the name provided in the configuration file is
112 used.
113 </p>
114
115 <p>
116 The <e>bus device number</e> step checks the device bus number. For
117 non-hot-swappable environments this procedure is sufficient to
118 identify a hardware device. For instance PCI bus numbers rarely change in the
119 lifetime of a system. Again, if namedev finds a match between this position and
120 a given configuration file, the name provided in that configuration file is
121 used.
122 </p>
123
124 <p>
125 Likewise the <e>bus topology</e> is a rather static way of defining devices as
126 long as the user doesn't switch devices. When the position of the device matches
127 a given setting provided by the user, the accompanying name is used.
128 </p>
129
130 <p>
131 The fourth step, <e>statically given name</e>, is a simple string replacement.
132 When the kernel name (the default name) matches a given replacement string, the
133 substitute name will be used.
134 </p>
135
136 <p>
137 The final step (<e>kernel provided name</e>) is a catch-all: this one takes
138 the default name provided by the kernel. In the majority of cases this is
139 sufficient as it matches the device naming used on current Linux systems.
140 </p>
141
142 </body>
143 </section>
144 <section>
145 <title>libsysfs</title>
146 <body>
147
148 <p>
149 udev interacts with the kernel through the sysfs pseudo filesystem. The libsysfs
150 project provides a common API to access the information given by the sysfs
151 filesystem in a generic way. This allows for querying all kinds of hardware
152 without having to make assumptions on the kind of hardware.
153 </p>
154
155 </body>
156 </section>
157 <section>
158 <title>udev</title>
159 <body>
160
161 <p>
162 Every time the kernel notices an update in the device structure, it calls the
163 <path>/sbin/hotplug</path> program. Hotplug runs the applications linked in the
164 <path>/etc/hotplug.d/default</path> directory where you will also find a symlink
165 to the udev application. Hotplug directs the information given by the kernel to
166 the udev application which performs the necessary actions on the
167 <path>/dev</path> structure (creating or deleting device files).
168 </p>
169
170 </body>
171 </section>
172 </chapter>
173
174 <chapter>
175 <title>Using udev on Gentoo</title>
176 <section>
177 <title>Requirements</title>
178 <body>
179
180 <p>
181 udev is meant to be used in combination with a 2.6 kernel (like
182 <c>vanilla-sources</c> or <c>gentoo-sources</c> with the default 2005.0
183 profile). If you're using such a kernel then you just have to make sure that
184 you have a recent <c>sys-apps/baselayout</c> version. That's all you need.
185 </p>
186
187 <pre caption="Installing udev">
188 # <i>emerge udev</i>
189 </pre>
190
191 <p>
192 udev will install <c>hotplug-base</c> as one of its dependencies. You do not
193 need to install <c>hotplug</c> unless you want your modules automatically
194 loaded when you plug devices in. <c>hotplug</c> also handles the automated
195 bringup of network devices and firmware downloading.
196 </p>
197
198 <pre caption="Installing optional hotplug scripts">
199 # <i>emerge hotplug</i>
200 </pre>
201
202 <p>
203 If you want modules loaded for devices that have been plugged in before you
204 boot, use the coldplug package:
205 </p>
206
207 <pre caption="Installing the coldplug package">
208 # <i>emerge coldplug</i>
209 </pre>
210
211 <p>
212 Don't forget to add <c>coldplug</c> to the boot runlevel:
213 </p>
214
215 <pre caption="Adding coldplug to the boot runlevel">
216 # <i>rc-update add coldplug boot</i>
217 </pre>
218
219 <note>
220 You no longer need to emerge <c>coldplug</c> if you're using udev version 103
221 and higher, as udev itself will handle module loading. If you are upgrading to
222 version 103, you must unmerge coldplug (<c>emerge -aC coldplug</c>) before
223 upgrading udev. Be sure to remove the coldplug init script from all runlevels
224 (<c>rc-update del coldplug</c>), and then delete it from
225 <path>/etc/init.d/</path> afterward.
226 </note>
227
228 <p>
229 Kernelwise, be sure to activate the following options:
230 </p>
231
232 <pre caption="Required kernel options">
233 General setup ---&gt;
234 [*] Support for hot-pluggable devices
235
236 File systems ---&gt;
237 Pseudo filesystems ---&gt;
238 [*] /proc file system support
239 [*] Virtual memory file system support (former shm fs)
240 </pre>
241
242 <p>
243 You can leave the <c>/dev file system support (OBSOLETE)</c> active if you
244 wish but you have to make sure that "Automatically mount at boot" is disabled:
245 </p>
246
247 <pre caption="Don't automatically mount devfsd">
248 File systems ---&gt;
249 Pseudo Filesystems ---&gt;
250 [*] /dev file system support (OBSOLETE)
251 [ ] Automatically mount at boot
252 </pre>
253
254 <p>
255 If you use <c>genkernel</c>, don't forget to run it with the <c>--udev</c>
256 option to enable all the required kernel configuration directives. The default
257 configuration given by this <c>genkernel</c> invocation is sufficient.
258 </p>
259
260 </body>
261 </section>
262 <section>
263 <title>Configuration</title>
264 <body>
265
266 <p>
267 If you want to use the udev-tweaks Gentoo added to make your life
268 comfortable, then read no more. Gentoo will use udev but keep a static
269 <path>/dev</path> so that you will never have any missing device nodes.
270 The Gentoo init scripts won't run the devfsd daemon and will deactivate devfs
271 when you boot up.
272 </p>
273
274 <p>
275 But if you are a die-hard and want to run a udev-only, no-tweaked system as is
276 intended by the udev development (including the difficulties of missing device
277 nodes because udev doesn't support them yet), by all means, read on :)
278 </p>
279
280 <p>
281 We'll deactivate the rules that save the device file nodes: edit the
282 <c>RC_DEVICE_TARBALL</c> variable in <path>/etc/conf.d/rc</path> and set it to
283 <c>no</c>:
284 </p>
285
286 <pre caption="/etc/conf.d/rc">
287 RC_DEVICE_TARBALL="no"
288 </pre>
289
290 <p>
291 If you have included devfs support in your kernel, you can deactivate it in
292 the bootloader configuration: add <c>gentoo=nodevfs</c> as a kernel parameter.
293 If you want to use devfs and deactivate udev, add <c>gentoo=noudev</c> as kernel
294 parameter.
295 </p>
296
297 </body>
298 </section>
299 </chapter>
300
301 <chapter>
302 <title>Known Issues</title>
303 <section>
304 <title>Missing device node files at boot</title>
305 <body>
306
307 <p>
308 If you can't boot successfully because you get an error about
309 <path>/dev/null</path> not found, or because the initial console is missing, the
310 problem is that you lack some device files that must be available <e>before</e>
311 <path>/dev</path> is mounted and handled by udev. This is common on Gentoo
312 machines installed from old media.
313 </p>
314
315 <p>
316 If you run <c>sys-apps/baselayout-1.8.12</c> or later, this problem is
317 alleviated since the boot process should still manage to complete. However, to
318 get rid of those annoying warnings, you should create the missing device nodes
319 as described below.
320 </p>
321
322 <p>
323 To see which devices nodes are present before the <path>/dev</path> filesystem
324 is mounted, run the following commands:
325 </p>
326
327 <pre caption="Listing device nodes available at boot">
328 # <i>mkdir test</i>
329 # <i>mount --bind / test</i>
330 # <i>cd test/dev</i>
331 # <i>ls</i>
332 </pre>
333
334 <p>
335 The devices needed for a successful boot are <path>/dev/null</path> and
336 <path>/dev/console</path>. If they didn't show up in the previous test, you have
337 to create them manually. Issue the following commands in the
338 <path>test/dev/</path> directory:
339 </p>
340
341 <pre caption="Creating necessary device node files">
342 # <i>mknod -m 660 console c 5 1</i>
343 # <i>mknod -m 660 null c 1 3</i>
344 </pre>
345
346 <p>
347 When you're finished, don't forget to unmount the <path>test/</path> directory:
348 </p>
349
350 <pre caption="Unmounting the test/ directory">
351 # <i>cd ../..</i>
352 # <i>umount test</i>
353 # <i>rmdir test</i>
354 </pre>
355
356 </body>
357 </section>
358 <section>
359 <title>udev and nvidia</title>
360 <body>
361
362 <p>
363 If you use the proprietary driver from nVidia and the X server fails to start on
364 a udev-only system, then make sure you have:
365 </p>
366
367 <ul>
368 <li>
369 the <c>nvidia</c> module listed in
370 <path>/etc/modules.autoload.d/kernel-2.6</path>
371 </li>
372 <li>
373 a version of <c>nvidia-kernel</c> equal to or greater than
374 <c>media-video/nvidia-kernel-1.0.5336-r2</c>
375 </li>
376 <li>
377 a version of baselayout equal to or greater than
378 <c>sys-apps/baselayout-1.8.12</c>
379 </li>
380 </ul>
381
382 <p>
383 If <c>xorg-x11</c> refuses to start, it might be because the
384 <path>/dev/nvidia</path> device file is missing. If that is the case, run
385 <path>/sbin/NVmakedevices.sh</path> to (re)create it.
386 </p>
387
388 </body>
389 </section>
390 <section>
391 <title>LVM2 Names Disappear</title>
392 <body>
393
394 <p>
395 When you use <c>udev</c> and LVM2 together, you might notice that your created
396 volume groups and logical volumes have disappeared. Well, they haven't, but they
397 are unfortunately named <path>/dev/dm-#</path> with # being 0, 1, ...
398 </p>
399
400 <p>
401 To fix this, edit <path>/etc/udev/rules.d/50-udev.rules</path> and uncomment the
402 following line:
403 </p>
404
405 <pre caption="Uncomment this line from /etc/udev/rules.d/50-udev.rules">
406 KERNEL="dm-[0-9]*", PROGRAM="/sbin/devmap_name %M %m", NAME="%k", SYMLINK="%c"
407 </pre>
408
409 <p>
410 Next, install <c>sys-fs/multipath-tools</c> which contains the
411 <c>devmap_name</c> application.
412 </p>
413
414 <pre caption="Installing multipath-tools">
415 <comment>(At the moment of writing, multipath-tools is only available in the testing branch:)</comment>
416 # <i>echo "=sys-fs/multipath-tools-0.4.2 ~x86" &gt;&gt; /etc/portage/package.keywords</i>
417 # <i>emerge multipath-tools</i>
418 </pre>
419
420 </body>
421 </section>
422 <section>
423 <title>No Consistent Naming between DevFS and udev</title>
424 <body>
425
426 <p>
427 Even though our intention is to have a consistent naming scheme between both
428 dynamical device management solutions, sometimes naming differences do occur.
429 </p>
430
431 <p>
432 One reported clash is with a HP Smart Array 5i RAID controller (more precisely
433 the <c>cciss</c> kernel module). With udev, the devices are named
434 <path>/dev/cciss/cXdYpZ</path> with X, Y and Z regular numbers. With devfs, the
435 devices are <path>/dev/hostX/targetY/partZ</path> or symlinked from
436 <path>/dev/cciss/cXdY</path>.
437 </p>
438
439 <p>
440 If this is the case, don't forget to update your <path>/etc/fstab</path> and
441 bootloader configuration files accordingly.
442 </p>
443
444 <p>
445 The same happens with all-round symlinks that used to exist in
446 <path>/dev</path>, such as <path>/dev/mouse</path>, which <c>udev</c> doesn't
447 create anymore. Be certain to check your X configuration file and see if the
448 Device rule for your mouse points to an existing device file.
449 </p>
450
451 <p>
452 Another issue is the difference in naming of terminals between devfs and udev.
453 While devfs calls its terminals <c>tty</c>, udev calls them <c>vc</c> and
454 <c>tty</c>. This could lead to a problem in case you are restricting root
455 logins from consoles using <path>/etc/securetty</path>. You will need to make
456 sure that both <c>tty1</c> and <c>vc/1</c> are listed in
457 <path>/etc/securetty</path> to ensure that root can login using the console.
458 </p>
459
460 </body>
461 </section>
462 <section>
463 <title>Other issues</title>
464 <body>
465
466 <p>
467 If device nodes are not created when a module is loaded from
468 <path>/etc/modules.autoload.d/kernel-2.6</path> but they appear when you load
469 the module manually with modprobe then you should try upgrading to
470 <c>sys-apps/baselayout-1.8.12</c> or later.
471 </p>
472
473 <p>
474 Support for the framebuffer devices (<path>/dev/fb/*</path>) comes with the
475 kernel starting from version 2.6.6-rc2.
476 </p>
477
478 <p>
479 For kernels older than 2.6.4 you have to explicitly include support for the
480 <path>/dev/pts</path> filesystem.
481 </p>
482
483 <pre caption="Enabling the /dev/pts filesystem">
484 File systems ---&gt;
485 Pseudo filesystems ---&gt;
486 [*] /dev/pts file system for Unix98 PTYs
487 </pre>
488
489 </body>
490 </section>
491 </chapter>
492
493 <chapter>
494 <title>Resources &amp; Acknowledgements</title>
495 <section>
496 <body>
497
498 <p>
499 The udev talk on the Linux Symposium (Ottawa, Ontario Canada - 2003) given by
500 Greg Kroah-Hartman (IBM Corporation) provided a solid understanding on the udev
501 application.
502 </p>
503
504 <p>
505 <uri link="http://webpages.charter.net/decibelshelp/LinuxHelp_UDEVPrimer.html">Decibel's
506 UDEV Primer</uri> is an in-depth document about udev and Gentoo.
507 </p>
508
509 <p>
510 <uri link="http://www.reactivated.net/udevrules.php">Writing udev rules</uri> by
511 fellow Gentoo developer Daniel Drake is an excellent document to learn how to
512 customize your udev installation.
513 </p>
514
515 </body>
516 </section>
517 </chapter>
518
519 </guide>

  ViewVC Help
Powered by ViewVC 1.1.20