AOSP Foundations
2 min read

The Vendor Ramdisk

Understand how the vendor ramdisk handles the highly specialized early-boot tasks before handing control to the generic framework.

As established in the Partition Architecture module, the modern Android boot sequence merges the generic init_boot ramdisk with the hardware-specific vendor_boot ramdisk.

This merged ramdisk allows the initial boot sequence to remain strictly modular while still providing the generic init process with the proprietary tools it needs to mount the physical storage.

First Stage init

When the Linux kernel executes /init from the merged ramdisk, it is running the "First Stage" init.

This stage is incredibly minimal. Its entire purpose is to set up the necessary environment to mount the actual, physical partitions (like /system and /vendor).

  1. Loading Kernel Modules: First Stage init scans the vendor ramdisk for .ko files (Loadable Kernel Modules). It immediately loads the proprietary UFS/eMMC storage drivers into the kernel so the system can actually see the physical flash memory.
  2. Mounting the Partitions: It reads the fstab (File System Table) provided by the vendor. It physically mounts the /system, /vendor, and /product partitions as read-only.
  3. SELinux Setup: It loads the compiled SELinux policy rules from the newly mounted /system and /vendor partitions into the kernel, rigorously enforcing mandatory access control from the very start.
// Simplified C++ snippet of First Stage init (system/core/init/first_stage_init.cpp)
int main(int argc, char** argv) {
    DoFirstStageMount();
    SetInitEnv();
    LoadSelinuxPolicy();
    // Proceed to pivot root...
}

The Pivot Root

Once the First Stage init has successfully mounted the massive, physical /system partition, the tiny memory-based ramdisk is no longer needed as the root of the file system.

The init process executes a crucial Linux system call called pivot_root (or chroot on older systems).

  • This command instantly swaps the temporary ramdisk with the massive /system partition, making /system the new permanent root (/) of the file system.
  • The old ramdisk is unmounted, and its memory is returned to the system pool to save RAM.

Transition to Second Stage

With the physical partitions mounted and the root filesystem pivoted, the original init binary executes the real, full-featured /system/bin/init binary located on the physical flash storage. This transition marks the end of the early-boot ramdisk phase and the beginning of the Second Stage init.

# Developers can inspect the early boot logs to see the pivot root transition
adb shell dmesg | grep "init:"