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

Search This thread

jahsonroy

New member
Jun 15, 2022
2
0
mg and modifying system. img inside of it.
  1. unpacking super image: ...
  2. resizing system. img in order to make enough space for modifications. ...
  3. mounting system. img. ...
  4. edit it as you want. ...
  5. umount system. ...
  6. shrink the edit system. img into the minimum possible size. ...
  7. generating new super.image.
30-Nov-2020
 

NaiimAb10

New member
Jun 17, 2022
3
0
Hello,

Thank you for your post. It was really helpful. But I'm having a problem. I'm trying to modify system image for Samsung s22 but I couldn't as the system is f2fs file, I mounted using fedora. The problem is I cannot modify any file as it says it's read-only file system ( I tried all ways I could think about but no luck ). do you have any idea? I also copied files from mounted folder to another folder with rsync and was able to create super.img but when flashed with odin I get bootloop. Not sure what to do
 

sayazop

New member
Jun 28, 2022
1
0
I extracted odm, product, system & vendor from an OTA zip, converted them to sparse and replaced the originals from an older aml_upgrade_package.img (extracted using xVortex kitchen v5). techzpod download mobdro
 
Last edited:

PTechz

Member
Jun 25, 2022
13
5
It is working!!! Thank you so much! You're awesome, you're really awesome!

My device, Redmi 9Activ (Cattail). Thanks bro, you're epic!

;)
 

PTechz

Member
Jun 25, 2022
13
5
Can I make (super.bin) file readwriteable with this? From (read only to read write). Please reply me!

Android 10
 

jacobel640

Member
Oct 14, 2018
5
0
i'm stock in the last step, got an error:
Not enough space on device for partition product
Code:
lpmake --metadata-size 65536 --super-name super --metadata-slots 1 
--device super:4831838208 --group main:3253381856 
--partition system:readonly:1470657484:main --image system=./system1.img 
--partition vendor:readonly:446656512:main --image vendor=./vendor1.img 
--partition product:readonly:1338654504:main --image product=./product1.img --sparse 
--output ./super.new.img
lpmake I 07-12 01:01:38 22864 22864 builder.cpp:1012] [liblp]
Partition system will resize from 0 bytes to 1470660608 bytes
lpmake I 07-12 01:01:38 22864 22864 builder.cpp:1012] [liblp]
Partition vendor will resize from 0 bytes to 446656512 bytes
lpmake E 07-12 01:01:38 22864 22864 builder.cpp:599] [liblp]
Partition product is part of group main which does not have enough space free 
(1338654720 requested, 1917317120 used out of 3253381856)
Not enough space on device for partition product with size 1338654504

need help!
 

ltk6260

Member
May 4, 2022
22
0
need help please if someone can take a look
[email protected]:~/Test/otatools/bin$ ./lpmake --metadata-size 65536 --super-name super --metadata-slots 1 --device super:2457862144 --group main:2066169856 --partition system:readonly:715890140:main --image system=./system-squeak-arm32_binder64-ab-vndklite-gogapps.img --partition vendor:readonly:212828160:main --image vendor=./vendor.img --sparse --output ./super-new.img

lpmake I 07-23 14:33:51 27743 27743 builder.cpp:1012] [liblp]Partition system will resize from 0 bytes to 715890688 bytes

lpmake I 07-23 14:33:51 27743 27743 builder.cpp:1012] [liblp]Partition vendor will resize from 0 bytes to 212828160 bytes

Invalid sparse file format at header magic

lpmake E 07-23 14:33:52 27743 27743 images.cpp:384] [liblp]read failed: Success
 

ltk6260

Member
May 4, 2022
22
0
system.img is only 682 MiB can't be true. unsparse system.img with simg2img first
Hi, I may be a little out of context. I'm trying to flash this system-squeak-arm32_binder64-ab-vndklite-gogapps.img to a Calypso U318AA phone from ATT.
When I checked the size of the ...gogapps.img file I got a size of 715890140 so that's what I put in the command.
Can you help me understand what you were seeing? I'm still new to all of this and have been working from this thread https://forum.xda-developers.com/t/what-is-this-calypso-a318uu.4372081/
 

aIecxs

Senior Member
Feb 17, 2016
1,889
538
gitlab.com
unsparse with simg2img first
Code:
$ ls -lh
$ file system-*.img
$ simg2img system-squeak-arm32_binder64-ab-vndklite-gogapps.img system2.img
$ file system2.img
$ ls -l
 

ltk6260

Member
May 4, 2022
22
0
unsparse with simg2img first
Code:
$ ls -lh
$ file system-*.img
$ simg2img system-squeak-arm32_binder64-ab-vndklite-gogapps.img system2.img
$ file system2.img
$ ls -l
Hmm here's what i got.

file system-*.img
system-squeak-arm32_binder64-ab-vndklite-gogapps.img: XZ compressed data, checksum CRC64

./simg2img system-squeak-arm32_binder64-ab-vndklite-gogapps.img system2.img
Invalid sparse file format at header magic
Failed to read sparse file

EDIT:this is running in ubuntu in a virtualbox vm on my windows desktop if that matters
EDIT2:also this was a .img.xz file originally when i downloaded it but maybe i didn't uncompress the xz correctly?
Edit3: maybe i'm on to something now. redownloaded the .img.xz and unxz'd it again and now ls-lh is showing:
ls -l system-squeak-arm32_binder64-ab-vndklite-gogapps.img
-rwxrwxrwx 1 luke luke 1853341696 Jul 19 13:54 system-squeak-arm32_binder64-ab-vndklite-gogapps.img


Edit4: Holy crap it works. gosh i feel silly. i didn't unxz the file correctly this whole time. once i redid that i was able to simply 'fastboot flash system' like in the other thread i linked previously. Did a factory reset and phones' already up and running on the new android12.
I have two of these phones, and just use em to play around with and test out different apps. The stock stuff was bloated, slow (hw is trash i know) but they occassionally would lock up on apps for me etc. So my whole goal with playing around was to just try and get something clean/lightweight/stable
 
Last edited:

irnehhenri

Member
Mar 5, 2011
6
5
Step3 I get this when I run "sudo mount -t ext4 -o loop system.img system"

mount: system: failed to setup loop device for system.img.
Run dmesg and it will probably give you a slightly better error message.

If it's because the filesystem has shared blocks (the same issue I had), you should have an error message like this in dmesg (I guess code 4000 refers to the "shared blocks" feature, but I couldn't find anything about this in the e2fsck documentation):
EXT4-fs (loop*): couldn't mount RDWR because of unsupported optional features (4000)`.

If your device has enough room to fit the filesystem after unsharing (sum of all partition sizes <= device size) you can run e2fsck -E unshare_blocks <your .img file or loop device> and after that you will be able to mount as R/W.

Btw: mounting as R/O should always work (mount -o ro), but then obviously you can't change anything.
 
  • Like
Reactions: aIecxs

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    Step3 I get this when I run "sudo mount -t ext4 -o loop system.img system"

    mount: system: failed to setup loop device for system.img.
    Run dmesg and it will probably give you a slightly better error message.

    If it's because the filesystem has shared blocks (the same issue I had), you should have an error message like this in dmesg (I guess code 4000 refers to the "shared blocks" feature, but I couldn't find anything about this in the e2fsck documentation):
    EXT4-fs (loop*): couldn't mount RDWR because of unsupported optional features (4000)`.

    If your device has enough room to fit the filesystem after unsharing (sum of all partition sizes <= device size) you can run e2fsck -E unshare_blocks <your .img file or loop device> and after that you will be able to mount as R/W.

    Btw: mounting as R/O should always work (mount -o ro), but then obviously you can't change anything.
  • 11
    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
    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.
    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
    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
    1
    Step3 I get this when I run "sudo mount -t ext4 -o loop system.img system"

    mount: system: failed to setup loop device for system.img.
    Run dmesg and it will probably give you a slightly better error message.

    If it's because the filesystem has shared blocks (the same issue I had), you should have an error message like this in dmesg (I guess code 4000 refers to the "shared blocks" feature, but I couldn't find anything about this in the e2fsck documentation):
    EXT4-fs (loop*): couldn't mount RDWR because of unsupported optional features (4000)`.

    If your device has enough room to fit the filesystem after unsharing (sum of all partition sizes <= device size) you can run e2fsck -E unshare_blocks <your .img file or loop device> and after that you will be able to mount as R/W.

    Btw: mounting as R/O should always work (mount -o ro), but then obviously you can't change anything.