package/petitboot: misc fixes/enhancement
v4 cover package/petitboot: misc fixes/enhancement
The br2-external tree used to build OpenPOWER firmware has long carried petitboot as a custom package[1]. Now that petitboot has been added to buildroot proper, it would be nice to leverage the base package instead.
To make that transition easier, here is a set of patches which port over some of the enhancements made to that external package.
[1] https://github.com/open-power/op-build/tree/master/openpower/package/petitboot
---
v4:
* Change the buildroot menu help to say that petitboot *looks best* in a UTF-8 locale, not that it *needs* one.
* Change the shutdown patch to accomodate any buildroot init system.
* Split the user separation patch into a couple of smaller ones with better log messages.
v3:
* Add a number of small fixes.
* Add user separation, so the UI runs as non-root.
* Remove udev rules that enabled some additional types of boot devices. These should more appropriately live outside of buildroot.
* Remove a sysctl.d file to silence kernel output. I think there's a bug upstream; see https://github.com/open-power/petitboot/pull/103
v2:
* Use Laurent's suggested additions to "run pb-console at boot" patch.
Reza Arbab (5):
package/petitboot: minor makefile cleanup package/petitboot: prefer UTF-8 support package/petitboot: fix shutdown package/petitboot: run script when exiting to shell package/petitboot: run UI as non-root user
package/petitboot/Config.in | 9 ++++++-- package/petitboot/S15pb-discover | 4 +++- package/petitboot/kexec-restart | 26 ++++++++++++++++++++++++ package/petitboot/pb-console | 6 ++++-- package/petitboot/pb-shell | 10 +++++++++ package/petitboot/petitboot.mk | 35 ++++++++++++++++++++++++++------ package/petitboot/shell_profile | 3 +++ 7 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 package/petitboot/kexec-restart create mode 100644 package/petitboot/pb-shell create mode 100644 package/petitboot/shell_profile
Signature · 6 lines
2.39.3 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v4 1/5 package/petitboot: minor makefile cleanup
Normalize the order of arguments to $(INSTALL). Remove an unnecessary pair of parentheses.
--- package/petitboot/petitboot.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
package/petitboot/petitboot.mk +3 -3
@@ -55,15 +55,15 @@ define PETITBOOT_POST_INSTALL $(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) -m 0755 -D $(PETITBOOT_PKGDIR)/S15pb-discover \ + $(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/S15pb-discover \ $(TARGET_DIR)/etc/init.d/S15pb-discover $(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-console \ $(TARGET_DIR)/etc/init.d/pb-console mkdir -p $(TARGET_DIR)/etc/udev/rules.d - (for port in $(PETITBOOT_GETTY_PORT); do \ + for port in $(PETITBOOT_GETTY_PORT); do \ printf 'SUBSYSTEM=="tty", KERNEL=="%s", RUN+="/etc/init.d/pb-console start $$name"\n' "$$port"; \ - done) > $(TARGET_DIR)/etc/udev/rules.d/petitboot-console-ui.rules + done > $(TARGET_DIR)/etc/udev/rules.d/petitboot-console-ui.rules mkdir -p $(TARGET_DIR)/usr/share/udhcpc/default.script.d/ ln -sf /usr/sbin/pb-udhcpc \
Signature · 6 lines
2.39.3 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v4 2/5 package/petitboot: prefer UTF-8 support
In reply to Reza ArbabThe petitboot UI looks much nicer in a Unicode locale:
* Items in the language selection submenu use multibyte Unicode characters. In other locales, they say "Unable to display text in this locale".
* The combination of TERM=linux with a UTF-8 locale is required to trigger a special-case workaround in ncurses code[1]. Without this, line-drawing characters in the menu look like q's.
Add a reminder that a UTF-8 locale should be generated for things to look right.
[1] https://invisible-island.net/ncurses/ncurses.faq.html#no_line_drawing
--- package/petitboot/Config.in | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
package/petitboot/Config.in +6 -2
@@ -3,12 +3,14 @@ config BR2_PACKAGE_PETITBOOT depends on BR2_PACKAGE_KEXEC_ARCH_SUPPORTS || BR2_PACKAGE_KEXEC_LITE_ARCH_SUPPORTS depends on BR2_USE_MMU # lvm2 depends on BR2_USE_WCHAR # elfutils + depends on BR2_ENABLE_LOCALE depends on !BR2_STATIC_LIBS # elfutils, lvm2 depends on BR2_TOOLCHAIN_HAS_THREADS # elfutils, lvm2 depends on BR2_PACKAGE_HAS_UDEV select BR2_PACKAGE_ELFUTILS select BR2_PACKAGE_LVM2 # devmapper select BR2_PACKAGE_NCURSES + select BR2_PACKAGE_NCURSES_WCHAR # run-time dependencies select BR2_PACKAGE_KEXEC if !BR2_PACKAGE_KEXEC_LITE_ARCH_SUPPORTS select BR2_PACKAGE_KEXEC_LITE if BR2_PACKAGE_KEXEC_LITE_ARCH_SUPPORTS && !BR2_PACKAGE_KEXEC
@@ -17,12 +19,14 @@ config BR2_PACKAGE_PETITBOOT help Petitboot is a small kexec-based bootloader + NOTE: petitboot looks best in a UTF-8 locale (BR2_GENERATE_LOCALE) + http://www.kernel.org/pub/linux/kernel/people/geoff/petitboot/petitboot.html -comment "petitboot needs a toolchain w/ wchar, dynamic library, threads, udev /dev management" +comment "petitboot needs a toolchain w/ wchar, locale, dynamic library, threads, udev /dev management" depends on BR2_PACKAGE_KEXEC_ARCH_SUPPORTS depends on BR2_USE_MMU - depends on !BR2_USE_WCHAR || BR2_STATIC_LIBS || \ + depends on !BR2_USE_WCHAR || !BR2_ENABLE_LOCALE || BR2_STATIC_LIBS || \ !BR2_TOOLCHAIN_HAS_THREADS || \ !BR2_PACKAGE_HAS_UDEV
Signature · 6 lines
2.39.3 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v4 3/5 package/petitboot: fix shutdown
In reply to Reza ArbabIt'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.
--- package/petitboot/kexec-restart | 26 ++++++++++++++++++++++++++ package/petitboot/petitboot.mk | 20 +++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 package/petitboot/kexec-restart
package/petitboot/kexec-restart new file +26 -0
@@ -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
package/petitboot/petitboot.mk +17 -3
@@ -21,7 +21,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.
@@ -46,17 +46,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
Signature · 6 lines
2.39.3 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v4 4/5 package/petitboot: run script when exiting to shell
In reply to Reza ArbabWhen the user selects the shell escape option from the petitboot menu, reset the terminal and print some helpful text before running the shell.
To do this, override the default HOST_PROG_SH (/bin/sh) with a small script. Doing so also enables someone to customize this behavior by overlaying a different script.
--- package/petitboot/pb-shell | 10 ++++++++++ package/petitboot/petitboot.mk | 3 +++ 2 files changed, 13 insertions(+) create mode 100644 package/petitboot/pb-shell
package/petitboot/pb-shell new file +10 -0
@@ -0,0 +1,10 @@ +#!/bin/sh + +reset + +cat <<EOM +Exiting petitboot. Type 'exit' to return. +You may run 'pb-sos' to gather diagnostic data. +EOM + +exec /bin/sh -l
package/petitboot/petitboot.mk +3 -0
@@ -21,6 +21,7 @@ PETITBOOT_CONF_OPTS = \ --without-twin-x11 \ $(if $(BR2_PACKAGE_BUSYBOX),--enable-busybox,--disable-busybox) \ HOST_PROG_KEXEC=/usr/sbin/kexec \ + HOST_PROG_SH=/usr/libexec/petitboot/pb-shell \ HOST_PROG_SHUTDOWN=/usr/sbin/kexec-restart # HPA and Busybox tftp are supported. HPA tftp is part of Buildroot's tftpd
@@ -73,6 +74,8 @@ define PETITBOOT_POST_INSTALL $(TARGET_DIR)/usr/sbin/kexec-restart $(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-console \ $(TARGET_DIR)/etc/init.d/pb-console + $(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-shell \ + $(TARGET_DIR)/usr/libexec/petitboot/pb-shell mkdir -p $(TARGET_DIR)/etc/udev/rules.d for port in $(PETITBOOT_GETTY_PORT); do \
Signature · 6 lines
2.39.3 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v4 5/5 package/petitboot: run UI as non-root user
In reply to Reza ArbabThough the petitboot UI is a user application, it is currently being run by root only because we use getty to display it on the console.
Create an unprivileged user to run the UI instead. The unix socket the pb-discover daemon sets up is accessible to "petitgroup", so that should be the gid, with arbitrary uid "petituser" to match.
This is currently the chain of processes leading to the UI:
1. /etc/init.d/pb-console start console
2. /usr/libexec/petitboot/pb-console --getty --detach -- -n -i 0 console linux
3. /sbin/getty -l/usr/libexec/petitboot/pb-console -n -i 0 console linux
4. /usr/libexec/petitboot/pb-console
5. /usr/sbin/petitboot-nc
Instead of (3) running the pb-console helper directly with "getty -l", we can use "agetty -a" to autologin petituser, and run pb-console via petituser's login shell:
1. /etc/init.d/pb-console start console
2. /usr/libexec/petitboot/pb-console --getty=/sbin/agetty --detach -- -a petituser -n -i console linux
3. /sbin/agetty -a petituser -n -i console linux
4. /home/petituser/.profile
5. /usr/libexec/petitboot/pb-console
6. /usr/sbin/petiboot-nc
Here, everything from (4) down is running as petituser. In (4), use $PPID to determine if we're logging in via getty, so that logging in by other means will give a normal shell.
--- package/petitboot/Config.in | 1 + package/petitboot/S15pb-discover | 4 +++- package/petitboot/pb-console | 6 ++++-- package/petitboot/petitboot.mk | 6 ++++++ package/petitboot/shell_profile | 3 +++ 5 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 package/petitboot/shell_profile
package/petitboot/Config.in +1 -0
@@ -16,6 +16,7 @@ config BR2_PACKAGE_PETITBOOT select BR2_PACKAGE_KEXEC_LITE if BR2_PACKAGE_KEXEC_LITE_ARCH_SUPPORTS && !BR2_PACKAGE_KEXEC select BR2_PACKAGE_NVME if ( BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le ) select BR2_PACKAGE_POWERPC_UTILS if ( BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le ) + select BR2_PACKAGE_UTIL_LINUX_AGETTY help Petitboot is a small kexec-based bootloader
package/petitboot/S15pb-discover +3 -1
@@ -12,7 +12,9 @@ fi start() { printf 'Starting %s: ' "$DAEMON" - mkdir -p /var/log/petitboot + # shellcheck disable=SC2174 # only apply -m to deepest dir + mkdir -p -m 0775 /var/log/petitboot + chown petituser:petitgroup /var/log/petitboot # shellcheck disable=SC2086 # we need the word splitting start-stop-daemon -S -q -b -m -p "$PIDFILE" -x "/usr/sbin/$DAEMON" \
package/petitboot/pb-console +4 -2
@@ -3,14 +3,16 @@ DAEMON="pb-console" PB_CONSOLE_PORT=${2:-"console"} -PB_CONSOLE_ARGS="--getty --detach -- -n -i 0 $PB_CONSOLE_PORT linux" +PB_CONSOLE_ARGS="--getty=/sbin/agetty --detach -- -a petituser -n -i $PB_CONSOLE_PORT linux" # shellcheck source=/dev/null [ -r "/etc/default/petitboot" ] && . "/etc/default/petitboot" start() { printf 'Starting %s on %s: ' "$DAEMON" "$PB_CONSOLE_PORT" - mkdir -p /var/log/petitboot + # shellcheck disable=SC2174 # only apply -m to deepest dir + mkdir -p -m 0775 /var/log/petitboot + chown petituser:petitgroup /var/log/petitboot # shellcheck disable=SC2086 # we need the word splitting start-stop-daemon -S -q -x "/usr/libexec/petitboot/$DAEMON" \
package/petitboot/petitboot.mk +6 -0
@@ -76,6 +76,8 @@ define PETITBOOT_POST_INSTALL $(TARGET_DIR)/etc/init.d/pb-console $(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-shell \ $(TARGET_DIR)/usr/libexec/petitboot/pb-shell + $(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/shell_profile \ + $(TARGET_DIR)/home/petituser/.profile mkdir -p $(TARGET_DIR)/etc/udev/rules.d for port in $(PETITBOOT_GETTY_PORT); do \
@@ -89,4 +91,8 @@ endef PETITBOOT_POST_INSTALL_TARGET_HOOKS += PETITBOOT_POST_INSTALL +define PETITBOOT_USERS + petituser -1 petitgroup -1 * /home/petituser /bin/sh - petitboot user +endef + $(eval $(autotools-package))
package/petitboot/shell_profile new file +3 -0
@@ -0,0 +1,3 @@ +if [ "$PPID" = "1" ]; then + exec /usr/libexec/petitboot/pb-console +fi
Signature · 6 lines
2.39.3 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 8 lines · Reza Arbab
v4:
* Change the buildroot menu help to say that petitboot *looks best* in a UTF-8 locale, not that it *needs* one.* Change the shutdown patch to accomodate any buildroot init system.
* Split the user separation patch into a couple of smaller ones with better log messages.
I think this addresses Arnout's feedback from v3. Is there something more I could do to get this series committed?
Signature · 5 lines
Reza Arbab _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot