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 pve-kernel-meta v2 4/8] proxmox-boot: refresh based on bootloader config instead of bootmode
Date: Thu,  3 Mar 2022 20:07:53 +0100	[thread overview]
Message-ID: <20220303190759.3527703-5-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20220303190759.3527703-1-s.ivanov@proxmox.com>

ignore the current bootmode (uefi/legacy) when deciding which configs
to generate - make this decision based on the found boot loader
configs on the ESP.

Change systemd-boot to load the kernel+initrd from the ESPs root where
grub needs them. This prevents the double use of space for systems
having both boot-loaders present (since FAT does not support
symlinks). While this is against the recommendations of the
boot-loader-specification [0]) it works fine (and we deviate from [0]
by not having the machine-id in the kernel subdirs anyways).
The UEFI spec on the directory structure [1], also should be fine with
it.

Additionally adapt the output of `p-b-t status` to the new paths

[0] https://systemd.io/BOOT_LOADER_SPECIFICATION/
[1] section 13.3.1.3 of
https://uefi.org/sites/default/files/resources/UEFI_Spec_2_9_2021_03_18.pdf

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
adapted to use the helpers added in patch 3/8

 bin/proxmox-boot-tool        | 14 +++----
 proxmox-boot/zz-proxmox-boot | 78 ++++++++++++------------------------
 2 files changed, 32 insertions(+), 60 deletions(-)

diff --git a/bin/proxmox-boot-tool b/bin/proxmox-boot-tool
index a499154..31a5552 100755
--- a/bin/proxmox-boot-tool
+++ b/bin/proxmox-boot-tool
@@ -396,20 +396,18 @@ _status_detail() {
 
 	result=""
 	if mountpoint_has_sd_boot "${mountpoint}"; then
-		if [ ! -d "${mountpoint}/$PMX_ESP_DIR" ]; then
-			warn "${path}/$PMX_ESP_DIR does not exist"
-		fi
-		versions_uefi=$(ls -1 ${mountpoint}/$PMX_ESP_DIR | awk '{printf (NR>1?", ":"") $0}')
-		result="uefi (versions: ${versions_uefi})"
+		result="uefi"
 	fi
 	if mountpoint_has_grub "${mountpoint}"; then
-		versions_grub=$(ls -1 ${mountpoint}/vmlinuz-* | awk '{ gsub(/.*\/vmlinuz-/, ""); printf (NR>1?", ":"") $0 }')
 		if [ -n "$result" ]; then
-		    result="${result}, grub (versions: ${versions_grub})"
+			result="${result}, grub"
 		else
-		    result="grub (versions: ${versions_grub})"
+			result="grub"
 		fi
 	fi
+	versions=$(find "${mountpoint}" -maxdepth 1 -name 'vmlinuz-*' | awk '{ gsub(/.*\/vmlinuz-/, ""); printf (NR>1?", ":"") $0 }')
+	result="${result} (versions: ${versions})"
+
 	echo "$curr_uuid is configured with: $result"
 	umount "${mountpoint}" || \
 		{ warn "umount of ${path} failed - failure"; exit 0; }
diff --git a/proxmox-boot/zz-proxmox-boot b/proxmox-boot/zz-proxmox-boot
index a6629aa..fa0ea4a 100755
--- a/proxmox-boot/zz-proxmox-boot
+++ b/proxmox-boot/zz-proxmox-boot
@@ -75,33 +75,33 @@ update_esp_func() {
 		{ warn "creation of mountpoint ${mountpoint} failed - skipping"; return; }
 	mount "${path}" "${mountpoint}" || \
 		{ warn "mount of ${path} failed - skipping"; return; }
-	if [ -d /sys/firmware/efi ]; then
-		if ! mountpoint_has_sd_boot "${mountpoint}"; then
-			warn "${path} contains no loader.conf - skipping"
-			return
-		fi
-		if [ ! -d "${mountpoint}/$PMX_ESP_DIR" ]; then
-			warn "${path}/$PMX_ESP_DIR does not exist- skipping"
-			return
-		fi
-	elif ! mountpoint_has_grub "${mountpoint}"; then
-		warn "${path} contains no grub directory - skipping"
+	sd_boot=""
+	grub=""
+	if mountpoint_has_sd_boot "${mountpoint}"; then
+		sd_boot=1
+	fi
+	if mountpoint_has_grub "${mountpoint}"; then
+		grub=1
+	fi
+	if [ -z "$sd_boot" ] && [ -z "$grub" ]; then
+		warn "${path} contains no bootloader config - skipping!"
 		return
 	fi
 	warn "Copying and configuring kernels on ${path}"
-	copy_and_config_kernels "${mountpoint}"
+	copy_and_config_kernels "${mountpoint}" "${sd_boot}"
 
 	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
+	if [ -n "$sd_boot" ]; then
 		set_systemd_boot_default "${mountpoint}" "${pinned_kernel}"
-		remove_old_kernels_efi "${mountpoint}"
-	else
+		remove_old_kernels "${mountpoint}"
+	fi
+	if [ -n "$grub" ]; then
 		set_grub_default "${pinned_kernel}"
-		remove_old_kernels_legacy "${mountpoint}"
+		remove_old_kernels "${mountpoint}"
 		mount --bind "${mountpoint}" "/boot"
 		update-grub
 		umount /boot
@@ -116,7 +116,7 @@ update_esp_func() {
 
 copy_and_config_kernels() {
 	esp="$1"
-
+	sd_boot="$2"
 
 	for kver in ${BOOT_KVERS}; do
 
@@ -132,52 +132,25 @@ copy_and_config_kernels() {
 			continue
 		fi
 
-		if [ -d /sys/firmware/efi ]; then
-
-			warn "	Copying kernel and creating boot-entry for ${kver}"
-			KERNEL_ESP_DIR="${PMX_ESP_DIR}/${kver}"
-			KERNEL_LIVE_DIR="${esp}/${KERNEL_ESP_DIR}"
-			mkdir -p "${KERNEL_LIVE_DIR}"
-			cp --preserve=timestamps "${linux_image}" "${KERNEL_LIVE_DIR}/"
-			cp --preserve=timestamps "${initrd}" "${KERNEL_LIVE_DIR}/"
+		warn "	Preparing kernel and initrd for ${kver}"
+		cp --preserve=timestamps "${linux_image}" "${esp}/"
+		cp --preserve=timestamps "${initrd}" "${esp}/"
 
-			# create loader entry
+		if [ -n "$sd_boot" ]; then
+		# create loader entry
 			cat > "${esp}/loader/entries/proxmox-${kver}.conf" <<- EOF
 				title    ${LOADER_TITLE}
 				version  ${kver}
 				options  ${CMDLINE}
-				linux    /${KERNEL_ESP_DIR}/vmlinuz-${kver}
-				initrd   /${KERNEL_ESP_DIR}/initrd.img-${kver}
+				linux    /vmlinuz-${kver}
+				initrd   /initrd.img-${kver}
 			EOF
-		else
-			warn "	Copying kernel ${kver}"
-			cp --preserve=timestamps "${linux_image}" "${esp}/"
-			cp --preserve=timestamps "${initrd}" "${esp}/"
-		fi
-	done
-
-}
-
-remove_old_kernels_efi() {
-	esp="$1"
-
-	for kerneldir in "${esp}/${PMX_ESP_DIR}"/*; do
-		if [ ! -d "${kerneldir}" ]; then
-			warn "	${kerneldir} is not a directory - skipping"
-			continue
 		fi
-
-		kver="$(echo "${kerneldir}" | sed -r "s#^${esp}/${PMX_ESP_DIR}/(.+)\$#\\1#")"
-
-		echo "${BOOT_KVERS}" | grep -q "${kver}" && continue;
-		warn "	Removing old version ${kver}"
-		rm -rf "${kerneldir}"
-		rm -f "${esp}/loader/entries/proxmox-${kver}.conf"
 	done
 
 }
 
-remove_old_kernels_legacy() {
+remove_old_kernels() {
 	esp="$1"
 
 	for kernel in "${esp}/"vmlinuz-*; do
@@ -187,6 +160,7 @@ remove_old_kernels_legacy() {
 		warn "	Removing old version ${kver}"
 		rm -rf "${esp}/vmlinuz-${kver}"
 		rm -rf "${esp}/initrd.img-${kver}"
+		rm -rf "${esp}/loader/entries/proxmox-${kver}.conf"
 	done
 
 }
-- 
2.30.2





  parent reply	other threads:[~2022-03-03 19:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-03 19:07 [pve-devel] [PATCH pve-kernel-meta/pve-installer v2] improve boot-mode switching Stoiko Ivanov
2022-03-03 19:07 ` [pve-devel] [PATCH pve-kernel-meta v2 1/8] rename pve-efiboot-manual-kernels to proxmox-boot-manual-kernels Stoiko Ivanov
2022-03-04 10:51   ` Thomas Lamprecht
2022-03-03 19:07 ` [pve-devel] [PATCH pve-kernel-meta v2 2/8] proxmox-boot: add reinit subcommand Stoiko Ivanov
2022-03-03 19:07 ` [pve-devel] [PATCH pve-kernel-meta v2 3/8] proxmox-boot: add helpers to check for bootloader configs Stoiko Ivanov
2022-03-03 19:07 ` Stoiko Ivanov [this message]
2022-03-03 19:07 ` [pve-devel] [PATCH pve-kernel-meta v2 5/8] proxmox-boot: remove now obsolete EFI/proxmoxdir if it exists Stoiko Ivanov
2022-03-03 19:07 ` [pve-devel] [PATCH pve-kernel-meta v2 6/8] proxmox-boot: init bootloaders based on esp contents Stoiko Ivanov
2022-03-03 19:07 ` [pve-devel] [PATCH pve-kernel-meta v2 7/8] proxmox-boot: allow to manually specify bootloader Stoiko Ivanov
2022-03-03 19:07 ` [pve-devel] [PATCH pve-kernel-meta v2 8/8] proxmox-boot: fix #3729 add --graceful to bootctl invocation Stoiko Ivanov
2022-03-03 19:07 ` [pve-devel] [PATCH installer v2 1/2] remove /mnt/hostrun after install Stoiko Ivanov
2022-03-03 19:07 ` [pve-devel] [PATCH installer v2 2/2] use proxmox-boot-tool for all uefi installs Stoiko Ivanov

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=20220303190759.3527703-5-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