How Initramfs Works in the Linux Boot Sequence

The initial RAM file system, or initramfs, is a temporary root file system loaded into memory during the Linux boot process to prepare the system before the real root file system can be mounted. Modern Linux systems rely on diverse and complex storage setups—such as RAID, LVM, network-attached storage, or LUKS encryption—which often require device drivers and user-space utilities that are not built directly into the kernel. This article explains the exact role initramfs plays during the Linux boot sequence, detailing its loading phase, execution flow, and how it hands over control to the permanent operating system.

1. Bootloader Handoff

The boot sequence begins with firmware (BIOS or UEFI), which initializes hardware and launches the bootloader (such as GRUB). The bootloader locates the Linux kernel image (vmlinuz) and the initramfs image (initramfs.img or initrd.img) on the boot partition. It loads both files into physical system memory (RAM) and then transfers execution control directly to the kernel, providing it with the memory coordinates of the loaded initramfs archive.

2. Kernel Initialization and Unpacking

Once the kernel takes control, it sets up core processor functions, virtual memory, and internal data structures. The initramfs is typically a gzipped or zstd-compressed cpio archive. The kernel checks the allocated memory space, extracts this archive, and populates a temporary, memory-backed file system called tmpfs (or rootfs). At this point, the kernel mounts this in-memory file system as its provisional root directory (/).

3. Execution of the /init Script

With the temporary root file system mounted, the kernel executes the first user-space program located at /init. Unlike a fully booted system where PID 1 is a comprehensive init system like systemd, this initial /init process is typically a specialized shell script or a minimal systemd-based environment provided by tools such as Dracut, Mkinitcpio, or Initramfs-tools.

The /init program executes several critical preparation steps:

4. Mounting the Real Root File System

Once the target storage device is accessible and its partition structure is recognized, the /init script reads the kernel command line parameters (such as root=UUID=...) to identify the permanent root device. It then mounts the real root partition to a predefined mount point within the temporary file system, traditionally /sysroot or /newroot.

5. The Root Transition (switch_root)

After successfully mounting the real root file system and verifying its integrity, the initramfs completes its final task:

  1. It cleans up the temporary environment by moving virtual file systems like /dev, /proc, and /sys over to the real root mount point.
  2. It calls the switch_root utility (or equivalent system call).
  3. switch_root deletes all files from the tmpfs to free up system memory, shifts /sysroot to become the new system root directory (/), and replaces the running /init process with the real initialization daemon (typically /sbin/init or /usr/lib/systemd/systemd) as PID 1.

From this transition point onward, the Linux operating system runs entirely off its permanent disk storage, having successfully navigated the initialization phase via the initramfs.