• 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

Zacharee1

Recognized Developer / Retired Forum Moderator
Quoting them in the command seems to make the path arguments work but still get the same error above for the supersize attrib.
I'm not sure what happened, since I'm pretty sure I tested the script before I uploaded it, but after looking at it, that version shouldn't work.

Use this one instead.
 

Attachments

  • lpmakesimple.zip
    863 bytes · Views: 72
  • Love
Reactions: lebigmac

beta.0

Senior Member
Jul 26, 2016
52
9
I'm not sure what happened, since I'm pretty sure I tested the script before I uploaded it, but after looking at it, that version shouldn't work.

Use this one instead.
Yes that one works great, the attrib labels were wrong in the other one. Thanks for the working script Zach!

Just a minor cosmetic bug, partition sizes are printed twice. The reason why is not at all obvious in the script.

Code:
Size for partition file ./system.img is 609792000
Size for partition file ./vendor.img is 261836800
Size for partition file ./odm.img is 2633728
Size for partition file ./product.img is 496869376
Size for partition file ./system.img is 609792000
Size for partition file ./vendor.img is 261836800
Size for partition file ./odm.img is 2633728
Size for partition file ./product.img is 496869376
./lpmake --metadata-size 65536 --metadata-slots 1 --device super:1677721600 --group main:1371131904 --partition system:readonly:609792000:main --image system=./system.img --partition vendor:readonly:261836800:main --image vendor=./vendor.img --partition odm:readonly:2633728:main --image odm=./odm.img --partition product:readonly:496869376:main --image product=./product.img --sparse --output ./super.new.img
lpmake I 08-12 22:52:49 22525 22525 builder.cpp:1012] [liblp]Partition system will resize from 0 bytes to 609792000 bytes
lpmake I 08-12 22:52:49 22525 22525 builder.cpp:1012] [liblp]Partition vendor will resize from 0 bytes to 261836800 bytes
lpmake I 08-12 22:52:49 22525 22525 builder.cpp:1012] [liblp]Partition odm will resize from 0 bytes to 2633728 bytes
lpmake I 08-12 22:52:49 22525 22525 builder.cpp:1012] [liblp]Partition product will resize from 0 bytes to 496869376 bytes
Invalid sparse file format at header magic
Invalid sparse file format at header magic
Invalid sparse file format at header magic
Invalid sparse file format at header magic
 

FR8148

Senior Member
Sep 5, 2012
122
22
This version of lpunpack doesn't work on Android 11 super images. Allways this error:

lpunpack E 08-25 17:54:01 2064 2064 reader.cpp:171] [liblp]Logical partition metadata has invalid checksum.
lpunpack E 08-25 17:54:02 2064 2064 reader.cpp:171] [liblp]Logical partition metadata has invalid checksum.
Image does not appear to be in super-partition format.!

I have found one version for Android 11 here:


but I dont't get to build it, allways several errors.
Could you try to build lpunpack (and lpmake, they are together) and post it here?
Thanks in advance.
 

kilosatt

Member
Sep 7, 2021
6
0
I put all images, system, vendor, product, and odm in /otatools/bin/ folder and when I run ./lpmake
Code:
./lpmake --metadata-size 65536 --super-name super --metadata-slots 1 --device super:6023020544 --group main:4732334080 --partition system:readonly:3227881472:main --image system=./system.img --partition vendor:readonly:567611392:main --image vendor=./vendor.img --partition odm:readonly:4349952:main --image odm=./odm.img --partition product:readonly:932491264:main --image product./product.img --sparse --output ./super.img
it does nothing. Just terminal output is: Expected PARTITION=FILE

What I am doing wrong?
I'm using Ubuntu linux machine. File sizes are correct.
 
Last edited:

achakian0000

Member
Nov 30, 2020
15
1
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
Google's software downloads these files to me
1632883009572.png

How do I compile them?
 
  • Like
Reactions: jacobel640

AndyJN

New member
May 22, 2019
2
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
Hi

I have followed your instructions in order to edit the init.rc file to alter the boot on charge power behaviour for a Samsung A3. When I try and use Odin to reflash the phone - I end up with an error screen showing vbmeta HASH_MISMATCH
 

Attachments

  • BrickedA3.jpg
    BrickedA3.jpg
    233.4 KB · Views: 17

lebigmac

Senior Member
Jan 31, 2017
971
588
Hi

I have followed your instructions in order to edit the init.rc file to alter the boot on charge power behaviour for a Samsung A3. When I try and use Odin to reflash the phone - I end up with an error screen showing vbmeta HASH_MISMATCH
Hi. Did you try disable dm-verity and verification? There is avbctl binary in my SystemRW project that can do this. Maybe it helps with booting.

I know Samsung deleted fastboot from all their devices which is a shame otherwise you could also use that for disabling dm-verity by flashing empty vbmeta with special parameters:

fastboot --disable-verity --disable-verification flash vbmeta vbmeta.img

Good luck!
 
Last edited:

jacobel640

New member
Oct 14, 2018
3
0
i'm really new in linux and i need an explanation on how to install the "lpmake" tool on ubuntu
please help me🙏

my results
[email protected]:~# ./lpmake -bash: ./lpmake: No such file or directory
 

sarbazg180

Member
Dec 12, 2021
8
1
Hi

I have some questions

i want to make my system rw that can be edited in the device so i make system.img 3GB

1- How exactly i found super.img size?? Is it none edited super.img size?

2- is it ok if i repack without make system.img to minimal possible size(because i heard that system.img is ro due to google minimize img size)?

3- is it right method to make /system rw?

Sorry for may bad English 😉
 

lolvatveo

Senior Member
Nov 1, 2020
62
1
help. problem is junk apps will recover when system run without root (restart phone to lost root) even its folder in priv-app has been deleted. how do i solve it? anyone know how to completely delete it? I can't identify these bloatware, it only appear when unroot, disappear when root. No way to uninstall it normally, I need help to find the folder of these bloatware and delete it. i think it can only remove folder in system/app or priv-app to remove bloatware. this is the case especially when i unroot it shows up again. And the additional download file managers can't show them to know directory where it's installed from, this special bloatware simply doesn't work using system/app. So anyone with a solution please help<- my bad englísh
 

SwedishForenger

Senior Member
Mar 26, 2021
221
40
help. problem is junk apps will recover when system run without root (restart phone to lost root) even its folder in priv-app has been deleted. how do i solve it? anyone know how to completely delete it? I can't identify these bloatware, it only appear when unroot, disappear when root. No way to uninstall it normally, I need help to find the folder of these bloatware and delete it. i think it can only remove folder in system/app or priv-app to remove bloatware. this is the case especially when i unroot it shows up again. And the additional download file managers can't show them to know directory where it's installed from, this special bloatware simply doesn't work using system/app. So anyone with a solution please help<- my bad englísh

.

Are you on Stock android rom or Custom rom?

.
 

lolvatveo

Senior Member
Nov 1, 2020
62
1
Im in custom ROM (rooted). My partition system is dynamic, using system as root and rooting it's not easy
 

SwedishForenger

Senior Member
Mar 26, 2021
221
40
Im in custom ROM (rooted). My partition system is dynamic, using system as root and rooting it's not easy
.

If apps are restored, you can't have system root. seems to me you onely have partial root. If so. you dont actually delete the apps. You only disables them for user 0.


Try this:
adb shell pm uninstall -k --user 0 XXXXXNAME of you app

.
 

lolvatveo

Senior Member
Nov 1, 2020
62
1
I guessed wrong, when booting without root bloatware will reinstall itself to the system folder. Help me find the cause and how to fix it. Above command not executing, when re-enable root by booting into recovery i got into data/user/0 but no bloatware folder, bloatware folder in system app also disappeared.
 

SwedishForenger

Senior Member
Mar 26, 2021
221
40
I guessed wrong, when booting without root bloatware will reinstall itself to the system folder. Help me find the cause and how to fix it. Above command not executing, when re-enable root by booting into recovery i got into data/user/0 but no bloatware folder, bloatware folder in system app also disappeared.

.

ALL apps that exist in your mobile, whether they are hidden or not, can be seen in a root scan of the phone.

Scan the phone:
adb shell pm list packages

screenshot_1.png

Find the apps you want to delete....
Let's say I want to delete my phones Recorder.

The name of this file is: com.google.android.apps.recorder

To permanently delete that file, will I tell ADB to look up that file in the phone and delete it

adb uninstall com.google.android.apps.recorder​
Ore
adb uninstall --user 0 com.google.android.apps.recorder


.
 

lolvatveo

Senior Member
Nov 1, 2020
62
1
this uninstallation is only temporary for the user, i checked the system partition again and was surprised to notice that all my junk delete modifications are stock restored. which contains a whole list of junk apps will be installed if i select india country because it has indian letters which i deleted as root, and many bloatware, junk subfolders are also restored in /system, inside system/app priv-app has the bloatware folder recover and the uninstall command is just a command to hide it from the user. maybe you need an itel p15 w5005p like me to understand it clearly. i don't know how it restores and where is this backup file, I have to edit system.img? note I won't be able to find bloatware packages with adb shell as root because they will disappear (delete) with the modification I did. i can only uninstall if i unroot and bloatware they recover up. my phone use system as root and ram disk is in recovery. whenever want to flash an image or modify a file that vbmeta will verify the file must be signed and edited vbmeta otherwise the system will not boot. That's my phone system. When I used the first command without root I got: internal memory error. I tried the second command and it didn't remove the bloatware folder in /system, the apk files were still intact. it just makes the app disappear from the screen.
 
Last edited:

SwedishForenger

Senior Member
Mar 26, 2021
221
40
this uninstallation is only temporary for the user, i checked the system partition again and was surprised to notice that all my junk delete modifications are stock restored. which contains a whole list of junk apps will be installed if i select india country because it has indian letters which i deleted as root, and many bloatware, junk subfolders are also restored in /system, inside system/app priv-app has the bloatware folder recover and the uninstall command is just a command to hide it from the user. maybe you need an itel p15 w5005p like me to understand it clearly. i don't know how it restores and where is this backup file, I have to edit system.img? note I won't be able to find bloatware packages with adb shell as root because they will disappear (delete) with the modification I did. i can only uninstall if i unroot and bloatware they recover up. my phone use system as root and ram disk is in recovery. whenever want to flash an image or modify a file that vbmeta will verify the file must be signed and edited vbmeta otherwise the system will not boot. That's my phone system. When I used the first command without root I got: internal memory error. I tried the second command and it didn't remove the bloatware folder in /system, the apk files were still intact. it just makes the app disappear from the screen.

.

Yes my friend. as I said. you don't have system root. You only have partial root.
But yes, you can deconstruct your phones firmware and make your changes, and compile the rom back together and flash it. It's exactly what a custom rom is. My suggestion is that you find a custom rom you like and flash it over your original. That way, you circumvent the problem.

.
 
  • Like
Reactions: J.Michael

lolvatveo

Senior Member
Nov 1, 2020
62
1
is my root just a user instance with more permissions? when i make changes in system is it just fake for "user with multiple permissions" does it have no real impact on the system?
 

lebigmac

Senior Member
Jan 31, 2017
971
588
First disable the annoying bloatware and then reboot your device a couple of times. If no bootloop or other errors then it's safe to delete it with your favorite root file browser app. Make sure to mount your partition as rw before trying to delete files off it (see image below) !
Good luck! (y)
1-jpg.5235933
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    this uninstallation is only temporary for the user, i checked the system partition again and was surprised to notice that all my junk delete modifications are stock restored. which contains a whole list of junk apps will be installed if i select india country because it has indian letters which i deleted as root, and many bloatware, junk subfolders are also restored in /system, inside system/app priv-app has the bloatware folder recover and the uninstall command is just a command to hide it from the user. maybe you need an itel p15 w5005p like me to understand it clearly. i don't know how it restores and where is this backup file, I have to edit system.img? note I won't be able to find bloatware packages with adb shell as root because they will disappear (delete) with the modification I did. i can only uninstall if i unroot and bloatware they recover up. my phone use system as root and ram disk is in recovery. whenever want to flash an image or modify a file that vbmeta will verify the file must be signed and edited vbmeta otherwise the system will not boot. That's my phone system. When I used the first command without root I got: internal memory error. I tried the second command and it didn't remove the bloatware folder in /system, the apk files were still intact. it just makes the app disappear from the screen.

    .

    Yes my friend. as I said. you don't have system root. You only have partial root.
    But yes, you can deconstruct your phones firmware and make your changes, and compile the rom back together and flash it. It's exactly what a custom rom is. My suggestion is that you find a custom rom you like and flash it over your original. That way, you circumvent the problem.

    .
    1
    is my root just a user instance with more permissions? when i make changes in system is it just fake for "user with multiple permissions" does it have no real impact on the system?
    .

    Yes. user root is just temp root in factory rom. Think of it all as SAFETY- cards on computers.
    When people uses the computers in the library, or in schools or in big office environments,
    it would have been IMPOSSIBLE for the administrator to keep track of all computers so that users did not do things like install programs, make personal settings or give computers viruses with their old usb sticks from home etc etc.

    Restore_PCI_Card.gif

    To prevent the influence of all human factors in a large data system, the administrator installs windows on a SAFETY cards. "an encrypted and locked hard drive", which the computer takes a new copy from to its local hard disk and opens it for you, each time the computer reboots.
    This means that the computer starts with a clean copy of windows every day, and regardless of previous settings, programs or errors made by the user the day before.

    So if you want to get around the problems of having all your settings and programs removed every computer boot, you just install your own windows on a usb stick and force bios setings on the PC to boot your windows from theusb, instead of the windows from the SAFETY cards.

    And that's what custom rom does. Uses the phone's hardware and forces the phone to start an alternative OS, In this alternative environment, you are the administrator and decide what is to be saved or deleted. But as on a computer with SAFETY cards, Remove the usb stick with your windows on, and the computer / your phone will go back to factory stock OS, and back to apps and drivers the other administrator has chosen to be pre-installed on the devise.

    .
  • 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
    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.
    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
    is my root just a user instance with more permissions? when i make changes in system is it just fake for "user with multiple permissions" does it have no real impact on the system?
    .

    Yes. user root is just temp root in factory rom. Think of it all as SAFETY- cards on computers.
    When people uses the computers in the library, or in schools or in big office environments,
    it would have been IMPOSSIBLE for the administrator to keep track of all computers so that users did not do things like install programs, make personal settings or give computers viruses with their old usb sticks from home etc etc.

    Restore_PCI_Card.gif

    To prevent the influence of all human factors in a large data system, the administrator installs windows on a SAFETY cards. "an encrypted and locked hard drive", which the computer takes a new copy from to its local hard disk and opens it for you, each time the computer reboots.
    This means that the computer starts with a clean copy of windows every day, and regardless of previous settings, programs or errors made by the user the day before.

    So if you want to get around the problems of having all your settings and programs removed every computer boot, you just install your own windows on a usb stick and force bios setings on the PC to boot your windows from theusb, instead of the windows from the SAFETY cards.

    And that's what custom rom does. Uses the phone's hardware and forces the phone to start an alternative OS, In this alternative environment, you are the administrator and decide what is to be saved or deleted. But as on a computer with SAFETY cards, Remove the usb stick with your windows on, and the computer / your phone will go back to factory stock OS, and back to apps and drivers the other administrator has chosen to be pre-installed on the devise.

    .