User:AskorbinovayaKislota/MountFromAndroid
Mounting PostmarketOS root from Android
You might want to chroot into PostmarketOS rootfs when your system becomes unbootable, but Android is working
We are using Termux utilities. Please install util-linux and e2fsprogs
Also, run everything with sudo, do not use su (or it will use /system/bin utils)
You have to turn off selinux, otherwise you will get I/O error when trying to access loop devices, and this message in dmesg:
[ 4008.063490] type=1400 audit(1745848927.113:1971): avc: denied { read } for comm="loop36" path="/dev/block/mmcblk0p2" dev="tmpfs" ino=1472 scontext=u:r:kernel:s0 tcontext=u:object_r:block_device:s0 tclass=blk_file permissive=0
Set permissive mode: setenforce 0
Verify that you are in permissive: getenforce
$PART
is your PostmarketOS partition, example: /dev/block/by-name/pmos
Setup loop device:
losetup --partscan --show -f $PART
It will print the found loop device name, example on my system: /dev/block/loop36
Now, try mounting the root partition:
mkdir pmos mount /dev/block/loop36p2 -t ext4 pmos/
Unfortunately, it fails with mount: '/dev/block/loop36p2'->'pmos/': Invalid argument
Dmesg shows the full error:
[ 426.524451] EXT4-fs (loop36p2): couldn't mount RDWR because of unsupported optional features (10000)
My old 4.19 kernel doesn't support new ext4 features that are used in newer kernels.
To fix it, run (answer suggested by deepseek):
tune2fs -O ^metadata_csum_seed /dev/block/loop36p2 e2fsck /dev/block/loop36p2
Now try mounting it again:
mount /dev/block/loop36p2 -t ext4 pmos/ mount /dev/blocm/loop36p1 pmos/boot/
When you are done, detach the loop device and restore selinux enforcing:
losetup -d /dev/block/loop36 setenforce 1 getenforce
Without --partscan
If you are mounting it from recovery, you only have Android's toybox, and its losetup does not support the --partscan
argument, but you can specify offsets manually.
Run sgdisk --print $PART
Example output:
Disk /dev/block/mmcblk0p2: 125171712 sectors, 59.7 GiB Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): AF858D45-A92B-4ECA-A748-A8E5CE8DE816 Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 125171678 Partitions will be aligned on 2048-sector boundaries Total free space is 2014 sectors (1007.0 KiB) Number Start (sector) End (sector) Size Code Name 1 2048 499711 243.0 MiB EF00 primary 2 499712 125171678 59.4 GiB 8305 primary
Note the sector size (512), offset/size for boot partition (2048-499711) and for root partition (499712-125171678)
Now, create the loopback devices:
losetup -o $(( 2048*512 )) -S $(( (499711-2048)*512 )) --show -f $PART losetup -o $(( 499712*512 )) -S $(( (125171678-499712)*512 )) --show -f $PART
Notice the values - first we setup the boot partition, then root partition, and then losetup prints where did it setup this (example: /dev/block/loop36
, /dev/block/loop37
)
Don't forget that this time you should use loop36/37 instead of loop36p1/loop36p2