From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id A7F9560496 for ; Fri, 4 Feb 2022 19:45:58 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 90B2D462 for ; Fri, 4 Feb 2022 19:45:58 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id A5DCA3DF for ; Fri, 4 Feb 2022 19:45:55 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 7AF60461B0 for ; Fri, 4 Feb 2022 19:45:55 +0100 (CET) From: Stoiko Ivanov To: pve-devel@lists.proxmox.com Date: Fri, 4 Feb 2022 19:45:35 +0100 Message-Id: <20220204184538.3139247-4-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220204184538.3139247-1-s.ivanov@proxmox.com> References: <20220204184538.3139247-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.248 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH pve-kernel-meta v2 3/4] proxmox-boot: add kernel next-boot command X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Feb 2022 18:45:58 -0000 by setting the desired version in a dedicated file, which is used by the systemd service as condition for removing it and refreshing upon reboot Signed-off-by: Stoiko Ivanov --- bin/proxmox-boot-tool | 34 +++++++++++++++++------ debian/pve-kernel-helper.install | 1 + debian/rules | 3 ++ proxmox-boot/Makefile | 4 +++ proxmox-boot/functions | 3 ++ proxmox-boot/proxmox-boot-cleanup.service | 13 +++++++++ proxmox-boot/zz-proxmox-boot | 3 ++ 7 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 proxmox-boot/proxmox-boot-cleanup.service diff --git a/bin/proxmox-boot-tool b/bin/proxmox-boot-tool index 31342a6..5d878f6 100755 --- a/bin/proxmox-boot-tool +++ b/bin/proxmox-boot-tool @@ -299,8 +299,9 @@ usage() { warn " $0 init " warn " $0 clean [--dry-run]" warn " $0 refresh [--hook ]" - warn " $0 kernel " - warn " $0 kernel " + warn " $0 kernel " + warn " $0 kernel list" + warn " $0 kernel unpin [--next-boot]" warn " $0 status [--quiet]" warn " $0 help" } @@ -322,16 +323,20 @@ help() { echo "" echo " refresh all configured EFI system partitions. Use --hook to only run the specified hook, omit to run all." echo "" - echo "USAGE: $0 kernel " + echo "USAGE: $0 kernel " echo "" echo " add/remove pve-kernel with ABI to list of synced kernels, in addition to automatically selected ones." echo " pin pve-kernel with ABI sets it as the default entry to be booted." + echo " next-boot pve-kernel with ABI sets the kernel version for the next boot." echo " NOTE: you need to manually run 'refresh' once you're finished with adding/removing/pinning kernels from the list" echo "" - echo "USAGE: $0 kernel " + echo "USAGE: $0 kernel list" echo "" echo " list kernel versions currently selected for inclusion on ESPs." - echo " unpin sets the latest kernel as the default entry (undoes a previous pin)" + echo "" + echo "USAGE: $0 kernel unpin [--next-boot]" + echo "" + echo " unpin removes pinned and next-boot kernel settings. Use --next-boot to only remove a next-boot setting." echo "" echo "USAGE: $0 status [--quiet]" echo "" @@ -400,6 +405,7 @@ status() { pin_kernel() { ver="$1" + pin_file="$2" if [ -z "$ver" ]; then warn "E: is mandatory" @@ -407,17 +413,25 @@ pin_kernel() { exit 1 fi + if [ -z "$pin_file" ]; then + pin_file="$PINNED_KERNEL_CONF" + fi + if [ ! -e "/boot/vmlinuz-$ver" ]; then warn "E: no kernel image found in /boot for '$ver', not setting default." exit 1 fi - echo "$ver" > "$PINNED_KERNEL_CONF" + echo "$ver" > "$pin_file" echo "Set kernel '$ver' $PINNED_KERNEL_CONF. Use the 'refresh' command to update the ESPs." } unpin_kernel() { - rm -f "$PINNED_KERNEL_CONF" - echo "Removed $PINNED_KERNEL_CONF. Use the 'refresh' command to update the ESPs." + rm -f "$NEXT_BOOT_PIN" + echo "Removed $NEXT_BOOT_PIN. Use the 'refresh' command to update the ESPs." + if [ -z "$1" ]; then + rm -f "$PINNED_KERNEL_CONF" + echo "Removed $PINNED_KERNEL_CONF. Use the 'refresh' command to update the ESPs." + fi } if [ -z "$1" ]; then @@ -496,6 +510,10 @@ case "$1" in unpin_kernel "$2" exit 0 ;; + 'next-boot') + pin_kernel "$2" "${NEXT_BOOT_PIN}" + exit 0 + ;; *) warn "E: invalid 'kernel' subcommand '$cmd'." warn "" diff --git a/debian/pve-kernel-helper.install b/debian/pve-kernel-helper.install index 5f264aa..33170fb 100644 --- a/debian/pve-kernel-helper.install +++ b/debian/pve-kernel-helper.install @@ -2,6 +2,7 @@ etc/grub.d/000_proxmox_boot_header etc/kernel/postinst.d/* etc/kernel/postrm.d/* etc/initramfs/post-update.d/proxmox-boot-sync +lib/systemd/system/proxmox-boot-cleanup.service usr/sbin/proxmox-boot-tool usr/sbin/grub-install usr/share/pve-kernel-helper/scripts/functions diff --git a/debian/rules b/debian/rules index 58f7f7d..3dd1bc8 100755 --- a/debian/rules +++ b/debian/rules @@ -12,5 +12,8 @@ debian/control: $(wildcard debian/*.in) %: dh $@ +override_dh_installsystemd: + dh_installsystemd --no-start + .PHONY: build clean build clean: diff --git a/proxmox-boot/Makefile b/proxmox-boot/Makefile index effd726..2b0685d 100644 --- a/proxmox-boot/Makefile +++ b/proxmox-boot/Makefile @@ -2,12 +2,14 @@ KERNEL_HOOKSCRIPTS = proxmox-auto-removal zz-proxmox-boot INITRAMFS_HOOKSCRIPTS = proxmox-boot-sync SHARE_FILES = functions GRUB_CFG_SNIPPET = 000_proxmox_boot_header +SYSTEMD_SERVICES = proxmox-boot-cleanup.service POSTINSTHOOKDIR = ${DESTDIR}/etc/kernel/postinst.d POSTRMHOOKDIR = ${DESTDIR}/etc/kernel/postrm.d POSTINITRAMFSHOOKDIR = ${DESTDIR}/etc/initramfs/post-update.d SHARE_SCRIPTDIR = ${DESTDIR}/usr/share/pve-kernel-helper/scripts GRUB_CFG_DIR = ${DESTDIR}/etc/grub.d +SERVICE_DIR = ${DESTDIR}/lib/systemd/system .PHONY: all all: @@ -23,6 +25,8 @@ install: install -m 0755 ${SHARE_FILES} ${SHARE_SCRIPTDIR} install -d ${GRUB_CFG_DIR} install -m 0755 ${GRUB_CFG_SNIPPET} ${GRUB_CFG_DIR} + install -d ${SERVICE_DIR} + install -m 0644 ${SYSTEMD_SERVICES} ${SERVICE_DIR} .PHONY: clean distclean distclean: diff --git a/proxmox-boot/functions b/proxmox-boot/functions index d97a7a1..b1a10a5 100755 --- a/proxmox-boot/functions +++ b/proxmox-boot/functions @@ -6,6 +6,7 @@ ESPTYPE='c12a7328-f81f-11d2-ba4b-00a0c93ec93b' MANUAL_KERNEL_LIST="/etc/kernel/pve-efiboot-manual-kernels" PINNED_KERNEL_CONF="/etc/kernel/proxmox-boot-pin" +NEXT_BOOT_PIN="/etc/kernel/next-boot-pin" MOUNTROOT="${TMPDIR:-/var/tmp}/espmounts" # relative to the ESP mountpoint @@ -60,6 +61,7 @@ kernel_keep_versions() { fi pinned_kernel="$(get_first_line "$PINNED_KERNEL_CONF")" + nextboot_kernel="$(get_first_line "$NEXT_BOOT_PIN")" kernels="$(cat <<-EOF $running_version @@ -69,6 +71,7 @@ kernel_keep_versions() { $series_metapackages $oldseries_latest_kernel $pinned_kernel + $nextboot_kernel EOF )" diff --git a/proxmox-boot/proxmox-boot-cleanup.service b/proxmox-boot/proxmox-boot-cleanup.service new file mode 100644 index 0000000..4f9da94 --- /dev/null +++ b/proxmox-boot/proxmox-boot-cleanup.service @@ -0,0 +1,13 @@ +[Unit] +Description=Clean up bootloader next-boot setting +After=systemd-remount-fs.service +ConditionPathExists=/etc/kernel/next-boot-pin + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/sbin/proxmox-boot-tool kernel unpin --next-boot +ExecStart=/usr/sbin/proxmox-boot-tool refresh + +[Install] +WantedBy=multi-user.target diff --git a/proxmox-boot/zz-proxmox-boot b/proxmox-boot/zz-proxmox-boot index 7958a5d..5fe16a6 100755 --- a/proxmox-boot/zz-proxmox-boot +++ b/proxmox-boot/zz-proxmox-boot @@ -93,6 +93,9 @@ update_esp_func() { pinned_kernel=$(get_first_line "${PINNED_KERNEL_CONF}") + if [ -e "${NEXT_BOOT_PIN}" ]; then + pinned_kernel=$(get_first_line "${NEXT_BOOT_PIN}") + fi if [ -d /sys/firmware/efi ]; then set_systemd_boot_default "${mountpoint}" "${pinned_kernel}" remove_old_kernels_efi "${mountpoint}" -- 2.30.2