Translation(s): none


What is an initramfs

The initramfs is a temporary filesystem image used to help the Linux Kernel mount the root filesystem and run the main Init system.

The kernel has 3 ways to find and mount the root filesystem:

  1. all required device and filesystem drivers can be compiled into the kernel, The kernel uses the root= kernel command line option and if present, the init= option is used to find the system's main Init system.

  2. some device and filesystem drivers can be built as modules and stored in an Initrd. The initrd must contain a binary /linuxrc which loads the driver modules. It is also possible to mount the final root filesystem via linuxrc and use the pivot_root syscall.

  3. An initramfs can be used to run tasks from userspace. The work previously done by the kernel is instead done by an /init stored in the initramfs. This binary is responsible for doing all the things the kernel would have done. The initramfs must be a cpio archive.

See https://www.kernel.org/doc/html/latest/filesystems/ramfs-rootfs-initramfs.html for more information.

By default, Debian uses an initramfs created and managed by the initramfs-tools package.

Why use initramfs

Using an initramfs allows:

Configuring the initramfs with initramfs-tools

The initramfs-tools package is configured through the files in /etc/initramfs-tools/. You can edit /etc/initramfs-tools/initramfs.conf but it is better to putting files into /etc/initramfs-tools/conf.d/. See the man-page initramfs.conf(5) for details.

For example, you can change modules to be included in the initramfs by the driver policy by setting MODULES=dep in a file named /etc/initramfs-tools/conf.d/driver-policy: this will cause the system to include only the drivers the system thinks it needs, instead of most available modules: beware that if a needed driver isn't included in the initramfs your system will fail to boot.

If you wish to add an executable file or libraries to an initramfs image, you need to write an initramfs hook and place it under the directory /etc/initramfs-tools/hooks/, take a look at initramfs-tools(7) man-page for a comprehensive tutorial. Since these hooks are POSIX shell script, don't forget to make it executable.

Features available in an initramfs

The initramfs includes:

How to inspect initramfs

The initramfs-tools-core package provides lsinitramfs to list files inside the initramfs and unmkinitramfs to extract files from the initramfs.

Alternatively, you can do the following (assuming path/to/initrd already exists as empty working directory):

The microcode cpio archive size can be independently checked by cpio -t </initrd.img >/dev/null

(This manual method somehow worked for me at one point. But this is not reliable. /usr/bin/lsinitramfs has a comment "cpio won't tell us the true size".)

Please note Debian currently use gzip as the compression method and the above method assumes so. Ubuntu seems to start using LZ4 as of March 2018. initramfs-tools in Debian supports LZ4 since Debian buster (893845).

Using CPU microcode data

This basic initramfs image may be prepended with an uncompressed cpio archive holding microcode data to be loaded very early in the boot process.

At boot time, the kernel performs the followings:

See also

See:


CategoryKernel | CategoryBootProcess