GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing docs.kernel.org — Using the initial RAM disk (initrd) — The Linux Kernel documentation Using the initial RAM disk (initrd)¶Written 1996,2000 by Werner Almesberger <werner.almesberger@epfl.ch> and Hans Lermen <lermen@fgan.de> initrd provides the capability to load a RAM disk by the boot loader. This RAM disk can then be mounted as the root file system and programs can be run from it. Afterwards, a new root file system can be mounted from a different device. The previous root (from initrd) is then moved to a directory and can be subsequently unmounted. initrd is mainly designed to allow system startup to occur in two phases, where the kernel comes up with a minimum set of compiled-in drivers, and where additional modules are loaded from initrd. This document gives a brief overview of the use of initrd. A more detailed discussion of the boot process can be found in [1]. Operation¶When using initrd, the system typically boots as follows:
Note that changing the root directory does not involve unmounting it. It is therefore possible to leave processes running on initrd during that procedure. Also note that file systems mounted under initrd continue to be accessible. Boot command-line options¶initrd adds the following new options: initrd=<path> (e.g. LOADLIN) Loads the specified file as the initial RAM disk. When using LILO, you have to specify the RAM disk image file in /etc/lilo.conf, using the INITRD configuration variable. noinitrd initrd data is preserved but it is not converted to a RAM disk and the "normal" root file system is mounted. initrd data can be read from /dev/initrd. Note that the data in initrd can have any structure in this case and doesn't necessarily have to be a file system image. This option is used mainly for debugging. Note: /dev/initrd is read-only and it can only be used once. As soon as the last process has closed it, all data is freed and /dev/initrd can't be opened anymore. root=/dev/ram0 initrd is mounted as root, and the normal boot procedure is followed, with the RAM disk mounted as root. Compressed cpio images¶Recent kernels have support for populating a ramdisk from a compressed cpio archive. On such systems, the creation of a ramdisk image doesn’t need to involve special block devices or loopbacks; you merely create a directory on disk with the desired initrd content, cd to that directory, and run (as an example): find . | cpio --quiet -H newc -o | gzip -9 -n > /boot/imagefile.img Examining the contents of an existing image file is just as simple: mkdir /tmp/imagefile cd /tmp/imagefile gzip -cd /boot/imagefile.img | cpio -imd --quiet Installation¶First, a directory for the initrd file system has to be created on the “normal” root file system, e.g.: # mkdir /initrd The name is not relevant. More details can be found on the pivot_root(2) man page. If the root file system is created during the boot procedure (i.e. if
you’re building an install floppy), the root file system creation
procedure should create the If initrd will not be mounted in some cases, its content is still accessible if the following device has been created: # mknod /dev/initrd b 1 250 # chmod 400 /dev/initrd Second, the kernel has to be compiled with RAM disk support and with support for the initial RAM disk enabled. Also, at least all components needed to execute programs from initrd (e.g. executable format and file system) must be compiled into the kernel. Third, you have to create the RAM disk image. This is done by creating a file system on a block device, copying files to it as needed, and then copying the content of the block device to the initrd file. With recent kernels, at least three types of devices are suitable for that:
We’ll describe the loopback device method:
For experimenting with initrd, you may want to take a rescue floppy and
only add a symbolic link from Finally, you have to boot the kernel and load initrd. Almost all Linux boot loaders support initrd. Since the boot process is still compatible with an older mechanism, the following boot command line parameters have to be given: root=/dev/ram0 rw (rw is only necessary if writing to the initrd file system.) With LOADLIN, you simply execute: LOADLIN <kernel> initrd=<disk_image> e.g.: LOADLIN C:\LINUX\BZIMAGE initrd=C:\LINUX\INITRD.GZ root=/dev/ram0 rw With LILO, you add the option image = /bzImage initrd = /boot/initrd.gz append = "root=/dev/ram0 rw" and run For other boot loaders, please refer to the respective documentation. Now you can boot and enjoy using initrd. Changing the root device¶When finished with its duties, init typically changes the root device and proceeds with starting the Linux system on the “real” root device.
Mounting the new root file system is easy: it just needs to be mounted on a directory under the current root. Example: # mkdir /new-root # mount -o ro /dev/hda1 /new-root The root change is accomplished with the pivot_root system call, which
is also available via the # cd /new-root # mkdir initrd # pivot_root . initrd Now, the init process may still access the old root via its executable, shared libraries, standard input/output/error, and its current root directory. All these references are dropped by the following command: # exec chroot . what-follows <dev/console >dev/console 2>&1 Where what-follows is a program under the new root, e.g. Note: implementation details of pivot_root may change with time. In order to ensure compatibility, the following points should be observed:
Now, the initrd can be unmounted and the memory allocated by the RAM disk can be freed: # umount /initrd # blockdev --flushbufs /dev/ram0 It is also possible to use initrd with an NFS-mounted root, see the pivot_root(8) man page for details. Usage scenarios¶The main motivation for implementing initrd was to allow for modular kernel configuration at system installation. The procedure would work as follows:
The key role of initrd here is to reuse the configuration data during normal system operation without requiring the use of a bloated “generic” kernel or re-compiling or re-linking the kernel. A second scenario is for installations where Linux runs on systems with
different hardware configurations in a single administrative domain. In
such cases, it is desirable to generate only a small set of kernels
(ideally only one) and to keep the system-specific part of configuration
information as small as possible. In this case, a common initrd could be
generated with all the necessary modules. Then, only A third scenario is more convenient recovery disks, because information like the location of the root FS partition doesn’t have to be provided at boot time, but the system loaded from initrd can invoke a user-friendly dialog and it can also perform some sanity checks (or even some form of auto-detection). Last not least, CD-ROM distributors may use it for better installation
from CD, e.g. by using a boot floppy and bootstrapping a bigger RAM disk
via initrd from CD; or by booting via a loader like Obsolete root change mechanism¶The following mechanism was used before the introduction of pivot_root. Current kernels still support it, but you should _not_ rely on its continued availability. It works by mounting the “real” root device (i.e. the one set with rdev
in the kernel image or with root=... at the boot command line) as the
root file system when linuxrc exits. The initrd file system is then
unmounted, or, if it is still busy, moved to a directory In order to use this mechanism, you do not have to specify the boot command options root, init, or rw. (If specified, they will affect the real root file system, not the initrd environment.) If /proc is mounted, the “real” root device can be changed from within linuxrc by writing the number of the new root FS device to the special file /proc/sys/kernel/real-root-dev, e.g.: # echo 0x301 >/proc/sys/kernel/real-root-dev Note that the mechanism is incompatible with NFS and similar file systems. This old, deprecated mechanism is commonly called Mixed change_root and pivot_root mechanism¶In case you did not want to use
#! /bin/sh mount -n -t proc proc /proc echo 0x0100 >/proc/sys/kernel/real-root-dev umount -n /proc Once linuxrc exited, the kernel would mount again your initrd as root,
this time executing Resources¶ |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |