istoreos: add boot disk detection fallback

This commit is contained in:
jjm2473 2023-01-10 11:20:39 +08:00
parent 18e2f3990d
commit 44b39455e2
2 changed files with 33 additions and 10 deletions

View File

@ -2,9 +2,9 @@
# mmcblk0
_getbootdisk()
{
local rootpart=`grep -Fm1 ' - squashfs /dev/root ' /proc/self/mountinfo | cut -d' ' -f3`
local rootpart="`grep -Fm1 ' - squashfs /dev/root ' /proc/self/mountinfo | cut -d' ' -f3`"
[ -z "$rootpart" ] && return 1
local devpath=`readlink /sys/dev/block/$rootpart`
local devpath="`readlink /sys/dev/block/$rootpart`"
[ -z "$devpath" ] && return 1
rootpart="${devpath##*/}"
devpath="${devpath%%/$rootpart}"
@ -24,7 +24,7 @@ _getpartofdisk()
[ -z "$dev" ] && return 1
local major="${dev%%:*}"
local minor="${dev##*:}"
local devpath=`readlink /sys/dev/block/$major:$(($minor + $part))`
local devpath="`readlink /sys/dev/block/$major:$(($minor + $part))`"
[ -z "$devpath" ] && return 1
echo "${devpath##*/}"
}
@ -32,9 +32,31 @@ _getpartofdisk()
_get_overlay_partition_default()
{
local bootdisk="`_getbootdisk`"
[ -z "$bootdisk" ] && return 1
cat /sys/block/$bootdisk/uevent > /tmp/.bootdisk
[ -z "$bootdisk" ] && {
log "getbootdisk failed"
return 1
}
if [ -e /rom/note -a -e "/sys/block/$bootdisk/uevent" ]; then
# we are in mount_root if /rom/note exists
cat "/sys/block/$bootdisk/uevent" > /tmp/.bootdisk
fi
local overlay_dev="`_getpartofdisk $bootdisk 3`"
[ -z "$overlay_dev" ] && {
log "getpartofdisk $bootdisk 3 failed"
return 1
}
OVERLAY_DEV="/dev/$overlay_dev"
return 0
}
_get_overlay_partition_fallback()
{
log "get_overlay_partition_fallback"
rm -f /tmp/.bootdisk >/dev/null 2>&1
local overlay_dev=$(
. /lib/upgrade/common.sh
export_bootdevice && export_partdevice overlay_dev 3 && echo $overlay_dev
)
[ -z "$overlay_dev" ] && return 1
OVERLAY_DEV="/dev/$overlay_dev"
return 0
@ -42,7 +64,7 @@ _get_overlay_partition_default()
get_overlay_partition()
{
_get_overlay_partition_default || {
_get_overlay_partition_default || _get_overlay_partition_fallback || {
log "Unable to determine overlay partition"
return 1
}

View File

@ -41,10 +41,10 @@ do_reset_nofs()
echo "Already resetted" >&2
return 1
fi
if ! blkid -o device -t LABEL=$OVERLAY_LABEL "$OVERLAY_DEV" >/dev/null; then
echo "Overlay partition $OVERLAY_DEV not labeled $OVERLAY_LABEL" >&2
return 1
fi
# if ! blkid -o device -t LABEL=$OVERLAY_LABEL "$OVERLAY_DEV" >/dev/null; then
# echo "Overlay partition $OVERLAY_DEV not labeled $OVERLAY_LABEL" >&2
# return 1
# fi
echo "RESET000" | dd of="$OVERLAY_DEV" bs=512 count=1 conv=notrunc,sync,fsync 2>/dev/null
echo 3 > /proc/sys/vm/drop_caches
@ -53,6 +53,7 @@ do_reset_nofs()
do_reset_ext_overlay()
{
[ -d /ext_overlay ] && mountpoint -q /ext_overlay || return 0
rm -f /ext_overlay/etc/.extroot-uuid
touch /ext_overlay/.reset
sync /ext_overlay