Search code examples
androidbootinitrd

What is contained in Android's init on initrd.img?


I unpacked the initrd.img with cat initrd.img | gunzip | cpio -vid and then there's an executable called init which I think is the first thing the kernel runs. However, what does it do? Is there an example of one that I can look on google AOSP source so I have an idea? This one is likely modified by Xiaomi


Solution

  • Here's a brief explanation of android bootup and init

    • On android bootup , the bootloader locates and loads the linux kernel. The linux kernel boots into the userspace from the kernelspace using the initramfs functionality in the kernel.
    • The ramdisk is essentially a disk image that contains everything associated with the root filesystem of the device, essentially the '/ ' directory. The initramfs mounts the ramdisk into memory ( a temporary filesystem ) .
    • Later, initramfs looks into the memory and loads and executes the init binary. The ramdisk.img has C files which configure what init does .
    • Init is the first process executed in the userspace which is responsible for getting the core userspace functionality up and running.
    • initrc files , the ones responsible for configuring what init actually does have set of instructions with scripts which run on certain event triggers ( such as on init, on fs, on boot).
    • init keeps on running and monitors the system for certain changes in the properties (triggers). Instructions associated with these triggers are executed upon change in the properties. (Such as USB Debugging on/off)
    • Additionally, init executes native processes called services which are essentially daemons such as installd, logd, ueventd etc. init also restarts services that may exit/killed. Daemon processes have limited ability to communicate to each other and use local sockets to read and write data from.

    To read further you can refer here and this youtube video