1
0
Fork 0

Fix wrimg.sh device detection: use GPT PARTLABEL instead of filesystem LABEL

check_device() was using lsblk -o LABEL (filesystem labels) to identify
partitions, but mkimg.sh sets the labels via e2label which can silently
fail if the partition image wasn't built with an ext4 filesystem label.
The system partition in particular often shows as '/' (the mkfs.ext4
default) instead of 'system'.

Switch to lsblk -o PARTLABEL (GPT partition names), which are always set
correctly by mkimg.sh via sfdisk's name= parameter, and are preserved
regardless of filesystem layer.

Also broaden find_device() to check sde and mmcblk[01] entries.

Copyright (C) 2026 Brendan Szymanski <hello@bscubed.dev>
This commit is contained in:
Brendan Szymanski 2026-07-14 10:23:21 -04:00
parent 10a332665b
commit 70ad05528c

View file

@ -18,11 +18,15 @@ check_device() {
fi
done
PARTITION1=$(lsblk -o LABEL,SIZE -b /dev/${1}1 | tail -n 1)
PARTITION2=$(lsblk -o LABEL,SIZE -b /dev/${1}2 | tail -n 1)
PARTITION3=$(lsblk -o LABEL,SIZE -b /dev/${1}3 | tail -n 1)
PARTITION4=$(lsblk -o LABEL,SIZE -b /dev/${1}4 | tail -n 1)
PARTITION5=$(lsblk -o LABEL,SIZE -b /dev/${1}5 | tail -n 1)
# Use GPT partition names (PARTLABEL) instead of filesystem labels (LABEL).
# mkimg.sh always sets the GPT names via sfdisk name=; filesystem labels
# may be missing (e.g. / for the root default) if e2label failed during
# image creation.
PARTITION1=$(lsblk -o PARTLABEL,SIZE -b /dev/${1}1 | tail -n 1)
PARTITION2=$(lsblk -o PARTLABEL,SIZE -b /dev/${1}2 | tail -n 1)
PARTITION3=$(lsblk -o PARTLABEL,SIZE -b /dev/${1}3 | tail -n 1)
PARTITION4=$(lsblk -o PARTLABEL,SIZE -b /dev/${1}4 | tail -n 1)
PARTITION5=$(lsblk -o PARTLABEL,SIZE -b /dev/${1}5 | tail -n 1)
if [ $(echo ${PARTITION1} | awk {'print $1'}) != "boot" ] || [ $(echo ${PARTITION1} | awk {'print $2'}) != "134217728" ]; then
return 1
@ -45,7 +49,7 @@ check_device() {
}
find_device() {
for SDX in "sda" "sdb" "sdc" "sdd"; do
for SDX in "sda" "sdb" "sdc" "sdd" "sde" "mmcblk0" "mmcblk1"; do
check_device ${SDX}
if [ $? == "0" ]; then
break
@ -67,7 +71,7 @@ confirm() {
echo "Writing ${2} image..."
fi
echo "Writing to device /dev/${DEVICE}..."
lsblk -o NAME,LABEL,SIZE /dev/${DEVICE}
lsblk -o NAME,PARTLABEL,LABEL,SIZE /dev/${DEVICE}
read -p "Continue (y/n)? " -n 1 -r RESPONSE
echo ""