diff options
author | Klaus Kudielka <klaus.kudielka@gmail.com> | 2019-05-08 20:40:50 +0200 |
---|---|---|
committer | Christian Lamparter <chunkeey@gmail.com> | 2019-05-11 16:37:11 +0200 |
commit | ad62247800a10654ab7a3d94ea9c6b43a834f301 (patch) | |
tree | b70b1d866bb558d5fd6e550408f81d1a935981c7 /package/base-files/files | |
parent | 6411eac5da19359c45fdd9543725369ba9526384 (diff) | |
download | upstream-ad62247800a10654ab7a3d94ea9c6b43a834f301.tar.gz upstream-ad62247800a10654ab7a3d94ea9c6b43a834f301.tar.bz2 upstream-ad62247800a10654ab7a3d94ea9c6b43a834f301.zip |
base-files: improve lib/upgrade/common.sh
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, and do it consistently.
root=PARTUUID=<pseudo PARTUUID for MBR> (any partition) and root=/dev/*
(any partition) are accepted.
The root of the problem is that the *existing* export_bootdevice in
/lib/upgrade/common.sh behaves differently, if the kernel is booted with
root=/dev/..., or if it is booted with root=PARTUUID=...
In the former case, it reports back major/minor of the root partition,
in the latter case it reports back major/minor of the complete boot disk.
Targets, which boot with root=/dev/... *and* use export_bootdevice /
export_partdevice, have added workarounds to this behaviour, by specifying
*negative* increments to the export_partdevice function.
Consequently, those targets have to be adapted to use positive increments,
otherwise they are broken by the change to export_bootdevice.
Fixes: 4e8345ff68 ("mvebu: base-files: autodetect upgrade device")
Signed-off-by: Klaus Kudielka <klaus.kudielka@gmail.com>
Tested-by: Tomasz Maciej Nowak <tomek_n@o2.pl>
Diffstat (limited to 'package/base-files/files')
-rw-r--r-- | package/base-files/files/lib/upgrade/common.sh | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh index b3a29fb32e..bbedeefd26 100644 --- a/package/base-files/files/lib/upgrade/common.sh +++ b/package/base-files/files/lib/upgrade/common.sh @@ -101,35 +101,41 @@ get_magic_long() { } export_bootdevice() { - local cmdline uuid disk uevent line + local cmdline bootdisk rootpart uuid blockdev 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 - 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="${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 "') + 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]-[a-f0-9][a-f0-9]) + uuid="${rootpart#PARTUUID=}" + uuid="${uuid%-[a-f0-9][a-f0-9]}" + for blockdev in $(find /dev -type b); do + set -- $(dd if=$blockdev bs=1 skip=440 count=4 2>/dev/null | hexdump -v -e '4/1 "%02x "') if [ "$4$3$2$1" = "$uuid" ]; then - uevent="/sys/class/block/${disk##*/}/uevent" + uevent="/sys/class/block/${blockdev##*/}/uevent" break fi done ;; /dev/*) - uevent="/sys/class/block/${disk##*/}/uevent" + uevent="/sys/class/block/${rootpart##*/}/../uevent" ;; esac |