A temporary initial root filesystem can be used in the boot process of a Linux kernel. It is typically mounted in primary storage and used to make necessary preparations before the normal root filesystem can be mounted.

Mechanisms for providing an initial root filesystem include:


An initial root filesystem facilitates modular kernel configuration during startup.

Rationale

During system startup, the Unix kernel (e.g. Linux) is loaded into memory, and it remains resident throughout the operation of the system.

To minimise the amount of code loaded into memory, for maximum modularity, and sometimes to provide a single generic kernel image, the Linux kernel can be compiled omitting code that is necessary to load the operating system, since it is not possible to statically compile all the code into the kernel without making it too large to start on computers with limited memory or from lower-capacity media. Some of this code is located in modules known as kernel modules; the rest is userspace applications. This raises the problem of detecting and loading the necessary modules to mount the normal root filesystem.

Another situation raising similar problems is hibernation, which suspends the computer to disk by dumping an image of the entire system and then powering off. On next boot, this image has to be accessible before it can be loaded back into memory.

To detect and load necessary modules for the normal root filesystem, an initial root filesystem is used. This filesystem contains utilities that perform the hardware detection, module loading and device discovery necessary to mount the normal root filesystem.

initrd

The initial ramdisk, or initrd is a file containing an initial root filesystem.

Device node /dev/initrd references a read-only block device. The device is a RAM drive initialised by the bootloader before the kernel is started. The kernel can then use device /dev/initrd in the first phase of a two-phased system startup.

  1. In the first startup phase, the kernel mounts an initial root filesystem from the contents of /dev/initrd.

  2. In the second phase, additional drivers and/or other modules are loaded from the initial root filesystem. After loading the drivers and modules, a new root filesystem (the normal root filesystem) is mounted from a different device.

The following bootloader options when used with initrd, affect the kernel's boot-up operation:

initrd=filename 

This option specifies the file to load as the contents of /dev/initrd. The file name specified with this option will typically be a gzipped filesystem image.

noinitrd 

This bootloader option disables the two phase boot-up operation. The kernel performs the usual boot sequence as if /dev/initrd was not initialised. With this option, any contents of /dev/initrd loaded into memory by the bootloader contents are preserved. This option permits the contents of /dev/initrd to be any data and need not be limited to a filesystem image. However, device /dev/initrd is read-only and can be read only one time after system startup.

root=device-name 

This option specifies the device to be used as the normal root filesystem. The device specified by this option must be a mountable device having a suitable root filesystem.

linuxrc

linuxrc (linux run command) is the first process executed after initrd is mounted.

This makes it possible to boot a small modularised kernel and to load the drivers that are really needed as modules. linuxrc assists in loading relevant drivers manually.

linuxrc has numerous potential uses, including the following:

Once the initial root filesystem is mounted, if executable file /linuxrc is present, the kernel executes it as its first process. When /linuxrc exits, the kernel assumes that it has mounted the real root filesystem and executes /sbin/init to begin the normal boot process.

The file /linuxrc can be any valid executable, including an executable program, symbolic link or shell script.

initramfs

initramfs was introduced in Linux kernel 2.6.13.

A RAM-based filesystem known as tmpfs or shmfs is a standard component of the kernel. This system is in many ways much more flexible and efficient than the original fixed-size ramdisk: it does not require formatting, and uses as little or as much memory as is required to hold the data. Another similar system, ramfs, is available, and users may choose which particular dynamic RAM filesystem to use.

Along with the code for tmpfs, which is used in the kernel of nearly all Linux configurations, the only requirement to make a suitable virtual drive for booting to is the ability to decompress an archive of files. Files are compressed using the cpio archive format and the decompressed files are stored to a tmpfs-like filesystem. This system is known as initramfs.

Implementation

The kernel image and an image of the initial root filesystem must be stored somewhere accessible by the boot firmware of the computer or the bootloader. This is usually one of the following:

The bootloader loads the kernel and initial root filesystem image into memory and then starts the kernel, passing in the memory address of the image. At the end of its boot sequence, the kernel tries to determine the format of the image from its first few blocks of data:

The normal root filesystem cannot simply be mounted over /, since that would make the scripts and tools on the initial root filesystem inaccessible for any final cleanup tasks:

Most initial root filesystems implement /linuxrc or /init as a shell script and thus include a minimal shell along with some essential utilities.


example initrd: initial ramdisk
home Home Page