initramfs Explained

Before the kernel can mount your real filesystem and start systemd, it faces a classic chicken-and-egg problem. initramfs is the solution — a tiny temporary filesystem loaded into RAM that gives the kernel what it needs to find and mount the real root.

The Chicken-and-Egg Problem

What problem does initramfs solve? To mount your root filesystem on an LVM volume on a LUKS-encrypted NVMe drive, the kernel needs NVMe driver, LVM tools, and LUKS decryption code. But those tools live on the root filesystem it's trying to mount. initramfs breaks this deadlock.

What initramfs Actually Is

initramfs is a cpio archive (compressed with gzip/zstd) that the kernel extracts into a tmpfs at boot. GRUB loads both the kernel and initramfs into RAM.

$ ls -lh /boot/initrd.img-$(uname -r) -rw-r--r-- 1 root root 79M initrd.img-6.2.0 # Inspect contents mkdir /tmp/initrd-inspect && cd /tmp/initrd-inspect zcat /boot/initrd.img-$(uname -r) | cpio -idmv 2>/dev/null | head -20 # Inside you'll find a minimal Linux userspace: # bin/ sbin/ lib/ lib64/ etc/ scripts/ usr/

What's Inside initramfs

  • Kernel modules: Storage drivers (nvme, ahci), filesystem drivers (ext4, btrfs), encryption (dm-crypt)
  • busybox: Minimal Unix utilities (ls, mount, sh)
  • udev: Device manager — creates /dev entries for disks
  • /init script: The first program that runs — orchestrates the whole early boot
  • LVM/LUKS tools: lvm, cryptsetup (if your root needs them)

What Happens Inside initramfs

1. Kernel mounts initramfs as / (root) in tmpfs 2. Kernel runs /init (the initramfs init script) 3. /init loads storage drivers (modprobe nvme) 4. udev creates /dev/nvme0n1, /dev/sda, etc. 5. /init finds root device (from root= kernel param) - If LUKS: prompt for passphrase, decrypt - If LVM: activate volume group 6. /init mounts real root at /mnt/real-root (or /sysroot) 7. pivot_root /mnt/real-root /mnt/real-root/old-root (or switch_root) — switch / to real filesystem 8. systemd (the real PID 1) takes over

Rebuilding initramfs

You need to rebuild initramfs after: adding storage drivers, changing encryption setup, or installing a new kernel.

# Debian/Ubuntu sudo update-initramfs -u -k $(uname -r) # Fedora/RHEL (uses dracut) sudo dracut --force # Arch Linux (uses mkinitcpio) sudo mkinitcpio -P

Frequently Asked Questions

What will I learn here?

This page covers the core concepts and techniques you need to understand the topic and progress confidently to the next lesson.

How should I use this page?

Start with the overview, then follow the section links to deepen your understanding. Use the table of contents on the right to jump to specific sections.

What should I read next?

Use the navigation below to continue to the next lesson or explore related topics.