Editing system.img inside super.img and flashing our modifications



Hello and welcome to my first post.
today I will talk about editing super.img and modifying system.img inside of it.
In android 10 and bigger, sometimes there is no system.img in ROM it because google starting use Dynamic Partitions for more flexible images size – more details here

instead of system.img we will see super.img that include few partition inside.

So In this case, in order to do our modifications in the rom we should unpack the super.img and after that to unpack the system.img and then build it again.

1) I will use ubuntu in vbox so you need a linux machine.
2) some super.img for editing.

1) unpacking super.img
2) resizing system.img in order to insert our MODS to the rom
3) mounting system.img
4) do our modifications
5) umounting system
6) shrink edited system.img to the minimal size
7) generating new super.img
8) flashing it to our device

Let’s Start!
1) unpacking super image:
First of all the super.img file might be in sparse format so we need to make it raw image
open termianl in super.img directory and type:

simg2img super.img super.ext4.img

now we got new file named super.ext4.img: we are working with this file.

There are multiple ways to unpack super.img:
for example: using imjtool or using lpunpack
If you use imjtool follow this

I will use lpunpck tool (Official tool from google)

locate lpunpack and super.ext4.img and open terminal in this folder.
Then type:

./lpunpack super.ext4.img

wait for it it may take couple of minutes.
now our folder looks like this:


2)resizing system.img in order to make enough space for modifications
turn back into your terminal and type:

fallocate -l 2G system.img

This command allocates more space for system.img (Changing to 2GB)
After that type:

resize2fs system.img 2G

This command increases the file system size of the partition to 2G

3) mounting system.img
Create new folder and mount:

mkdir system
sudo mount -t ext4 -o loop system.img system

Now system dir contains all system.img files.
4)edit it as you want
In order to make changes you should use superuser:
when you typing a command while you modifying use sudo prefix.
you can use the file explorer with superuser permissions by typing:

sudo nautilus

5) umount system
*)make sure the terminal is not in system directory or some sub dir of it


sudo umount system
e2fsck -yf system.img

(fixes file system errors)
6) shrink the edit system.img into the minimum possible size

resize2fs -M system.img

fix the file system again:

e2fsck -yf system.img

7) generating new super.img
as you can see at the image above, in my case the super.ext4.img contaings 3 partitions:
1)system.img(that we worked with)

in you case it may be different so follow the logic of the following command and not copy paste it.

another tool from google that called lpmake using for packing super.img.
How this tool works

so let’s start with generating:
this is the documentation of the tool: link
at first we should get each partitions file size
we can do it by:

stat -c '%n %s' system.img

do it for all partitions files

And this is tricky and critical step:
***DO NOT COPY!!***

./lpmake --metadata-size 65536 --super-name super --metadata-slots 1 --device super:4294967296 --group main:3139354624 --partition system:readonly:1434726400:main --image system=./system.img --partition vendor:readonly:330866688:main --image vendor=./vendor.img --partition product:readonly:1373761536:main --image product=./product.img --sparse --output ./super.new.img

1) –metadata-size: The maximum size that partition metadata may consume. A partition entry uses 64 bytes and an extent entry uses 16 bytes. I think 65536 should work in most cases.

2) –metadata-slots – The number of slots available for storing metadata. This should match the number of update slots on the device, 2 for A/B devices and 1 for non-A/B.

3)–device super: The size of the “super” partition on the device. It must match exactly, and it must be evenly divisible by the sector size (512 bytes).

4) –group main:4293513600: sum of all partitions files sizes

5) –partition system:readonly:1577095168:main –image system=./system.img : Every parition file size with permissions(readonly) and input img file

good work we got new custom rom!


credit to(for repacking step):
XDA Post: https://forum.xda-developers.com/showpost.php?p=82241115&postcount=70

8) flashing the new rom to a physical device
First of all we should unlock the boot loader without unlocking we may brick the phone


It can be done by allowing oem unlock in developers options and rebooting into bootloader and type:

fastboot flashing unlock

But it may not work – it depends on your device so check in google.
After you unlocked the bootloader flash the new rom by:

fastboot flash super super.new.img

If your devices alert for unlocked bootloader(orange state)
you can remove this annoying alert
just search on google.
if you have mediatek check this link: