Skip to contentSkip to conversation

Bug 8729 - grub: create a script to boot between rootfs and a maintenance partition

PATCH New [email protected] 1 participant 1 message Nov 10, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bug 8729 - grub: create a script to boot between rootfs and a maintenance partition

From: Dimitris Tassopoulos <[email protected]>

Hi all, I've have a patch which is ready for testing and evaluation.

I've send that also to to the poky mail-list but that list seems a bit and I've seen everyone send their patches to the yocto-list.

In order to build the qemu wic image you need to apply the patch and then add these to the end of your local.conf file.

MACHINE ?= "qemux86"
MACHINE_FEATURES += "pcbios efi"
IMAGE_FSTYPES += "wic"
WKS_FILE = "directdisk-multi-rootfs.wks.in"
EFI_PROVIDER = "grub-efi"

IMAGE_INSTALL_append = " \
                grub \
                grub-efi \
                grub-multibootconf-cntr-rst \

"
EXTRA_IMAGEDEPENDS += "ovmf" PREFERRED_RPROVIDER_virtual/grub-bootconf = "grub-multibootconf"

Then build the core-image-minimal image (that's the only one I've tried). If the build ends without errors then load the image with:

$ runqemu wic kvm ovmf

You can debug the grub bootloader script by setting the 'GRUB_DEBUG = 1' flag in poky/meta/recipes-bsp/grub/grub-multibootconf_1.00.bb.

Finally, grub-multibootconf-cntr-rst is a service that resets the boot counter when the OS loads. This is meant only for testing, therefore if you remove that then the boot counter will increment until reaches the max limit and then Grub will fallback to the rescue partition.Therefore, if you want to test that it works properly you need to either disable the init/service or remove it from the IMAGE_INSTALL. Also the counter timeout value is set in poky/meta/recipes-bsp/grub/grub-multibootconf_1.00.bb with the GRUB_BOOT_TRIES variable.

---
 meta/recipes-bsp/grub/files/bootcntr-rst.init |  35 +++++
 .../grub/files/bootcntr-rst.service           |   9 ++
 .../recipes-bsp/grub/files/grub-multiboot.cfg | 148 ++++++++++++++++++
 meta/recipes-bsp/grub/grub-efi_2.02.bb        |   2 +-
 .../grub/grub-multibootconf-cntr-rst_1.00.bb  |  30 ++++
 .../grub/grub-multibootconf_1.00.bb           | 107 +++++++++++++
 meta/recipes-bsp/grub/grub_2.02.bb            |   2 +
 .../canned-wks/directdisk-multi-rootfs.wks    |  23 ---
 .../canned-wks/directdisk-multi-rootfs.wks.in |  22 +++
 9 files changed, 354 insertions(+), 24 deletions(-)
 create mode 100755 meta/recipes-bsp/grub/files/bootcntr-rst.init
 create mode 100644 meta/recipes-bsp/grub/files/bootcntr-rst.service
 create mode 100644 meta/recipes-bsp/grub/files/grub-multiboot.cfg
 create mode 100644 meta/recipes-bsp/grub/grub-multibootconf-cntr-rst_1.00.bb
 create mode 100644 meta/recipes-bsp/grub/grub-multibootconf_1.00.bb
 delete mode 100644 scripts/lib/wic/canned-wks/directdisk-multi-rootfs.wks
 create mode 100644 scripts/lib/wic/canned-wks/directdisk-multi-rootfs.wks.in
meta/recipes-bsp/grub/files/bootcntr-rst.init new file +35 -0
new file mode 100755
index 0000000000..e89dbf53e2
@@ -0,0 +1,35 @@
+#!/bin/sh
+#/etc/init.d/bootcntr-rst: reset the grub boot counter.
+
+### BEGIN INIT INFO
+# Provides:          Grub boot counter reset
+# Short-Description: Resets the bootcntr grub env var
+# Required-Start:    $all
+# Required-Stop:     $all
+# Should-Start:      
+# Should-Stop:       
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+### END INIT INFO
+
+. /etc/init.d/functions
+
+case "$1" in
+    start)
+        /usr/bin/grub-editenv /boot/EFI/BOOT/bootcntr.env set bootcntr=0
+        ;;
+    stop)
+        echo "No stop available"
+	;;
+    status)
+        echo $(/usr/bin/grub-editenv /boot/EFI/BOOT/bootcntr.env list)
+        ;;
+    *)
+        echo $"Usage: $0 {start|stop|status}"
+        exit 2
+esac
+
+
+
+
+
meta/recipes-bsp/grub/files/bootcntr-rst.service new file +9 -0
new file mode 100644
index 0000000000..3582036241
@@ -0,0 +1,9 @@
+[Unit]
+Description=Resets the grub boot counter. This should be used only for testing
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/grub-editenv /boot/EFI/BOOT/bootcntr.env set bootcntr=0
+
+[Install]
+WantedBy=multi-user.target
meta/recipes-bsp/grub/files/grub-multiboot.cfg new file +148 -0

148 lines not on this page · raw message

meta/recipes-bsp/grub/grub-efi_2.02.bb +1 -1
index 14fce97ff0..56621d33f7 100644
@@ -85,7 +85,7 @@ do_install_class-target() {
 }
 
 GRUB_BUILDIN ?= "boot linux ext2 fat serial part_msdos part_gpt normal \
-                 efi_gop iso9660 configfile search loadenv test"
+                 efi_gop iso9660 configfile search loadenv test hashsum eval echo cat reboot sleep read"
 
 do_deploy() {
 	install -m 644 ${B}/${GRUB_IMAGE_PREFIX}${GRUB_IMAGE} ${DEPLOYDIR}
meta/recipes-bsp/grub/grub-multibootconf-cntr-rst_1.00.bb new file +30 -0
new file mode 100644
index 0000000000..15e4da355f
@@ -0,0 +1,30 @@
+DESCRIPTION = "Service to reset the grub boot counter. This should be used only for testing!"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
+
+inherit systemd
+
+RDEPENDS_${PN} += "bash"
+
+SRC_URI = " \
+            file://bootcntr-rst.service \
+            file://bootcntr-rst.init \
+            "
+S = "${WORKDIR}"
+
+do_install[depends] = "grub-multibootconf:do_install"
+
+do_install () {
+    install -d ${D}${sysconfdir}/init.d
+    install -m 0755 ${WORKDIR}/bootcntr-rst.init ${D}${sysconfdir}/init.d/bootcntr-rst
+	install -d ${D}${systemd_unitdir}/system/ ${D}${sysconfdir}/systemd/system/
+	install -m 0644 ${WORKDIR}/bootcntr-rst.service ${D}${systemd_unitdir}/system
+}
+
+INITSCRIPT_PACKAGES = "${PN}"
+INITSCRIPT_NAME = "bootcntr-rst"
+INITSCRIPT_PARAMS = "start 99 S ."
+
+NATIVE_SYSTEMD_SUPPORT = "1"
+SYSTEMD_PACKAGES = "${PN}"
+SYSTEMD_SERVICE_${PN} = "bootcntr-rst.service"
\ No newline at end of file
meta/recipes-bsp/grub/grub-multibootconf_1.00.bb new file +107 -0

108 lines not on this page · raw message

meta/recipes-bsp/grub/grub_2.02.bb +2 -0
index e0973759fb..cedabc7da8 100644
@@ -27,3 +27,5 @@ do_install_append () {
 
 INSANE_SKIP_${PN} = "arch"
 INSANE_SKIP_${PN}-dbg = "arch"
+
+BBCLASSEXTEND = "native"
\ No newline at end of file
scripts/lib/wic/canned-wks/directdisk-multi-rootfs.wks deleted +0 -23
deleted file mode 100644
index f61d941d6d..0000000000
@@ -1,23 +0,0 @@
-# short-description: Create multi rootfs image using rootfs plugin
-# long-description: Creates a partitioned disk image with two rootfs partitions
-# using rootfs plugin.
-#
-# Partitions can use either
-#   - indirect rootfs references to image recipe(s):
-#     wic create directdisk-multi-indirect-recipes -e core-image-minimal \
-#         --rootfs-dir rootfs1=core-image-minimal
-#         --rootfs-dir rootfs2=core-image-minimal-dev
-#
-#   - or paths to rootfs directories:
-#     wic create directdisk-multi-rootfs \
-#         --rootfs-dir rootfs1=tmp/work/qemux86_64-poky-linux/core-image-minimal/1.0-r0/rootfs/
-#         --rootfs-dir rootfs2=tmp/work/qemux86_64-poky-linux/core-image-minimal-dev/1.0-r0/rootfs/
-#
-#   - or any combinations of -r and --rootfs command line options
-
-part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
-part / --source rootfs --rootfs-dir=rootfs1 --ondisk sda --fstype=ext4 --label platform --align 1024
-part /rescue --source rootfs --rootfs-dir=rootfs2 --ondisk sda --fstype=ext4 --label secondary --align 1024
-
-bootloader  --timeout=0  --append="rootwait rootfstype=ext4 video=vesafb vga=0x318 console=tty0 console=ttyS0,115200n8"
-
scripts/lib/wic/canned-wks/directdisk-multi-rootfs.wks.in new file +22 -0
new file mode 100644
index 0000000000..d661063257
@@ -0,0 +1,22 @@
+# short-description: Create multi rootfs image using rootfs plugin
+#
+# This wks file is meant to be used when the grub-multibootconf is set as the
+# preferred RPROVIDER for virtual/grub-bootconf. By default the --source for
+# both partitions is set to the same image, but you can change that with any
+# image you wish. Because wic creates its own boot partition which overrides
+# the grub boot files from the grub-multibootconf recipe, you need to used the
+# --rootfs-dir and --exclude-path options.
+#
+# --rootfs-dir: This needs to point to the actual /boot folder in the image.
+#       Usually, this pointed by ${IMAGE_ROOTFS} variable. 
+#
+# --exclude-path: This will force wic tool to exclude the /boot folder in the
+#       rootfs and will not override it.
+#
+# With both options provided, wic tool will use the rootfs/boot folder to creates
+# the boot partition.
+#
+bootloader --ptable gpt
+part /boot --source rootfs --rootfs-dir=${IMAGE_ROOTFS}/boot --fstype=vfat --ondisk sda --label boot --active --align 1024
+part / --source rootfs --ondisk sda --fstype=ext4 --label root --align 1024 --exclude-path boot/
+part /rescue --source rootfs --ondisk sda --fstype=ext4 --label rescue --align 1024 --exclude-path boot/
\ No newline at end of file
Signature · 1 line
2.17.1