[TOOL][WIN,LIN,AND,DARW] Super image tools | extract or make partitions RW in super partition

Search This thread

munjeni

Senior Member
Jun 2, 2011
9,580
22,215
For example you have extracted system_a partition with superunpack:

Do not pass 1 at the end since it somehow make partition with errors! Simple without 1 at the end like this:
../superunpack super_X-FLASH-ALL-2389.bin

Code:
  partition_1_name = system_a
    attributes = 0x1
    first_extent_index = 0x0
    num_extents = 0x1
    group_index = 0x1
    partition_group = somc_dynamic_partitions_a
    extent num_sectors = 0x3c7998 (0x78f33000 bytes total)
    extent target_type = 0x0
    extent target_data = 0x800 (dumping offset = 0x100000)
    extent target_source = 0x0
      Filetype EXT4. EXT4 size = 0x77094000
      Dumping system_a.ext4 ...
      ....................................................
      ....................................................
      ....................................................
      ....................................................
      ..............................

Its extracted as a true RO dynamic partition. Next step is to resize it to the enought size that e2fsck have enought resource for clone blocks during unshare blocks:

Code:
resize2fs system_a.ext4 2G

Now you have resized it to 2 Gb. Next step is unshare blocks. By that way e2fsck converts dynamic partition to normal partition making them rw too:

Code:
e2fsck -y -E unshare_blocks system_a.ext4

If everything right you will not see any error code. To be sure you can do it again:

Code:
e2fsck -y -E unshare_blocks system_a.ext4

If you see errors do everything from begining, surepunpack...etc and resize partition to a longer size than 2G. If no error you are ready for next step:

Code:
e2fsck -fy system_a.ext4

This step checks for errors and fix them. if you se no errors at the end you are ok. In the sime time your partition is RW! You should now mont them and modify:

Code:
[email protected] /media/hdd/sony/rom # mount -t ext4 -o,rw system_a.ext4 rr
[email protected] /media/hdd/sony/rom # ls rr
acct  bin         cache   d     data_mirror    default.prop  etc   init.environ.rc  lost+found  mnt  oem          proc     res     storage  system      vendor
apex  bugreports  config  data  debug_ramdisk  dev           init  linkerconfig     metadata    odm  postinstall  product  sdcard  sys      system_ext

As you can see its mounted rw without problem. Now when you modify everything you need to resize partition back to the needed size, look at this from the top:

Code:
extent num_sectors = 0x3c7998 (0x78f33000 bytes total)

As you see partition need to be this size: (0x78f33000 / 4096) = 0x78F33 . Now convert HEX to DEC trought this site -> https://www.binaryhexconverter.com/hex-to-decimal-converter . Put 78F33 and convert to dec you will get something like 495411 , now you are ready resize partition back to the desired size:

Don't forget to unmont partition first!
Code:
umount rr
e2fsck -fy system_a.ext4
resize2fs system_a.ext4 495411

And if everything right it will be resized. In my case since I didn't deleted anything in mounted partition I have no enought space to resize to the desired size and getting error:

Code:
error: New size smaller than minimum (506087)

In case of error its clear that you need to delete much more files in partition in order to resize them back to desired size!!! That explain why superrepack tool is not working on almost half of the devices today! But if you done them sucesfully you can write back modified partition to the super partition this way:

see this log from the top:
extent target_data = 0x800 (dumping offset = 0x100000)
extent num_sectors = 0x3c7998 (0x78f33000 bytes total)

Convert 0x100000 from hex to dec = 1048576
Convert 0x78f33000 from hex to dec = 2029203456

Now command to write them back to super partition is:

Code:
dd if=system_a.ext4 of=super.img bs=1 seek=1048576 count=2029203456 conv=notrunc
sync

Easy and clear now? Thats it! In your case you will need img2simg because if I am not wrong it was compressed sparse image in your case? Hope this help! :)
 
Last edited:
  • Like
Reactions: starbucks2010

starbucks2010

Senior Member
Jun 30, 2010
3,154
1,866
I cannot pass the resize2fs command.
 

Attachments

  • vendor_error_resize2fs.png
    vendor_error_resize2fs.png
    17.7 KB · Views: 10

munjeni

Senior Member
Jun 2, 2011
9,580
22,215
Try everything from the beginning! Do superunpack first, than the rest, if possible post here log of the every each step if you get any error, I will try to help you. Read carefully tutorial above your post
 

starbucks2010

Senior Member
Jun 30, 2010
3,154
1,866
Ok, I'll do that. One more thing, the super unpacked resulted files are system.bin, vendor.bin. etc ... .bin files not .img files. Can this be an issue?
 

munjeni

Senior Member
Jun 2, 2011
9,580
22,215
Yes! Take a look at hex first 4 magic bytes and determine is it ext4 or something else e.g. sparse image. Tutorial above is for ext4 partitions only! If its is something else whole procedure is diferent since calculation need to be figured out e.g. if it is sparse and you unsparse and again sparse it will be for sure with diferent size so calculation need to be changed too and I do not have time for help! Hope ext4 is enought to understand what need to be done.

For example first 4 bytes is 3A FF 26 ED

search google for "android header magic ed26ff3a", the result would be android sparse which mean you have sparse image, so you need simg2img to unsparse them. The similar way you can figure almost every other format trought hex editor and google search
 
Last edited:

starbucks2010

Senior Member
Jun 30, 2010
3,154
1,866
I know that all 4 images (system.img, vendor,.img product.img and odm.img) inside super.img are f2fs type. This is probably the reason of that error.
 

starbucks2010

Senior Member
Jun 30, 2010
3,154
1,866
yes, super.img is a dynamic partition.
I will give up as samsung seems to make it impossible to mount rw their f2fs partitions.

Thank you very much for your help anyway.
 

Attachments

  • vendor_error_resize_f2fs.png
    vendor_error_resize_f2fs.png
    62.7 KB · Views: 9

Pervokur

Senior Member
Feb 15, 2022
145
44
can't remove RO.... mb it's should be easy to create new img and copy everything to it

Info: sector size = 512
Info: total sectors = 3778792 (1845 MB)
Info: MKFS version
"5.4.0-62-generic"
Info: FSCK version
from "4.19.136-perf+"
to "4.19.136-perf+"
Info: superblock features = 6008 : extra_attr compression ro Info: superblock encrypt level = 0, salt = 00000000000000000000000000000000
Info: total FS sectors = 3778792 (1845 MB)
Both cp1 and cp2 are valid. Info: checkpoint state = 281 : allow_nocrc nat_bits unmount
Info: checkpoint state = 81 : nat_bits unmount
Info: CKPT version = 4322 Info: Checked valid nat_bits in checkpoint
Info: checkpoint state = 281 : allow_nocrc nat_bits unmount

[FSCK] Max image size: 1309 MB, Free space: 352 MB
[FSCK] Unreachable nat entries [Ok..] [0x0][FSCK] SIT valid block bitmap checking [Ok..]
[FSCK] Hard link checking for regular file [Ok..] [0x0][FSCK] valid_block_count matching with CP [Ok..] [0x51156]
[FSCK] valid_node_count matching with CP (de lookup) [Ok..] [0x9f6]
[FSCK] valid_node_count matching with CP (nat lookup) [Ok..] [0x9f6]
[FSCK] valid_inode_count matched with CP [Ok..] [0x868]
[FSCK] free segment_count matched with CP [Ok..] [0x10a] [FSCK] next block offset is free [Ok..]
[FSCK] fixing SIT types [FSCK] other corrupted bugs [Ok..]
Done: 0.077075 secs
 
  • Like
Reactions: starbucks2010

starbucks2010

Senior Member
Jun 30, 2010
3,154
1,866
do you know how can I read all characteristics/features of the original image to replicate them on the new image?
 

munjeni

Senior Member
Jun 2, 2011
9,580
22,215
You must clone things if you plan to copy from partition to partition, including uuids and things, selinux labels, permissions....etc and thats not a very easy. Thats not something like cp -fr xx xx . One more thing, it is signed image? In that case apsolutly no way to make RW
 

munjeni

Senior Member
Jun 2, 2011
9,580
22,215
I'm checked your vendor image, yes its signed! See picture. Without a valid key you can NOT sign/modify/create new image, forget it! I realy don't know how things work on Samsung phones so I will not comment further. Does Samsung can be bootloader unlocked to allow unsigned images boot? What is your phone model?
 

Attachments

  • 2022-07-06_091658.jpg
    2022-07-06_091658.jpg
    72 KB · Views: 9
Last edited:

starbucks2010

Senior Member
Jun 30, 2010
3,154
1,866
I have a S22 Ultra Exynos model S908B and yes, the bootloader can be unlocked on this model.
Unsigned images can be flashed.
 

munjeni

Senior Member
Jun 2, 2011
9,580
22,215
I'm afraid it won't be that easy! Look at this:

Queued up yesterday into the F2FS "dev" code for its kernel driver is the RO feature when marked in a file-system's superblock then allows bypassing the provisioning/reserve spaces and segment summary area (SSA). Similarly, yesterday was a merge for the RO feature to the f2fs-tools user-space component for this file-system. "This patch adds a readonly feature on small partitions by eliminating on-disk layout for data writes such as provisioning/reserved space and SSA. This requires f2fs updates to understand RO feature in superblock."

Probably our ro images is precisely adjusted to the minimum size and that there is no room for expansion e.g. to make them rw
 

munjeni

Senior Member
Jun 2, 2011
9,580
22,215
Try change those two bytes from 40 to 00 and see if it is now rw
 

Attachments

  • 2022-07-06_101651.jpg
    2022-07-06_101651.jpg
    307.4 KB · Views: 7

Top Liked Posts

  • There are no posts matching your filters.
  • 2
    I'm not a expert in overlayfs and android, I just did couple of .rc scripts for magisk (overlay.d folder in boot ramdisk) for testing.

    There was something like this:

    on post-fs-data
    exec /system/bin/mount -t overlay overlay -o lowerdir=/system,upperdir=/data/overlay/system/upper,workdir=/data/overlay/system/work /system


    test when execute cmd after boot:

    mount | grep " / "
    /dev/block/dm-0 on / type ext4 (ro,seclabel,nodev,relatime,discard)

    mount | grep "/system"
    overlay on /system type overlay (rw,seclabel,relatime,lowerdir=/system,upperdir=/data/overlay/system/upper,workdir=/data/overlay/system/work)


    For testing I recommend to use something like

    on post-fs-data && property:persist.sys.safemode=true
    setprop persist.sys.safemode ""
    »»»»other commands

    boot to safemode and see if your system still works)
    Yes thats it! What need to be manualy tried first before anything is:

    Code:
    mkdir -p /data/local/tmp/work
    mkdir -p /data/local/tmp/upper
    mount -t overlay overlay -o lowerdir=/system,upperdir=/data/local/tmp/upper,workdir=/data/local/tmp/work /system

    If that work than it will definitelly work on ramdisk level. Overlayfs is an powerfull thing, ideal to beat our android RO. I'm running overlayfs on Openvrt ruter Fritz Box 7360SL and an external 1Tb hard disc, I'm compiled a ton of things that way from 2017. and I have now it like full Linux envinronment with compiled a lot of things directly inside router, Apache, PHP, Mysql, GCC, Python, Torrent.... many more things , see how powerfull overlayfs can convert an router into an true Linux -> https://pastebin.com/5zCQTrSc :) And when I disconnect external hard disc everything is stock and unmodified, no need to mess by reinstalling anything.

    List of things compiled on router directly:
    Code:
    [email protected]:~# ls -l /overlay/ROM/squashfs-root
    total 1808
    drwxr-xr-x  7 root  root     4096 May  8  2018 MediaInfo
    drwxr-xr-x  7 root  root     4096 May  7  2018 MediaInfoLib
    drwxr-xr-x  6 root  root     4096 Nov  2  2017 ZenLib
    drwxr-xr-x 28  1001  1001    4096 May 26  2018 apr-1.6.3
    drwxr-xr-x 21  1001  1001    4096 May 27  2018 apr-util-1.6.1
    drwxrwxr-x  9 root  root     4096 May 26  2018 autoconf-2.69
    drwxr-xr-x 11  1000   998    4096 May 26  2018 automake-1.16
    drwxr-xr-x  2 root  root     4096 Jun 21  2018 bin
    drwxr-xr-x 14 root  root     4096 May 28  2018 bison-2.7.91
    drwxr-xr-x  2 root  root     4096 May 27  2018 bzip2-1.0.6
    drwxrwxr-x 11 root  root     4096 May 25  2018 coreutils-8.29
    drwxr-xr-x  2 root  root     4096 May 26  2018 crypt_0_03
    drwxr-xr-x 13  1000  1000    4096 May 27  2018 curl-7.60.0
    drwxr-xr-x 22 root  root     4096 Jun 20  2018 cyrus-sasl
    drwxrwxr-x 14   100 users    4096 Apr 13  2017 db-6.2.32
    drwxr-xr-x  2 root  root     4096 Jun 19  2018 dev
    drwxr-xr-x 29 root  root     4096 Jun 22  2018 etc
    drwxrwxr-x 14  1000  1000    4096 May 26  2018 expat-2.1.0
    drwxr-xr-x 11 root  root     4096 May 28  2018 flex-2.6.0
    drwxrwxr-x 22  1000  1000    4096 May 27  2018 fontconfig-2.13.0
    drwxr-xr-x  8  1000 users    4096 May 27  2018 freetype-2.9.1
    drwxr-xr-x  2 root  root     4096 May 26  2018 getconf-master
    drwxr-xr-x 10 root  root     4096 May 27  2018 gettext-0.19.8.1
    drwxr-xr-x 27 root  root    20480 Jun  1  2018 git-master
    drwxr-xr-x 16  1001 root     4096 May 27  2018 gmp-6.1.2
    drwxr-xr-x  7 root  root     4096 May 27  2018 gperf-3.1
    drwxr-sr-x 12 root     40    4096 May 28  2018 httpd-2.4.33
    drwxr-xr-x 13 root  root     4096 May 29  2018 imap-2007f
    -rwxr-xr-x  1 root  root       78 Nov 18  2017 init
    drwxr-xr-x  4   500 users    8192 May 27  2018 jpeg-9c
    drwxr-xr-x 11 root  root     4096 Jun 21  2018 lib
    drwxrwxr-x 15 root  root     4096 May 27  2018 libgd-gd-2.2.5
    drwxr-xr-x 22 root  root     4096 May 26  2018 libiconv-1.15
    drwxr-xr-x  7  1000  1000    4096 May 26  2018 libmbfl-1.2.0
    drwxrwxrwx  9   500 adm      4096 May 26  2018 libmcrypt-2.5.8
    drwxr-xr-x 13   179  1001    8192 Apr  7  2020 libpcap-1.9.1
    drwxr-xr-x 12  1004  5101    4096 May 27  2018 libpng-1.6.34
    drwxr-xr-x 13  1000  1000    4096 May 27  2018 libssh2-1.8.0
    drwxr-xr-x 10 root  root     4096 Feb 18  2019 libtorrent
    drwxrwxr-x  4  1000  1000    4096 May 27  2018 libuuid-1.0.3
    drwxrwxr-x 19  1000  1000    8192 May 28  2018 libxml2-2.9.8
    drwxr-xr-x 13 root  root     4096 May 31  2018 lynx2-8-8
    drwxr-xr-x  4 root  root     4096 May 26  2018 lzip-1.19
    drwxr-xr-x 10 root  root     4096 May 26  2018 mhash-0.9.9.9
    drwxr-xr-x  2 root  root     4096 May 28  2018 mnt
    -rw-r--r--  1 root  root  1374500 Dec  6  2009 mpfr-2.4.0.tar.gz
    drwxr-xr-x 11 root  root     4096 Feb 18  2019 musl-1.1.16
    drwxr-xr-x  2 root  root     4096 May 28  2018 musl_crypt
    drwxrwxrwx 32  7155    10    4096 May 27  2018 mysql-5.1.73
    drwxr-xr-x 18  1001 users    4096 May 27  2018 ncurses-6.1
    drwxr-xr-x 18 root  root     4096 May 26  2018 openssl-1.1.0h
    drwxr-xr-x  2 root  root     4096 Nov 18  2017 overlay
    drwxr-xr-x  9  1169  1169    8192 May 27  2018 pcre-8.42
    drwxr-xr-x  8  1169  1169    4096 May 26  2018 pcre2-10.31
    drwxr-xr-x 27   544   513    8192 May 26  2018 perl-5.26.2
    drwxr-xr-x 19 root  root     4096 May 30  2018 php-7.2.6
    drwxrwxr-x  5  1000  1000    4096 May 27  2018 pkg-config-0.29.2
    drwxr-xr-x  2 root  root     4096 Nov 18  2017 proc
    drwxr-xr-x  2 root  root     4096 Nov 18  2017 rom
    drwxr-xr-x  4 root  root     4096 Jun 21  2018 root
    drwxr-xr-x  9 root  root     4096 Feb 18  2019 rtorrent
    drwxr-xr-x  2 root  root     4096 Jun 21  2018 sbin
    drwxr-xr-x 22 root  root     4096 Jun 20  2018 sendmail-8.15.2
    drwxr-xr-x  9   556    21    4096 Apr  7  2020 ssldump-0.9b3
    -rw-r--r--  1 root  root   137435 Apr  7  2020 ssldump-0.9b3.tar.gz
    drwxr-xr-x  2 root  root     4096 Nov 18  2017 sys
    drwxr-xr-x  2 29189 29189    4096 May 25  2018 termcap-1.3.1
    drwxr-xr-x 12  1107  5100    4096 May 27  2018 tiff-4.0.9
    drwxrwxrwt  2 root  root     4096 May 25  2018 tmp
    drwxr-xr-x 25 root  root     4096 Jun 21  2018 usr
    drwxr-xr-x  6 root  root     4096 May 27  2018 uuid-1.6.2
    lrwxrwxrwx  1 root  root        4 May 25  2018 var -> /tmp
    drwxr-xr-x  4 root  root     4096 Nov 18  2017 www
    drwxr-xr-x  6 root  root     4096 Feb 17  2019 xmlrpc-c
    drwxr-xr-x 14 root  root     4096 May 28  2018 zlib-1.2.11
    [email protected]:~#
    1
    Even I have done true mainline kernel and Openvrt on Xperia Z1 Compact -> https://forum.xda-developers.com/t/...ria-z1-compact-as-a-true-wifi-router.3720998/
    1
    kernel of my phone prevents mounting /system, so magisk can't mount modules

    but this actually works

    rc script:
    on load_persist_props_action
    exec -- /system/bin/mount -t overlay overlay -o lowerdir=/system,upperdir=/data/system/ou,workdir=/data/system/ow /system

    on zygote-start
    exec -- /system/bin/mount /sbin/.magisk/zygisk/app_process32 /system/bin/app_process32
    exec -- /system/bin/mount /sbin/.magisk/zygisk/app_process64 /system/bin/app_process64

    #####

    manualy "mounting" all modules

    su -c cp -r /sbin/.magisk/modules/*/system/* /system

    doing all stuff in couple of commands...that's illegal, right? =)
    Yes android fs mannager probably not allow all this. Take a look at https://android.googlesource.com/platform/system/core/+/master/init/

    1
    I mean that's actually works for me. No problems when upper layer in /data.
    I also tried different partitions and with some others it's works only with SE linux disabled.
  • 43
    Disclaimer:

    Super image tools was made for testing and educational purposes, ME is not responsible for what you do on/with your device using our tools, you must agree that you using our tools on your own risk, I am not responsible for anything else!


    How to use superunpack:

    - First step, unpack super.sin using my tool or use @IgorEisberg unsin tool
    - Step two, Superunpack. On windows just drag and drop unpacked super image onto our exe to start extraction. Also you can use it from command line, from script or from etc. On Linux use it from command line. No need to set slot like it was a case on lpunpack, our tool will auto extract all slot images for you, enjoy!
    - If you need to unpack partition images in RW mode add parameter 1 at the end of command line e.g. "superunpack super.img 1", than resize partition using resize2fs, repair and unshare blocks using e2fsck. Or if you unpack without rw you no need to resize or repair it, just mount it ro.

    How to manualy patch super partition in under Linux:
    https://forum.xda-developers.com/t/...s-rw-in-super-partition.4120963/post-87112415

    Note that, superunpack is a tool for extract all logical partitions from super image or directly from super partition.

    How to use superrepack:

    adb push superrepack.arm64_pie /data/local/tmp
    adb shell
    su
    cd /data/local/tmp
    mv superrepack.arm64_pie superrepack
    chmod 755 superrepack
    stop
    ./superrepack /dev/block/bootdevice/by-name/super system_a
    sync
    reboot

    Note that, superrepack is a tool to convert logical RO partitions iside your phone super partition to RW mode without extracting anything, all things is done on the fly directly inside super partition/image! In this example system_a partiton is converted to the rw mode, if you need other partitions to rw just change system_a argument. Or if you need all partitions to rw mode do it without partition rw argumet e.g: "./superrepack /dev/block/bootdevice/by-name/super". YOU MUST RUN TOOL 4-5 TIMES UNTIL ALL ERRORS DISAPEARS!!! One of the well known errors is: "Couldn't clone file: Could not allocate block in ext2 filesystem". Look at /data/local/tmp/script.log each time and make sure it not contain any error otherwise you are not done things right and partition is not repaired yet!!! More info -> https://forum.xda-developers.com/t/...s-rw-in-super-partition.4120963/post-84966715

    Platform:

    - Superunpack is working on Windows, Linux, Android, Darwin11, just chose right binary.
    - Superrepack is working only under android


    Changelog:

    - version 1 (21.Jun.2020), initial version
    - version 1.1 (22.Jun.2020), dump file format detection, partition size correction in case ext4, partition group detection, have extraction progress bar, improvements
    - version 2 (03.04.2021) implemented possibility to extract partition images to rw mode using Superunpack & I have made new tool called Superrepack
    - version 2 (04.04.2021) implemented arguments so you would do conversion on single partition instead of doing it on all partitions
    - version 3 (04.04.2021) implemented return codes and implemented output logs to be more scripting friendly
    - version 4 - not released
    - version 5 (08.04.2021) implemented resize and repair partitions after switching to rw mode. Implemented build script for building resize2fs, e2fsck, simg2ims, img2simg, lptools
    - version 6 (08.04.2021) better loop device detection and setup
    - version 7 (08.04.2021) fix selinux status detection
    - version 8 (15.04.2021) fix loop device setup in superrepack
    - version 9 (16.04.2021) make losetup android compatible
    - version 10 - not released
    - version 11 (01.05.2021) simplified, removed needs for parameter rw, implemented dm-verity disabler
    - version 12 (05.05.2021) make old logs always deleted before fresh log is created, this prevent concentation with old logs
    - version 13 (06.05.2021) make linux version so you should do the things on your super partition dump in linux machine
    - version 14 (07.05.2021) fix compilation mess between linux and android
    - version 15 (08.05.2021) use libselinux to determine and set selinux to permissive mode instead of popening getenforce-setenforce tools

    Credits:

    - me and me :)


    Source code:

    - source code -> https://github.com/munjeni/super_image_dumper
    18
    I'm not one of those who make paid software and promote on xda, my work is always free. Even I'm always providing source code for free, source code of this tool is here -> https://github.com/munjeni/super_image_dumper , enjoy! ;)
    3
    Version 7 is out! V6 had error detecting slinux status. I do not have device with super partition for test my tool but I have only hope that all is ok. Let me know! :)
    3
    Pixel 4a, working. V13
    3
    how about simg2img