Skip to content

Commit b38e13a

Browse files
committed
board/common: check if partition/LABEL is available
Check if partition/LABEL is available before trying to run tune2fs and mount commands on it. This change masks the kernel output: LABEL=var: Can't lookup blockdev commne when running `make run` on x86_64 builds. Signed-off-by: Joachim Wiberg <[email protected]>
1 parent 04c8647 commit b38e13a

File tree

1 file changed

+36
-7
lines changed
  • board/common/rootfs/usr/libexec/infix

1 file changed

+36
-7
lines changed

board/common/rootfs/usr/libexec/infix/mnt

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,18 @@ find_partition_by_label()
108108
esac
109109

110110
disk="/dev/$devname"
111+
112+
#
113+
# 1. Try GPT/MBR partition label using sgdisk
114+
#
111115
result=$(sgdisk -p "$disk" 2>/dev/null | awk -v label="$label" -v devname="$devname" '
112-
/^ *[0-9]/ {
116+
/^ *[0-9]/ {
113117
if ($7 == label) {
114-
if (devname ~ /^(mmcblk|nvme|loop)/) {
115-
print devname "p" $1
116-
} else {
117-
print devname $1
118-
}
119-
exit 0
118+
if (devname ~ /^(mmcblk|nvme|loop)/)
119+
print devname "p" $1;
120+
else
121+
print devname $1;
122+
exit 0;
120123
}
121124
}
122125
')
@@ -125,7 +128,30 @@ find_partition_by_label()
125128
echo "$result"
126129
return 0
127130
fi
131+
132+
#
133+
# 2. Fallback: Check if the whole disk is an ext4/ext2/ext3 filesystem
134+
#
135+
136+
# Check for ext4/ext2/ext3 magic number (0xEF53) at offset 1080 (1024+56).
137+
magic_number=$(dd if="$disk" bs=1 skip=1080 count=2 2>/dev/null | od -t x2 -A n | tr -d ' \n')
138+
139+
# Check for both Little-Endian ('53ef') and Big-Endian ('ef53') interpretations of 0xEF53.
140+
# This supports bi-endian architectures like MIPS that may run in BE mode,
141+
# as well as the LE mode which is standard for RISC-V and ext filesystems.
142+
if [ "$magic_number" = "ef53" ] || [ "$magic_number" = "53ef" ]; then
143+
144+
# Read the volume label from offset 1144 (1024+120)
145+
fslabel=$(dd if="$disk" bs=1 skip=1144 count=16 2>/dev/null | tr -d '\000')
146+
logger $opt -p user.notice -t "$nm" "Found label $fslabel on disk $disk ..."
147+
148+
if [ "$fslabel" = "$label" ]; then
149+
echo "$devname"
150+
return 0
151+
fi
152+
fi
128153
done
154+
129155
return 1
130156
}
131157

@@ -276,6 +302,9 @@ mount_rw()
276302
# If something is already setup, leave it be.
277303
mountpoint -q "/$1" && return 0
278304

305+
# If partition doesn't exist (var is optional), signal caller.
306+
find_partition_by_label "$1" >/dev/null || return 1
307+
279308
# Check if /var has been resized to fill the sdcard/eMMC
280309
if [ "$1" = "var" ] && is_mmc; then
281310
if [ -f /mnt/aux/resized ] || [ -f /mnt/aux/resized.failed ]; then

0 commit comments

Comments
 (0)