Typo
[linux_from_scratch_hints.git] / OLD / mk_initrd+devfs.txt
blob647d81c4a3d60e9a0e072381000c71a2dc2fcffa
1 AUTHOR: Martial Daumas <martial@nasgaia.org>
3 DATE: 2003-09-18
5 LICENSE: GNU Free Documentation License Version 1.2
7 SYNOPSIS: How to create a basic mk_initrd command that works nice with LFS and devfs.
9 DESCRIPTION:
10 Initial Ram-disk (AKA initrd) is a minimal linux system that is run before the 
11 actual root partition is mounted, it contains an executable file called linuxrc 
12 (either a simple script as well as a more complicated compiled program) which is 
13 automatically run, and when it's finished, normal boot sequence goes on. This 
14 is mostly needed to load kernel modules needed to mount the root partition, thus
15 it can be either a FS module (ie: reiserfs, jfs...), hardware modules (scsi, 
16 raid controller, lvm...).
18 If you use LFS for your own usage, you generally know in advance what will
19 be the modules needed to get your root partition mounted, so you can simply 
20 have theses supports compiled in the kernel, and forget about initrd, 
21 and this hint. Initrd can be helpful in the following circumstances:
23 -You want to distribute a pre-compiled kernel and keep it as small and scalable
24  as possible and you build a modular kernel, so that only needed modules are
25  loaded in memory (that's my case).
27 -You are building an embedded system, for example on a live CD-ROM, and you 
28  don't know in advance on what kind of hardware it will be run, in which 
29  case linuxrc can be handy to proceed tests or interactive actions, or 
30  further tweakings.
32 -Mounting your root partition requires features that are only available as 
33  a separate module for some reason.
35 -Some features are impossible to compile at the same time in the kernel,
36  due to conflicts, once again initrd can help.
38 In previous versions of the kernel, creating an initrd was possibly 
39 complicated task, mainly in writing a correct linuxrc.  This hint is 
40 intended for those using devfs, with a 2.4.x kernel, version 2.4.19
41 and later. 2.6 kernel is not covered here but this hint will be updated 
42 soon.
44 You can build an initrd by hands easily, but here we'll rather create a
45 mk_initrd command (as found on some other distros), that is strictly minimal, 
46 and can be reused whenever you setup change. This is primarily intended to
47 explain how thing works.
49 PREREQUISITES:
50 - linux kernel 2.4.19 or later, compiled with maximum modules use.
51 - the ash shell (optionnal).
52 - sufficient knowledge of how kernel works at boot time, as well
53 as modules and boot loaders usage.
54 - You also need the latest versions of these files (subject to possible 
55 updates):
57         http://nasgaia.org/~martial/lfs/initrd.conf
58         http://nasgaia.org/~martial/lfs/linuxrc
59         http://nasgaia.org/~martial/lfs/mk_initrd
61 HINT:
62 1. Create the configuration file
63 ================================
65 This file cans be use to scale the initrd to your needs.  Copy the
66 initrd.conf file in /etc, remember to edit it as needed to suit your
67 libraries version.
69 Syntax: 
71 In LFS_INITRD_BINARIES and LFS_INITRD_SHLIBS, the first fields specify
72 where to find the needed file on the current system, the second ones specify 
73 where to place this file in the initrd, and its name (if you need to change it
74 for some reasons).
76 LFS_INITRD_LNS allows to create symbolic links within the initrd (the second
77 field is the name of the link)
79 Other options are quite self-explanatory, feel free to adapt to your needs. If
80 you don't have the ash shell, you can replace by bash, but you'll have less
81 space left for modules, just remember to replace #!/bin/ash by #!/bin/bash
82 later on in linuxrc. 
84 2. Create the linuxrc script
85 ============================
87 When the kernel is passed an initrd option via the boot loader, it uncompresses
88 the ram-disk into the memory, and always try to execute the /linuxrc command.
90 What we create here is strictly minimal, and thanks to the use of devfs, we 
91 don't have to deal anymore with mounting the real root partition and no more
92 needs for pivot_root, everything is done automatically by the kernel itself
93 (which eases a _lot_ the whole process).
95 Note: the value of the root partition is stored in the kernel at compile
96 time, it that value is not correct (ie: you compiled the kernel somewhere
97 else), see rdev(8) to change it.
99 Create a /usr/share/mk_initrd directory to store linuxrc with:
100 mkdir -p /usr/share/mk_initrd
102 Now copy the file linuxrc  as /usr/share/mk_initrd/linuxrc - please make
103 it executable as needed (chmod +x).
105 3.Create the mk_initrd command
106 ==============================
108 Last but not the least, we now create the mk_initrd command itself. The use
109 of that script is explained later.
111 Copy mk_initrd in /usr/sbin/ and make it executable:
113 4. Using mk_initrd
114 ==================
116 As usage() tells, you simply have to call mk_initrd passing a space
117 separated list of modules with full paths (most of the time only one module
118 is needed). The important thing to remind is that modules will be probed in the
119 same order as given on the command line, thus, if you want to load both a
120 device support (let's SCSI or RAID controller) and a FS support (let's
121 say reiserfs or jfs) the hardware support logically should be activated prior
122 to the FS support. If the hardware support comes in several modules, the order
123 is generally significant too; use lsmod to determine which is the modules order.
125 The linuxrc provided here is to be considered as an example, in many cases you'll
126 have to include an other set of binaries and libs, and have linuxrc behave in
127 a more complicated (or safer) manner.
129 5. A word on booting with grub
130 ==============================
132 To boot with initrd enabled, it's really simple, just add an initrd line
133 in /boot/grub/menu.lst , like this:
135 initrd (hdX,Y)/boot/initrd.gz
137 under the line starting with "kernel /boot/...."
139 Remember that devfs auto-mounting is required for this to work, so if
140 you didn't compiled your kernel with the "mount at boot time" option,
141 add devfs=mount on the kernel line (or append line with lilo).
143 6. Ideas to make it better
144 ==========================
146 Since it's possible to use larger initrd (either specify it when compiling
147 the kernel, or use special boot option), you might want to use initrd in other
148 contexts, and it worth having more available commands; give BusyBox a try, you
149 can obtain a nice set of Unix commands in something like 200Ko (dynamically 
150 linked against glibc, even less against ulibc or dietlibc).
152 ACKNOWLEDGEMENTS:
153 I especially wish to thank Richard Lightman for his help and explanations on how
154 initrd now works, I'd certainly still be stuck with outdated docs without him :-)
156 CHANGELOG:
157 [2002-10-26]
158         * initial release
159 [2003-09-16]
160         * new hints format update
161         * English correctness updates
162 [2003-09-18]
163         * making separate files for scripts