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

[SCRIPT][LINUX] Mount System as read write (Android 10+)

Status
Not open for further replies.
Search This thread

aIecxs

Senior Member
Feb 17, 2016
1,107
341
gitlab.com
do a simple check if file is sparsed. if you extract system.img from OTA it is always compressed in some way, could be brotli, sdat, simg or payload. But if extracted from super.img (or pulled from device) it is different, these are plain (mountable) partition images

Nevertheless always take care of fat32 file size limitation 4 GiB (applies even for sdcardfs fuse/vold mounted emulated internal storage)
 

lebigmac

Senior Member
Jan 31, 2017
867
505
Alright folks. I think it's ready for release :D
Looking for some beta testers both with and without super image
PM me with some details about your phone such as model, android version , do you have super or not...

The only thing that's missing is the script automatically flashing the partitions to the phone... Do you want this functionality to be automated or do you prefer flashing manually?
 
Last edited:
  • Like
Reactions: ronlkh1965

jhill110

Senior Member
Oct 12, 2012
1,897
1,326
Santa Barbara
HTC U11
Moto G Power
OK guys I think it's ready for release :D
Looking for some beta testers both with and without super image
PM me with some details about your phone such as model, android version , do you have super or not etc...

The only thing that's missing is the script automatically flashing the partitions to the phone... Do you want this functionality to be automated or do you prefer flashing manually?
both...:geek:
 

lebigmac

Senior Member
Jan 31, 2017
867
505
Here is screenshot of me flashing system from recovery using dd command.
Funny thing is it actually worked LOL!
Took almost 8 minutes though as you must use raw file. Doesn't work with sparse file! I know because I've tried it lol

img_20210313_123046-jpg.5248501


I was thinking of adding a prompt at the end of the script asking whether or not the user is brave enough to flash the new file to the phone using dd command ;)

Flashing with dd is a bit slow. I can flash a sparse super on my Xiaomi with fastboot in just 2 minutes.

Anyone know how to port fastboot to Android and use fastboot flash from recovery?
 
Last edited:
  • Like
Reactions: Frxhb

lebigmac

Senior Member
Jan 31, 2017
867
505
Universal version coming very very soon. Get ready.
It will work directly on the phone so no need for computer :)
 
Last edited:

aIecxs

Senior Member
Feb 17, 2016
1,107
341
gitlab.com
Anyone know how to port fastboot to Android and use fastboot flash from recovery?
do you mean `fastbootd` this is only available from stock recovery. in custom recovery you can flash from PC
Code:
adb push super.img /dev/block/bootdevice/by-name/super

or flash from MicroSD Card (if file is smaller than 4 GiB)
Code:
adb shell
cat /external_sd/super.img > /dev/block/bootdevice/by-name/super
 
  • Like
Reactions: lebigmac

kory-vadim

Member
Dec 12, 2016
17
14
LOL I fixed it. I must run simg2img on the file first.
Now it all makes sense!

Kory aren't you the guy that said unsparsing the file is waste of time? Well guess what. It's a very important step for the proper functioning of the script.

Maybe I shouldn't listen to random strangers on the internet :D
tune2fs and resize2fs do not work with sparse images.
I didn't tell you anything about converting from sparse.
I talked about not having to convert from raw to sparse before building super.img.
 
  • Like
Reactions: lebigmac and aIecxs

lebigmac

Senior Member
Jan 31, 2017
867
505
oh yeah right. You said resparsing the file is waste of time. My bad ;)
Well guess what. In next version there is no more resparsing at the end. And lots of invalid header magic warnings ;)
 
Last edited:

lebigmac

Senior Member
Jan 31, 2017
867
505
Last steps to do:
Make flashable zip.

If the script is executed in flashable zip, will it automatically switch to the TWRP terminal? If not, how can I achieve this?
 
Last edited:

lebigmac

Senior Member
Jan 31, 2017
867
505
New error just when I was about to release new version!
How the hell am I supposed to fix this error? Lpmake give pretty much zero text output. I've got absolutely no clue what's going on inside lpmake...
@kory-vadim you think it's failing because of invalid sparse file format at header magic?

new_error.jpg
 
Last edited:
  • Like
Reactions: Frxhb

lebigmac

Senior Member
Jan 31, 2017
867
505
Ok I run it again this time with custom extra size and now it's actually giving an error
makesysrw: Shrinking size of /data/local/tmp/makesysrw_1.05/files/super/vendor.img back to custom size: 1172 MB...
resize2fs 1.44.4 (18-Aug-2018)
Resizing the filesystem on /data/local/tmp/makesysrw_1.05/files/super/vendor.img to 300032 (4k) blocks.
resize2fs: No space left on device while trying to resize /data/local/tmp/makesysrw_1.05/files/super/vendor.img
Please run 'e2fsck -fy /data/local/tmp/makesysrw_1.05/files/super/vendor.img' to fix the filesystem
after the aborted resize operation.

Debugging this is a nightmare but somebody have to do it :)
 
Last edited:

ronlkh1965

Member
Feb 22, 2021
21
10
OK guys I think it's ready for release :D
Looking for some beta testers both with and without super image
PM me with some details about your phone such as model, android version , do you have super or not etc...

The only thing that's missing is the script automatically flashing the partitions to the phone... Do you want this functionality to be automated or do you prefer flashing manually?
I am ready to test.
Mi9Pro5G CRUX Android 10 Miui12
No super.img
 
Last edited:
  • Like
Reactions: lebigmac

lebigmac

Senior Member
Jan 31, 2017
867
505
Hi @ronlkh1965
Thank you for your interest in the new upcoming version.
I was just about to release it today but when I did my final testing I noticed an error. I don't know how to fix it?!
It was working so well yesterday and now this.
Here is my full log. I cannot really see an error. Only invalid sparse file format at header magic.
The problem is at the very end when doing the lpmake command to merge all extracted images into new super_fixed image.
I don' t know what is lpmake doing under the hood. Maybe I have to modify lpmake source code and recompile it to know exactly what's causing the error.

I will try it on an external sdcard. Maybe this issue has to do with not enough space on read only system...

------------------------------------------------------------------------
| makeSystemRW v1.15 automated script (by amateur:) lebigmac @xda ©2021) |
| Thx @munjeni @Brepro1, @AndyYan, @gabrielfrias, @YOisuPU, @topjohnwu |
| without your help this script would not be possible! |
------------------------------------------------------------------------
makesysrw: Custom input detected: ./files/super/super_original.bin
makesysrw: Phone is in TWRP recovery mode. Initiating procedure...
makesysrw: Your super partition is located at: /dev/block/sda15

makesysrw: Unpacking embedded partitions from super...
makesysrw: Nested partitions were successfully extracted from super:

════════════════════════════════════════════════════════════════════════

makesysrw: Minimum size of product.img in bytes: 1176604672
makesysrw: Minimum size of product.img in MB: 1122
makesysrw: Current size of product.img in bytes: 1199497216
makesysrw: Current size of product.img in MB: 1143
makesysrw: New size of product.img in 512-byte sectors: 2928460

makesysrw: Increasing filesystem size of /data/local/tmp/makesysrw_1.05/files/super/product.img by 1/4...
Resizing the filesystem on /data/local/tmp/makesysrw_1.05/files/super/product.img to 366057 (4k) blocks.
The filesystem on /data/local/tmp/makesysrw_1.05/files/super/product.img is now 366057 (4k) blocks long.

makesysrw: Removing 'shared_blocks feature' of /data/local/tmp/makesysrw_1.05/files/super/product.img...
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

product: ***** FILE SYSTEM WAS MODIFIED *****
product: 1303/1920 files (12.7% non-contiguous), 291367/366057 blocks
makesysrw: Read-only lock successfully removed

makesysrw: Shrinking size of /data/local/tmp/makesysrw_1.05/files/super/product.img back to: 1122 MB...
Resizing the filesystem on /data/local/tmp/makesysrw_1.05/files/super/product.img to 291408 (4k) blocks.
The filesystem on /data/local/tmp/makesysrw_1.05/files/super/product.img is now 291408 (4k) blocks long.

════════════════════════════════════════════════════════════════════════

makesysrw: Minimum size of system.img in bytes: 2676789248
makesysrw: Minimum size of system.img in MB: 2552
makesysrw: Current size of system.img in bytes: 2728165376
makesysrw: Current size of system.img in MB: 2601
makesysrw: New size of system.img in 512-byte sectors: 6660560

makesysrw: Increasing filesystem size of /data/local/tmp/makesysrw_1.05/files/super/system.img by 1/4...
Resizing the filesystem on /data/local/tmp/makesysrw_1.05/files/super/system.img to 832570 (4k) blocks.
The filesystem on /data/local/tmp/makesysrw_1.05/files/super/system.img is now 832570 (4k) blocks long.

makesysrw: Removing 'shared_blocks feature' of /data/local/tmp/makesysrw_1.05/files/super/system.img...
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 3A: Optimizing directories
Pass 4: Checking reference counts
Pass 5: Checking group summary information

/: ***** FILE SYSTEM WAS MODIFIED *****
/: 5704/7488 files (20.8% non-contiguous), 679259/832570 blocks
makesysrw: Read-only lock successfully removed

makesysrw: Shrinking size of /data/local/tmp/makesysrw_1.05/files/super/system.img back to: 2552 MB...
Resizing the filesystem on /data/local/tmp/makesysrw_1.05/files/super/system.img to 679304 (4k) blocks.
The filesystem on /data/local/tmp/makesysrw_1.05/files/super/system.img is now 679304 (4k) blocks long.

════════════════════════════════════════════════════════════════════════

makesysrw: Minimum size of vendor.img in bytes: 1124446208
makesysrw: Minimum size of vendor.img in MB: 1072
makesysrw: Current size of vendor.img in bytes: 1146658816
makesysrw: Current size of vendor.img in MB: 1093
makesysrw: New size of vendor.img in 512-byte sectors: 2799460

makesysrw: Increasing filesystem size of /data/local/tmp/makesysrw_1.05/files/super/vendor.img by 1/4...
Resizing the filesystem on /data/local/tmp/makesysrw_1.05/files/super/vendor.img to 349932 (4k) blocks.
The filesystem on /data/local/tmp/makesysrw_1.05/files/super/vendor.img is now 349932 (4k) blocks long.

makesysrw: Removing 'shared_blocks feature' of /data/local/tmp/makesysrw_1.05/files/super/vendor.img...
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 3A: Optimizing directories
Pass 4: Checking reference counts
Pass 5: Checking group summary information

vendor: ***** FILE SYSTEM WAS MODIFIED *****
vendor: 2990/3696 files (17.8% non-contiguous), 319314/349932 blocks
makesysrw: Read-only lock successfully removed

makesysrw: Shrinking size of /data/local/tmp/makesysrw_1.05/files/super/vendor.img back to: 1072 MB...
Resizing the filesystem on /data/local/tmp/makesysrw_1.05/files/super/vendor.img to 319352 (4k) blocks.
The filesystem on /data/local/tmp/makesysrw_1.05/files/super/vendor.img is now 319352 (4k) blocks long.

makesysrw: Joining all extracted images back into one single super image...

Invalid sparse file format at header magic.
Invalid sparse file format at header magic.

makesysrw: Error! failed to create super_fixed.img file
 
Last edited:

lebigmac

Senior Member
Jan 31, 2017
867
505
After trying it on external sdcard that is formatted to ext4 same error. I guess it wasn't a space issue after all.
It looks like this new universal version needs further testing :D
Back to the drawing board...
 
Last edited:
  • Like
Reactions: ronlkh1965
Status
Not open for further replies.

Top Liked Posts

  • There are no posts matching your filters.
  • 50
    This Linux-only version is pretty much deprecated at this point. Please use the BRAND NEW UNIVERSAL VERSION instead! Thank you.

    Ladies and gentlemen. Let me present to you my very first release here at the XDA forums:
    Welcome to:
    makeSystemRW v1.04
    automated bash script by lebigmac for Android 10 and above
    Creation date: February 2021
    Updated: March 2021


    Requirements:
    • LINUX ONLY!
    • Android 10 or newer
    • This version only supports devices with super image.
      Check if you have super by running
      ls -Alg /dev/block/by-name
    • phone must be rooted + bootloader unlocked + 10 GB free space on phone
    • at least 20 GB free space on computer for dumping data
    • adb and fastboot commands should be in your $PATH environment variable
    I'm not 100% sure if this is a necessary requirement but I also disabled dm-verity and verification on my device just in case by simply booting into TWRP and then executing these 2 commands:
    Code:
    adb disable-verity
    
    adb shell avbctl disable-verification

    Description: A script for all Android power users that wish to make their read-only Android 10+ system read-write-able again to remove bloatware and make more thorough customizations to their device.

    In a nutshell this is what the script is doing:

    • dumps your existing super image to your pc
    • extracts the embedded read-only partitions (system, vendor, product, etc...)
    • makes these partitions read-write-able
    • joins everything back together to new flashable super.img
    • flashes it to device
    User data is not affected.

    Usage:
    Simply call the script from the shell.
    Optional arguments (replace x with your custom value) :

    • in=x : With this flag you can specify an existing super.img and skip the entire dumping of the super image process. Here you can use the super_original.img which you dumped earlier with makesysrw or the official super.img from your downloaded firmware. You probably have to unsparse the official super.img first using the included simg2img tool for superunpack to recognize it properly. If omitted, makesysrw will dump super image from phone to ./super_original.img
    • out=x : With this argument you can specify the output path. If omitted, default output value is ./super_fixed.img
    • size=x : With this parameter you can specify the extra free space (in megabytes) that will be added to each partition. If omitted, default extra size is 0 (shrink to minimum)
    Examples:
    Code:
    # Run this command if you're first time user:
    # Specify the extra free space in megabytes for each partition:
    ./makesysrw.sh size=100
    
    # Plug an existing raw super image into the script like this:
    ./makesysrw.sh in=./super_original_raw.img size=100
    
    # Specify both the input file as well as the output destination:
    ./makesysrw.sh in=./super_original_raw.img out=./super_fixed.img size=100
    
    # For unsparsing the (sparse) super.img from your phone manufacturer's firmware you can do:
    ./tools/bin/simg2img ./super_sparse.img ./super_raw.img

    NOTE: I did not come up with all this by myself. After searching for a solution for countless days without success, going even as far as learning hex editing - I coincidentally came across a couple of very interesting threads burried deep inside the new forum interface where this technique has been described and discussed by various enthousiasts (links can be found below in the credits section). So I take absolutely no credit for the underlying core mechanisms of the script. I'm only the amateur who put it all together into a compact script so that everybody can enjoy an Android system that's read-write-able again. Just like it used to be in Android 9 or earlier. Before this annoying 'shared_blocks feature' was implemented.

    Credits: Big thanks to @munjeni for allowing me to use his amazing superunpack tool instead of the default lpunpack. Source code can be found here.
    Also big thanks to @Brepro1 without your awesome tutorial guiding me I couldn't have created this script.
    Thanks @AndyYan your
    interesting thread also helped me a lot for automating the script especially the lpdump part.
    More thanks @gabrielfrias for his
    helpful comment
    Thanks @YOisuPU and of course @topjohnwu for discovering the 'shared_blocks feature'
    Thanks @bynarie for making available his
    otatools package! A part of it is now bundled with the archive

    Disclaimer: This is open source software and is provided as is without any kind of warranty or support whatsoever. By using and viewing this software you agree to the following terms:
    Under no circumstances shall the author be held responsible for any damages or negative consequences that may arrise from the (inappropriate) use of this software.
    All responsibility and liability lies with the end-user. You hereby agree not to abuse this software for illegal purposes. Use this software at your own risk!

    Please feel free to improve this script as you see fit (as long as you don't add anything malicious)
    and make sure to post your feedback, suggestions and improvements in the official thread right here.


    3.jpg


    2.jpg


    5.jpg


    1.jpg


    0.jpg

    Mod Edit: Download link removed
    Please click my like button below if you like it! Thanks​
    4
    It would be very helpful if you guys could please give me some feedback if the script works for you.
    Which device are you using?
    Your Android version?
    Did you disable dm-verity and verification before running the script?
    Your suggestions to enhance the script. Remember this is only version 1.0
    Thanks!

    @thor_1979
    4
    Ok folks I fixed the problem. I'm wrapping it all up and making a flashable zip and then uploading today. I promised the new universal version would be available this week. Well today is still this week ;)
    I'm so done with this project lol. It was a great bash programming exercise for me but I'm happy if I can start working on something new. I spent too much time on this project already.

    EDIT: Just found a genius called @Kolibass who figured out a way to flash an 8 GB large file in just under 30 seconds. Now compare this to the 2-5 minutes using traditional fastboot! Holy cow that's fast. Multithreading anyone?
    3
    Are you serious it actually works on your device? lmao
    Congratulations. You are the first person to try it :D

    The script pretty much does the same thing as your awesome tutorial describes.
    Without your tutorial this script would not exist so thank you very much for making it available!
    3
    Simply extract the downloaded archive and open a terminal shell in the extracted folder by right clicking inside it and select Open in Terminal

    Then run this command if you're running it for the first time
    Code:
    ./makesysrw.sh size=100

    or this command if you already have your raw super.img file
    Code:
    ./makesysrw.sh in=./existing_super_image.img size=100

    If you can't launch the script file make sure it is executable on your computer.