Linux Initrd vs Initramfs: Key Differences

During the Linux boot process, the kernel requires a temporary root filesystem to load essential drivers and prepare the real storage device. Historically, Linux used the Initial RAM Disk (initrd) for this purpose, but modern systems rely almost exclusively on the Initial RAM Filesystem (initramfs). While both provide early userspace capabilities, the Linux operating system manages them fundamentally differently at the architectural, memory management, and execution levels.

Architecture: Block Device vs. Tmpfs

The primary difference between initrd and initramfs lies in how the kernel treats the allocated memory:

Memory Overhead and Caching

The operational structure of initrd introduces significant memory inefficiency:

Execution Flow and Root Transition

The kernel follows different sequences to initialize userspace and switch to the permanent root filesystem:

The initrd Process

  1. The bootloader loads the kernel and the initrd file into memory.
  2. The kernel creates a RAM disk device (/dev/ram0) and mounts it as the temporary root.
  3. The kernel executes /linuxrc in userspace.
  4. Once /linuxrc loads storage and bus drivers, it mounts the real root filesystem.
  5. The kernel calls pivot_root to make the real filesystem the new root, unmounts the temporary root, and launches /sbin/init.
  6. Reclaiming the memory used by /dev/ram0 requires tearing down the block device, which can leave lingering artifacts if not handled precisely.

The initramfs Process

  1. The bootloader loads the initramfs archive into memory (or the archive is built directly into the kernel binary).
  2. The kernel initializes an instance of rootfs (an internal tmpfs) and unpacks the cpio archive directly into it.
  3. The kernel executes /init as PID 1.
  4. Once /init prepares the system and mounts the real root device, it uses utility commands like switch_root or run-init.
  5. switch_root deletes all files within the tmpfs to immediately free the memory, moves the mounted real root filesystem to /, and executes the real /sbin/init.

Kernel Integration

An initrd must always be prepared as a standalone disk image and loaded separately by bootloaders like GRUB. In contrast, initramfs allows deep integration: a cpio archive can be embedded directly into the kernel binary (vmlinux) during compilation. This makes initramfs suitable for embedded devices and specialized environments where a single self-contained kernel binary is required without relying on external image loading.