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:
- initrd (Block Device): An
initrdimage is a filesystem image (typically ext2) wrapped inside a simulated block device (/dev/ramX). Because it acts as a block device, the Linux kernel must include a built-in filesystem driver just to read the image before it can load any modular drivers. - initramfs (Archive in Tmpfs): An
initramfsis acpioarchive (usually compressed with gzip, xz, or zstd) unpacked directly into an instance oftmpfs, the kernel's native in-memory filesystem. Becausetmpfsinteracts directly with the VFS (Virtual File System) page cache, no intermediate block device or filesystem driver is required to mount it.
Memory Overhead and Caching
The operational structure of initrd introduces
significant memory inefficiency:
- Double Caching in initrd: When using
initrd, the kernel creates a RAM disk block device and reads data into the page cache. Because the contents are treated as a block device containing a filesystem, the files extracted inside it are cached a second time. This causes the same data to occupy double the physical memory. Furthermore, the size of a RAM disk is fixed at creation time, meaning unused space allocated to/dev/ram0is wasted. - Dynamic Sizing in initramfs:
tmpfsscales dynamically based precisely on the size of the files stored within it. There is no block layer overhead and zero duplicate caching, as the kernel reads directly from the page cache.
Execution Flow and Root Transition
The kernel follows different sequences to initialize userspace and switch to the permanent root filesystem:
The initrd Process
- The bootloader loads the kernel and the
initrdfile into memory. - The kernel creates a RAM disk device (
/dev/ram0) and mounts it as the temporary root. - The kernel executes
/linuxrcin userspace. - Once
/linuxrcloads storage and bus drivers, it mounts the real root filesystem. - The kernel calls
pivot_rootto make the real filesystem the new root, unmounts the temporary root, and launches/sbin/init. - Reclaiming the memory used by
/dev/ram0requires tearing down the block device, which can leave lingering artifacts if not handled precisely.
The initramfs Process
- The bootloader loads the
initramfsarchive into memory (or the archive is built directly into the kernel binary). - The kernel initializes an instance of
rootfs(an internaltmpfs) and unpacks thecpioarchive directly into it. - The kernel executes
/initas PID 1. - Once
/initprepares the system and mounts the real root device, it uses utility commands likeswitch_rootorrun-init. switch_rootdeletes all files within thetmpfsto 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.