How to modify the boot.img in Android

22Jan - by qkim0x01 - 1 - In /Android

Modifying init.rc can be tricky because init.rc is read only once at system boot up, and it’s restored from the recovery image when rebooted.

Therefore, to modify init.rc, you need to modify the recovery image.

I’m writing this post based on Nexus7, but editing init.rc should be similar with other Android devices.

Steps to edit init.rc
  1. Download boot.img from Android device
  2. Unpack the boot.img
  3. Edit init.rc
  4. Repack the boot.img
  5. Replace the boot.img with new boot image


  1. Download boot.img from Android device

First go into Android shell using

, and check out the partitions using this command

For my device, the command prints out


From the above list of partitions, we need to find out which one is boot partition

In order to find boot partition, run

And the command will give the name of each partition like shown below

LNX -> boot.img

From the output above, we know LNX -> /dev/block/mmcblk0p2 is the boot.img

Using fdisk -l /dev/block/mmcblk0p2 to get more information


Copy the image from boot partitions to /data/local/tmp/ directory using this command


Now we need to bring the boot.img from android device to our computer using

This command will copy boot.img to your current directory executing the command


2. Unpack the boot.img

The boot and recover images are not proper filesystems, so we are going to need to unpack the boot image to see the contents in there.

We can extract the image using a script, which you can download from here : Extract-Tool

Will extract files such as


3. Edit init.rc

init.rc and other files are in boot.img-ramdisk/ directory, so you can change the bootimage as you want.


4. Repack the boot.img

Run this command to repack boot image and mkbootimg should be in same directory.


5. Replace the boot.img with new boot image





One thought on “How to modify the boot.img in Android”

  1. While unpacking, hit with following error
    ~/prac/android$ ~/github-repos/android/boot-image-extract/ boot.img
    Found a secondary file after the ramdisk image. According to the spec (mkbootimg.h) this file can exist, but this script is not designed to deal with this scenario.

Leave a Reply

Your email address will not be published. Required fields are marked *