]> git.proxmox.com Git - pve-installer.git/blobdiff - proxinstall
efiboot: remove redundant call to zz-pve-efiboot
[pve-installer.git] / proxinstall
index 8c424dcd0513c2741b59c93d6ff37e9a1086e6f2..963152aaa8df5bcfed4a1ddbf742057a223905cc 100755 (executable)
@@ -40,6 +40,11 @@ my $zfstestpool = "test_rpool";
 my $zfspoolname = $opt_testmode ? $zfstestpool : 'rpool';
 my $zfsrootvolname = "$setup->{product}-1";
 
+my $product_fullname = {
+    pve => 'Proxmox VE',
+    pmg => 'Proxmox MailGateway',
+};
+
 my $storage_cfg_zfs = <<__EOD__;
 dir: local
        path /var/lib/vz
@@ -587,6 +592,7 @@ sub hd_list {
        next if $info !~ m/^E: DEVTYPE=disk$/m;
 
        next if $info =~ m/^E: ID_CDROM/m;
+       next if $info =~ m/^E: ID_FS_TYPE=iso9660/m;
 
        my ($name) = $info =~ m/^N: (\S+)$/m;
 
@@ -900,6 +906,7 @@ my $clean_disk = sub {
        next if $part eq $disk;
        next if $part !~ /^\Q$disk\E/;
        eval { syscmd("pvremove -ff -y $part"); };
+       eval { syscmd("zpool labelclear -f $part"); };
        eval { syscmd("dd if=/dev/zero of=$part bs=1M count=16"); };
     }
 };
@@ -965,11 +972,78 @@ sub partition_bootable_disk {
     return ($os_size, $osdev, $efibootdev);
 }
 
+sub get_pv_list_from_vgname {
+    my ($vgname) = @_;
+
+    my $res;
+
+    my $parser = sub {
+       my $line = shift;
+       $line =~ s/^\s+//;
+       $line =~ s/\s+$//;
+       return if !$line;
+       my ($pv, $vg_uuid) = split(/\s+/, $line);
+
+       if (!defined($res->{$vg_uuid}->{pvs})) {
+           $res->{$vg_uuid}->{pvs} = "$pv";
+       } else {
+           $res->{$vg_uuid}->{pvs} .= ", $pv";
+       }
+    };
+    run_command("pvs --noheadings -o pv_name,vg_uuid -S vg_name='$vgname'", $parser, undef, 1);
+
+    return $res;
+}
+
+sub ask_existing_vg_rename_or_abort {
+    my ($vgname) = @_;
+
+    # this normally only happens if one put a disk with a PVE installation in
+    # this server and that disk is not the installation target.
+    my $duplicate_vgs = get_pv_list_from_vgname($vgname);
+    return if !$duplicate_vgs;
+
+    my $message = "Detected existing '$vgname' Volume Group(s)! Do you want to:\n";
+
+    for my $vg_uuid (keys %$duplicate_vgs) {
+       my $vg = $duplicate_vgs->{$vg_uuid};
+
+       # no high randomnes properties, but this is only for the cases where
+       # we either have multiple "$vgname" vgs from multiple old PVE disks, or
+       # we have a disk with both a "$vgname" and "$vgname-old"...
+       my $short_uid = sprintf "%08X", rand(0xffffffff);
+       $vg->{new_vgname} = "$vgname-OLD-$short_uid";
+
+       $message .= "rename VG backed by PV '$vg->{pvs}' to '$vg->{new_vgname}'\n";
+    }
+    $message .= "or cancel the installation?";
+
+    my $dialog = Gtk3::MessageDialog->new($window, 'modal', 'question', 'ok-cancel', $message);
+    my $response = $dialog->run();
+    $dialog->destroy();
+
+    if ($response eq 'ok') {
+       for my $vg_uuid (keys %$duplicate_vgs) {
+           my $vg = $duplicate_vgs->{$vg_uuid};
+           my $new_vgname = $vg->{new_vgname};
+
+           syscmd("vgrename $vg_uuid $new_vgname") == 0 ||
+               die "could not rename VG from '$vg->{pvs}' ($vg_uuid) to '$new_vgname'!\n";
+       }
+    } else {
+       set_next("_Reboot", sub { exit (0); } );
+       display_html("fail.htm");
+       die "Cancled installation by user, due to already existing volume group '$vgname'\n";
+    }
+}
+
 sub create_lvm_volumes {
     my ($lvmdev, $os_size, $swap_size) = @_;
 
     my $vgname = $setup->{product};
 
+    ask_existing_vg_rename_or_abort($vgname);
+
     my $rootdev = "/dev/$vgname/root";
     my $datadev = "/dev/$vgname/data";
     my $swapfile;
@@ -1080,24 +1154,8 @@ sub compute_swapsize {
 sub prepare_systemd_boot_esp {
     my ($espdev, $targetdir) = @_;
 
-    my $espuuid = find_dev_by_uuid($espdev);
-    my $espmp = "var/tmp/$espuuid";
-    mkdir "$targetdir/$espmp";
-
-    syscmd("mount -n $espdev -t vfat $targetdir/$espmp") == 0 ||
-       die "unable to mount ESP $espdev\n";
-
-    File::Path::make_path("$targetdir/$espmp/EFI/proxmox") ||
-       die "unable to create directory $targetdir/$espmp/EFI/proxmox\n";
-
-    syscmd("chroot $targetdir bootctl --no-variables --path /$espmp install") == 0 ||
-       die "unable to install systemd-boot loader\n";
-    write_config("timeout 3\ndefault proxmox-*\n",
-       "$targetdir/$espmp/loader/loader.conf");
-
-    syscmd("umount $targetdir/$espmp") == 0 ||
-       die "unable to umount ESP $targetdir/$espmp\n";
-
+    syscmd("chroot $targetdir pve-efiboot-tool init $espdev") == 0 ||
+       die "unable to init ESP and install systemd-boot loader on '$espdev'\n";
 }
 
 sub prepare_grub_efi_boot_esp {
@@ -1106,21 +1164,29 @@ sub prepare_grub_efi_boot_esp {
     syscmd("mount -n $espdev -t vfat $targetdir/boot/efi") == 0 ||
        die "unable to mount $espdev\n";
 
-    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";
+    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";
+       # 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 = $@;
 
-    syscmd("umount $targetdir/boot/efi") == 0 ||
-       die "unable to umount $targetdir/boot/efi\n";
+    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 {
@@ -1161,6 +1227,8 @@ sub extract_data {
        die "unable to load zfs kernel module\n" if !$i;
     }
 
+    my $bootloader_err;
+
     eval {
 
 
@@ -1249,11 +1317,8 @@ sub extract_data {
                my $devname = $di->{devname};
                $di->{by_id} = find_stable_path ("/dev/disk/by-id", $devname);
 
-               # Note: using /dev/disk/by-id/ does not work for unknown reason, we get
-               # cannot create 'rpool': no such pool or dataset
-               #my $osdev = find_stable_path ("/dev/disk/by-id", $di->{osdev}) || $di->{osdev};
+               my $osdev = find_stable_path ("/dev/disk/by-id", $di->{osdev}) || $di->{osdev};
 
-               my $osdev = $di->{osdev};
                $vdev =~ s/ $devname/ $osdev/;
            }
 
@@ -1374,6 +1439,10 @@ sub extract_data {
            die "unable to mount proc on $targetdir/proc\n";
        syscmd("mount -n -t sysfs sysfs $targetdir/sys") == 0 ||
            die "unable to mount sysfs on $targetdir/sys\n";
+       if ($boot_type eq 'efi') {
+           syscmd("mount -n -t efivarfs efivarfs $targetdir/sys/firmware/efi/efivars") == 0 ||
+               die "unable to mount efivarfs on $targetdir/sys/firmware/efi/efivars: $!\n";
+       }
        syscmd("chroot $targetdir mount --bind /mnt/hostrun /run") == 0 ||
            die "unable to re-bindmount hostrun on /run in chroot\n";
 
@@ -1502,6 +1571,13 @@ sub extract_data {
        diversion_add($targetdir, "/usr/sbin/update-grub", "/bin/true");
        diversion_add($targetdir, "/usr/sbin/update-initramfs", "/bin/true");
 
+       my $machine_id = run_command("systemd-id128 new");
+       die "unable to create a new machine-id\n" if ! $machine_id;
+       write_config($machine_id, "$targetdir/etc/machine-id");
+
+       syscmd("cp /etc/hostid $targetdir/etc/") == 0 ||
+           die "unable to copy hostid\n";
+
        syscmd("touch  $targetdir/proxmox_install_mode");
 
        my $grub_install_devices_txt = '';
@@ -1636,28 +1712,41 @@ _EOD
            symlink ("/proc/mounts", "$targetdir/etc/mtab");
            syscmd("mount -n --bind /dev $targetdir/dev");
 
-           syscmd("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0 ||
-               die "unable to install initramfs\n";
-
-           foreach my $di (@$bootdevinfo) {
-               my $dev = $di->{devname};
-               syscmd("chroot $targetdir /usr/sbin/grub-install --target i386-pc --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
-                       die "unable to install the i386-pc boot loader on '$dev'\n";
-
-               if (my $esp = $di->{esp}) {
-                   if ($use_zfs) {
-                       prepare_systemd_boot_esp($esp, $targetdir);
-                   } else {
-                       prepare_grub_efi_boot_esp($dev, $esp, $targetdir);
-                   }
+           my $bootloader_err_list = [];
+           eval {
+               syscmd("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0 ||
+                   die "unable to install initramfs\n";
+
+               foreach my $di (@$bootdevinfo) {
+                   my $dev = $di->{devname};
+                   eval {
+                       syscmd("chroot $targetdir /usr/sbin/grub-install --target i386-pc --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
+                               die "unable to install the i386-pc boot loader on '$dev'\n";
+                   };
+                   push @$bootloader_err_list, $@ if $@;
+
+                   eval {
+                       if (my $esp = $di->{esp}) {
+                           if ($use_zfs) {
+                               prepare_systemd_boot_esp($esp, $targetdir);
+                           } else {
+                               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 $@;
 
-           syscmd("chroot $targetdir /etc/kernel/postinst.d/zz-pve-efiboot") == 0 ||
-               die "unable to generate systemd-boot config\n";
+           if (scalar(@$bootloader_err_list) > 0) {
+               $bootloader_err = "bootloader setup errors:\n";
+               map { $bootloader_err .= "- $_" } @$bootloader_err_list;
+               warn $bootloader_err;
+           }
 
            syscmd("umount $targetdir/dev");
        }
@@ -1729,6 +1818,7 @@ _EOD
     syscmd("umount $targetdir/mnt/hostrun");
     syscmd("umount $targetdir/tmp");
     syscmd("umount $targetdir/proc");
+    syscmd("umount $targetdir/sys/firmware/efi/efivars");
     syscmd("umount $targetdir/sys");
 
     if ($use_zfs) {
@@ -1750,6 +1840,10 @@ _EOD
        syscmd("zpool export $zfspoolname");
     }
 
+    if ($bootloader_err) {
+       $err = $err ? "$err\n$bootloader_err" : $bootloader_err;
+    }
+
     die $err if $err;
 }
 
@@ -1799,6 +1893,9 @@ sub display_html {
        my $title = "END USER LICENSE AGREEMENT (EULA)";
        $data =~ s/__LICENSE__/$license/;
        $data =~ s/__LICENSE_TITLE__/$title/;
+    } elsif ($filename eq 'success.htm') {
+       my $addr = $ipversion == 6 ? "[${ipaddress}]" : "$ipaddress";
+       $data =~ s/\@IPADDR\@/$addr/;
     }
 
     $htmlview->load_html($data, $url);
@@ -3232,11 +3329,18 @@ sub create_intro_view {
 
     cleanup_view();
 
+    if (int($total_memory) < 1024) {
+       my $fullname = $product_fullname->{$setup->{product}};
+
+       display_error("Less than 1 GiB of usable memory detected, installation will probably fail.\n\n".
+           "See 'System Requirements' in the $fullname documentation.");
+    }
+
     if ($setup->{product} eq 'pve') {
        eval {
            my $cpuinfo = file_get_contents('/proc/cpuinfo');
            if ($cpuinfo && !($cpuinfo =~ /^flags\s*:.*(vmx|svm)/m)) {
-               display_error("No support for KVM virtualisation detected.\n\n" .
+               display_error("No support for KVM virtualization detected.\n\n" .
                              "Check BIOS settings for Intel VT / AMD-V / SVM.")
            }
        };