mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-01 13:23:01 +02:00
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 <troglobit@gmail.com>
This commit is contained in:
@@ -108,15 +108,18 @@ find_partition_by_label()
|
||||
esac
|
||||
|
||||
disk="/dev/$devname"
|
||||
|
||||
#
|
||||
# 1. Try GPT/MBR partition label using sgdisk
|
||||
#
|
||||
result=$(sgdisk -p "$disk" 2>/dev/null | awk -v label="$label" -v devname="$devname" '
|
||||
/^ *[0-9]/ {
|
||||
/^ *[0-9]/ {
|
||||
if ($7 == label) {
|
||||
if (devname ~ /^(mmcblk|nvme|loop)/) {
|
||||
print devname "p" $1
|
||||
} else {
|
||||
print devname $1
|
||||
}
|
||||
exit 0
|
||||
if (devname ~ /^(mmcblk|nvme|loop)/)
|
||||
print devname "p" $1;
|
||||
else
|
||||
print devname $1;
|
||||
exit 0;
|
||||
}
|
||||
}
|
||||
')
|
||||
@@ -125,7 +128,30 @@ find_partition_by_label()
|
||||
echo "$result"
|
||||
return 0
|
||||
fi
|
||||
|
||||
#
|
||||
# 2. Fallback: Check if the whole disk is an ext4/ext2/ext3 filesystem
|
||||
#
|
||||
|
||||
# Check for ext4/ext2/ext3 magic number (0xEF53) at offset 1080 (1024+56).
|
||||
magic_number=$(dd if="$disk" bs=1 skip=1080 count=2 2>/dev/null | od -t x2 -A n | tr -d ' \n')
|
||||
|
||||
# Check for both Little-Endian ('53ef') and Big-Endian ('ef53') interpretations of 0xEF53.
|
||||
# This supports bi-endian architectures like MIPS that may run in BE mode,
|
||||
# as well as the LE mode which is standard for RISC-V and ext filesystems.
|
||||
if [ "$magic_number" = "ef53" ] || [ "$magic_number" = "53ef" ]; then
|
||||
|
||||
# Read the volume label from offset 1144 (1024+120)
|
||||
fslabel=$(dd if="$disk" bs=1 skip=1144 count=16 2>/dev/null | tr -d '\000')
|
||||
logger $opt -p user.notice -t "$nm" "Found label $fslabel on disk $disk ..."
|
||||
|
||||
if [ "$fslabel" = "$label" ]; then
|
||||
echo "$devname"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -276,6 +302,9 @@ mount_rw()
|
||||
# If something is already setup, leave it be.
|
||||
mountpoint -q "/$1" && return 0
|
||||
|
||||
# If partition doesn't exist (var is optional), signal caller.
|
||||
find_partition_by_label "$1" >/dev/null || return 1
|
||||
|
||||
# Check if /var has been resized to fill the sdcard/eMMC
|
||||
if [ "$1" = "var" ] && is_mmc; then
|
||||
if [ -f /mnt/aux/resized ] || [ -f /mnt/aux/resized.failed ]; then
|
||||
|
||||
Reference in New Issue
Block a user