[OpenWrt-Devel] [PATCH 3/3] x86: add preinit hook for bootloader upgrade
Tomasz Maciej Nowak
tomek_n at o2.pl
Mon May 27 08:46:30 EDT 2019
The current OpenWrt installations lack the necessary bits to upgrade
bootloader on sysupgrade, therefore add preinit hook which will perform
upgrade of the bootloader on first boot after sysupgrade.
Signed-off-by: Tomasz Maciej Nowak <tomek_n at o2.pl>
---
.../lib/preinit/81_upgrade_bootloader | 19 +++++++++++++++++++
.../x86/base-files/lib/upgrade/platform.sh | 3 ++-
2 files changed, 21 insertions(+), 1 deletion(-)
create mode 100644 target/linux/x86/base-files/lib/preinit/81_upgrade_bootloader
diff --git a/target/linux/x86/base-files/lib/preinit/81_upgrade_bootloader b/target/linux/x86/base-files/lib/preinit/81_upgrade_bootloader
new file mode 100644
index 0000000000..3a4e756b1e
--- /dev/null
+++ b/target/linux/x86/base-files/lib/preinit/81_upgrade_bootloader
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+upgrade_bootloader() {
+ local diskdev
+
+ . /lib/upgrade/common.sh
+
+ if [ ! -f /boot/grub/upgraded ] && export_bootdevice && export_partdevice diskdev 0; then
+ echo "(hd0) /dev/$diskdev" > /tmp/device.map
+ /usr/sbin/grub-bios-setup \
+ -m "/tmp/device.map" \
+ -d "/boot/grub" \
+ -r "hd0,msdos1" \
+ "/dev/$diskdev" \
+ && touch /boot/grub/upgraded
+ fi
+}
+
+[ "$INITRAMFS" = "1" ] || boot_hook_add preinit_main upgrade_bootloader
diff --git a/target/linux/x86/base-files/lib/upgrade/platform.sh b/target/linux/x86/base-files/lib/upgrade/platform.sh
index 1a42fd3a11..05bbd97f3b 100644
--- a/target/linux/x86/base-files/lib/upgrade/platform.sh
+++ b/target/linux/x86/base-files/lib/upgrade/platform.sh
@@ -106,7 +106,8 @@ platform_do_upgrade() {
-m "/tmp/device.map" \
-d "/tmp/boot/boot/grub" \
-r "hd0,msdos1" \
- "/dev/$diskdev"
+ "/dev/$diskdev" \
+ && touch /boot/grub/upgraded
umount /tmp/boot
fi
--
2.21.0
_______________________________________________
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