package/petitboot: misc fixes/enhancement
v5 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
---
v5:
* Rebase to apply on top of some recent NLS fixes.
* Nobody replied to v4. Cc'ing some more people in hopes of getting these changes into the next release.
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 | 4 ++++ 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, 79 insertions(+), 9 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 v5 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
@@ -63,15 +63,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
Yann E. MORIN
AppliedRe: [Buildroot] [PATCH v5 1/5] package/petitboot: minor makefile cleanup
Reza, All,
On 2024-02-07 11:51 -0600, Reza Arbab spake thusly:
Quoted 4 lines
Normalize the order of arguments to $(INSTALL). Remove an unnecessary pair of parentheses.
Signed-off-by Reza Arbab <[email protected]>
Applied to master, thanks.
Regards,
Yann E. MORIN.
Quoted 34 lines
--- package/petitboot/petitboot.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)package/petitboot/petitboot.mk +3
-3@@ -63,15 +63,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
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------' _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Re: [Buildroot] [PATCH v5 1/5] package/petitboot: minor makefile cleanup
In reply to Reza ArbabQuoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Reza" == Reza Arbab <[email protected]> writes:
Normalize the order of arguments to $(INSTALL). Remove an unnecessary pair of parentheses.
Signed-off-by Reza Arbab <[email protected]>
Committed to 2023.11.x, thanks.
Signature · 5 lines
Bye, Peter Korsgaard _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v5 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.
Turn on wchar support in ncurses, and 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 | 3 +++ 1 file changed, 3 insertions(+)
package/petitboot/Config.in +3 -0
@@ -10,6 +10,7 @@ config BR2_PACKAGE_PETITBOOT 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
@@ -18,6 +19,8 @@ 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 if BR2_PACKAGE_PETITBOOT
Signature · 6 lines
2.39.3 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Yann E. MORIN
AppliedRe: [Buildroot] [PATCH v5 2/5] package/petitboot: prefer UTF-8 support
Reza, All,
On 2024-02-07 11:51 -0600, Reza Arbab spake thusly:
Quoted 33 lines
The 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.
Turn on wchar support in ncurses, and 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
Signed-off-by Reza Arbab <[email protected]>--- package/petitboot/Config.in | 3 +++ 1 file changed, 3 insertions(+)package/petitboot/Config.in +1
-0@@ -10,6 +10,7 @@ config BR2_PACKAGE_PETITBOOT 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
package/petitboot/Config.in config BR2_PACKAGE_PETITBOOT · line 22
Quoted 4 lines
package/petitboot/Config.in +1
-0@@ -18,6 +19,8 @@ config BR2_PACKAGE_PETITBOOT help Petitboot is a small kexec-based bootloader + NOTE: petitboot looks best in a UTF-8 locale (BR2_GENERATE_LOCALE)
$ ./utils/docker-run make check-package
package/petitboot/Config.in:22: help text: <tab><2 spaces><62 chars> (http://nightly.buildroot.org/#writing-rules-config-in)I slightly reworded that sentence to better fit.
Applied to master with the above fixed, thanks.
Regards,
Yann E. MORIN.
Quoted 10 lines
package/petitboot/Config.in +0
-0http://www.kernel.org/pub/linux/kernel/people/geoff/petitboot/petitboot.html if BR2_PACKAGE_PETITBOOTSignature · 6 lines
2.39.3 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------' _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Re: [Buildroot] [PATCH v5 2/5] package/petitboot: prefer UTF-8 support
In reply to Reza ArbabQuoted 11 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Reza" == Reza Arbab <[email protected]> writes:
The 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.
Quoted 6 lines
Turn on wchar support in ncurses, and 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
Signed-off-by Reza Arbab <[email protected]>
Committed to 2023.11.x, thanks.
Signature · 5 lines
Bye, Peter Korsgaard _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v5 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
@@ -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
Signature · 6 lines
2.39.3 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Re: [Buildroot] [PATCH v5 3/5] package/petitboot: fix shutdown
Quoted 14 lines · Reza Arbab
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.
Quoted 5 lines
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 <[email protected]>
Applied to master, thanks. I still modified it pretty heavily though, see
below. You may want to re-test it on your side as well.
Quoted 22 lines
--- 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 +10
-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
package/petitboot/kexec-restart line 20
Quoted 10 lines
package/petitboot/kexec-restart new file +10
-0+ ;; + /sbin/openrc-init) + /sbin/openrc-shutdown --kexec now + ;; + /usr/lib/systemd/systemd) + /usr/bin/systemctl kexec + ;; + *) + /usr/sbin/kexec -f -e + ;;
Rather than dynamically discovering the init system, I elected to do it
statically based on the config, and sed-ing the appropriate command into a skeleton script.
Quoted 11 lines
package/petitboot/kexec-restart new file +6
-0+esac + +while : +do + sleep 1 +donepackage/petitboot/petitboot.mk +0
-0
package/petitboot/petitboot.mk PETITBOOT_CONF_OPTS = \ · line 32
Quoted 5 lines
package/petitboot/petitboot.mk +1
-1@@ -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
I kept this in /usr/libexec/petitboot.
Quoted 16 lines
package/petitboot/petitboot.mk +9
-0# 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 || \
package/petitboot/petitboot.mk else · line 61
Quoted 10 lines
package/petitboot/petitboot.mk +5
-2+ $(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
I kept the installation of kexec-restart in this location instead of at the
end, that makes the diff more reasonable and I couldn't discern any particular reasoning behind the ordering.
Regards,
Arnout
package/petitboot/petitboot.mk else · line 84
Quoted 11 lines
package/petitboot/petitboot.mk +2
-0$(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
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v5 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 so output is raw rather than being confined to the ncurses window set up for the petitboot menu, 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
package/petitboot/petitboot.mk +3 -0
@@ -29,6 +29,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
@@ -81,6 +82,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
Re: [Buildroot] [PATCH v5 4/5] package/petitboot: run script when exiting to shell
Quoted 10 lines · Reza Arbab
When the user selects the shell escape option from the petitboot menu, reset the terminal so output is raw rather than being confined to the ncurses window set up for the petitboot menu, 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.Signed-off-by Reza Arbab <[email protected]>
Applied to master, thanks.
Regards,
Arnout
Quoted 35 lines
--- 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/shpackage/petitboot/petitboot.mk +1
-0@@ -29,6 +29,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
package/petitboot/petitboot.mk define PETITBOOT_POST_INSTALL · line 89
Quoted 8 lines
package/petitboot/petitboot.mk +2
-0@@ -81,6 +82,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 \
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v5 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
@@ -84,6 +84,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 \
@@ -97,4 +99,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
Re: [Buildroot] [PATCH v5 5/5] package/petitboot: run UI as non-root user
Quoted 45 lines · Reza Arbab
Though 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-consolestart 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-ncInstead 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-consolestart 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-ncHere, 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.
Signed-off-by Reza Arbab <[email protected]>--- 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 +0
-0
package/petitboot/Config.in config BR2_PACKAGE_PETITBOOT · line 19
Quoted 4 lines
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
Although util-linux is selected indirectly through other dependencies (e.g.
eudev/systemd), it's better to do it explicitly.
Applied to master with that changed, thanks.
Regards,
Arnout
Quoted 69 lines
package/petitboot/Config.in +0
-0help Petitboot is a small kexec-based bootloaderpackage/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@@ -84,6 +84,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 \@@ -97,4 +99,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 +0
-0
package/petitboot/shell_profile line 3
Quoted 3 lines
package/petitboot/shell_profile new file +3
-0@@ -0,0 +1,3 @@ +if [ "$PPID" = "1" ]; then + exec /usr/libexec/petitboot/pb-console +fi
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot