main/postmarketos-initramfs: fixup device-mapper paths (MR 4204)

findfs might produce a block device path like /dev/dm-3, these can
change across boots and devices. Make things more readable and
consistent by mapping from the /dev/dm-* path to the equivalent
/dev/mapper/xyz path. Combined with invoking kpartx from a
/dev/disk/by-partlabel/abc symlink, this results in the final block
device having a name like /dev/mapper/userdata2 on an Android device.

Whilst this is just nicer to work with, this will be especially useful for
the upcoming ondev2 postmarketOS installer to make device-specific
configuration and detection easier.
This commit is contained in:
Caleb Connolly 2023-06-29 00:26:00 +01:00
parent 89fba12fbb
commit 6f44124c1b
No known key found for this signature in database
GPG key ID: 7A342565FF635F79

View file

@ -145,6 +145,19 @@ mount_subpartitions() {
done
}
# Rewrite /dev/dm-X paths to /dev/mapper/...
pretty_dm_path() {
dm="$1"
n="${dm#/dev/dm-}"
# If the substitution didn't do anything, then we're done
[ "$n" = "$dm" ] && echo "$dm" && return
# Get the name of the device mapper device
name="/dev/mapper/$(cat "/sys/class/block/dm-${n}/dm/name")"
echo "$name"
}
find_root_partition() {
[ -n "$PMOS_ROOT" ] && echo "$PMOS_ROOT" && return
@ -213,6 +226,7 @@ find_root_partition() {
PMOS_ROOT="$(blkid | grep "crypto_LUKS" | cut -d ":" -f 1 | head -n 1)"
fi
PMOS_ROOT=$(pretty_dm_path "$PMOS_ROOT")
echo "$PMOS_ROOT"
}
@ -253,6 +267,7 @@ find_boot_partition() {
done
fi
PMOS_BOOT=$(pretty_dm_path "$PMOS_BOOT")
echo "$PMOS_BOOT"
}