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

repack-bootimg.pl and mkbootimg should be in same directory.

 

5. Replace the boot.img with new boot image
 

 

 

Resource

http://droidcore.blogspot.com/2012/12/how-to-edit-initrc-in-android.html

http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack%2C_Edit%2C_and_Re-Pack_Boot_Images#Background

https://forum.xda-developers.com/showthread.php?t=1739119

 

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/unpack-bootimg.pl 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.
    ~/prac/android$

Leave a Reply

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