mount_digiparts: detect active block root by mounted device

Bootable SD cards may boot with root=/dev/mmcblkXpY instead of
root=PARTUUID=... In that case mount_digiparts.sh treated the system
as NAND/UBI and failed to mount the Digi partitions.
Resolve the active system from the block device mounted as "/" before
falling back to the existing UBI logic.

https://onedigi.atlassian.net/browse/DEL-9676

Signed-off-by: Isaac Hermida <isaac.hermida@digi.com>
This commit is contained in:
Isaac Hermida 2026-05-20 19:00:42 +02:00
parent 7522d609d8
commit 6325cddb21
1 changed files with 64 additions and 21 deletions

View File

@ -17,10 +17,61 @@
BASE_INIT="$(readlink -f "@base_sbindir@/init")" BASE_INIT="$(readlink -f "@base_sbindir@/init")"
BASE_INIT_ORIG="$(readlink -f "@base_sbindir@/init.orig")" BASE_INIT_ORIG="$(readlink -f "@base_sbindir@/init.orig")"
INIT_SYSTEMD="@systemd_unitdir@/systemd" INIT_SYSTEMD="@systemd_unitdir@/systemd"
EMMCROOTFS="$(grep -qs 'root=PARTUUID.*' /proc/cmdline 2>/dev/null && echo 1)"
get_block_disk() {
local dev
local syspath
dev="${1##*/}"
syspath="$(readlink -f "/sys/class/block/${dev}")"
[ -n "${syspath}" ] || return
if [ -f "${syspath}/partition" ]; then
basename "$(dirname "${syspath}")"
else
basename "${syspath}"
fi
}
get_root_disk() {
local ROOT_DEV
local devname
local uevent
ROOT_DEV="$(stat -c%D /)"
for uevent in /sys/class/block/*/uevent; do
devname="$(sed -ne 's/^DEVNAME=//p' "${uevent}")"
[ -n "${devname}" ] || continue
if [ "$(stat -c"%02t%02T" "/dev/${devname}")" = "${ROOT_DEV}" ]; then
get_block_disk "${devname}"
break
fi
done
}
get_active_system() { get_active_system() {
if [ -z "${EMMCROOTFS}" ]; then local ROOT_DEV
local devname
local label
local uevent
ROOT_DEV="$(stat -c%D /)"
for uevent in /sys/class/block/*/uevent; do
devname="$(sed -ne 's/^DEVNAME=//p' "${uevent}")"
label="$(sed -ne 's/^PARTNAME=//p' "${uevent}")"
[ -n "${devname}" ] || continue
[ -n "${label}" ] || continue
if [ "$(stat -c"%02t%02T" "/dev/${devname}")" = "${ROOT_DEV}" ]; then
ACTIVE_SYSTEM="${label}"
break
fi
done
if [ -z "${ACTIVE_SYSTEM}" ]; then
# For a read-only filesystem this will be /dev/ubiblock0_X # For a read-only filesystem this will be /dev/ubiblock0_X
# For an ubifs filesystem this will be ubiX:rootfs_X # For an ubifs filesystem this will be ubiX:rootfs_X
ACTIVE_SYSTEM="$(sed -e 's/^.*root=\([^ ]*\) .*$/\1/' /proc/cmdline 2>/dev/null)" ACTIVE_SYSTEM="$(sed -e 's/^.*root=\([^ ]*\) .*$/\1/' /proc/cmdline 2>/dev/null)"
@ -36,25 +87,6 @@ get_active_system() {
#Character device major/minor: 242:6 #Character device major/minor: 242:6
ACTIVE_SYSTEM="$(ubinfo "${ACTIVE_SYSTEM}" | sed -ne '/^Name/s,.* \([^[:blank:]]\+\)$,\1,g;T;p')" ACTIVE_SYSTEM="$(ubinfo "${ACTIVE_SYSTEM}" | sed -ne '/^Name/s,.* \([^[:blank:]]\+\)$,\1,g;T;p')"
fi fi
else
local MMCROOT_DEV
local devname
local label
local uevent
MMCROOT_DEV="$(stat -c%D /)"
for uevent in /sys/class/block/*/uevent; do
devname="$(sed -ne 's/^DEVNAME=//p' "${uevent}")"
label="$(sed -ne 's/^PARTNAME=//p' "${uevent}")"
[ -n "${devname}" ] || continue
[ -n "${label}" ] || continue
if [ "$(stat -c"%02t%02T" "/dev/${devname}")" = "${MMCROOT_DEV}" ]; then
ACTIVE_SYSTEM="${label}"
break
fi
done
fi fi
if [ -z "${ACTIVE_SYSTEM}" ]; then if [ -z "${ACTIVE_SYSTEM}" ]; then
@ -82,6 +114,17 @@ elif [ "${SUBSYSTEM}" = "ubi" ]; then
[ -n "${result}" ] && exit 0 [ -n "${result}" ] && exit 0
fi fi
if [ "${SUBSYSTEM}" = "block" ]; then
ROOT_DISK="$(get_root_disk)"
DEV_DISK="$(get_block_disk "${DEVNAME}")"
if [ -n "${ROOT_DISK}" ] && [ -n "${DEV_DISK}" ] &&
[ "${ROOT_DISK}" != "${DEV_DISK}" ]; then
logger "Skip mounting partition '${PARTNAME}', because it does not belong to the root disk"
exit 0
fi
fi
MOUNT_FOLDER=${PARTNAME} MOUNT_FOLDER=${PARTNAME}
MOUNT_PARAMS="-o silent" MOUNT_PARAMS="-o silent"
# Mount 'linux' partition as read-only # Mount 'linux' partition as read-only