postmarketos-initramfs: fix device mapper path on android devices with subpartitions (MR 5632)

On android devices using subpartitions, during boot we set up the
subpartitions so the rootfs is /dev/mapper/userdata2, however during
resize_root_partition() we resolve the original block device (e.g. sda17
on the op6) and re-create the device mapper. This results in the cached
rootfs path being wrong (since after resize it's created as
/dev/mapper/sda17p2).

Cache the subpartition source device so we re-create it to be
consistent. Otherwise the filesystem resize fails and the device drops
to debug shell on first boot.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-09-25 18:19:00 +02:00
parent cd3e041ba2
commit 897dd2b832
No known key found for this signature in database
GPG Key ID: 0583312B195F64B6
2 changed files with 12 additions and 5 deletions

View File

@ -1,8 +1,8 @@
# Maintainer: Caleb Connolly <caleb@postmarketos.org>
# Co-Maintainer: Clayton Craft <clayton@craftyguy.net>
pkgname=postmarketos-initramfs
pkgver=3.3.4
pkgrel=1
pkgver=3.3.5
pkgrel=0
pkgdesc="Base files for the postmarketOS initramfs / initramfs-extra"
url="https://postmarketos.org"
options="!check" # no tests
@ -93,6 +93,6 @@ sha512sums="
929a8e6cca6b2b4ac6af89fc3912e80315f51c9bf6e9479124ccb7ebe9e99c6c1cafb98d3aa01b0a76a2f6e0071ba3eb86c7a2169a15c2e1788d69458bea3471 00-initramfs-base.files
c4ce6c9ef5b1aa8fce0937676eb68f0172474cb86f2ab9d839f327b1c58f22ed6ae2a48133dd1c04ede33324ce82f78863f68ab6e62f88b716964b3b84f0ae9e 00-initramfs-extra-base.files
7ea2c318e3b63b84ba8eb09e31dd74cdd9c86f5f4d8970ab54bb9213930e913c09728b60d429828007ea2dbb0472fd50dc3daae2efbe307babf854e4d8ecb238 init.sh
12c4db4cde4a015d1e94dd9f1552023c0facf221d015ff7a0a807ef976c42d8e89bae6cbbf06f9d68b0aa1b78b2bf8a03a3710c2b0c4957af6d818f3e8820da5 init_functions.sh
7518662b584328cc94b108d9283c19c4d551d0a25d51b4fed60b4367c129789a5d895ab68244ec448c92c6818e7cefc68552184b6e9098c8f9b9c7fcf008517d init_functions.sh
ba3275a9af788c7c782322a22a0f144d5e50e3498ea6886486a29331f23ae89cd32d500a3635cfa7cab369afba92edc18aeca64ccbf0cd589061cce23d15b46c unudhcpd.conf
"

View File

@ -4,6 +4,7 @@ ROOT_PARTITION_UNLOCKED=0
ROOT_PARTITION_RESIZED=0
PMOS_BOOT=""
PMOS_ROOT=""
SUBPARTITION_DEV=""
CONFIGFS="/config/usb_gadget"
CONFIGFS_ACM_FUNCTION="acm.usb0"
@ -157,6 +158,7 @@ mount_subpartitions() {
case "$(kpartx -l "$partition" 2>/dev/null | wc -l)" in
2)
echo "Mount subpartitions of $partition"
SUBPARTITION_DEV="$partition"
kpartx -afs "$partition"
# Ensure that this was the *correct* subpartition
# Some devices have mmc partitions that appear to have
@ -165,6 +167,7 @@ mount_subpartitions() {
break
fi
kpartx -d "$partition"
SUBPARTITION_DEV=""
continue
;;
*)
@ -519,8 +522,12 @@ resize_root_partition() {
# external partition.
if [ -z "${partition##"/dev/mapper/"*}" ] || [ -z "${partition##"/dev/dm-"*}" ]; then
# Get physical device
partition_dev=$(dmsetup deps -o blkdevname "$partition" | \
awk -F "[()]" '{print "/dev/"$2}')
if [ -n "$SUBPARTITION_DEV" ]; then
partition_dev="$SUBPARTITION_DEV"
else
partition_dev=$(dmsetup deps -o blkdevname "$partition" | \
awk -F "[()]" '{print "/dev/"$2}')
fi
if has_unallocated_space "$partition_dev"; then
echo "Resize root partition ($partition)"
# unmount subpartition, resize and remount it