[pve-devel] [PATCH pve-kernel-meta 5/5] proxmox-boot: allow to manually specify bootloader

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


this commit adds the optional [--legacy|--uefi] arguments to
`p-b-t init`. If provided the respective boot-loader is installed
(regardless of what is found on the esp, and of the boot-mode)

This should make switching the boot-mode possible without the need
to boot into a live CD, chrooting and manually running the necessary
p-b-t commands.

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

diff --git a/bin/proxmox-boot-tool b/bin/proxmox-boot-tool
index c697f64..68401ee 100755
--- a/bin/proxmox-boot-tool
+++ b/bin/proxmox-boot-tool
@@ -126,6 +126,7 @@ format() {
 
 init_bootloader() {
 	part="$1"
+	mode="$2"
 
 	install_sd_boot=""
 	install_grub=""
@@ -153,17 +154,25 @@ 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
+	if [ -n "$mode" ]; then
+		if [ "$mode" = "--uefi" ]; then
+			install_sd_boot=1
+		elif [ "$mode" = "--legacy" ]; then
+			install_grub=1
+		fi
 	else
-	    install_grub=1
+		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
 	fi
 
 	if [ -n "$install_sd_boot" ]; then
@@ -192,7 +201,6 @@ init_bootloader() {
 	fi
 	echo "Unmounting '$part'."
 	umount "$part"
-
 	echo "Adding '$part' to list of synced ESPs.."
 	_add_entry_to_list_file "$ESP_LIST" "$UUID"
 
@@ -339,7 +347,7 @@ usage() {
 	warn "USAGE: $0 <commands> [ARGS]"
 	warn ""
 	warn "       $0 format <partition> [--force]"
-	warn "       $0 init <partition>"
+	warn "       $0 init <partition> [--legacy|--uefi]"
 	warn "       $0 reinit"
 	warn "       $0 clean [--dry-run]"
 	warn "       $0 refresh [--hook <name>]"
@@ -530,10 +538,17 @@ case "$1" in
 			usage
 			exit 1
 		fi
-		init_bootloader "$@"
-		echo "Refreshing kernels and initrds.."
-		refresh
-		exit 0
+		if [ -z "$2" ] || [ "$2" = "--legacy" ] || [ "$2" = "--uefi" ]; then
+			init_bootloader "$@"
+			echo "Refreshing kernels and initrds.."
+			refresh
+			exit 0
+		else
+			warn "E: invalid 'init' mode '$2'."
+			warn ""
+			usage
+			exit 1
+		fi
 	;;
 	'reinit')
 		reexec_in_mountns "$@"
-- 
2.30.2






More information about the pve-devel mailing list