main/postmarketos-initramfs: use only one method to resize the root partition (MR 4204)

This removes the possibility that multiple resize root partition methods
could be invoked. I'm not sure how likely this is in practice, but it
seems like we should avoid the possiblity altogether.

This also adds some more helpful printing to stdout when the partition
resize is skipped / not done.
This commit is contained in:
Clayton Craft 2023-07-23 20:31:23 +01:00 committed by Caleb Connolly
parent 6f44124c1b
commit 97727c59cb
No known key found for this signature in database
GPG key ID: 7A342565FF635F79

View file

@ -387,22 +387,24 @@ resize_root_partition() {
parted -f -s "$partition_dev" resizepart 2 100% parted -f -s "$partition_dev" resizepart 2 100%
kpartx -afs "$partition_dev" kpartx -afs "$partition_dev"
ROOT_PARTITION_RESIZED=1 ROOT_PARTITION_RESIZED=1
else
echo "Not resizing root partition ($partition): no free space left"
fi fi
fi
# Resize the root partition (non-subpartitions). Usually we do not want # Resize the root partition (non-subpartitions). Usually we do not want
# this, except for QEMU devices and non-android devices (e.g. # this, except for QEMU devices and non-android devices (e.g.
# PinePhone). For them, it is fine to use the whole storage device and # PinePhone). For them, it is fine to use the whole storage device and
# so we pass PMOS_FORCE_PARTITION_RESIZE as kernel parameter. # so we pass PMOS_FORCE_PARTITION_RESIZE as kernel parameter.
if grep -q PMOS_FORCE_PARTITION_RESIZE /proc/cmdline; then elif grep -q PMOS_FORCE_PARTITION_RESIZE /proc/cmdline; then
partition_dev="$(echo "$partition" | sed -E 's/p?2$//')" partition_dev="$(echo "$partition" | sed -E 's/p?2$//')"
if has_unallocated_space "$partition_dev"; then if has_unallocated_space "$partition_dev"; then
echo "Resize root partition ($partition)" echo "Resize root partition ($partition)"
parted -f -s "$partition_dev" resizepart 2 100% parted -f -s "$partition_dev" resizepart 2 100%
partprobe partprobe
ROOT_PARTITION_RESIZED=1 ROOT_PARTITION_RESIZED=1
else
echo "Not resizing root partition ($partition): no free space left"
fi fi
fi
# Resize the root partition (non-subpartitions) on Chrome OS devices. # Resize the root partition (non-subpartitions) on Chrome OS devices.
# Match $deviceinfo_cgpt_kpart not being empty instead of cmdline # Match $deviceinfo_cgpt_kpart not being empty instead of cmdline
@ -410,14 +412,19 @@ resize_root_partition() {
# partitioning methods. This also resizes third partition instead of # partitioning methods. This also resizes third partition instead of
# second, because these devices have an additional kernel partition # second, because these devices have an additional kernel partition
# at the start. # at the start.
if [ -n "$deviceinfo_cgpt_kpart" ]; then elif [ -n "$deviceinfo_cgpt_kpart" ]; then
partition_dev="$(echo "$partition" | sed -E 's/p?3$//')" partition_dev="$(echo "$partition" | sed -E 's/p?3$//')"
if has_unallocated_space "$partition_dev"; then if has_unallocated_space "$partition_dev"; then
echo "Resize root partition ($partition)" echo "Resize root partition ($partition)"
parted -f -s "$partition_dev" resizepart 3 100% parted -f -s "$partition_dev" resizepart 3 100%
partprobe partprobe
ROOT_PARTITION_RESIZED=1 ROOT_PARTITION_RESIZED=1
else
echo "Not resizing root partition ($partition): no free space left"
fi fi
else
echo "Unable to resize root partition: failed to find qualifying partition"
fi fi
} }