Progress Β· 0/7 phases
π₯Ύ π₯Ύ Phase 3 β Boot Process & Linux Kernel
5 min read Β· Notion
Phase 3 β Boot Process & Linux Kernel
Duration: 4β5 weeks | Level: Intermediate
Understanding boot sequence is the skeleton key to all AOSP internals. Every component you study later fits into this sequence.
π Android Full Boot Sequence
Power ON
β
BootROM (chip-level, vendor code)
β
Bootloader (e.g. U-Boot / LK / UEFI)
β
Linux Kernel
β
init (PID 1) β parses init.rc
β
Zygote (app process incubator)
β
System Server (all Java system services)
β
Activity Manager Service (AMS)
β
Home Launcher (first Activity)Each step is a separate deep area. Learn them from bottom to top.
1οΈβ£ BootROM & Bootloader
BootROM
- Burned into SoC (System-on-Chip) at manufacture time
- Loads the bootloader from flash into SRAM and executes it
- Handles secure boot verification (on modern devices)
Bootloader
- Sets up hardware (RAM, clocks, peripherals)
- Displays the boot logo
- Decides boot mode: normal boot, recovery, fastboot
- Verifies kernel signature (Android Verified Boot / AVB)
- Loads kernel image + initrd into RAM and jumps to kernel entry
Key concepts:
fastbootmode = bootloader-level USB protocol for flashing- Unlocking bootloader disables AVB signature verification
- OEMs implement their own bootloaders (LK, UEFI-based)
2οΈβ£ Linux Kernel
Android runs a modified Linux kernel with Android-specific patches:
| Feature | Description |
|---|---|
| Binder | Android's IPC mechanism (not in mainline Linux) |
| Ashmem | Anonymous shared memory |
| Logger | logcat kernel driver (/dev/log) |
| Wakelocks | Power management β prevents CPU sleep |
| ION allocator | Shared memory between CPU and GPU/camera |
| Low Memory Killer (LMK) | Kills background processes when memory is low |
Kernel Boot Steps
Kernel entry (arch/arm64/kernel/head.S)
β
Start kernel (init/main.c: start_kernel())
β
Mount initial RAM disk (initramfs / initrd)
β
Run /init (userspace begins)Key kernel files to read
kernel/drivers/android/binder.c # Binder IPC driver
kernel/drivers/android/ashmem.c # Shared memory
kernel/drivers/staging/android/ion/ # ION allocator3οΈβ£ init β PID 1
init is the first userspace process. Source: system/core/init/
What init does
- Mounts filesystems (
/proc,/sys,/dev) - Parses
init.rcand device-specific.rcfiles - Starts critical daemons:
ueventd,servicemanager,vold,netd - Starts Zygote
- Monitors services β restarts them on crash
init.rc syntax
# Service definition
service zygote /system/bin/app_process64 -Xzygote /system/bin --zygote --start-system-server
class main
socket zygote stream 660 root system
onrestart write /sys/android_power/request_state wake
onrestart restart media
# Action trigger
on boot
write /proc/sys/kernel/panic_on_oops 1
start zygoteKey files:
system/core/init/main.cppβ entry pointsystem/core/init/init.cppβ rc file parsingsystem/core/rootdir/init.rcβ main rc file
4οΈβ£ Zygote
Zygote is the parent of all Android app processes.
Why Zygote exists
- Starting a JVM process is slow (seconds).
- Zygote pre-loads all Android framework classes and resources once at boot.
- When launching a new app, the OS forks Zygote β a fork is milliseconds.
- The forked process has all framework code already loaded in memory (Copy-on-Write).
Zygote startup
app_process64 starts
β
ZygoteInit.main() (frameworks/base/core/java/com/android/internal/os/ZygoteInit.java)
β
Preload classes (preloaded-classes file ~7000 classes)
Preload resources (drawables, colors)
β
Start SystemServer in a fork
β
Open Zygote socket and wait for fork requestsLaunching an app
AMS sends fork request via Zygote socket
β
Zygote forks itself
β
Child process: ActivityThread.main() runs
β
App's Application.onCreate() β Activity.onCreate()Key file: frameworks/base/core/java/com/android/internal/os/ZygoteInit.java
5οΈβ£ SystemServer
SystemServer runs in a Zygote-forked process and starts all Java system services:
// frameworks/base/services/java/com/android/server/SystemServer.java
private void startBootstrapServices() {
mActivityManagerService = ActivityManagerService.Lifecycle.startService(...);
mPackageManagerService = PackageManagerService.main(...);
// ...
}
private void startCoreServices() { ... }
private void startOtherServices() {
// WindowManagerService, InputManagerService,
// NetworkManagementService, AudioService, etc.
}All system services register themselves with ServiceManager (the IPC registry).
π οΈ Hands-On Tasks
-
Add a log to
ZygoteInit.java, rebuild, and watch it inlogcat -b all:adb logcat -s Zygote -
Read
init.rcand list every service that starts before Zygote. -
Trace the
startActivitycall from app β AMS β Zygote fork β ActivityThread. -
Read
ActivityThread.main()and understand what the main Looper is doing. -
Use
adb shell pson the emulator β identify PID 1 (init), Zygote, and SystemServer.
β Phase 3 Checklist
- Can draw the full boot sequence from power-on to launcher
- Understand BootROM vs Bootloader roles
- Know Android-specific Linux kernel additions (Binder, Wakelocks, LMK)
- Read
system/core/init/main.cpp - Understand
init.rcservice/action syntax - Know why Zygote exists and how forking saves time
- Read
ZygoteInit.javaand understand preloading - Read
SystemServer.javaβ list bootstrap, core, and other services - Run
adb shell psand identify all key processes - Traced
startActivityfrom app process to Zygote fork