Skip to content

Commit f728a5b

Browse files
committed
refact(image-factory): Detect boot and root partition by filesystem type
The debug shell derived the partition numbers from TARGET, which meant it had to be told the layout it was about to inspect. blkid reports the filesystem, so vfat is the boot partition and btrfs the root one for every layout. Signed-off-by: Simon Walz <contact@simonwalz.de>
1 parent 6834b6d commit f728a5b

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

‎image-factory/mount_image.sh‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,33 @@ partprobe "${LOOPDEV}"
3838
kpartx -av "${LOOPDEV}"
3939
sleep 1
4040

41-
if [[ "${TARGET}" == "rpi" ]]; then
42-
TARGET_BOOT_PARTITION_NUM=1
43-
TARGET_ROOT_PARTITION_NUM=2
44-
else
45-
TARGET_BOOT_PARTITION_NUM=2
46-
TARGET_ROOT_PARTITION_NUM=3
47-
fi
41+
# Find the boot and root partitions by filesystem type. The partition numbers
42+
# differ per layout: MBR + FAT boot (1/2), GPT + bios_grub + ESP (2/3).
43+
LOOP_NAME="$(basename "${LOOPDEV}")"
44+
TARGET_BOOT_PARTITION=""
45+
TARGET_ROOT_PARTITION=""
46+
47+
for part in "/dev/mapper/${LOOP_NAME}p"*; do
48+
[[ -b "${part}" ]] || continue
49+
case "$(blkid -s TYPE -o value "${part}" 2>/dev/null)" in
50+
vfat)
51+
[[ -n "${TARGET_BOOT_PARTITION}" ]] || TARGET_BOOT_PARTITION="${part}"
52+
;;
53+
btrfs)
54+
[[ -n "${TARGET_ROOT_PARTITION}" ]] || TARGET_ROOT_PARTITION="${part}"
55+
;;
56+
esac
57+
done
58+
59+
[[ -n "${TARGET_BOOT_PARTITION}" ]] \
60+
|| raise "No FAT boot partition found in ${IMAGE}. Was the image built?"
61+
[[ -n "${TARGET_ROOT_PARTITION}" ]] \
62+
|| raise "No BTRFS root partition found in ${IMAGE}. Was the image built?"
63+
64+
echo "Boot partition: ${TARGET_BOOT_PARTITION} (vfat)"
65+
echo "Root partition: ${TARGET_ROOT_PARTITION} (btrfs)"
4866

49-
TARGET_BOOT_PARTITION="/dev/mapper/$(basename "${LOOPDEV}")p${TARGET_BOOT_PARTITION_NUM}"
5067
export TARGET_BOOT_PARTITION
51-
TARGET_ROOT_PARTITION="/dev/mapper/$(basename "${LOOPDEV}")p${TARGET_ROOT_PARTITION_NUM}"
5268
export TARGET_ROOT_PARTITION
5369
TARGET_BOOT="${TARGET_BOOT:-"/mnt/boot"}"
5470
TARGET_ROOT="${TARGET_ROOT:-"/mnt/os"}"

0 commit comments

Comments
 (0)