• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

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

Search This thread

Brepro1

Member
Oct 22, 2018
13
10
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.

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

steps:
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:
Code:
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
Open terminal in imjtool path and super.img path and type
Code:
./imjtool.ELF64 super.img extract
if you got and error run it as superuser by
Code:
sudo ./imjtool.ELF64 super.img extract
I will use lpunpck tool (Official tool from google)

locate lpunpack and super.ext4.img and open terminal in this folder.
Then type:
Code:
./lpunpack super.ext4.img
wait for it it may take couple of minutes.
now our folder looks like this:

kIY7JpC.png


2)resizing system.img in order to make enough space for modifications
turn back into your terminal and type:
Code:
fallocate -l 2G system.img
This command allocates more space for system.img (Changing to 2GB)
After that type:
Code:
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:
Code:
mkdir system
Code:
sudo mount -t ext4 -o loop system.img system
Now system dir contains all system.img files.
4)edit it as you want
***IMPORTANT***
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:
Code:
sudo nautilus
5) umount system
*)make sure the terminal is not in system directory or some sub dir of it
if Yes just type
Code:
cd ..
to go up in the directories tree (do it many times until you will be in the same directory like the image in the top)

type:
Code:
sudo umount system
Code:
e2fsck -yf system.img
(fixes file system errors)
6) shrink the edit system.img into the minimum possible size
by:
Code:
resize2fs -M system.img
fix the file system again:
Code:
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)
2)vendor.img
3)product.img

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
it creates empty super.img with all headers stuff and pushing partitions into it


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:
Code:
stat -c '%n %s' system.img
do it for all partitions files

And this is tricky and critical step:
***DO NOT COPY!!***
Code:
./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

explanation:
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!:):eek:

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:
Code:
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:
Code:
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:
https://forum.hovatek.com/thread-31664.html
 

saga1900

New member
Jan 6, 2021
4
0
I'm trying to modify my system.img (/system/build.prop) to include support for multi users. After struggling a lot, I've succeeded following your guide (that's an awesome work btw) to unpack, mount, modify, umount and repack super.img. Then, after flashing the new super.img, nothing changes on the phone. I've tried adding and removing files to the system.img before reflashing, and after flashing, i've verified using adb shell. It seem that the image flashed do not contains my modifications. In other words, I succeed to repack a modified super.img, but flashing the new super.img do not modify the phone itself. Any clues? Can you help me?

Phone is Umidigi A7 Pro 64GB
 
  • Sad
Reactions: firky

Brepro1

Member
Oct 22, 2018
13
10
I'm trying to modify my system.img (/system/build.prop) to include support for multi users. After struggling a lot, I've succeeded following your guide (that's an awesome work btw) to unpack, mount, modify, umount and repack super.img. Then, after flashing the new super.img, nothing changes on the phone. I've tried adding and removing files to the system.img before reflashing, and after flashing, i've verified using adb shell. It seem that the image flashed do not contains my modifications. In other words, I succeed to repack a modified super.img, but flashing the new super.img do not modify the phone itself. Any clues? Can you help me?

Phone is Umidigi A7 Pro 64GB
Hey dear thank you for the compliment, please tell me more about how did you flash the new image.
hey dear did you flash it by using sp flash tool? did you unlocked the bootloader? did you see orange state warning when the device booted after flashing?
 

saga1900

New member
Jan 6, 2021
4
0
Hey dear thank you for the compliment, please tell me more about how did you flash the new image.
hey dear did you flash it by using sp flash tool? did you unlocked the bootloader? did you see orange state warning when the device booted after flashing?

Hi, thx for your reply!

I've unlocked the bootloader as you oriented, and after that, I'm seeing the orange warning!I tried flashing using two methods. Using SP Flash Tool, and using flashboot.

Using SP Flash Tool was straight forward. Just selected the Scatter File, then picked the new super.img. Successfully flashed, but no changes on the phone.

Using flashboot: ./flashboot flash super super.modified.img


What a did, in short, was:

1.) simg2img super.img super.raw
2.) imjtool super.raw extract (also tried using lpunpack as you oriented)
3.) mount -t ext4 -o loop system.img /mount/point
4.) edit everything needed
5.) umount /mount/point
6.) repacked super.img using lpmake
7.) flashed the new super.img using SPFT or flashboot. Boths succeeds, but none really modifies the phone

To double check that the new super.img is correct, I've extracted it again, and double checked my changes. and they are there.
 

NguyenNhutNam

New member
Jan 20, 2021
2
0
i cant mounr system.img . Cant you help me
#sudo mount -t ext4 -o loop system.img system
mount: /home/nam/system: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error
 

dewettie

Senior Member
Sep 15, 2013
62
23
Anyone can help how to repack an unpacked super.img?
Try to delete an app in the product and system.img and post the instructions to repack everything into a super.img again.
My goal is to remove most of the preinstalled Google apps.

Here is the firmware link

How do you get this size, from the scatter file super partition size?
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).

After repacking I also get this error, is it normal?
'Invalid sparse file format at header magic'
 

EfrenKilller

New member
Feb 16, 2021
1
0
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.

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

steps:
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:
Code:
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
Open terminal in imjtool path and super.img path and type
Code:
./imjtool.ELF64 super.img extract
if you got and error run it as superuser by
Code:
sudo ./imjtool.ELF64 super.img extract
I will use lpunpck tool (Official tool from google)

locate lpunpack and super.ext4.img and open terminal in this folder.
Then type:
Code:
./lpunpack super.ext4.img
wait for it it may take couple of minutes.
now our folder looks like this:

kIY7JpC.png


2)resizing system.img in order to make enough space for modifications
turn back into your terminal and type:
Code:
fallocate -l 2G system.img
This command allocates more space for system.img (Changing to 2GB)
After that type:
Code:
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:
Code:
mkdir system
Code:
sudo mount -t ext4 -o loop system.img system
Now system dir contains all system.img files.
4)edit it as you want
***IMPORTANT***
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:
Code:
sudo nautilus
5) umount system
*)make sure the terminal is not in system directory or some sub dir of it

if Yes just type
Code:
cd ..
to go up in the directories tree (do it many times until you will be in the same directory like the image in the top)

type:
Code:
sudo umount system
Code:
e2fsck -yf system.img
(fixes file system errors)
6) shrink the edit system.img into the minimum possible size
by:
Code:
resize2fs -M system.img
fix the file system again:
Code:
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)
2)vendor.img
3)product.img

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
it creates empty super.img with all headers stuff and pushing partitions into it


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:
Code:
stat -c '%n %s' system.img
do it for all partitions files

And this is tricky and critical step:
***DO NOT COPY!!***
Code:
./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

explanation:
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!:):eek:

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:
Code:
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:
Code:
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:
https://forum.hovatek.com/thread-31664.html

when I put the command line

./lpmake --metadata-size 65536 --super-name super --metadata-slots 2 --device super: 6836715520 --group main: 6642450432 --partition system: readonly: 5244977152: main --image system =. / system.img --partition odm: readonly: 4349952: main --image odm =. / odm.img --partition product: readonly: 752545792: main --image product =. / product.img --partition vendor: readonly: 640577536: main --image vendor =. / Vendor.img --sparse --output ./super_new.img

it says this: Invalid sparse file format at header magic

why ????
 

giubenez

Member
Mar 30, 2011
41
5
I edited the vendor.img but something strange happens:


$stat -c '%n %s' *
super.img 3758096384
product.img 1596944384
system.img 1128718336
vendor.img 544976896

$../otatools/bin/lpmake --metadata-size 65536 --super-name super --metadata-slots 1 --device super:3758096384 --group main:3270639616 --partition system:readonly:1128718336:main --image system=./system.img --partition vendor:readonly:544976896:main --image vendor=./vendor.img --partition product:readonly:1596944384:main --image product=./product.img --sparse --output ./super.new.img
lpmake I 02-17 12:18:27 2646704 2646704 builder.cpp:1012] [liblp]Partition system will resize from 0 bytes to 1128718336 bytes
lpmake I 02-17 12:18:27 2646704 2646704 builder.cpp:1012] [liblp]Partition vendor will resize from 0 bytes to 544976896 bytes
lpmake I 02-17 12:18:27 2646704 2646704 builder.cpp:1012] [liblp]Partition product will resize from 0 bytes to 1596944384 bytes
Invalid sparse file format at header magic
Invalid sparse file format at header magic
Invalid sparse file format at header magic

BUT....

$stat -c '%n %s' super.new.img
super.new.img 3248851200

which is not divisible by 512!

Shouldn't it be 3758096384 ?
 
  • Wow
Reactions: lebigmac

lebigmac

Senior Member
Jan 31, 2017
884
515
@Brepro1 thank you so much for writing this detailed guide.
Thanks to your detailed guide I was able to create an automated bash script that performs all of these steps automatically and makes all read only partitions inside super.img (system, vendor , product, etc...) into read write-able partitions again and flash to device as a brand new super.img.
It would be an honor for me if you could please try it and let me know if it works on your device. Thanks.

Here is the link:
https://forum.xda-developers.com/t/script-mount-system-as-read-write-android-10.4240703/
 
Last edited:
  • Like
Reactions: Ayoub$#

vp1117

Senior Member
Jan 30, 2019
55
6
I have same issue as already was mentioned by NguyenNhutNam on Jan-20, i.e.:

In response to
sudo mount -t ext4 -o loop system.img edit
I'm getting this:
wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error.

And Linux tells me this:
file system.img
system.img: Linux rev 1.0 ext2 filesystem data, UUID=4729639d-b5f2-5cc1-a120-9ac5f788683c (extents) (large files) (huge files)


Of course, I tried:
sudo mount -t ext2 -o loop system.img edit
only to get this:
wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error.

Any ideas?
 

lebigmac

Senior Member
Jan 31, 2017
884
515
The code below works great in Ubuntu
Code:
sudo su
mkdir /mnt/dir
mount -t ext4 -o loop,rw ./system.img /mnt/dir

But as soon as I try it directly inside Android I get this error:
Code:
mount: '/dev/block/loop10'->'/mnt/dir': Block device required
I guess this must be some kind of Android limitation...
 
  • Like
Reactions: Ayoub$#
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
None of this is working on the Moto One 5g Ace. All I want to do is get into /product/media/audio/ringtones to delete the crappy ones like I do with EVERY VERSION OF ANDROID and replace them with my own. I can't even open the images up and mod them because of the Read only xx. Please help and give detailed instructions like I'm a 5 year old. Have tried on linux and windows to ZERO success and LeBigMac's script didn't do xxxxx either.
Mod Edit: Post edited.
 
Last edited by a moderator:

Top Liked Posts

  • There are no posts matching your filters.
  • 8
    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.

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

    steps:
    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:
    Code:
    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
    Open terminal in imjtool path and super.img path and type
    Code:
    ./imjtool.ELF64 super.img extract
    if you got and error run it as superuser by
    Code:
    sudo ./imjtool.ELF64 super.img extract
    I will use lpunpck tool (Official tool from google)

    locate lpunpack and super.ext4.img and open terminal in this folder.
    Then type:
    Code:
    ./lpunpack super.ext4.img
    wait for it it may take couple of minutes.
    now our folder looks like this:

    kIY7JpC.png


    2)resizing system.img in order to make enough space for modifications
    turn back into your terminal and type:
    Code:
    fallocate -l 2G system.img
    This command allocates more space for system.img (Changing to 2GB)
    After that type:
    Code:
    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:
    Code:
    mkdir system
    Code:
    sudo mount -t ext4 -o loop system.img system
    Now system dir contains all system.img files.
    4)edit it as you want
    ***IMPORTANT***
    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:
    Code:
    sudo nautilus
    5) umount system
    *)make sure the terminal is not in system directory or some sub dir of it
    if Yes just type
    Code:
    cd ..
    to go up in the directories tree (do it many times until you will be in the same directory like the image in the top)

    type:
    Code:
    sudo umount system
    Code:
    e2fsck -yf system.img
    (fixes file system errors)
    6) shrink the edit system.img into the minimum possible size
    by:
    Code:
    resize2fs -M system.img
    fix the file system again:
    Code:
    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)
    2)vendor.img
    3)product.img

    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
    it creates empty super.img with all headers stuff and pushing partitions into it


    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:
    Code:
    stat -c '%n %s' system.img
    do it for all partitions files

    And this is tricky and critical step:
    ***DO NOT COPY!!***
    Code:
    ./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

    explanation:
    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!:):eek:

    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:
    Code:
    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:
    Code:
    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:
    https://forum.hovatek.com/thread-31664.html
    2
    I made a Python script to make repacking a super.img a little easier. To use it, you'll need Python 3 and `argparse` installed (`pip3 install argparse`). You'll also need `lpmake` available somewhere (you can download a prebuilt version here: https://forum.xda-developers.com/t/guide-ota-tools-lpunpack.4041843/).

    Basic usage can be seen by running `python3 lpmakesimple.py -h`.
    An example would be: `python3 lpmakesimple.py ./lpmake ./super.new.img 4294967296 system=./system.img,vendor=./vendor.img,product=./product.img`

    EDIT 8/12/2021: Added a fixed version.
    1
    @Brepro1 thank you so much for writing this detailed guide.
    Thanks to your detailed guide I was able to create an automated bash script that performs all of these steps automatically and makes all read only partitions inside super.img (system, vendor , product, etc...) into read write-able partitions again and flash to device as a brand new super.img.
    It would be an honor for me if you could please try it and let me know if it works on your device. Thanks.

    Here is the link:
    https://forum.xda-developers.com/t/script-mount-system-as-read-write-android-10.4240703/
    1
    The code below works great in Ubuntu
    Code:
    sudo su
    mkdir /mnt/dir
    mount -t ext4 -o loop,rw ./system.img /mnt/dir

    But as soon as I try it directly inside Android I get this error:
    Code:
    mount: '/dev/block/loop10'->'/mnt/dir': Block device required
    I guess this must be some kind of Android limitation...
    1
    fallocate -l 1G vendor.img
    resize2fs vendor.img 1G
    e2fsck -E unshare_blocks vendor.img
    mkdir vendor
    sudo mount -o rw,loop -t ext4 vendor.img vendor

    *make any changes*

    sudo umount vendor

    This worked for me, I used it to disable fileencryption in fstab of a stock ROM.