[Android Software/Hacking General [Developers Only]] lebigmac:
Mod Edit

New thread is located here: https://xdaforums.com/t/script-mount-system-as-read-write-android-10.4240703/

Mod Edit End

So I managed to successfully run the command that @topjohnwu suggested on Twitter

e2fsck -E unshare_blocks system.ext4

directly on the extracted system.ext4 image file (which was extracted from super.img using this amazing tool)

And the image still fails to be mounted as rw using the command below. Mounting as ro works just fine though.

sudo mount -t ext4 -o loop,rw system.ext4 /mnt/dir
mount: /mnt/dir: wrong fs type, bad option, bad superblock on /dev/loop18, missing codepage or helper program, or other error.

root:~# e2fsck -E unshare_blocks system.ext4
[...]
/system/lib/libpdfium.so (inode #3345, mod time Thu Jan 1 02:00:00 2009)
/system/lib/libhwui.so (inode #3260, mod time Thu Jan 1 02:00:00 2009)
/system/lib/libchrome.so (inode #3204, mod time Thu Jan 1 02:00:00 2009)
/system/lib/libbluetooth.so (inode #3184, mod time Thu Jan 1 02:00:00 2009)
/system/apex/com.android.runtime.release.apex (inode #119, mod time Thu Jan 1 02:00:00 2009)
clone_file: Could not allocate block in ext2 filesystem returned from clone_file_block
clone_file: Could not allocate block in ext2 filesystem returned from clone_file_block
Couldn't clone file: Could not allocate block in ext2 filesystem
File /system/usr/keylayout/Vendor_054c_Product_05c4_Version_8100.kl (inode #5649, mod time Thu Jan 1 02:00:00 2009)
has 1 multiply-claimed block(s), shared with 3 file(s):
/system/usr/keylayout/Vendor_054c_Product_09cc_Version_8100.kl (inode #5653, mod time Thu Jan 1 02:00:00 2009)
/system/usr/keylayout/Vendor_054c_Product_09cc_Version_8000.kl (inode #5652, mod time Thu Jan 1 02:00:00 2009)
/system/usr/keylayout/Vendor_054c_Product_05c4_Version_8000.kl (inode #5648, mod time Thu Jan 1 02:00:00 2009)
clone_file: Could not allocate block in ext2 filesystem returned from clone_file_block
Couldn't clone file: Could not allocate block in ext2 filesystem
File /system/usr/keylayout/Vendor_054c_Product_05c4_Version_8111.kl (inode #5650, mod time Thu Jan 1 02:00:00 2009)
has 1 multiply-claimed block(s), shared with 1 file(s):
/system/usr/keylayout/Vendor_054c_Product_09cc_Version_8111.kl (inode #5654, mod time Thu Jan 1 02:00:00 2009)
clone_file: Could not allocate block in ext2 filesystem returned from clone_file_block
Couldn't clone file: Could not allocate block in ext2 filesystem
File /system/usr/keylayout/Vendor_054c_Product_09cc.kl (inode #5651, mod time Thu Jan 1 02:00:00 2009)
has 1 multiply-claimed block(s), shared with 1 file(s):
/system/usr/keylayout/Vendor_054c_Product_05c4.kl (inode #5647, mod time Thu Jan 1 02:00:00 2009)
clone_file: Could not allocate block in ext2 filesystem returned from clone_file_block
Couldn't clone file: Could not allocate block in ext2 filesystem
File /system/usr/keylayout/Vendor_054c_Product_09cc_Version_8000.kl (inode #5652, mod time Thu Jan 1 02:00:00 2009)
has 1 multiply-claimed block(s), shared with 3 file(s):
/system/usr/keylayout/Vendor_054c_Product_09cc_Version_8100.kl (inode #5653, mod time Thu Jan 1 02:00:00 2009)
/system/usr/keylayout/Vendor_054c_Product_05c4_Version_8100.kl (inode #5649, mod time Thu Jan 1 02:00:00 2009)
/system/usr/keylayout/Vendor_054c_Product_05c4_Version_8000.kl (inode #5648, mod time Thu Jan 1 02:00:00 2009)
clone_file: Could not allocate block in ext2 filesystem returned from clone_file_block
Couldn't clone file: Could not allocate block in ext2 filesystem
File /system/usr/keylayout/Vendor_054c_Product_09cc_Version_8100.kl (inode #5653, mod time Thu Jan 1 02:00:00 2009)
has 1 multiply-claimed block(s), shared with 3 file(s):
/system/usr/keylayout/Vendor_054c_Product_09cc_Version_8000.kl (inode #5652, mod time Thu Jan 1 02:00:00 2009)
/system/usr/keylayout/Vendor_054c_Product_05c4_Version_8100.kl (inode #5649, mod time Thu Jan 1 02:00:00 2009)
/system/usr/keylayout/Vendor_054c_Product_05c4_Version_8000.kl (inode #5648, mod time Thu Jan 1 02:00:00 2009)
clone_file: Could not allocate block in ext2 filesystem returned from clone_file_block
Couldn't clone file: Could not allocate block in ext2 filesystem
File /system/usr/keylayout/Vendor_054c_Product_09cc_Version_8111.kl (inode #5654, mod time Thu Jan 1 02:00:00 2009)
has 1 multiply-claimed block(s), shared with 1 file(s):
/system/usr/keylayout/Vendor_054c_Product_05c4_Version_8111.kl (inode #5650, mod time Thu Jan 1 02:00:00 2009)
clone_file: Could not allocate block in ext2 filesystem returned from clone_file_block
Couldn't clone file: Could not allocate block in ext2 filesystem
File /system/usr/share/zoneinfo/tz_version (inode #5688, mod time Thu Jan 1 02:00:00 2009)
has 1 multiply-claimed block(s), shared with 1 file(s):
/system/apex/com.android.runtime.release.apex (inode #119, mod time Thu Jan 1 02:00:00 2009)
Multiply-claimed blocks already reassigned or cloned.

File /system/usr/share/zoneinfo/tzdata (inode #5689, mod time Thu Jan 1 02:00:00 2009)
has 124 multiply-claimed block(s), shared with 1 file(s):
/system/apex/com.android.runtime.release.apex (inode #119, mod time Thu Jan 1 02:00:00 2009)
Multiply-claimed blocks already reassigned or cloned.

Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 3A: Optimizing directories
Failed to optimize directory /system/fonts (2249): Could not allocate block in ext2 filesystem
Failed to optimize directory /system/lib (2995): Could not allocate block in ext2 filesystem
Failed to optimize directory /system/lib/vndk-29 (3507): Could not allocate block in ext2 filesystem
Failed to optimize directory /system/lib64 (3762): Could not allocate block in ext2 filesystem
Failed to optimize directory /system/lib64/vndk-29 (4434): Could not allocate block in ext2 filesystem
Pass 4: Checking reference counts
Pass 5: Checking group summary information

/: ***** FILE SYSTEM WAS MODIFIED *****

/: ********** WARNING: Filesystem still has errors **********

/: 5704/6048 files (20.8% non-contiguous), 655526/655526 blocks