]> git.proxmox.com Git - pve-installer.git/blobdiff - proxinstall
copy /etc/hostid from installer root to target
[pve-installer.git] / proxinstall
index 9f6db5b93766b90c3724b7c851c405273599d07a..b256c6e020b902bd7c5a09b1aaf835fda2b2ca3b 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"); };
     }
 };
@@ -1090,18 +1097,39 @@ sub prepare_systemd_boot_esp {
     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 ||
+    syscmd("chroot $targetdir bootctl --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("chroot $targetdir /etc/kernel/postinst.d/zz-pve-efiboot") == 0 ||
-       die "unable to generate systemd-boot config\n";
 
     syscmd("umount $targetdir/$espmp") == 0 ||
        die "unable to umount ESP $targetdir/$espmp\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";
+
+    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";
+
+    syscmd("umount $targetdir/boot/efi") == 0 ||
+       die "unable to umount $targetdir/boot/efi\n";
+}
+
 sub extract_data {
     my ($basefile, $targetdir) = @_;
 
@@ -1201,18 +1229,24 @@ sub extract_data {
 
            my ($devlist, $bootdevlist, $vdev) = get_zfs_raid_setup();
 
-           my $disksize;
            foreach my $hd (@$devlist) {
                &$clean_disk(@$hd[1]);
            }
+
+           my $disksize;
            foreach my $hd (@$bootdevlist) {
                my $devname = @$hd[1];
 
                my ($size, $osdev, $efidev) =
                    partition_bootable_disk($devname, $config_options->{hdsize}, 'BF01');
+
                zfs_mirror_size_check($disksize, $size) if $disksize;
-               push @$bootdevinfo, { esp => $efidev, devname => $devname,
-                                       osdev => $osdev};
+
+               push @$bootdevinfo, {
+                   esp => $efidev,
+                   devname => $devname,
+                   osdev => $osdev
+               };
                $disksize = $size;
            }
 
@@ -1222,11 +1256,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/;
            }
 
@@ -1347,6 +1378,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";
 
@@ -1441,10 +1476,11 @@ sub extract_data {
        # 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') {
+       if ($boot_type eq 'efi' && !$use_zfs) {
            if (scalar(@$bootdevinfo)) {
                my $di = @$bootdevinfo[0]; # simply use first disk
-               if ($di->{esp} && ! $use_zfs) {
+
+               if ($di->{esp}) {
                    my $efi_boot_uuid = $di->{esp};
                    if (my $uuid = find_dev_by_uuid ($di->{esp})) {
                        $efi_boot_uuid = "UUID=$uuid";
@@ -1474,6 +1510,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 = '';
@@ -1583,6 +1626,7 @@ _EOD
        if ($use_zfs) {
            syscmd("sed -i -e 's/^GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"root=ZFS=$zfspoolname\\/ROOT\\/$zfsrootvolname boot=zfs\"/' $targetdir/etc/default/grub") == 0 ||
                die "unable to update /etc/default/grub\n";
+
            if ($boot_type eq 'efi') {
                write_config("root=ZFS=$zfspoolname/ROOT/$zfsrootvolname boot=zfs", "$targetdir/etc/kernel/cmdline");
            }
@@ -1615,32 +1659,23 @@ _EOD
                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 ($di->{esp} && $use_zfs) {
-                       prepare_systemd_boot_esp($di->{esp}, $targetdir);
-               } elsif ($di->{esp}) {
-                   syscmd("mount -n $di->{esp} -t vfat $targetdir/boot/efi") == 0 ||
-                       die "unable to mount $di->{esp}\n";
-                   my $rc = syscmd("chroot $targetdir /usr/sbin/grub-install --target x86_64-efi --no-floppy --bootloader-id='proxmox' $dev");
-                   if ($rc != 0) {
-                       if (-d '/sys/firmware/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";
-                       }
+               if (my $esp = $di->{esp}) {
+                   if ($use_zfs) {
+                       prepare_systemd_boot_esp($esp, $targetdir);
+                   } else {
+                       prepare_grub_efi_boot_esp($dev, $esp, $targetdir);
                    }
-                   # 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";
-
-                   syscmd("umount $targetdir/boot/efi") == 0 ||
-                       die "unable to umount $targetdir/boot/efi\n";
                }
            }
 
            syscmd("chroot $targetdir /usr/sbin/update-grub") == 0 ||
                die "unable to update boot loader config\n";
 
+           if ($use_zfs && $boot_type eq 'efi') {
+               syscmd("chroot $targetdir /etc/kernel/postinst.d/zz-pve-efiboot") == 0 ||
+                   die "unable to generate systemd-boot config\n";
+           }
+
            syscmd("umount $targetdir/dev");
        }
 
@@ -1711,6 +1746,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) {
@@ -3214,11 +3250,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.")
            }
        };