all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH 1/3] boot-tool: disarm upstream systemd-boot hookscripts
Date: Wed, 21 Jun 2023 16:32:25 +0200	[thread overview]
Message-ID: <20230621143227.1510250-2-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20230621143227.1510250-1-s.ivanov@proxmox.com>

With Debian Bookworm systemd-boot is a separate binary-package,
instead of part of the main systemd package.
Since it's not installed by default, Debian-upstream has added
hook-scripts to the package, which manage kernel copying to the esp
(kernel-install).

The hookscripts print a warning if the ESP is not mounted at
$SYSTEMD_ESP_PATH or /boot/efi, /efi or /boot - through `bootctl
is-installed --quiet` [0,1].

This patch adds a function, which disables the hookscripts from
upstream if /etc/kernel/proxmox-boot-uuids is present.
It adds an explanation as marker and 'exit 0' on top of the script, so
that users know why the scripts were touched (e.g. when a new
systemd-boot hookscript version from upstream asks what to do with the
local modifications)

While editing shell-script hooks from other packages is quite brittle
it still seems like the best option, to support most use-cases
(including users, who don't use proxmox-boot-tool, but want to
manually install systemd-boot).
Alternatives considered:
* dpkg-divert for all hookscripts - sadly the Debian policy manual
  warns against this
* adding Replaces: systemd-boot to d/control - afaict this would need
  systemd-boot to also declare this for proxmox-kernel-helper [3]

Tested on 2 VMs installed with the 8.0 ISO (once with legacy once with
uefi boot)

[0]
https://github.com/systemd/systemd/blob/8a38b62f37189b071a30f208530ce5dc278e521e/src/shared/find-esp.c#L503
[1]
https://github.com/systemd/systemd/blob/8a38b62f37189b071a30f208530ce5dc278e521e/src/boot/bootctl.c#L90
[2] https://www.debian.org/doc/debian-policy/ap-pkg-diversions.html
[3] https://www.debian.org/doc/debian-policy/ch-relationships.html

Reported-by: Aaron Lauterer <a.lauterer@proxmox.com>
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
 src/proxmox-boot/zz-proxmox-boot | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/proxmox-boot/zz-proxmox-boot b/src/proxmox-boot/zz-proxmox-boot
index c6c708c..c72f9ef 100755
--- a/src/proxmox-boot/zz-proxmox-boot
+++ b/src/proxmox-boot/zz-proxmox-boot
@@ -191,6 +191,27 @@ remove_old_kernels_legacy() {
 
 }
 
+disable_systemd_boot_hook() {
+
+	if [ ! -f "${ESP_LIST}" ]; then
+		return
+	fi
+
+	marker="# This hookfile has been disabled by proxmox-boot-tool"
+	for hookfile in \
+		"/etc/initramfs/post-update.d/systemd-boot" \
+		"/etc/kernel/postinst.d/zz-systemd-boot" \
+		"/etc/kernel/postrm.d/zz-systemd-boot" ; \
+	do
+		grep -q "$marker" "$hookfile" && continue
+		warn "	Disabling upstream hook $hookfile"
+		printf "#!/bin/sh\n\n%s\nexit 0\n" "$marker" > "$hookfile.pbt.tmp"
+		cat "$hookfile" >> "$hookfile.pbt.tmp"
+		mv "$hookfile.pbt.tmp" "$hookfile"
+	done
+
+}
+
 set -- $DEB_MAINT_PARAMS
 mode="${1#\'}"
 mode="${mode%\'}"
@@ -203,12 +224,14 @@ case $0:$mode in
 		reexec_in_mountns "$@"
 		BOOT_KVERS="$(boot_kernel_list "$@")"
 		update_esps
+		disable_systemd_boot_hook
 	;;
 	 */postrm.d/*:|*/postrm.d/*:remove)
 		reexec_in_mountns "$@"
 		# no newly installed kernel
 		BOOT_KVERS="$(boot_kernel_list)"
 		update_esps
+		disable_systemd_boot_hook
 	;;
 esac
 
-- 
2.30.2





  reply	other threads:[~2023-06-21 14:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-21 14:32 [pve-devel] [PATCH 0/3] adapt to systemd-boot hooks in bookworm Stoiko Ivanov
2023-06-21 14:32 ` Stoiko Ivanov [this message]
2023-06-21 14:32 ` [pve-devel] [PATCH 2/3] proxmox-boot: warn on missing systemd-boot package Stoiko Ivanov
2023-06-21 14:32 ` [pve-devel] [PATCH 3/3] d/control: add Recommends on systemd-boot Stoiko Ivanov
2023-06-21 15:37 ` [pve-devel] applied: [PATCH 0/3] adapt to systemd-boot hooks in bookworm Thomas Lamprecht

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=20230621143227.1510250-2-s.ivanov@proxmox.com \
    --to=s.ivanov@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal