[pve-devel] [PATCH installer 2/2] use proxmox-boot-tool for all uefi installs

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


grub by itself is only used for btrfs/ext4/xfs installs on legacy
systems
for zfs proxmox-boot-tool is used in legacy and uefi mode

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 proxinstall | 80 ++++++++++-------------------------------------------
 1 file changed, 14 insertions(+), 66 deletions(-)

diff --git a/proxinstall b/proxinstall
index bddcc5d..df65725 100755
--- a/proxinstall
+++ b/proxinstall
@@ -1220,37 +1220,6 @@ sub prepare_proxmox_boot_esp {
 	die "unable to init ESP and install proxmox-boot loader on '$espdev'\n";
 }
 
-sub prepare_grub_efi_boot_esp {
-    my ($dev, $espdev, $targetdir) = @_;
-
-    syscmd("mount -n $espdev -t vfat $targetdir/boot/efi") == 0 ||
-	die "unable to mount $espdev\n";
-
-    eval {
-	my $rc = syscmd("chroot $targetdir /usr/sbin/grub-install --target x86_64-efi --no-floppy --bootloader-id='proxmox' $dev");
-	if ($rc != 0) {
-	    if ($boot_type eq 'efi') {
-		die "unable to install the EFI boot loader on '$dev'\n";
-	    } else {
-		warn "unable to install the EFI boot loader on '$dev', ignoring (not booted using UEFI)\n";
-	    }
-	}
-	# also install fallback boot file (OVMF does not boot without)
-	mkdir("$targetdir/boot/efi/EFI/BOOT");
-	syscmd("cp $targetdir/boot/efi/EFI/proxmox/grubx64.efi $targetdir/boot/efi/EFI/BOOT/BOOTx64.EFI") == 0 ||
-	    die "unable to copy efi boot loader\n";
-    };
-    my $err = $@;
-
-    eval {
-	syscmd("umount $targetdir/boot/efi") == 0 ||
-	    die "unable to umount $targetdir/boot/efi\n";
-    };
-    warn $@ if $@;
-
-    die "failed to prepare EFI boot using Grub on '$espdev': $err" if $err;
-}
-
 sub extract_data {
     my ($basefile, $targetdir) = @_;
 
@@ -1266,6 +1235,7 @@ sub extract_data {
 
     my $use_zfs = 0;
     my $use_btrfs = 0;
+    my $btrfs_uuid;
 
     my $filesys = $config_options->{filesys};
 
@@ -1492,7 +1462,6 @@ sub extract_data {
 	}
 
 	mkdir "$targetdir/boot";
-	mkdir "$targetdir/boot/efi";
 
 	mkdir "$targetdir/var";
 	mkdir "$targetdir/var/lib";
@@ -1616,43 +1585,23 @@ sub extract_data {
 	if ($use_zfs) {
 	    # do nothing
 	} elsif ($use_btrfs) {
-	    my $fsuuid;
 	    my $cmd = "blkid -u filesystem -t TYPE=btrfs -o export $rootdev";
 	    run_command($cmd, sub {
 		my $line = shift;
 
 		if ($line =~ m/^UUID=([A-Fa-f0-9\-]+)$/) {
-		    $fsuuid = $1;
+		    $btrfs_uuid = $1;
 		}
 	    });
 
-	    die "unable to detect FS UUID" if !defined($fsuuid);
+	    die "unable to detect FS UUID" if !defined($btrfs_uuid);
 
-	    $fstab .= "UUID=$fsuuid / btrfs defaults 0 1\n";
+	    $fstab .= "UUID=$btrfs_uuid / btrfs defaults 0 1\n";
 	} else {
 	    my $root_mountopt = $fssetup->{$filesys}->{root_mountopt} || 'defaults';
 	    $fstab .= "$rootdev / $filesys ${root_mountopt} 0 1\n";
 	}
 
-	# mount /boot/efi
-	# Note: this is required by current grub, but really dangerous, because
-	# vfat does not have journaling, so it triggers manual fsck after each crash
-	# so we only mount /boot/efi if really required (efi systems).
-	if ($boot_type eq 'efi' && !$use_zfs) {
-	    if (scalar(@$bootdevinfo)) {
-		my $di = @$bootdevinfo[0]; # simply use first disk
-
-		if ($di->{esp}) {
-		    my $efi_boot_uuid = $di->{esp};
-		    if (my $uuid = find_dev_by_uuid ($di->{esp})) {
-			$efi_boot_uuid = "UUID=$uuid";
-		    }
-
-		    $fstab .= "${efi_boot_uuid} /boot/efi vfat defaults 0 1\n";
-		}
-	    }
-	}
-
 
 	$fstab .= "$swapfile none swap sw 0 0\n" if $swapfile;
 
@@ -1791,6 +1740,12 @@ _EOD
 
 	    write_config("root=ZFS=$zfspoolname/ROOT/$zfsrootvolname boot=zfs\n", "$targetdir/etc/kernel/cmdline");
 
+	} elsif ($boot_type eq 'efi') {
+	    if ($use_btrfs){
+		write_config("root=UUID=$btrfs_uuid ro quiet\n", "$targetdir/etc/kernel/cmdline");
+	    } else {
+		write_config("root=/dev/mapper/pve-root ro quiet\n", "$targetdir/etc/kernel/cmdline");
+	    }
 	}
 
 	diversion_remove($targetdir, "/usr/sbin/update-grub");
@@ -1823,7 +1778,7 @@ _EOD
 
 		foreach my $di (@$bootdevinfo) {
 		    my $dev = $di->{devname};
-		    if ($use_zfs) {
+		    if ($use_zfs || ($boot_type eq 'efi')) {
 			prepare_proxmox_boot_esp($di->{esp}, $targetdir);
 		    } else {
 			if (!$native_4k_disk_bootable) {
@@ -1833,18 +1788,11 @@ _EOD
 			    };
 			    push @$bootloader_err_list, $@ if $@;
 			}
-
-		    eval {
-			if (my $esp = $di->{esp}) {
-				prepare_grub_efi_boot_esp($dev, $esp, $targetdir);
-			    }
-			}
-		    };
-		    push @$bootloader_err_list, $@ if $@;
+			syscmd("chroot $targetdir /usr/sbin/update-grub") == 0 ||
+			    die "unable to update boot loader config\n";
+		    }
 		}
 
-		syscmd("chroot $targetdir /usr/sbin/update-grub") == 0 ||
-		    die "unable to update boot loader config\n";
 	    };
 	    push @$bootloader_err_list, $@ if $@;
 
-- 
2.30.2






More information about the pve-devel mailing list