Here you are going to find a simple guide how to unpack and modify the original system.img file that you can flash it using a Custom Recovery. The original system.img file, like the Google factory images for example, represents a sparsed ext4 loop mounted file system.
It is mounted into the /system of your Android device. But not all file system images are ext4. You may have a system image that can be a yaffs2 for example.
Note: This tutorial is only for ext4 file system, so don’t try to extract other file systems.
Here is the way how it is mounted in 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.