yashsingh1/xdaforums huggingface dataset:
[Miscellaneous Android Development] munjeni:
It seems one file is missing. Before unsharing blocks there was 7370 things inside ext4 image, after unsharing blocks one file is missing as you can see count is now 7369 :( So with this patch for e2fsck we stll have the same problem! :(

root@dm920 /media/hdd/sony/rom # /media/hdd/sony/rom/e2fsck/sbin/e2fsck -y -E unshare_blocks -E clone=zero -E shared=preserve ./system_a.ext4
e2fsck 1.46.5 (30-Dec-2021)
/: clean, 6470/6720 files, 478069/487572 blocks
root@dm920 /media/hdd/sony/rom # mount -t ext4 -o,rw system_a.ext4 rr
root@dm920 /media/hdd/sony/rom # ls -R1A rr | wc -l
7369
root@dm920 /media/hdd/sony/rom # 7370
bash: 7370: command not found

You should try compare what is deleted! It looks like com.android.vndk.current.apex is deleted?!! If we figure out why it is deleted than probably we have fix for our problem! :)

indeed deleted!

root@dm920 /media/hdd/sony/rom # ls rr/system/apex/com.android.vndk.current.apex
ls: cannot access 'rr/system/apex/com.android.vndk.current.apex': No such file or directory

That's why android runs into a boot loop! Maybe things can be fixed by implementing something which will make symlinks instead of clonning, in the same time it might save a lot of free space, in the same time it will break selinux labels! So in general the better way is try fix problem related to deletion. Good luck developers!!! :D
[Miscellaneous Android Development] Pervokur:
actually there is very simple way to do things with super partition - run Ubuntu from termux as root

no need to compile losetup ><

am I not genius? lol

You can even use gui with vnc/xsdl
[Miscellaneous Android Development] munjeni:
Ubuntu, windows, dos...etc emulators inside android is nothing new, these apps exist for almost ten years, and since Ubuntu is real Linux distro its expected that native tools like losetup or e2fsprogs is allready precompiled and working. Problem with superrepack is that its not possible to unshare blocks because partition size is not enought for that, even can't be resized to the enought size in order to unshare_blocks trought e2fsck
[Miscellaneous Android Development] starbucks2010:
Thank you for the explanation.

I don't know if I missed something or the fact that the vendor.img I use is in f2fs format but I cannot seem to be able to mount the resulted vendor.img (result after running v15 tool).

Is there a specific command to mount f2fs partitions besides -t f2fs options in mount command?

I can mount vendor.img using udisksctl loop-setup -f vendor.img but the mounted image is read-only.

Thanks.
[Miscellaneous Android Development] munjeni:
Yes I'm getting the same while want to mount ext4, trick is to pass -o,ro parameter to mount:

mount -o,ro xxx xxx
[Miscellaneous Android Development] ManhDV:
Great tool, thank you so much (y)
[Miscellaneous Android Development] munjeni:
I see that you have losetup vendor.img, thats wrong, you need to losetup super.img ! Vendor.img you no need losetup, instead directly mount with mount command
[Miscellaneous Android Development] starbucks2010:
But, if I use mount for vendor, I cannor modify anything inside this image as is always mounted read-only.
[Miscellaneous Android Development] Pervokur:
do something like this

sudo resize2fs -f system.img 2G

sudo e2fsck -y -E unshare_blocks system.img
[Miscellaneous Android Development] munjeni:
You even can't modify anything since thats dynamic partition! If you delete one file you will delete a lot off files without knowing that! See how dynamic partition work! Option is to resize partition first than perform unshare blocks, that will convert your dynamic partition to normal, after that you can do whatever you need. Wait a bit I will tell you step by step how to reconstruct whole super image with an example in details!
[Miscellaneous Android Development] starbucks2010:
I cannot pass the resize2fs command.
[Miscellaneous Android Development] munjeni:
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
[Miscellaneous Android Development] starbucks2010:
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?
[Miscellaneous Android Development] munjeni:
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
[Miscellaneous Android Development] kaiiori:
unable to convert super.sin to ext4 attached image
[Miscellaneous Android Development] munjeni:
Please read first post about "first step"
[Miscellaneous Android Development] munjeni:
New version is out & new tool!

Changelog:

- version 2 (implemented possibility to extract partition images to rw mode using Superunpack & I have made new tool called Superrepack

Superrepack tool is new, please do not use on block devices directly, need to be tested first! How to use superrepack: just drag and drop super.img over superrepack or use trought command line. Conversion from RO to RW is done in just 5 mili seccond!!! All partitions isconverted to RW mode, later I will add more command line options so you can chose which one to make RW instead of all. Enjoy! :)
[Miscellaneous Android Development] munjeni:
I don't know, this tools is made for Sony super images, and before using tools super.sin need to be extracted to raw format using unsin tools (as mentioned in OP). Does you need to do the same e.g. extract from sparse to raw format first?
[Miscellaneous Android Development] munjeni:
New version is out, forgot something sorry.
[Miscellaneous Android Development] munjeni:
I don't know anything about format of those images but I'm believing when it is installed to the phone it have the same format as Sony devices, dynamic disk is the same on every devices. This two commands should probably work for you (don't forget to change mmcblk0p13 to the real super partition!!!):

./superrepack /dev/block/mmcblk0p13

sync

You need root & you need to disable selinux and other protections before you do it, or do it trought recovery when it become available. Do in mind this tools is not tested on block devices directly but it should work, be ready for brick if it not work, see disclaimer!
[Miscellaneous Android Development] munjeni:
You must understand that dynamic disc is the same on all phones. New tool called superrepack is not the same like superunpack. Superunpack unpacks img but superrepack doing thing directly on image or on raw partition (block device). If it not work on image it should work on block device. You must understand that if your image is in sparse format it is during flashing extracted to the block device and while on block device it is the same raw format as Sony and other phones since dynamic disk is the same on every device. So superrepack should work while using directly on block device. "Should" mean it should brick your phone probably if it not work, somebody need to test and confirm.
[Miscellaneous Android Development] munjeni:
instead of image type your block device e.g. /dev/block/idontknowyourblockdevicetryfindit
[Miscellaneous Android Development] munjeni:
Do you have root? If no nothing can help, if yest steps is:

are you sure /dev/block/sde26 is super partition? If not do not perform any further steps

you need superrepack.arm64_pie

rename superrepack.arm64_pie to superrepack

upload superrepack to the /data/local/tmp

chmod it to 755 mode with command: chmod 755 /data/local/tmp/superrepack

disable selinux with command: setenforce 0

try run tool by command: /data/local/tmp/superrepack /dev/block/sde26

if all done right without error do one more command: sync

thats it. If you have error post log here. If you brick your phone read disclaimer on first post before you blame me and my tool.
[Miscellaneous Android Development] munjeni:
Its done! Now do reboot and after it boot do one more adb shell and try remount system to rw mode by command: setenforce 0; mount -o remount,rw /system
[Miscellaneous Android Development] munjeni:
It works but your mount command is not work! :) Try install better mount like busybox mount

Put busybox to /data/local/tmp than do it with busybox command: /data/local/tmp/busybox mount -o remount,rw /system

or install file explorer than install file explorer root addon, than trought file explorer remount system to rw mode
[Miscellaneous Android Development] munjeni:
Root Browser - Apps on Google Play

Powerful simple and customizable File Manager and Root Browser for superusers

play.google.com

File Explorer (Root Add-On) - Apps on Google Play

Adds root access capabilities to FX File Explorer.

play.google.com
[Miscellaneous Android Development] munjeni:
What you get with command: mount

If you not believing that your super partition is now modified try superunpack now with command: cd /data/local/tmp ; ./superunpack /dev/block/sde26

it will extract your super block device to the /data/local/tmp and all extracted partitions you can mount rw by command: mkdir rr ; mount system_a.ext4 rr

if it can't mount that mean my tool not worked (in that case repeat superrepack and look into dmesg for idea, it might be shown if something is blocked), if it mounted it mean that my tool perfectly made conversion from RO to RW but something need to be figured in relation to remount
[Miscellaneous Android Development] munjeni:
Can you show me output of the command mount?
[Miscellaneous Android Development] munjeni:
A/B idea is very good idea, but idea about having dynamic disk with RO is the crapest idea I have ever seen, I will not buy phone with dynamic disk until this B.S. is RW-able. Having my own phone under google control and not under my control is not acceptable for me.
[Miscellaneous Android Development] munjeni:
I need output of the single "mount" not of the "mount -o remount,rw /system"
[Miscellaneous Android Development] munjeni:
you can do it with adb shell for easy copy paste here instead of screenshooting, its easier for me to read log than read picture
[Miscellaneous Android Development] munjeni:
RW works?
[Miscellaneous Android Development] munjeni:
I have expected it working! Thanks for confirmation!
[Miscellaneous Android Development] lebigmac:
I'm happy for you @Articul8Madness that you finally got your system to R/W thanks to munjeni's awesome new tool. If it weren't for munjeni you would probably still be struggling to get my script running for the next 10 years! Thanks munjeni.
[Miscellaneous Android Development] starbucks2010:
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.
[Miscellaneous Android Development] munjeni:
Than I can't help, probably you need https://manpages.ubuntu.com/manpages/bionic/man8/resize.f2fs.8.html but I can't tell how it is working inside super partition even I don't know if it is in dynamic form, serch google and xda about how to make RW on f2fs
[Miscellaneous Android Development] starbucks2010:
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.
[Miscellaneous Android Development] Pervokur:
can you img upload somewhere?p
[Miscellaneous Android Development] starbucks2010:
super.img or only one of the .img files extracted from super.img?
[Miscellaneous Android Development] Pervokur:
only vendor
[Miscellaneous Android Development] starbucks2010:
s908b_avf1_vendor.zip

drive.google.com

Thank you.
[Miscellaneous Android Development] Pervokur:
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
[Miscellaneous Android Development] starbucks2010:
do you know how can I read all characteristics/features of the original image to replicate them on the new image?
[Miscellaneous Android Development] munjeni:
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
[Miscellaneous Android Development] munjeni:
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?
[Miscellaneous Android Development] starbucks2010:
I have a S22 Ultra Exynos model S908B and yes, the bootloader can be unlocked on this model.

Unsigned images can be flashed.
[Miscellaneous Android Development] munjeni:
Yes I found it trought picture, SM-S908B which leaded to the model S22, further searching also found that it is bootloader unlockable. Found some links which might point us to the right direction":

Linux 5.14 To Support F2FS Read-Only Feature - Phoronix

www.phoronix.com

f2fs: support RO feature - kernel/git/jaegeuk/f2fs.git - The f2fs filesystem

git.kernel.org

Probably only few bytes need to be patched to make image rw, I will search a bit how to do it
[Miscellaneous Android Development] munjeni:
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
[Miscellaneous Android Development] munjeni:
Try change those two bytes from 40 to 00 and see if it is now rw
[Miscellaneous Android Development] munjeni:
I'm tried, CRC is wrong after modifying it, more work is needed :)
[Miscellaneous Android Development] starbucks2010:
lemme know if you need any files/testing from my side

thank you very much for taking your time to help ... much appreciated
[Miscellaneous Android Development] munjeni:
Sorry I can't do this since a do not have phone with e2fs, even I'm unable to mount RO vendor under my Linux, it seems it is a specific Samsung f2fs format. What I found now is this -> https://xdaforums.com/t/recovery-unofficial-twrp-for-galaxy-s22-ultra-exynos.4453231/ , try ask there about how he mannaged to mount vendor rw! It might be possible that those thing is allready implemented in that twrp!
[Miscellaneous Android Development] Pervokur:
magisk can copy attrs

magisk64

--clone-attr SRC DEST clone permission, owner, and selinux context

--clone SRC DEST clone SRC to DEST
[Miscellaneous Android Development] Pervokur:
does your device support overlayfs? this is another solution for RO
[Miscellaneous Android Development] starbucks2010:
I think yes
[Miscellaneous Android Development] Pervokur:
check

mkdir -p /data/adb/overlay_test/layer1

mkdir -p /data/adb/overlay_test/layer2

mkdir -p /data/adb/overlay_test/merged

mount -t overlay -o lowerdir=/data/adb/overlay_test/layer1:/data/adb/overlay_test/layer2 overlay /data/adb/overlay_test/merged

if mount -t overlay | grep -q " /data/adb/overlay_test/merged "; then

is_overlayfs=true

fi

magisk_overlayfs/customize.sh at master · Magisk-Modules-Alt-Repo/magisk_overlayfs

Emulate read-write partition for read-only system partitions - magisk_overlayfs/customize.sh at master · Magisk-Modules-Alt-Repo/magisk_overlayfs

github.com

or extract /proc/config.gz
[Miscellaneous Android Development] starbucks2010:
I will have a read, thanks for the tip.
[Miscellaneous Android Development] munjeni:
Overlayfs is very good idea and very good feature, today every Openvrt router have this, very usefull feature! That way android RO have sense!
[Miscellaneous Android Development] iamatx:
can anyone guide me on how to do it in blue stack 5 android 7
[Miscellaneous Android Development] munjeni:
https://wiki.archlinux.org/title/Overlay_filesystem

https://xdaforums.com/t/tool-win-li...s-rw-in-super-partition.4120963/post-87121883

In short explanation you need kernel with enabled overlayfs module, than some changes in fstab like https://blog.csdn.net/jackone12347/article/details/121791592 as an example, the important is kernel support for overlayfs the rest is do-it-jurself and not so hard to understand.
[Miscellaneous Android Development] iamatx:
thankyou @munjeni is this similar

i mean it will work for BS

https://xdaforums.com/t/module-magiskhide-props-config-safetynet-prop-edits-and-more-v6-1-2.3789228/
[Miscellaneous Android Development] munjeni:
I don't know! Even I don't know what is needed for android to make overlayfs work, I'm just shared some links which might help! I'm not working on android for almost 2-3 and maybe more years
[Miscellaneous Android Development] Pervokur:
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)
[Miscellaneous Android Development] iamatx:
PS D:\A.T\DESKTOP\platform-tools> ./adb root

restarting adbd as root

PS D:\A.T\DESKTOP\platform-tools> adb remount

Not running as root. Try "adb root" first.

PS D:\A.T\DESKTOP\platform-tools>

idk
[Miscellaneous Android Development] iamatx:
thanks but am trying to do it in Bluestack 5 7/9
[Miscellaneous Android Development] munjeni:
Even I have done true mainline kernel and Openvrt on Xperia Z1 Compact -> https://xdaforums.com/t/native-lede...ria-z1-compact-as-a-true-wifi-router.3720998/
[Miscellaneous Android Development] iamatx:
thankyou for in detail guide but

OnePlus8T:/ $ su exec /system/bin/mount -t overlay overlay -o lowerdir=/system

mount: bad /etc/fstab: No such file or directory

OnePlus8T:/ $ mount -t overlay overlay -o lowerdir=/system

mount: bad /etc/fstab: No such file or directory

su mount -t overlay overlay -o lowerdir=/system

su: exec failed for -t Error:permission denied

drwxrwxr-x 16 system system 4096 2022-06-24 06:46 system

i guess i need to do it with.vdi file
[Miscellaneous Android Development] Pervokur:
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? =)
[Miscellaneous Android Development] munjeni:
You must be root as a first thing to do :)
[Miscellaneous Android Development] munjeni:
Yes android fs mannager probably not allow all this. Take a look at https://android.googlesource.com/platform/system/core/+/master/init/

init/first_stage_mount.cpp - platform/system/core - Git at Google

fs_mgr/fs_mgr_overlayfs.cpp - platform/system/core - Git at Google
[Miscellaneous Android Development] Pervokur:
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.
[Miscellaneous Android Development] Pervokur:
you have linked file about early mount, but I'm doing it before zygote starts.
[Miscellaneous Android Development] munjeni:
Actualy I'm out off interest since my phone do not have super partition, its old xperia 10, but good to know that, thanks!
[Miscellaneous Android Development] iamatx:
@Pervokur can u guide me am not able to get it done it's with Bluestack that they add stuff to block the editing system.

able to do it directly by accessing through windows and editing it with notepad ++ the data.vdi file
[Miscellaneous Android Development] munjeni:
https://appuals.com/root-bluestacks/
[Miscellaneous Android Development] iamatx:
thankyou but bluestack 5 has a broken mount magisk doesn't work on it even modded bcoz their dev did this
[Miscellaneous Android Development] Pervokur:
I did another ultimate "systemless" crap

mount -t ext4 system.img /somefolder

mount /somefolder/system /system

It's should be done before zygote starts. Or after booting and just force restart zygote

su -c killall surfaceflinger
[Miscellaneous Android Development] munjeni:
Nothing new!
[Miscellaneous Android Development] Pervokur:
but somehow I didn't see something like this in recommendations of how to make system.img smaller. Isn't it pretty simple to move folders with apks to /data and mount them on empty folders in /system right before zygote starts?