Typo
[linux_from_scratch_hints.git] / OLD / 2.6-udev.txt
blob22918d22da7a0b13ffba2ecc6b77cffe9a5c1760
1 AUTHOR: Ryan Reich
2 DATE:2004-03-08
3 VERSION: 2.0
4 LICENSE: GPL
5 PRIMARY URI: http://aptchi.homelinux.org/2.6-udev/
6 SYNOPSIS: Linux-2.6 and udev for a dynamic /dev
7 DESCRIPTION: This will describe how to install Linux-2.6 on your LFS system
8                  and set up dynamic device management with udev.
10         Introduction
12 In this hint, I will explain how to turn your plain ol' LFS system into a
13 shiny new Linux-2.6 LFS system, without doing a whole lot of recompiling.
14 There may be downsides to this, but I haven't noticed any with ordinary
15 desktop use. The main reason I wrote this, though, was to describe how to use
16 udev/sysfs as a replacement for devfsd/devfs, since I find the documentation
17 available to be a little lacking.
19 PREREQUISITES:
21 You need to get the following:
23                 Linux 2.6.*:
24 (http://www.kernel.org/pub/linux/kernel/v2.6/)
26         Grab the newest one.
28                 Module-init-tools
29 (http://www.kernel.org/pub/linux/utils/kernel/module-init-tools/)
31         This package replaces modutils since the module format changed in 2.6.
32         Grab the latest stable version. You're living enough on the edge using
33         2.6 without getting beta software as well.
35                 Sysfs init script
36 (http://www.linuxfromscratch.org/hints/downloads/attachments/2.6-udev/mountsys)
38         Just a little script to mount sysfs at boot. It's sensitive to the
39         2.4 vs. 2.6 issue, so it doesn't generate irritating messages if you
40         boot into 2.4 with it.
42                 Udev
43 (http://www.kernel.org/pub/linux/utils/kernel/hotplug/)
45         The userspace daemon which handles /dev dynamically, which devfs also
46         did once upon a time, before it was deprecated. This thing is still
47         under development, but the recent versions work fine and if something
48         doesn't work, it's probably a sysfs problem. Just get the latest
49         release.
51                 Hotplug scripts
52 (http://www.kernel.org/pub/linux/utils/kernel/hotplug/)
54         Udev relies upon hotplug to do its work, so you need these.
56                 Busybox (Optional)
57 (http://www.busybox.net/)
59         An all-in-one utility which incorporates miniscule versions of standard
60         Unix tools. In a major breakthrough, they have almost released version
61         1; get that. You only need this if you want to take the initrd approach
62         to udev. These days memory isn't much of an issue, so it's not strictly
63         necessary to shrink-wrap the initrd...but large kernels and initrds
64         have a way of crashing on boot, and you would be surprised how large
65         this can get if you have to include the shared libraries and everything.
67                 linuxrc (Optional)
68 (http://www.linuxfromsratch.org/hints/downloads/attachments/2.6-udev/linuxrc)
69    
70         A very basic initrd init script, which you only need if you are doing
71         the initrd approach.
73                 udev init script (Optional)
74 (http://www.linuxfromscratch.org/hints/downloads/attachments/2.6-udev/udev)
76         A pared-down version of the init script provided with udev, which also
77         does the tmpfs filesystem which I describe.  Only necessary if you are
78         NOT doing the initrd approach.
80         Module-init-tools
82 HINT:
83 The first thing you need to do is upgrade your module utilities.  In
84 particular, you want to be really careful that you don't overwrite your old
85 ones so that, in the very likely event you need to boot back into 2.4 because
86 something in 2.6 doesn't work right the first time, you actually can do this
87 still. Hence the somewhat extended build process:
89         tar xjvf module-init-tools-*.tar.bz2
90         cd module-init-tools-*/
91         ./configure --prefix=/
92         make moveold
93         make
94         make install
95         ./generate-modprobe.conf /etc/modprobe.conf
97                 Command explanations:
99 ./configure --prefix=/
101 Unlike almost everything else in LFS, this is a system utility probably
102 required at boot and must reside in /sbin.
104 make moveold
106 This copies modprobe, insmod, rmmod, and depmod to *.old (it also does this
107 for the man pages). This way, the new modprobe will check first to see your
108 kernel version; if you are using 2.4, it calls the .old modprobe instead of
109 proceeding itself. Hence no hassle.
111 ./generate-modprobe.conf /etc/modprobe.conf
113 module-init-tools has a much different system for the modules configuration
114 file than did modutils, and correspondingly it is kind enough to give you a
115 new file. It will even incorporate definitions you made in your old
116 modules.conf, which it will of course leave where it was so that modprobe.old
117 can find it if necessary.
119                 Configuration:
121 Reading the man page for modprobe and modprobe.conf is recommended, but the
122 gist of the changes is that all those confusing and complicated aboves and
123 belows and whatnot that went in modules.conf have been replaced with but two
124 commands: install and remove. alias still exists, of course. The following
125 are thus equivalent (for example):
127         below snd-intel8x0 snd-pcm-oss (modules.conf)
128         install snd-intel8x0 /sbin/modprobe snd-pcm-oss; /sbin/modprobe \
129                 --ignore-install snd-intel8x0 (modprobe.conf)
131 This means that if you execute `modprobe snd-intel8x0` in 2.6, modprobe will
132 literally run the sequence `modprobe snd-pcm-oss; modprobe snd-intel8x0`. The
133 --ignore-install means to ignore the line in the config file when running the
134 second modprobe, for of course to do otherwise would result in an endless
135 loop. remove works similarly; in general, this syntax is infinitely
136 extensible.
138         Linux-2.6.*
140 Now to compile a new kernel. The developers really spent a lot of time
141 improving even the build procedure in 2.6, so that numerous conveniences have
142 been introduced. For one, it will try to interpret the .config of your
143 current kernel, if it's located in /boot/config-`uname -r` (i.e.
144 /boot/config-2.4.22 if you are running linux-2.4.22). For two, there are now
145 two GUI config interfaces, xconfig and gconfig, using qt and gtk,
146 respectively, both better than the original xconfig. You should do:
148         tar xjvf linux-2.6.*.tar.bz2
149         cd linux-2.6.*/
150         make mrproper
151         make *config
152         make
153         make modules_install
154         cp arch/$(ARCH)/boot/bzImage /boot/image
155         cp System.map /boot/mapfile
157                 Command Explanations:
159 make mrproper
161 Always make mrproper the first time you use a tree. You never know what might
162 have snuck in.
164 make *config
166 I like xconfig, personally, but then, I use KDE also. Draw your own
167 conclusions. When configuring, do a very careful run-through because the
168 options have changed dramatically from 2.4. The CPU selection is different,
169 for example, and you really don't want the kernel compiled for the wrong CPU.
171 Another thing to watch out for is CONFIG_HOTPLUG. In kernels up through
172 2.6.3, it's in Bus options -> Hot-pluggable devices near the top of the base
173 config menu. In 2.6.4, it's under "General Setup". If you don't have this,
174 the hotplug scripts are useless and you can't use udev.
176 Also, if you plan to use the initrd approach to udev, make sure you enable
177 support for an initial ramdisk in the configuration. It's under Device
178 Drivers -> Block devices and you need to enable RAM disk support. Since you
179 will have an initrd, you might also want to look into the bootsplash patch
180 and utilities located at http://www.bootsplash.org. Their 2.6 patch is
181 outdated, almost as though they didn't look at their own link; a much newer
182 (and for the newest kernels, functional) patch is at ftp.suse.com, which is
183 right on the same page.
185 Finally, read the post-halloween docs at
186 http://www.codemonkey.org.uk/docs/post-halloween-2.6.txt to get incredibly
187 detailed information on what changed from 2.4. Really.  Do this.
189 make
191 What? Did you say I forgot make dep? No, I didn't; it got cut. You don't have
192 to specify bzImage either, since Image and zImage have gone the way of the
193 dodo. Just make will do. Oh, and they recommend you use gcc-2.95.3 to
194 compile; the instructions for this are in the BLFS book, so if you want to
195 use this compiler, just specify make CC=/opt/gcc-2.95.3/bin/gcc (path is as
196 given in BLFS-5.0).
198 cp stuff places
200 Here $(ARCH) is your machine's architecture, likely i386. If it's not, you
201 don't need this explanation.
203 Call the image and System.map whatever you like, so long as System.map is
204 called System.map-2.6.*. Yes, now the kernel supports VERSIONED map files, so
205 that you don't have to switch stuff around every time you boot into a
206 different kernel. Just append the version to the System.map and the kernel
207 will find it at boot.
209         Sysfs Init Script
211 You could do the rest in 2.4, but since udev won't work without sysfs, you
212 may as well reboot. You may also wish to update your init scripts to mount
213 sysfs. I have written a simple init script that should do this; place it in
214 /etc/rc.d/init.d, give it 754 permissions, and link it:
216         ln -nsf ../mountsys /etc/rc.d/rcsysinit.d/S30mountsys
218 The number, of course, depends on your setup; it should go after mountproc,
219 however, since I put in a line that checks /proc/filesystems to detect
220 kernels (like pre-2.5) that do not support sysfs.
222 Sysfs exports various device-related data; in fact, it exports so much it's
223 impossible to figure out what to do with it all. Some of it is useful for
224 configuring udev to correctly identify unusual or transientdevices, like USB
225 thingies. It's new, though, so I am not sure if anything else uses it aside
226 from udev.
228         Hotplug scripts
230 Anyway, now you're running 2.6. The hotplug scripts are easy to install:
232         tar xjvf hotplug-*.tar.bz2
233         cd hotplug-*/
234         make install
236 They're just shell scripts, after all. The README has other suggestions that
237 are not strictly necessary. One of the scripts installed is a boot script,
238 placed in /etc/rc.d/init.d/hotplug, which you may wish to run at boot. Sadly,
239 their script is not LFS-style and is quite hard to make LFS-style, so you
240 won't get any nice colored notifications when it runs. Put it somewhere at
241 the beginning of the runlevel queue so that it loads your USB, etc. drivers
242 before you need them.
244         Udev
246 And finally, we have udev.
248         tar xjvf udev-*.tar.bz2
249         cd udev-*/
250         make USE_LOG=false DEBUG=false USE_KLIBC=true INSTALL_DIR=/usr/bin udevdir=/dev
251         make install
253                 Command Explanations:
255 make ...
257 I used to have a patch for this, but it wasn't worth its weight in typos. The
258 options are self-explanatory, except USE_KLIBC, which refers to a special
259 linux-kernel version of the C library. Greg K-H recommends you use it.
261                 Configuration:
263 This is the fun part. Configuring udev itself is an exercise best left to the
264 reader; the man page is actually pretty helpful.  Configuration in this case
265 means telling udev what to name which devices and what permissions to give
266 them; the work is figuring out which device you are trying to name. The
267 information you use is drawn from sysfs; in addition, pciutils and usbutils
268 are quite helpful (they aren't given in the BLFS book, however).
270 In order to make /dev truly dynamic, you want to have as little in it as
271 possible which is permanent. There are two possibilities for this: to
272 maintain a minimal static /dev from which the kernel can boot and then fill
273 it up later, or to create the initial /dev from an initrd (of course, you'll
274 need a small, static /dev there, but conceptually it is more elegant. Make
275 sure you compiled your kernel with initrd support (as suggested above).
277         The Non-Initrd Method
279 First, though, the non-initrd way. This is easy: download my udev boot
280 script, put it some place in your boot process after the mountsys script, and
281 watch it work. It creates a tmpfs filesystem on /dev of maximum size 100k
282 (this is a dramatic overestimate; since device files take up no space, /dev
283 will always be 40k. However, each file needs a whole block, and you want
284 enough blocks to cover most eventualities.  You also don't want the tmpfs to
285 be too large, or else it will hog your memory) and runs udevstart, a
286 wonderful program which completely obviates the udev init script distributed
287 with the source code. If you want /dev/pts and /dev/shm mounted (and you do)
288 make sure that mountfs, or whatever script you have them mounted in, runs
289 after the udev script.
291         The Initrd Method
293 Note in the following that we construct the initrd in a real directory and
294 only at the end "burn" it into a separate filesystem. This is for two
295 reasons: one, so that you can make mistakes. If you did it all on the
296 separate filesystem, every wrong turn would unzero part of the filesystem and
297 it wouldn't compress as well. Of course, this isn't a boot disk and it sort
298 of doesn't mater how big the compressed image is...but it's aesthetic. And
299 second, you have more room if you do it on disk.
301         Busybox
303 Busybox has a menuconfig like the linux kernel, which makes it easy to choose
304 the utilities you want. Those are, for us,
306      * "Build as a static binary" in "Build Options"
307      * chroot, ln, and mkdir in "Coreutils"
308      * ash with "Optimize for size" and "Hide message" in "Another
309        Bourne-like Shell"
310      * freeramdisk, pivot_root, mount, and umount in "Linux system utilities"
312 Nothing else is necessary. If you plan to use the initrd to load modules as
313 well, throw in insmod, rmmod, and modprobe too. Finally, specify an
314 installation directory in "Installation options", which will be where we
315 construct the initrd. I use /tmp/tmp-initrd. Then make dep && make &&
316 make_install.
318         Udev for Initrd
320 Since we'll be using udev to do the work, you need to get it onto the ramdisk
321 also. However, I have had issues with it looking for the config file in the
322 wrong place, even though (allegedly) you can specify UDEV_CONFIG_FILE as an
323 environment variable. I suggest recompiling:
325         make clean
326         make USE_LOG=false DEBUG=false USE_KLIBC=true udevdir=/new-root/dev
327         mkdir -p /tmp/tmp-initrd/{etc/udev,new-root}
328         cp etc/udev/udev.{conf,rules,permissions} /tmp/tmp-initrd/etc/udev
329         cp udev udevstart /tmp/tmp-initrd/sbin
331 We don't need any other files and they hog space, so we just copy these five.
332 Make sure they say what you want them to. In particular, make sure udev.conf
333 has the devices directory correct, and remember it's relative to
334 /tmp/tmp-initrd
336         Building the Initial Ramdisk
338 Now create your linuxrc. As explained (confusingly, if you ask me) by the
339 initrd manpage, it's what the kernel runs as init when the initrd is loaded.
340 I have provided one which does the same thing as the init script, except also
341 does the maintenance operations that an initrd needs to do. Finally, I have
342 left a marker @root-dev@ which denotes your root device, and another @fstype@
343 on the same line which denotes its filesystem. Kindly replace them with a
344 real device and filesystem.
346 Finally, create /tmp/tmp-initrd/dev and put a few files in it. You need
347 console, hd?/hs?, null, ram0, tty[1-9], which you can either create by hand
348 or, as a test of your udev installation, using udevstart. The disk is, of
349 course, the device on which your root filesystem is located. Just chroot .
350 /bin/sh and run udevstart. Exit the chroot environment (which was necessary
351 because of the paths we hardwired into udev) and delete the devices you don't
352 want.
354 If you want to use the initrd for module loading, put them in now and modify
355 the linuxrc to suit them. Make sure you have no spare files lying around in
356 the initrd tree and figure out using du -sh how big it is. Mine is on the
357 order of 600k. Create a zeroed-out filesystem as follows:
359         dd if=/dev/zero of=initrd-udev bs=640k count=1
360         mke2fs -F -m0 initrd-udev
361         mkdir /initrd
362         mount -o loop initrd-udev /initrd
364                 Command Explanations
366 dd if=/dev/zero of=initrd-udev bs=640k count=1
368 The blocksize of course depends on how big your tree is. What matters here is
369 the number of inodes, since it limits how many files you can include, so I
370 used more space than necessary.
372 mke2fs -F -m0 initrd-udev
374 The -F disables an annoying question, and the -m0 says not to reserve space
375 for the superuser, who won't need it.
377 mount -o loop initrd-udev /mnt
379 If you are a current udev user following this section to get the initrd up,
380 beware that you may not have loop device support if you compiled it as a
381 module. Since udev doesn't do automatic module loading like devfs did and
382 since loop devices aren't hardware and hence not detected by hotplug, the
383 module probably isn't in. Load it first. The /initrd directory is necessary
384 for the boot process.
386 Now cp -a tmp-initrd/* /initrd, make sure your filesystem really was large
387 enough by observing any error messsages, unmount /initrd, and gzip -9
388 initrd-udev. Put the zipped initrd in /boot
390 When you boot, make sure the options include "root=/boot/initrd-udev.gz
391 init=/linuxrc". linuxrc calls the real init when it's done.
393         Closing Remarks
395 Be careful with your udev.conf in all the sections in which you install one
396 (depending on whether you use the initrd, there may be two).  If you used my
397 make command you should have the right entries for the path and all; however,
398 the default permissions are unnecessarily restrictive: 0600.  You probably
399 want to change those to 0666, or else (for example) your sound will probably
400 not work.
402 And speaking of sound: it has been observed that udev doesn't play well with
403 the alsa boot script.  In my case, it appeared that the problem was udev
404 being slow, or rather, being a process.  The alsa script will load your sound
405 card module if necessary, which will create the appropriate data in /sys and
406 signal /sbin/hotplug, which will call udev to make the nodes.  However, this
407 is all happening in sync with the rest of the bootscript; alsactl doesn't
408 know that the devices are being created so it will check as soon as modprobe
409 exits, and of course probably not find any devices since there's a rather
410 lengthy chain of events occuring in their creation.  The gist of this is that
411 I solved the problem by manually running modprobe, then `sleep 1`, and then
412 alsactl.  Similar issues may occur with other bootscripts in similar
413 situations: the point is that udev is not a kernel filesystem like devfs was,
414 and therefore actual time elapses between the end of the modprobe and the
415 creation of device nodes.
417 Also, be aware that sysfs is not yet completely implemented for all drivers,
418 and the most glaring exception is the parallel-port driver. If you have a
419 parallel-port printer and you want to use it, you must (for now) manually
420 create /dev/lp0:
422         mknod -m 666 /dev/lp0 c 6 0
424 If you have other printers you would change the 0 to the appropriate number.
425 This necessity is obviously a wart on sysfs at the moment, but remember that
426 linux-2.6 is still in its infancy.
428 In addition, those devices for which sysfs IS implemented often appear in
429 places you may not be used to.  To wit: the mouse device appears in
430 /dev/input, not /dev or /dev/misc.  This is actually a default rule and not
431 kernel policy, but the effect is the same.  So either change your
432 XF86Config-4 file or change the rule.  Also, I believe there may be issues
433 regarding "legacy" BSD tty's.  I don't use them, so I don't know if they
434 should appear; however, my brother reports that they do not, so if you rely
435 on them, you might want to consider moving over to Unix98 tty's.
437 Finally, in the continuing spirit of backwards-compatibility, if you
438 currently use devfs you have more work. Obviously you can't mount both devfs
439 and ramfs on /dev and expect both to work, and anyway, udev replaces devfs. I
440 suggest, therefore, that in configuring the kernel way back above, you make
441 sure to disable devfs entirely. Then, modify your devfs boot script:
443         mount -t devfs devfs /dev || exit 0
445 Thus, if devfs is not supported by the kernel (like it is not in your 2.6
446 kernel), the script will quit without mounting it and without giving an
447 error.
449 That's it! Hopefully your system boots without too much complaining.
451         Errors
453 None, I hope. However, inevitably I make a typo in a script or forget some
454 technicality, so please tell me if I've done this somewhere.
456 CHANGELOG:
458 [2004-04-10]
459 * Changed version to 2.1
460 * Corrected numerous not-really-fatal errors
462 [2004-03-12]
463 * Changed version to 2.0
464 * Updated location of CONFIG_HOTPLUG for kernel 2.6.4
465 * Added warning about /dev/lp0
466 * Removed the udev-lfs patch
467 * Created the (optional) udev bootscript
468 * Implemented the (optional) initrd procedure
470 [2004-03-04]
471 * Changed filename to 2.6-udev.txt (from 2.6-udev.hint, to be in
472   compliance with the Guidelines).
473 * Shortened the synopsis
474 * Stylistic changes
475 * Removed references to .tar.gz -- who uses these anyway?
476 * Added version number 1.1
477 * Improved some command explanations
478 * Removed reference to `make install`; I do not understand it, I do not use
479   it, and it appears to make assumptions about your system's layout that may
480   not correspond to the LFS layout.
481 * Removed the depmod command; silly me, make modules_install does it.
482 * Created the mountsys init script
483 * Created the udev-lfs patch and simplified the build commands
484 * Added the ERRORS section
485 * Added a paragraph about the minimal /dev
486 * Added a suggestion regarding the use of an initrd
488 [2004-02-21]
489 * Created the hint.