base-files: fix broken sysupgrade

Fixes: c7251e5594 ("x86: upgrade from
 img.gz error")

Signed-off-by: AmadeusGhost <amadeus@openjmu.xyz>
Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
This commit is contained in:
AmadeusGhost 2022-06-27 13:13:25 +08:00 committed by Tianling Shen
parent 806e1d6a3f
commit 097e65fade
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
7 changed files with 42 additions and 52 deletions

View File

@ -144,24 +144,26 @@ export_bootdevice() {
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
if [ "$4$3$2$1" = "$uuid" ]; then
uevent="/sys/class/block/${blockdev##*/}/uevent"
break
fi
done
;;
PARTUUID=????????-????-????-????-??????????02)
uuid="${rootpart#PARTUUID=}"
uuid="${uuid%02}00"
for disk in $(find /dev -type b); do
set -- $(dd if=$disk bs=1 skip=568 count=16 2>/dev/null | hexdump -v -e '8/1 "%02x "" "2/1 "%02x""-"6/1 "%02x"')
if [ "$4$3$2$1-$6$5-$8$7-$9" = "$uuid" ]; then
uevent="/sys/class/block/${disk##*/}/uevent"
break
fi
done
;;
/dev/*)
break
fi
done
;;
PARTUUID=????????-????-????-????-??????????0?/PARTNROFF=1 | \
PARTUUID=????????-????-????-????-??????????02)
uuid="${rootpart#PARTUUID=}"
uuid="${uuid%/PARTNROFF=1}"
uuid="${uuid%0?}00"
for disk in $(find /dev -type b); do
set -- $(dd if=$disk bs=1 skip=568 count=16 2>/dev/null | hexdump -v -e '8/1 "%02x "" "2/1 "%02x""-"6/1 "%02x"')
if [ "$4$3$2$1-$6$5-$8$7-$9" = "$uuid" ]; then
uevent="/sys/class/block/${disk##*/}/uevent"
break
fi
done
;;
/dev/*)
uevent="/sys/class/block/${rootpart##*/}/../uevent"
;;
0x[a-f0-9][a-f0-9][a-f0-9] | 0x[a-f0-9][a-f0-9][a-f0-9][a-f0-9] | \
@ -175,16 +177,16 @@ export_bootdevice() {
uevent="$class/../uevent"
fi
done
;;
esac
;;
esac
if [ -e "$uevent" ]; then
while read line; do
export -n "$line"
done < "$uevent"
export BOOTDEV_MAJOR=$MAJOR
export BOOTDEV_MINOR=$MINOR
return 0
if [ -e "$uevent" ]; then
while read line; do
export -n "$line"
done < "$uevent"
export BOOTDEV_MAJOR=$MAJOR
export BOOTDEV_MINOR=$MINOR
return 0
fi
return 1

View File

@ -7,7 +7,7 @@ mbl_do_platform_check() {
[ "$#" -gt 1 ] && return 1
export_bootdevice && export_partdevice diskdev -2 || {
export_bootdevice && export_partdevice diskdev 0 || {
echo "Unable to determine upgrade device"
return 1
}
@ -36,7 +36,7 @@ mbl_do_platform_check() {
mbl_do_upgrade() {
local diskdev partdev diff
export_bootdevice && export_partdevice diskdev -2 || {
export_bootdevice && export_partdevice diskdev 0 || {
echo "Unable to determine upgrade device"
return 1
}
@ -70,10 +70,6 @@ mbl_do_upgrade() {
#iterate over each partition from the image and write it to the boot disk
while read part start size; do
# root is /dev/sd[a|b]2 and not /dev/sd[a|b] this causes some problem
# one of which is this offset, I'm not sure what's the best fix, so
# here's a WA.
let part=$((part - 2))
if export_partdevice partdev $part; then
echo "Writing image to /dev/$partdev..."
get_image "$@" | dd of="/dev/$partdev" ibs="512" obs=1M skip="$start" count="$size" conv=fsync
@ -90,8 +86,7 @@ mbl_do_upgrade() {
mbl_copy_config() {
local partdev
# Same as above /dev/sd[a|b]2 is root, so /boot is -1
if export_partdevice partdev -1; then
if export_partdevice partdev 1; then
mount -t ext4 -o rw,noatime "/dev/$partdev" /mnt
cp -af "$CONF_TAR" /mnt/
umount /mnt

View File

@ -9,7 +9,7 @@ platform_check_image() {
[ "$#" -gt 1 ] && return 1
export_bootdevice && export_partdevice diskdev -2 || {
export_bootdevice && export_partdevice diskdev 0 || {
echo "Unable to determine upgrade device"
return 1
}
@ -38,7 +38,7 @@ platform_check_image() {
platform_do_upgrade() {
local diskdev partdev diff
export_bootdevice && export_partdevice diskdev -2 || {
export_bootdevice && export_partdevice diskdev 0 || {
echo "Unable to determine upgrade device"
return 1
}
@ -72,10 +72,6 @@ platform_do_upgrade() {
#iterate over each partition from the image and write it to the boot disk
while read part start size; do
# root is /dev/sd[a|b]2 and not /dev/sd[a|b] this causes some problem
# one of which is this offset, I'm not sure what's the best fix, so
# here's a WA.
let part=$((part - 2))
if export_partdevice partdev $part; then
echo "Writing image to /dev/$partdev..."
get_image "$@" | dd of="/dev/$partdev" ibs="512" obs=1M skip="$start" count="$size" conv=fsync
@ -92,8 +88,7 @@ platform_do_upgrade() {
platform_copy_config() {
local partdev
# Same as above /dev/sd[a|b]2 is root, so /boot is -1
if export_partdevice partdev -1; then
if export_partdevice partdev 1; then
mkdir -p /boot
[ -f /boot/kernel.img ] || mount -t vfat -o rw,noatime "/dev/$partdev" /boot
cp -af "$CONF_TAR" /boot/

View File

@ -6,7 +6,7 @@ move_config() {
. /lib/upgrade/common.sh
if export_bootdevice && export_partdevice partdev -1; then
if export_bootdevice && export_partdevice partdev 1; then
if mount -t vfat -o rw,noatime "/dev/$partdev" /mnt; then
if [ -f "/mnt/$BACKUP_FILE" ]; then
mv -f "/mnt/$BACKUP_FILE" /

View File

@ -1,7 +1,7 @@
platform_check_image() {
local diskdev partdev diff
export_bootdevice && export_partdevice diskdev -2 || {
export_bootdevice && export_partdevice diskdev 0 || {
echo "Unable to determine upgrade device"
return 1
}
@ -28,7 +28,7 @@ platform_check_image() {
platform_copy_config() {
local partdev
if export_partdevice partdev -1; then
if export_partdevice partdev 1; then
mount -t vfat -o rw,noatime "/dev/$partdev" /mnt
cp -af "$CONF_TAR" /mnt/
umount /mnt
@ -38,7 +38,7 @@ platform_copy_config() {
platform_do_upgrade() {
local diskdev partdev diff
export_bootdevice && export_partdevice diskdev -2 || {
export_bootdevice && export_partdevice diskdev 0 || {
echo "Unable to determine upgrade device"
return 1
}
@ -74,7 +74,6 @@ platform_do_upgrade() {
get_image "$@" | dd of="$diskdev" bs=1024 skip=8 seek=8 count=1016 conv=fsync
#iterate over each partition from the image and write it to the boot disk
while read part start size; do
part="$(($part - 2))"
if export_partdevice partdev $part; then
echo "Writing image to /dev/$partdev..."
get_image "$@" | dd of="/dev/$partdev" ibs="512" obs=1M skip="$start" count="$size" conv=fsync

View File

@ -6,7 +6,7 @@ move_config() {
. /lib/upgrade/common.sh
if export_bootdevice && export_partdevice partdev -1; then
if export_bootdevice && export_partdevice partdev 1; then
if mount -t vfat -o rw,noatime "/dev/$partdev" /mnt; then
if [ -f "/mnt/$BACKUP_FILE" ]; then
mv -f "/mnt/$BACKUP_FILE" /

View File

@ -1,7 +1,7 @@
platform_check_image() {
local diskdev partdev diff
export_bootdevice && export_partdevice diskdev -2 || {
export_bootdevice && export_partdevice diskdev 0 || {
echo "Unable to determine upgrade device"
return 1
}
@ -28,7 +28,7 @@ platform_check_image() {
platform_copy_config() {
local partdev
if export_partdevice partdev -1; then
if export_partdevice partdev 1; then
mount -t vfat -o rw,noatime "/dev/$partdev" /mnt
cp -af "$CONF_TAR" /mnt/
umount /mnt
@ -38,7 +38,7 @@ platform_copy_config() {
platform_do_upgrade() {
local diskdev partdev diff
export_bootdevice && export_partdevice diskdev -2 || {
export_bootdevice && export_partdevice diskdev 0 || {
echo "Unable to determine upgrade device"
return 1
}
@ -74,7 +74,6 @@ platform_do_upgrade() {
get_image "$@" | dd of="$diskdev" bs=1024 skip=8 seek=8 count=1016 conv=fsync
#iterate over each partition from the image and write it to the boot disk
while read part start size; do
part="$(($part - 2))"
if export_partdevice partdev $part; then
echo "Writing image to /dev/$partdev..."
get_image "$@" | dd of="/dev/$partdev" ibs="512" obs=1M skip="$start" count="$size" conv=fsync