How To Unpack & Repack ext4 Android System Images

To unpack and modify the original system.img file it’s not so complicated and in this post, we will walk you through a step by step guide how to do it. The original system.img file, like the Google factory image represents a sparsed ext4 loop mounted the file system.

It is mounted on the /system of your Android device. Not all the system images are an ext4 file. It might be for example a system file yaffs2. This is completely another thing so:

This method will work only on ext4 file systems. Do not try to extract any other file system.

Below is a way how a system image file is mounted on a Nexus device:

  • /dev/block/platform/omap/omap_hsmmc.0/by-name/system /system ext4 ro,realtime,barrier=1,data=ordered 0 0″


  • Linux box or virtual machine
  • simg2img, make_ext4fs binaries which can be downloaded from here.


Place the system.img and the 2 binaries in one directory and make sure that binaries have exec permission.

Step 1: Mount the file system.

  • mkdir sys
  • 2. ./simg2img system.img sys.raw
  • 3. sudo mount -t ext4 -o loop sys.raw sys/

Then you will have all your system partition mounted in ‘sys’ and you can modify whatever you want in ‘sys’. You can deodex apk and frameworks jars for example.

Step 2: Create a new flashable system image.

  • sudo ./make_ext4fs -s -l 512M -a system new.img sys/
  • sudo umount sys
  • rm -fr sys

Now simply you have to type ‘fastboot flash system new.img’

Note: You have to use the correct size for your new system image. Use tune2fs -l sys.raw and ‘Block count’, ‘Block size’ for making ext4fs -s parameters. you also can use ;cat/proc/partitions/ andyour device will find out the correct size.

If you have a Samsung Galaxy device and it doesn’t support fastboot, you can use heimdall instead.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: