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).
- Loading Kernel Modules: First Stage
initscans the vendor ramdisk for.kofiles (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. - Mounting the Partitions: It reads the
fstab(File System Table) provided by the vendor. It physically mounts the/system,/vendor, and/productpartitions as read-only. - SELinux Setup: It loads the compiled SELinux policy rules from the newly mounted
/systemand/vendorpartitions 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
/systempartition, making/systemthe 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:"