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

Search This thread

Loopback7084

Member
May 21, 2009
43
24
London
Hi all... I'm sorry this is 'slightly' off topic... Thanks for the great guide for unpacking / repacking. This has been a go-to thread for a long time for me. However I'm struggling with a follow-on activity. After stripping down a stock ROM image, I've come to add a few apks back to an image... a process many many years ago I used to refer to as 'slipstreaming'... and back when I last did it.. ( Android 7 )... it was very straightforward.

However, this image is android 12, and although I'm perfectly able to unpack & repack the image, and successfully boot and use it, no apps I add to the system.img will actually run. The process is thus:-

1) unpack super
2) resize2fs system img ( add space )
3) mount it
4) add the apks to ./system/app/[appname]/[app].apk
5) chmod the folder to 755 and the apk to 644 ( not entirely sure why this was found on searches )
6) unmount
7) resize2fs -M system
8) repack with lpmake
9) reflash the NAND, optionally wipe data ( depending on how much I've butchered the ROM ).

Everything "else" works... apart from the APKs I've added... ( they 'appear' as apps but not correctly - icons are "off" and the won't execute... ( see attached )... really grateful of any help... what am I doing wrong...?
 

Attachments

  • IMG_20230702_101558.jpg
    IMG_20230702_101558.jpg
    1.2 MB · Views: 12

harvey186

Senior Member
May 14, 2010
468
149
Hi all... I'm sorry this is 'slightly' off topic... Thanks for the great guide for unpacking / repacking. This has been a go-to thread for a long time for me. However I'm struggling with a follow-on activity. After stripping down a stock ROM image, I've come to add a few apks back to an image... a process many many years ago I used to refer to as 'slipstreaming'... and back when I last did it.. ( Android 7 )... it was very straightforward.

However, this image is android 12, and although I'm perfectly able to unpack & repack the image, and successfully boot and use it, no apps I add to the system.img will actually run. The process is thus:-

1) unpack super
2) resize2fs system img ( add space )
3) mount it
4) add the apks to ./system/app/[appname]/[app].apk
5) chmod the folder to 755 and the apk to 644 ( not entirely sure why this was found on searches )
6) unmount
7) resize2fs -M system
8) repack with lpmake
9) reflash the NAND, optionally wipe data ( depending on how much I've butchered the ROM ).

Everything "else" works... apart from the APKs I've added... ( they 'appear' as apps but not correctly - icons are "off" and the won't execute... ( see attached )... really grateful of any help... what am I doing wrong...?
try to add the apks in folder /system/priv-app/
 

Noah Allen

Member
Dec 23, 2021
38
4
I made this automated script that patches super.img with a new GSI system img
Link: https://github.com/ChromiumOS-Guy/SuperPatcherGSI
Hello
I am getting a new error with your latest tool.
When I tried to run the script on Ubuntu, it said "Permission denied."
So someone suggested running from usr/bin with Python, and it gave me this issue.
flags successfully verified and appear to be correct, error code (OK)
============================
unpacking...
============================
File "/home/noah/Desktop/SuperPatcherGSI/linux/SuperPatcherGSI.AppDir/usr/bin/lpunpack.py", line 61
match attributes:
^
SyntaxError: invalid syntax
============================
choose img to replace
============================
Traceback (most recent call last):
File "./SuperPatcherGSI.py", line 173, in <module>
err = main()
File "./SuperPatcherGSI.py", line 145, in main
IMGchoose() # replaces selcted partition with GSI
File "./SuperPatcherGSI.py", line 48, in IMGchoose
TempImgList = os.listdir(TempDIR)
FileNotFoundError: [Errno 2] No such file or directory: '/home/noah/Desktop/SuperPatcherGSI/linux/SuperPatcherGSI.AppDir/usr/bin/tmp'
 

harvey186

Senior Member
May 14, 2010
468
149
Hello
I am getting a new error with your latest tool.
When I tried to run the script on Ubuntu, it said "Permission denied."
So someone suggested running from usr/bin with Python, and it gave me this issue.
flags successfully verified and appear to be correct, error code (OK)
============================
unpacking...
============================
File "/home/noah/Desktop/SuperPatcherGSI/linux/SuperPatcherGSI.AppDir/usr/bin/lpunpack.py", line 61
match attributes:
^
SyntaxError: invalid syntax
============================
choose img to replace
============================
Traceback (most recent call last):
File "./SuperPatcherGSI.py", line 173, in <module>
err = main()
File "./SuperPatcherGSI.py", line 145, in main
IMGchoose() # replaces selcted partition with GSI
File "./SuperPatcherGSI.py", line 48, in IMGchoose
TempImgList = os.listdir(TempDIR)
FileNotFoundError: [Errno 2] No such file or directory: '/home/noah/Desktop/SuperPatcherGSI/linux/SuperPatcherGSI.AppDir/usr/bin/tmp'
That's not correct. The issue of 'no permission' is coming from none executable AppImage. And was solved when using
'bash' instead of . /
 
  • Like
Reactions: J.Michael
Dec 6, 2022
28
13
I have tried with bash. But I am getting the same error.
SuperPatcherGSI-x64.AppImage: SuperPatcherGSI-x64.AppImage: cannot execute binary file
you can always use the source directly just download my main and try to run SuperPatcherGSI.py directly (would love to help more but my distro was giving me trouble so I'm currently on clean install so I have stuff to do)
 
  • Like
Reactions: J.Michael

Noah Allen

Member
Dec 23, 2021
38
4
you can always use the source directly just download my main and try to run SuperPatcherGSI.py directly (would love to help more but my distro was giving me trouble so I'm currently on clean install so I have stuff to do)
Oh yeah. I have tried that too. It showed me like this.

flags successfully verified and appear to be correct, error code (OK)
============================
unpacking...
============================
File "/home/noah/Desktop/SuperPatcherGSI/linux/SuperPatcherGSI.AppDir/usr/bin/lpunpack.py", line 61
match attributes:
^
SyntaxError: invalid syntax
============================
choose img to replace
============================
Traceback (most recent call last):
File "./SuperPatcherGSI.py", line 173, in <module>
err = main()
File "./SuperPatcherGSI.py", line 145, in main
IMGchoose() # replaces selcted partition with GSI
File "./SuperPatcherGSI.py", line 48, in IMGchoose
TempImgList = os.listdir(TempDIR)
FileNotFoundError: [Errno 2] No such file or directory: '/home/noah/Desktop/SuperPatcherGSI/linux/SuperPatcherGSI.AppDir/usr/bin/tmp'
 
  • Like
Reactions: J.Michael
Dec 6, 2022
28
13
Oh yeah. I have tried that too. It showed me like this.

flags successfully verified and appear to be correct, error code (OK)
============================
unpacking...
============================
File "/home/noah/Desktop/SuperPatcherGSI/linux/SuperPatcherGSI.AppDir/usr/bin/lpunpack.py", line 61
match attributes:
^
SyntaxError: invalid syntax
============================
choose img to replace
============================
Traceback (most recent call last):
File "./SuperPatcherGSI.py", line 173, in <module>
err = main()
File "./SuperPatcherGSI.py", line 145, in main
IMGchoose() # replaces selcted partition with GSI
File "./SuperPatcherGSI.py", line 48, in IMGchoose
TempImgList = os.listdir(TempDIR)
FileNotFoundError: [Errno 2] No such file or directory: '/home/noah/Desktop/SuperPatcherGSI/linux/SuperPatcherGSI.AppDir/usr/bin/tmp'
I'm using lpunpack from here:
if this doesn't work then i guess something about you're linux install is weird, you can try downloading lpunpack binary (and its libs) from https://ci.android.com/builds/branches/aosp-master/grid and change the call to lpunpack.py to lpunpack binary it should work all the same the only reason i have the python version is that it doesn't require a lot of work to use
edit:
don't use ci.adnorid.com... version they have invalid utf-8 incoding so it can't run (at least through python)
 
Last edited:
  • Like
Reactions: J.Michael

Noah Allen

Member
Dec 23, 2021
38
4
I'm using lpunpack from here:
if this doesn't work then i guess something about you're linux install is weird, you can try downloading lpunpack binary (and its libs) from https://ci.android.com/builds/branches/aosp-master/grid and change the call to lpunpack.py to lpunpack binary it should work all the same the only reason i have the python version is that it doesn't require a lot of work to use
edit:
don't use ci.adnorid.com... version they have invalid utf-8 incoding so it can't run (at least through python)
Alright, thanks, it works. But I am having this issue. Could you please look into this?

lpmake E 08-07 20:33:31 70292 70292 images.cpp:320] [liblp]Partition should only have linear extents: mi_ext_b
 

sbanskot

Member
Jul 21, 2023
11
5
Hey guys,

I am relatively new to this custom ROM business, so maybe my situation is less complicated than it seems to me, so any advice would be appreciated.

I have a Samsung Galaxy Tab Active3 tablet that I have rooted with Magisk. Therefore, at the vbmeta.img level, dm-verity is surely disabled. I can confirm this because I can pretty much follow this XDA thread on modifying the system.img inside the stock super.img (Android 13) and flashing it back to the device. I do not get stuck in a boot loop or anything like that. I can confirm that I did all of this correctly.

The issue is that none of my changes that I made in the system.img persists once I boot the device. For example, I added a "hello_world.txt" into the root directory of system.img and I also added some comments to the init.environ.rc file. After flashing and booting up, these changes are gone. I am unsure as to why this is. I am using odin 3.14 to flash and I only flash the super.img partition.

Shouldn't magisk modifications to vbmeta.img have allowed me to flash custom ROM? Is my flashing step incorrect? After some research, I have some suspicion that it has to do with fstab and dtb. The fstab file in my device has the following for the system partition:

wait,avb=vbmeta, logical,first_stage_mount, avb_keys=/avb/q-gsi.avbpubkey:/avb/r-gsi.avbpubkey:/avb/s-gsi.avbpubkey

I am not sure where to go from here. This is a non A/B device btw.

Thank you for any help!
 
Dec 6, 2022
28
13
Hey guys,

I am relatively new to this custom ROM business, so maybe my situation is less complicated than it seems to me, so any advice would be appreciated.

I have a Samsung Galaxy Tab Active3 tablet that I have rooted with Magisk. Therefore, at the vbmeta.img level, dm-verity is surely disabled. I can confirm this because I can pretty much follow this XDA thread on modifying the system.img inside the stock super.img (Android 13) and flashing it back to the device. I do not get stuck in a boot loop or anything like that. I can confirm that I did all of this correctly.

The issue is that none of my changes that I made in the system.img persists once I boot the device. For example, I added a "hello_world.txt" into the root directory of system.img and I also added some comments to the init.environ.rc file. After flashing and booting up, these changes are gone. I am unsure as to why this is. I am using odin 3.14 to flash and I only flash the super.img partition.

Shouldn't magisk modifications to vbmeta.img have allowed me to flash custom ROM? Is my flashing step incorrect? After some research, I have some suspicion that it has to do with fstab and dtb. The fstab file in my device has the following for the system partition:

wait,avb=vbmeta, logical,first_stage_mount, avb_keys=/avb/q-gsi.avbpubkey:/avb/r-gsi.avbpubkey:/avb/s-gsi.avbpubkey

I am not sure where to go from here. This is a non A/B device btw.

Thank you for any help!
I didn't actually modify any system.img so i can't tell for sure but i do have some knowledge in linux and this seems like a permission problem the user can't see you're files because permissions are not correct as for why you're comments don't show up inside existing files all i can say is it sounds like some fallback idk android that much, I will at somepoint make my own GSI but i have a lot of project going on so all i have is general knowledge on the the topic and can only make educated guesses still i hope this helps :)
 

zhaozhixin

New member
Nov 29, 2009
3
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
Thank you, this help me a lot. I have been took weeks with Amlogic Kitchen which the bluetooth did not work with Android 10
 
Dec 6, 2022
28
13
Alright, thanks, it works. But I am having this issue. Could you please look into this?

lpmake E 08-07 20:33:31 70292 70292 images.cpp:320] [liblp]Partition should only have linear extents: mi_ext_b
i already had this issue just delete the partition and make a new one with size of 0 with the same name (this is now possible in latest release of my tool)
that is if you don't need the data in mi_ext_b which you probably don't because i assume you are using some GSI and not stock ROM (which is the only ROM that will ever need the partition) on my phone i deleted all dynamic partitions but system_a vendor_a product_a and it works so if you don't use Stock ROM you can do this method if not then i guess you can try repairing the img to only have linear extensions (could probably do it by flashing to an SD then changing the extensions with gparted then dd it back to an .img file)
 

Noah Allen

Member
Dec 23, 2021
38
4
i already had this issue just delete the partition and make a new one with size of 0 with the same name (this is now possible in latest release of my tool)
that is if you don't need the data in mi_ext_b which you probably don't because i assume you are using some GSI and not stock ROM (which is the only ROM that will ever need the partition) on my phone i deleted all dynamic partitions but system_a vendor_a product_a and it works so if you don't use Stock ROM you can do this method if not then i guess you can try repairing the img to only have linear extensions (could probably do it by flashing to an SD then changing the extensions with gparted then dd it back to an .img file)
Well, I did it for GSI, But now I am trying to port a MIUI Rom. I couldn't use your tool at all. Giving errors. Here are the logs.
 

Attachments

  • error.txt
    1 KB · Views: 2
Dec 6, 2022
28
13
Well, I did it for GSI, But now I am trying to port a MIUI Rom. I couldn't use your tool at all. Giving errors. Here are the logs.
SuperPatcherGSI-x64.AppImage: SuperPatcherGSI-x64.AppImage: cannot execute binary file
you need to chmod, just do sudo chmod +x SuperPatcherGSI-x64.AppImage
also use my new release v1.5.3, also make sure you have the libs: argparse , copy , enum , io , json , re , struct , sys , dataclasses , pathlib , string and typing, all should be by default but check anyways (you nned them for lpunpack.py) if you still can't use lpunpack.py you can try editing SuperPatcherGSI.py to use a binary instead of lpunpack.py i already commented what will happen if you try to do it but you can try anyways for reference the problem is your linux install because if i can run this on arch/debian/WSL/etc.. and on different hardware then its something with you're install maybe config files or something idk, hoped this helped :)
 

Noah Allen

Member
Dec 23, 2021
38
4
SuperPatcherGSI-x64.AppImage: SuperPatcherGSI-x64.AppImage: cannot execute binary file
you need to chmod, just do sudo chmod +x SuperPatcherGSI-x64.AppImage
also use my new release v1.5.3, also make sure you have the libs: argparse , copy , enum , io , json , re , struct , sys , dataclasses , pathlib , string and typing, all should be by default but check anyways (you nned them for lpunpack.py) if you still can't use lpunpack.py you can try editing SuperPatcherGSI.py to use a binary instead of lpunpack.py i already commented what will happen if you try to do it but you can try anyways for reference the problem is your linux install because if i can run this on arch/debian/WSL/etc.. and on different hardware then its something with you're install maybe config files or something idk, hoped this helped :)
I think it works. But somehow it doesn't let me keep choosing a number because it doesn't show anything to choose me. Could you please take a look at my problem? Something was wrong from the beginning. It should convert to non-sparse, shouldn't it?

python3 SuperPatcherGSI.py -i super.img -o output.img -s 2
flags successfully verified and appear to be correct, error code (OK)
============================
unpacking...
============================
File "/home/noah/Desktop/SuperPatcherGSI/SuperPatcherGSI.AppDir/usr/bin/lpunpack.py", line 61
match attributes:
^
SyntaxError: invalid syntax
============================
img manipulation
============================
Chosse Operation:
1. Delete Partition
2. Replace Partition
3. Add Partition
select: 3
Input Partition Name: test
Input Partition Size: 0
name: test
size: 0
Is This Correct? (Y/n): y
0+0 records in
0+0 records out
0 bytes copied, 0.000422027 s, 0.0 kB/s
Replace/Delete/Add another (Y/n): y
Chosse Operation:
1. Delete Partition
2. Replace Partition
3. Add Partition
select: 1
option number 0 test.img size of (0) bytes
Please Choose: 0
Partition Deleted!
Replace/Delete/Add another (Y/n): y
Chosse Operation:
1. Delete Partition
2. Replace Partition
3. Add Partition
select: 2
Please Choose:
 
Dec 6, 2022
28
13
I think it works. But somehow it doesn't let me keep choosing a number because it doesn't show anything to choose me. Could you please take a look at my problem? Something was wrong from the beginning. It should convert to non-sparse, shouldn't it?

python3 SuperPatcherGSI.py -i super.img -o output.img -s 2
flags successfully verified and appear to be correct, error code (OK)
============================
unpacking...
============================
File "/home/noah/Desktop/SuperPatcherGSI/SuperPatcherGSI.AppDir/usr/bin/lpunpack.py", line 61
match attributes:
^
SyntaxError: invalid syntax
============================
img manipulation
============================
Chosse Operation:
1. Delete Partition
2. Replace Partition
3. Add Partition
select: 3
Input Partition Name: test
Input Partition Size: 0
name: test
size: 0
Is This Correct? (Y/n): y
0+0 records in
0+0 records out
0 bytes copied, 0.000422027 s, 0.0 kB/s
Replace/Delete/Add another (Y/n): y
Chosse Operation:
1. Delete Partition
2. Replace Partition
3. Add Partition
select: 1
option number 0 test.img size of (0) bytes
Please Choose: 0
Partition Deleted!
Replace/Delete/Add another (Y/n): y
Chosse Operation:
1. Delete Partition
2. Replace Partition
3. Add Partition
select: 2
Please Choose:
very simple problem lpunpack.py crashes (you still have the same problem) so you don't get you're super.img unpacked but my script just continues like nothing happened (bug on my side that i can't do anything about) so it doesn't show any images (i also make .temp through lpunpack so it dose not let you make or see any images even if created (if you ask me you're python install is the problem try updating python3 to latest version if this still dose not work you can unpack manually and put unpacked contents in a .temp folder and run the appimages unpack will crash but you'll still get to next stages of script)
 

Top Liked Posts

  • There are no posts matching your filters.
  • 21
    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.
    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
    why don't use magisk native systemless method? just overlay magisk module with desired mods
    https://topjohnwu.github.io/Magisk/guides.html#easy-replace
    2
    use busybox mount applet instead of toybox