Free — no signup required

Stage 4: The Initramfs Trick

2 min read

Solving the Chicken-and-Egg Problem

Here is the dilemma: the kernel needs to mount your root filesystem (which might be on an NVMe SSD, a software RAID array, an encrypted LVM volume, or a network share). To do that, it needs the right device driver. But those drivers are stored as modules (.ko files) on the root filesystem — the very filesystem it cannot yet access.

This is a genuine circular dependency. The solution is elegant: the initramfs.

What is initramfs?

initramfs (Initial RAM Filesystem) is a compressed cpio archive that GRUB loads into RAM alongside the kernel. The kernel mounts this archive as a temporary root filesystem entirely in memory — no disk access required. It contains:

  • A minimal set of device drivers (storage controllers, filesystem drivers, crypto modules for LUKS encryption, etc.)
  • Essential tools: mount, lvm, mdadm, cryptsetup
  • An init script (usually /init) that orchestrates the pivot

The Pivot Process

The initramfs /init script runs and performs the following:

  1. Loads the necessary kernel modules to access the real storage device.
  2. Assembles any software RAID arrays (mdadm --assemble).
  3. Activates LVM volume groups (lvm vgchange -ay).
  4. Decrypts LUKS-encrypted volumes if needed (prompting for a passphrase).
  5. Mounts the real root filesystem at a temporary mount point.
  6. Calls switch_root (or pivot_root) to replace the in-memory initramfs with the real root filesystem.
  7. Executes /sbin/init on the real filesystem — handing control to PID 1.

The initramfs (found at /boot/initrd.img-<kernel-version>) is a compressed cpio archive that can be extracted and browsed, revealing a small filesystem tree — bin, lib, sbin, scripts, and so on. The init file at the root is the script that runs first. The lib/modules/ directory contains the kernel modules bundled into the initramfs.

When initramfs Goes Wrong

If the initramfs cannot find or mount the real root filesystem, you will see a message to the effect of "Gave up waiting for root file system device," followed by an alert that the expected UUID does not exist and "Dropping to a shell!" This drops you into a minimal busybox shell inside the initramfs environment. Common causes: a missing storage driver, a corrupted filesystem, a wrong UUID in GRUB's kernel parameters, or a failed RAID/LVM assembly.

This is one of 18 chapters

Every chapter is free — Kubernetes, Terraform, SRE, distributed systems, and more — with fast daily review built in.

Sign up free