diff options
author | Domenico Andreoli <cavokz@gmail.com> | 2007-05-23 16:58:11 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-23 23:14:14 -0400 |
commit | 9d9a2000e683ecd497b65d5f3e73b048c68976e1 (patch) | |
tree | ee3cdc06a21de648154eab11355f077ff60d26d5 | |
parent | a778b73ff793d34c0082f76110f73a7754915067 (diff) |
documentation: Documentation/initrd.txt
Final clearification of the pivot_root mechanism, which brings this
document really up-to-date.
Signed-off-by: Domenico Andreoli <cavok@dandreoli.com>
Cc: "Randy.Dunlap" <rdunlap@xenotime.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | Documentation/initrd.txt | 74 |
1 files changed, 46 insertions, 28 deletions
diff --git a/Documentation/initrd.txt b/Documentation/initrd.txt index 15f1b35deb34..d3dc505104da 100644 --- a/Documentation/initrd.txt +++ b/Documentation/initrd.txt | |||
@@ -27,16 +27,20 @@ When using initrd, the system typically boots as follows: | |||
27 | 1) the boot loader loads the kernel and the initial RAM disk | 27 | 1) the boot loader loads the kernel and the initial RAM disk |
28 | 2) the kernel converts initrd into a "normal" RAM disk and | 28 | 2) the kernel converts initrd into a "normal" RAM disk and |
29 | frees the memory used by initrd | 29 | frees the memory used by initrd |
30 | 3) initrd is mounted read-write as root | 30 | 3) if the root device is not /dev/ram0, the old (deprecated) |
31 | 4) /linuxrc is executed (this can be any valid executable, including | 31 | change_root procedure is followed. see the "Obsolete root change |
32 | mechanism" section below. | ||
33 | 4) root device is mounted. if it is /dev/ram0, the initrd image is | ||
34 | then mounted as root | ||
35 | 5) /sbin/init is executed (this can be any valid executable, including | ||
32 | shell scripts; it is run with uid 0 and can do basically everything | 36 | shell scripts; it is run with uid 0 and can do basically everything |
33 | init can do) | 37 | init can do). |
34 | 5) linuxrc mounts the "real" root file system | 38 | 6) init mounts the "real" root file system |
35 | 6) linuxrc places the root file system at the root directory using the | 39 | 7) init places the root file system at the root directory using the |
36 | pivot_root system call | 40 | pivot_root system call |
37 | 7) the usual boot sequence (e.g. invocation of /sbin/init) is performed | 41 | 8) init execs the /sbin/init on the new root filesystem, performing |
38 | on the root file system | 42 | the usual boot sequence |
39 | 8) the initrd file system is removed | 43 | 9) the initrd file system is removed |
40 | 44 | ||
41 | Note that changing the root directory does not involve unmounting it. | 45 | Note that changing the root directory does not involve unmounting it. |
42 | It is therefore possible to leave processes running on initrd during that | 46 | It is therefore possible to leave processes running on initrd during that |
@@ -70,7 +74,7 @@ initrd adds the following new options: | |||
70 | root=/dev/ram0 | 74 | root=/dev/ram0 |
71 | 75 | ||
72 | initrd is mounted as root, and the normal boot procedure is followed, | 76 | initrd is mounted as root, and the normal boot procedure is followed, |
73 | with the RAM disk still mounted as root. | 77 | with the RAM disk mounted as root. |
74 | 78 | ||
75 | Compressed cpio images | 79 | Compressed cpio images |
76 | ---------------------- | 80 | ---------------------- |
@@ -137,11 +141,11 @@ We'll describe the loopback device method: | |||
137 | # mkdir /mnt/dev | 141 | # mkdir /mnt/dev |
138 | # mknod /mnt/dev/console c 5 1 | 142 | # mknod /mnt/dev/console c 5 1 |
139 | 5) copy all the files that are needed to properly use the initrd | 143 | 5) copy all the files that are needed to properly use the initrd |
140 | environment. Don't forget the most important file, /linuxrc | 144 | environment. Don't forget the most important file, /sbin/init |
141 | Note that /linuxrc's permissions must include "x" (execute). | 145 | Note that /sbin/init's permissions must include "x" (execute). |
142 | 6) correct operation the initrd environment can frequently be tested | 146 | 6) correct operation the initrd environment can frequently be tested |
143 | even without rebooting with the command | 147 | even without rebooting with the command |
144 | # chroot /mnt /linuxrc | 148 | # chroot /mnt /sbin/init |
145 | This is of course limited to initrds that do not interfere with the | 149 | This is of course limited to initrds that do not interfere with the |
146 | general system state (e.g. by reconfiguring network interfaces, | 150 | general system state (e.g. by reconfiguring network interfaces, |
147 | overwriting mounted devices, trying to start already running demons, | 151 | overwriting mounted devices, trying to start already running demons, |
@@ -154,7 +158,7 @@ We'll describe the loopback device method: | |||
154 | # gzip -9 initrd | 158 | # gzip -9 initrd |
155 | 159 | ||
156 | For experimenting with initrd, you may want to take a rescue floppy and | 160 | For experimenting with initrd, you may want to take a rescue floppy and |
157 | only add a symbolic link from /linuxrc to /bin/sh. Alternatively, you | 161 | only add a symbolic link from /sbin/init to /bin/sh. Alternatively, you |
158 | can try the experimental newlib environment [2] to create a small | 162 | can try the experimental newlib environment [2] to create a small |
159 | initrd. | 163 | initrd. |
160 | 164 | ||
@@ -163,15 +167,14 @@ boot loaders support initrd. Since the boot process is still compatible | |||
163 | with an older mechanism, the following boot command line parameters | 167 | with an older mechanism, the following boot command line parameters |
164 | have to be given: | 168 | have to be given: |
165 | 169 | ||
166 | root=/dev/ram0 init=/linuxrc rw | 170 | root=/dev/ram0 rw |
167 | 171 | ||
168 | (rw is only necessary if writing to the initrd file system.) | 172 | (rw is only necessary if writing to the initrd file system.) |
169 | 173 | ||
170 | With LOADLIN, you simply execute | 174 | With LOADLIN, you simply execute |
171 | 175 | ||
172 | LOADLIN <kernel> initrd=<disk_image> | 176 | LOADLIN <kernel> initrd=<disk_image> |
173 | e.g. LOADLIN C:\LINUX\BZIMAGE initrd=C:\LINUX\INITRD.GZ root=/dev/ram0 | 177 | e.g. LOADLIN C:\LINUX\BZIMAGE initrd=C:\LINUX\INITRD.GZ root=/dev/ram0 rw |
174 | init=/linuxrc rw | ||
175 | 178 | ||
176 | With LILO, you add the option INITRD=<path> to either the global section | 179 | With LILO, you add the option INITRD=<path> to either the global section |
177 | or to the section of the respective kernel in /etc/lilo.conf, and pass | 180 | or to the section of the respective kernel in /etc/lilo.conf, and pass |
@@ -179,7 +182,7 @@ the options using APPEND, e.g. | |||
179 | 182 | ||
180 | image = /bzImage | 183 | image = /bzImage |
181 | initrd = /boot/initrd.gz | 184 | initrd = /boot/initrd.gz |
182 | append = "root=/dev/ram0 init=/linuxrc rw" | 185 | append = "root=/dev/ram0 rw" |
183 | 186 | ||
184 | and run /sbin/lilo | 187 | and run /sbin/lilo |
185 | 188 | ||
@@ -191,7 +194,7 @@ Now you can boot and enjoy using initrd. | |||
191 | Changing the root device | 194 | Changing the root device |
192 | ------------------------ | 195 | ------------------------ |
193 | 196 | ||
194 | When finished with its duties, linuxrc typically changes the root device | 197 | When finished with its duties, init typically changes the root device |
195 | and proceeds with starting the Linux system on the "real" root device. | 198 | and proceeds with starting the Linux system on the "real" root device. |
196 | 199 | ||
197 | The procedure involves the following steps: | 200 | The procedure involves the following steps: |
@@ -217,7 +220,7 @@ must exist before calling pivot_root. Example: | |||
217 | # mkdir initrd | 220 | # mkdir initrd |
218 | # pivot_root . initrd | 221 | # pivot_root . initrd |
219 | 222 | ||
220 | Now, the linuxrc process may still access the old root via its | 223 | Now, the init process may still access the old root via its |
221 | executable, shared libraries, standard input/output/error, and its | 224 | executable, shared libraries, standard input/output/error, and its |
222 | current root directory. All these references are dropped by the | 225 | current root directory. All these references are dropped by the |
223 | following command: | 226 | following command: |
@@ -249,10 +252,6 @@ disk can be freed: | |||
249 | It is also possible to use initrd with an NFS-mounted root, see the | 252 | It is also possible to use initrd with an NFS-mounted root, see the |
250 | pivot_root(8) man page for details. | 253 | pivot_root(8) man page for details. |
251 | 254 | ||
252 | Note: if linuxrc or any program exec'ed from it terminates for some | ||
253 | reason, the old change_root mechanism is invoked (see section "Obsolete | ||
254 | root change mechanism"). | ||
255 | |||
256 | 255 | ||
257 | Usage scenarios | 256 | Usage scenarios |
258 | --------------- | 257 | --------------- |
@@ -264,15 +263,15 @@ as follows: | |||
264 | 1) system boots from floppy or other media with a minimal kernel | 263 | 1) system boots from floppy or other media with a minimal kernel |
265 | (e.g. support for RAM disks, initrd, a.out, and the Ext2 FS) and | 264 | (e.g. support for RAM disks, initrd, a.out, and the Ext2 FS) and |
266 | loads initrd | 265 | loads initrd |
267 | 2) /linuxrc determines what is needed to (1) mount the "real" root FS | 266 | 2) /sbin/init determines what is needed to (1) mount the "real" root FS |
268 | (i.e. device type, device drivers, file system) and (2) the | 267 | (i.e. device type, device drivers, file system) and (2) the |
269 | distribution media (e.g. CD-ROM, network, tape, ...). This can be | 268 | distribution media (e.g. CD-ROM, network, tape, ...). This can be |
270 | done by asking the user, by auto-probing, or by using a hybrid | 269 | done by asking the user, by auto-probing, or by using a hybrid |
271 | approach. | 270 | approach. |
272 | 3) /linuxrc loads the necessary kernel modules | 271 | 3) /sbin/init loads the necessary kernel modules |
273 | 4) /linuxrc creates and populates the root file system (this doesn't | 272 | 4) /sbin/init creates and populates the root file system (this doesn't |
274 | have to be a very usable system yet) | 273 | have to be a very usable system yet) |
275 | 5) /linuxrc invokes pivot_root to change the root file system and | 274 | 5) /sbin/init invokes pivot_root to change the root file system and |
276 | execs - via chroot - a program that continues the installation | 275 | execs - via chroot - a program that continues the installation |
277 | 6) the boot loader is installed | 276 | 6) the boot loader is installed |
278 | 7) the boot loader is configured to load an initrd with the set of | 277 | 7) the boot loader is configured to load an initrd with the set of |
@@ -291,7 +290,7 @@ different hardware configurations in a single administrative domain. In | |||
291 | such cases, it is desirable to generate only a small set of kernels | 290 | such cases, it is desirable to generate only a small set of kernels |
292 | (ideally only one) and to keep the system-specific part of configuration | 291 | (ideally only one) and to keep the system-specific part of configuration |
293 | information as small as possible. In this case, a common initrd could be | 292 | information as small as possible. In this case, a common initrd could be |
294 | generated with all the necessary modules. Then, only /linuxrc or a file | 293 | generated with all the necessary modules. Then, only /sbin/init or a file |
295 | read by it would have to be different. | 294 | read by it would have to be different. |
296 | 295 | ||
297 | A third scenario are more convenient recovery disks, because information | 296 | A third scenario are more convenient recovery disks, because information |
@@ -337,6 +336,25 @@ This old, deprecated mechanism is commonly called "change_root", while | |||
337 | the new, supported mechanism is called "pivot_root". | 336 | the new, supported mechanism is called "pivot_root". |
338 | 337 | ||
339 | 338 | ||
339 | Mixed change_root and pivot_root mechanism | ||
340 | ------------------------------------------ | ||
341 | |||
342 | In case you did not want to use root=/dev/ram0 to trig the pivot_root mechanism, | ||
343 | you may create both /linuxrc and /sbin/init in your initrd image. | ||
344 | |||
345 | /linuxrc would contain only the following: | ||
346 | |||
347 | #! /bin/sh | ||
348 | mount -n -t proc proc /proc | ||
349 | echo 0x0100 >/proc/sys/kernel/real-root-dev | ||
350 | umount -n /proc | ||
351 | |||
352 | Once linuxrc exited, the kernel would mount again your initrd as root, | ||
353 | this time executing /sbin/init. Again, it would be duty of this init | ||
354 | to build the right environment (maybe using the root= device passed on | ||
355 | the cmdline) before the final execution of the real /sbin/init. | ||
356 | |||
357 | |||
340 | Resources | 358 | Resources |
341 | --------- | 359 | --------- |
342 | 360 | ||