Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 777 of 93611. Introduction to Embedded LinuxFree lesson

Mounting the Initial RAM Filesystem

Understand the purpose of the initramfs in providing early user-space support required to mount the final root filesystem.

In this lesson, you’ll learn how the initramfs acts as a crucial bridge between the kernel boot-up and the mounting of the final, persistent root filesystem.

The "Chicken and Egg" Problem

When your Linux kernel finishes initializing, it needs to mount the root filesystem (rootfs) to execute /sbin/init and start user-space applications. However, the storage device containing this rootfs (like an eMMC, NVMe, or network drive) often requires complex drivers, file system modules, or even network stacks to be initialized.

The kernel cannot load these drivers from the very filesystem it is trying to mount. This is the "chicken and egg" problem: you need the filesystem to get the drivers, but you need the drivers to mount the filesystem.

Enter the initramfs

The initramfs (Initial RAM Filesystem) is a compressed archive containing a minimal set of binaries, scripts, and kernel modules. During the boot sequence, the bootloader loads both the kernel image and this archive into RAM. The kernel then mounts this archive as a temporary root filesystem.

Because this happens entirely in memory, no hardware drivers are required for the "disk" access. Once the kernel is running, it executes a script (usually called init) inside the initramfs. This script can:

  1. Load necessary kernel modules (e.g., ext4.ko, nvme.ko).
  2. Perform cryptographic checks or decrypt partitions.
  3. Prepare the hardware environment.

Once the environment is ready, the initramfs script performs a switch_root or pivot_root operation, transitioning control to the real root filesystem located on your primary storage.

# Example logic inside an init script
insmod /lib/modules/mmc_core.ko
insmod /lib/modules/ext4.ko
mount /dev/mmcblk0p2 /mnt/root
exec switch_root /mnt/root /sbin/init

By offloading the "heavy lifting" of initialization to a temporary user-space environment, the kernel remains small and modular, ensuring your embedded device can handle diverse storage architectures without baking every possible driver into the static kernel image.

Key Takeaway: The initramfs provides a flexible, temporary user-space environment that enables the kernel to load the drivers necessary to mount the permanent system storage.