public inbox for pve-devel@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 installer v3 2/2] use proxmox-boot-tool for all uefi installs
Date: Fri, 11 Mar 2022 20:05:48 +0100	[thread overview]
Message-ID: <20220311190548.2937377-11-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20220311190548.2937377-1-s.ivanov@proxmox.com>

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@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





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

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-11 19:05 [pve-devel] [PATCH pve-kernel-meta/pve-installer v3] improve boot-mode switching Stoiko Ivanov
2022-03-11 19:05 ` [pve-devel] [PATCH pve-kernel-meta v3 1/8] rename pve-efiboot-manual-kernels to proxmox-boot-manual-kernels Stoiko Ivanov
2022-04-27 17:07   ` [pve-devel] applied: " Thomas Lamprecht
2022-03-11 19:05 ` [pve-devel] [PATCH pve-kernel-meta v3 2/8] proxmox-boot: add reinit subcommand Stoiko Ivanov
2022-04-27 17:07   ` [pve-devel] applied: " Thomas Lamprecht
2022-03-11 19:05 ` [pve-devel] [PATCH pve-kernel-meta v3 3/8] proxmox-boot: add helpers to check for bootloader configs Stoiko Ivanov
2022-03-11 19:05 ` [pve-devel] [PATCH pve-kernel-meta v3 4/8] proxmox-boot: refresh based on bootloader config instead of bootmode Stoiko Ivanov
2022-03-11 19:05 ` [pve-devel] [PATCH pve-kernel-meta v3 5/8] proxmox-boot: remove now obsolete EFI/proxmoxdir if it exists Stoiko Ivanov
2022-03-11 19:05 ` [pve-devel] [PATCH pve-kernel-meta v3 6/8] proxmox-boot: init bootloaders based on esp contents Stoiko Ivanov
2022-03-11 19:05 ` [pve-devel] [PATCH pve-kernel-meta v3 7/8] proxmox-boot: allow to manually specify bootloader Stoiko Ivanov
2022-03-11 19:05 ` [pve-devel] [PATCH pve-kernel-meta v3 8/8] proxmox-boot: fix #3729 add --graceful to bootctl invocation Stoiko Ivanov
2022-03-11 19:05 ` [pve-devel] [PATCH installer v3 1/2] remove /mnt/hostrun after install Stoiko Ivanov
2022-04-26  6:26   ` [pve-devel] applied: " Thomas Lamprecht
2022-03-11 19:05 ` Stoiko Ivanov [this message]

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=20220311190548.2937377-11-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal