From: Reza Arbab <arbab@linux.ibm.com>
To: buildroot@buildroot.org, Arnout Vandecappelle <arnout@mind.be>,
"Yann E . MORIN" <yann.morin.1998@free.fr>
Cc: Joel Stanley <joel@jms.id.au>,
Fabrice Fontaine <fontaine.fabrice@gmail.com>,
Laurent Vivier <laurent@vivier.eu>
Subject: [Buildroot] [PATCH v5 3/5] package/petitboot: fix shutdown
Date: Wed, 7 Feb 2024 11:51:33 -0600 [thread overview]
Message-ID: <20240207175135.1532037-4-arbab@linux.ibm.com> (raw)
In-Reply-To: <20240207175135.1532037-1-arbab@linux.ibm.com>
It's good practice to unmount filesystems and gracefully terminate
running services before running "kexec -e". So when a boot option has
been chosen from the petitboot menu, poke init to shut the system down
and kexec the new kernel.
One benefit to us in particular is that when pb-console is killed, it
notifies the user that we're booting:
trap 'reset; echo "SIGTERM received, booting..."; sleep 2' SIGTERM
This terminal reset is also useful, exiting the ncurses visual mode so
subsequent boot output is raw rather than being confined to the window
set up for the petitboot menu.
Currently we assume busybox init, but do not add an accompanying entry
in the inittab to run kexec, so things aren't working. Fix this and
accomodate the other buildroot init systems as well.
Signed-off-by: Reza Arbab <arbab@linux.ibm.com>
---
package/petitboot/kexec-restart | 26 ++++++++++++++++++++++++++
package/petitboot/petitboot.mk | 20 +++++++++++++++++---
2 files changed, 43 insertions(+), 3 deletions(-)
create mode 100644 package/petitboot/kexec-restart
diff --git a/package/petitboot/kexec-restart b/package/petitboot/kexec-restart
new file mode 100644
index 000000000000..14e6899f70bb
--- /dev/null
+++ b/package/petitboot/kexec-restart
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+case "$(/usr/bin/readlink -f /proc/1/exe)" in
+ /bin/busybox)
+ # inittab "restart" runlevel entry runs kexec
+ /bin/kill -QUIT 1
+ ;;
+ /sbin/init)
+ # inittab runlevel 6 entry runs kexec
+ /sbin/shutdown -r now
+ ;;
+ /sbin/openrc-init)
+ /sbin/openrc-shutdown --kexec now
+ ;;
+ /usr/lib/systemd/systemd)
+ /usr/bin/systemctl kexec
+ ;;
+ *)
+ /usr/sbin/kexec -f -e
+ ;;
+esac
+
+while :
+do
+ sleep 1
+done
diff --git a/package/petitboot/petitboot.mk b/package/petitboot/petitboot.mk
index 4c8bc35adb38..291083269ae9 100644
--- a/package/petitboot/petitboot.mk
+++ b/package/petitboot/petitboot.mk
@@ -29,7 +29,7 @@ PETITBOOT_CONF_OPTS = \
--without-twin-x11 \
$(if $(BR2_PACKAGE_BUSYBOX),--enable-busybox,--disable-busybox) \
HOST_PROG_KEXEC=/usr/sbin/kexec \
- HOST_PROG_SHUTDOWN=/usr/libexec/petitboot/bb-kexec-reboot
+ HOST_PROG_SHUTDOWN=/usr/sbin/kexec-restart
# HPA and Busybox tftp are supported. HPA tftp is part of Buildroot's tftpd
# package.
@@ -54,17 +54,31 @@ else
PETITBOOT_CONF_OPTS += --without-fdt
endif
+ifeq ($(BR2_INIT_BUSYBOX),y)
+define PETITBOOT_BUSYBOX_INITTAB
+ grep -q kexec $(TARGET_DIR)/etc/inittab || \
+ printf "\nnull::restart:/usr/sbin/kexec -f -e\n" >> $(TARGET_DIR)/etc/inittab
+endef
+PETITBOOT_TARGET_FINALIZE_HOOKS += PETITBOOT_BUSYBOX_INITTAB
+else ifeq ($(BR2_INIT_SYSV),y)
+define PETITBOOT_SYSV_INITTAB
+ grep -q kexec $(TARGET_DIR)/etc/inittab || \
+ $(SED) 's~^reb0:.*~reb0:6:wait:/usr/sbin/kexec -f -e~' $(TARGET_DIR)/etc/inittab
+endef
+PETITBOOT_TARGET_FINALIZE_HOOKS += PETITBOOT_SYSV_INITTAB
+endif
+
PETITBOOT_GETTY_PORT = $(patsubst %,'%',$(call qstrip,$(BR2_PACKAGE_PETITBOOT_GETTY_PORT)))
define PETITBOOT_POST_INSTALL
- $(INSTALL) -D -m 0755 $(@D)/utils/bb-kexec-reboot \
- $(TARGET_DIR)/usr/libexec/petitboot/bb-kexec-reboot
$(INSTALL) -D -m 0755 $(@D)/utils/hooks/01-create-default-dtb \
$(TARGET_DIR)/etc/petitboot/boot.d/01-create-default-dtb
$(INSTALL) -D -m 0755 $(@D)/utils/hooks/90-sort-dtb \
$(TARGET_DIR)/etc/petitboot/boot.d/90-sort-dtb
$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/S15pb-discover \
$(TARGET_DIR)/etc/init.d/S15pb-discover
+ $(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/kexec-restart \
+ $(TARGET_DIR)/usr/sbin/kexec-restart
$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-console \
$(TARGET_DIR)/etc/init.d/pb-console
--
2.39.3
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
next prev parent reply other threads:[~2024-02-07 17:52 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-07 17:51 [Buildroot] [PATCH v5 0/5] package/petitboot: misc fixes/enhancement Reza Arbab
2024-02-07 17:51 ` [Buildroot] [PATCH v5 1/5] package/petitboot: minor makefile cleanup Reza Arbab
2024-02-07 19:14 ` Yann E. MORIN
2024-03-08 11:27 ` Peter Korsgaard
2024-02-07 17:51 ` [Buildroot] [PATCH v5 2/5] package/petitboot: prefer UTF-8 support Reza Arbab
2024-02-07 19:43 ` Yann E. MORIN
2024-03-08 11:27 ` Peter Korsgaard
2024-02-07 17:51 ` Reza Arbab [this message]
2024-07-12 22:02 ` [Buildroot] [PATCH v5 3/5] package/petitboot: fix shutdown Arnout Vandecappelle via buildroot
2024-02-07 17:51 ` [Buildroot] [PATCH v5 4/5] package/petitboot: run script when exiting to shell Reza Arbab
2024-07-12 22:02 ` Arnout Vandecappelle via buildroot
2024-02-07 17:51 ` [Buildroot] [PATCH v5 5/5] package/petitboot: run UI as non-root user Reza Arbab
2024-07-12 22:03 ` Arnout Vandecappelle via buildroot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240207175135.1532037-4-arbab@linux.ibm.com \
--to=arbab@linux.ibm.com \
--cc=arnout@mind.be \
--cc=buildroot@buildroot.org \
--cc=fontaine.fabrice@gmail.com \
--cc=joel@jms.id.au \
--cc=laurent@vivier.eu \
--cc=yann.morin.1998@free.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox