From cfd3dd4af6df90e9b9f45fbd59c138c07605fb51 Mon Sep 17 00:00:00 2001 From: jjm2473 <1129525450@qq.com> Date: Tue, 31 Jan 2023 18:12:19 +0800 Subject: [PATCH] fix potential boot disk detection bug on NVMe --- .../files/lib/functions/istoreos-boot.sh | 35 ++++++++++--------- .../base-files/files/lib/upgrade/common.sh | 24 +++++++------ 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/package/base-files/files/lib/functions/istoreos-boot.sh b/package/base-files/files/lib/functions/istoreos-boot.sh index 28974274ba..939e4ac333 100644 --- a/package/base-files/files/lib/functions/istoreos-boot.sh +++ b/package/base-files/files/lib/functions/istoreos-boot.sh @@ -2,14 +2,14 @@ # mmcblk0 _getbootdisk() { - local rootpart="`grep -Fm1 ' - squashfs /dev/root ' /proc/self/mountinfo | cut -d' ' -f3`" - [ -z "$rootpart" ] && return 1 - local devpath="`readlink /sys/dev/block/$rootpart`" - [ -z "$devpath" ] && return 1 - rootpart="${devpath##*/}" - devpath="${devpath%%/$rootpart}" - local rootdisk="${devpath##*/}" - echo $rootdisk + local rootpart="`grep -Fm1 ' - squashfs /dev/root ' /proc/self/mountinfo | cut -d' ' -f3`" + [ -z "$rootpart" ] && return 1 + local devpath="`readlink /sys/dev/block/$rootpart`" + [ -z "$devpath" ] && return 1 + rootpart="${devpath##*/}" + devpath="${devpath%%/$rootpart}" + local rootdisk="${devpath##*/}" + echo "$rootdisk" } # > getpartofdisk sda 3 @@ -18,15 +18,16 @@ _getbootdisk() # mmcblk0p3 _getpartofdisk() { - local disk="$1" - local part="$2" - local dev="`cat /sys/block/$disk/dev`" - [ -z "$dev" ] && return 1 - local major="${dev%%:*}" - local minor="${dev##*:}" - local devpath="`readlink /sys/dev/block/$major:$(($minor + $part))`" - [ -z "$devpath" ] && return 1 - echo "${devpath##*/}" + local disk="$1" offset="$2" part + if [[ "$offset" = 0 ]]; then + echo "$disk" + else + part="$disk" + echo "$part" | grep -q '^.*\d$' && part="${part}p" + part="${part}"$(( ${offset} )) + echo "$part" + fi + return 0 } _get_overlay_partition_default() diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh index dcce8a9617..41d614e2c4 100644 --- a/package/base-files/files/lib/upgrade/common.sh +++ b/package/base-files/files/lib/upgrade/common.sh @@ -156,6 +156,7 @@ export_bootdevice() { done < /tmp/.bootdisk export BOOTDEV_MAJOR=$MAJOR export BOOTDEV_MINOR=$MINOR + export BOOTDEV_DEVNAME=$DEVNAME return 0 fi @@ -219,6 +220,7 @@ export_bootdevice() { done < "$uevent" export BOOTDEV_MAJOR=$MAJOR export BOOTDEV_MINOR=$MINOR + export BOOTDEV_DEVNAME=$DEVNAME return 0 fi fi @@ -227,18 +229,20 @@ export_bootdevice() { } export_partdevice() { - local var="$1" offset="$2" - local uevent line MAJOR MINOR DEVNAME DEVTYPE - - for uevent in /sys/class/block/*/uevent; do - while read line; do - export -n "$line" - done < "$uevent" - if [ $BOOTDEV_MAJOR = $MAJOR -a $(($BOOTDEV_MINOR + $offset)) = $MINOR -a -b "/dev/$DEVNAME" ]; then - export "$var=$DEVNAME" + local var="$1" offset="$2" part + offset=$(( ${offset} )) + if [[ "$offset" = 0 ]]; then + export "$var=$BOOTDEV_DEVNAME" + return 0 + else + part="$BOOTDEV_DEVNAME" + echo "$part" | grep -q '^.*\d$' && part="${part}p" + part="${part}${offset}" + if [ -b "/dev/$part" ]; then + export "$var=$part" return 0 fi - done + fi return 1 }