[OpenWrt-Devel] [PATCH 1/2] base-files: improve lib/upgrade/common.sh

Klaus Kudielka klaus.kudielka at gmail.com
Tue Apr 23 15:59:44 EDT 2019


Recently, upgrade device autodetection has been added to the mvebu target.
This exposes some shortcomings of the generic export_bootdevice function,
e.g. on the Turris Omnia: export_bootdevice silently reports the root
partition to be the boot device. This makes the sysupgrade process
fail at several places.

Fix this by clearly distinguishing between /proc/cmdline arguments which
specify the boot disk, and those which specify the root partition. Only
in the latter case, strip off the partition. Include /dev/mmcblk* and
/dev/sd* as potential arguments to "root=".

Fixes 4e8345ff68 ("mvebu: base-files: autodetect upgrade device")

Signed-off-by: Klaus Kudielka <klaus.kudielka at gmail.com>
---
 .../base-files/files/lib/upgrade/common.sh    | 27 +++++++++++++------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh
index b3a29fb32e..d906023dab 100644
--- a/package/base-files/files/lib/upgrade/common.sh
+++ b/package/base-files/files/lib/upgrade/common.sh
@@ -101,24 +101,30 @@ get_magic_long() {
 }
 
 export_bootdevice() {
-	local cmdline uuid disk uevent line
+	local cmdline bootdisk rootpart uuid disk uevent line
 	local MAJOR MINOR DEVNAME DEVTYPE
 
 	if read cmdline < /proc/cmdline; then
 		case "$cmdline" in
 			*block2mtd=*)
-				disk="${cmdline##*block2mtd=}"
-				disk="${disk%%,*}"
+				bootdisk="${cmdline##*block2mtd=}"
+				bootdisk="${bootdisk%%,*}"
 			;;
 			*root=*)
-				disk="${cmdline##*root=}"
-				disk="${disk%% *}"
+				rootpart="${cmdline##*root=}"
+				rootpart="${rootpart%% *}"
 			;;
 		esac
 
-		case "$disk" in
+		case "$bootdisk" in
+			/dev/*)
+				uevent="/sys/class/block/${bootdisk##*/}/uevent"
+			;;
+		esac
+
+		case "$rootpart" in
 			PARTUUID=[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]-02)
-				uuid="${disk#PARTUUID=}"
+				uuid="${rootpart#PARTUUID=}"
 				uuid="${uuid%-02}"
 				for disk in $(find /dev -type b); do
 					set -- $(dd if=$disk bs=1 skip=440 count=4 2>/dev/null | hexdump -v -e '4/1 "%02x "')
@@ -128,7 +134,12 @@ export_bootdevice() {
 					fi
 				done
 			;;
-			/dev/*)
+			/dev/mmcblk[0-9]p2)
+				disk="${rootpart%p2}"
+				uevent="/sys/class/block/${disk##*/}/uevent"
+			;;
+			/dev/sd[a-z]2)
+				disk="${rootpart%2}"
 				uevent="/sys/class/block/${disk##*/}/uevent"
 			;;
 		esac
-- 
2.17.1


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list