[pve-devel] [PATCH pve-kernel-meta 4/5] proxmox-boot: init bootloaders based on esp contents

Stoiko Ivanov s.ivanov at proxmox.com
Mon Feb 14 16:57:34 CET 2022


in addition to installing the boot loader for the current bootmode
(grub for legacy, systemd-boot for uefi) also install the bootloader
if its config is already present on the ESP.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 bin/proxmox-boot-tool | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/bin/proxmox-boot-tool b/bin/proxmox-boot-tool
index 320f49b..c697f64 100755
--- a/bin/proxmox-boot-tool
+++ b/bin/proxmox-boot-tool
@@ -127,6 +127,9 @@ format() {
 init_bootloader() {
 	part="$1"
 
+	install_sd_boot=""
+	install_grub=""
+
 	_get_partition_info "$part"
 
 	if [ -z "$PARTTYPE" ] || [ "$PARTTYPE" != "$ESPTYPE" ]; then
@@ -150,16 +153,35 @@ init_bootloader() {
 	echo "Mounting '$part' on '$esp_mp'."
 	mount -t vfat "$part" "$esp_mp"
 
+	if [ -e "${esp_mp}/$PMX_LOADER_CONF" ]; then
+		install_sd_boot=1
+	fi
+	if [ -d "${esp_mp}/grub" ]; then
+		install_grub=1
+	fi
+	# always init for the current boot-mode
 	if [ -d /sys/firmware/efi ]; then
+	    install_sd_boot=1
+	else
+	    install_grub=1
+	fi
+
+	if [ -n "$install_sd_boot" ]; then
 		echo "Installing systemd-boot.."
 		mkdir -p "$esp_mp/$PMX_ESP_DIR"
-		bootctl --path "$esp_mp" install
+		bootctl_args="--path ${esp_mp}"
+		if [ ! -d /sys/firmware/efi ]; then
+			bootctl_args="${bootctl_args} --no-variables"
+		fi
 
+		bootctl ${bootctl_args} install
 		echo "Configuring systemd-boot.."
 		echo "timeout 3" > "$esp_mp/$PMX_LOADER_CONF.tmp"
 		echo "default proxmox-*" >> "$esp_mp/$PMX_LOADER_CONF.tmp"
 		mv "$esp_mp/$PMX_LOADER_CONF.tmp" "$esp_mp/$PMX_LOADER_CONF"
-	else
+	fi
+
+	if [ -n "$install_grub" ]; then
 		echo "Installing grub i386-pc target.."
 		grub-install.real \
 			--boot-directory $esp_mp \
-- 
2.30.2






More information about the pve-devel mailing list