X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=proxinstall;h=d6b96b392d255b1f8595b699fe5e8a6754f8ba67;hb=2ba9752e99ac09946ec267a5121d93c197f52159;hp=d27a4963fadeb7dd10073c712158efdbdb7a94de;hpb=550958aa855b52c688344c0e65969566ec8c5d7b;p=pve-installer.git diff --git a/proxinstall b/proxinstall index d27a496..d6b96b3 100755 --- a/proxinstall +++ b/proxinstall @@ -93,7 +93,7 @@ my $proxmox_pkgdir = "${proxmox_cddir}/proxmox/packages/"; my $grub_plattform = "pc"; # pc, efi-amd64 or efi-ia32 -$grub_plattform = "efi-amd64" if -d "/sys/firmware/efi"; +$grub_plattform = "efi-amd64" if -d "/sys/firmware/efi"; my $IPV4OCTET = "(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9])?[0-9])"; my $IPV4RE = "(?:(?:$IPV4OCTET\\.){3}$IPV4OCTET)"; @@ -144,7 +144,9 @@ my $ipv4_mask_hash = { '255.255.255.224' => 27, '255.255.255.240' => 28, '255.255.255.248' => 29, - '255.255.255.252' => 30 + '255.255.255.252' => 30, + '255.255.255.254' => 31, + '255.255.255.255' => 32 }; my $ipv4_reverse_mask = [ @@ -226,9 +228,11 @@ if ($cmdline =~ m/maxroot=(\d+(\.\d+)?)[\s\n]/i) { if ($cmdline =~ m/minfree=(\d+(\.\d+)?)[\s\n]/i) { $config_options->{minfree} = $1; } - -if ($cmdline =~ m/maxvz=(\d+(\.\d+)?)[\s\n]/i) { - $config_options->{maxvz} = $1; + +if ($setup->{product} eq 'pve') { + if ($cmdline =~ m/maxvz=(\d+(\.\d+)?)[\s\n]/i) { + $config_options->{maxvz} = $1; + } } my $postfix_main_cf = <<_EOD; @@ -700,7 +704,7 @@ sub create_filesystem { my $fsdata = $fssetup->{$type} || die "internal error - unknown file system '$type'"; my $opts = $name eq 'root' ? $fsdata->{mkfs_root_opt} : $fsdata->{mkfs_data_opt}; - + update_progress (0, $rs, $re, "creating $name filesystem"); run_command ("$fsdata->{mkfs} $opts $dev", sub { @@ -777,9 +781,11 @@ sub zfs_create_rpool { syscmd ("zfs create $zfspoolname/ROOT") == 0 || die "unable to create zfs $zfspoolname/ROOT volume\n"; - - syscmd ("zfs create $zfspoolname/data") == 0 || - die "unable to create zfs $zfspoolname/data volume\n"; + + if ($setup->{product} eq 'pve') { + syscmd ("zfs create $zfspoolname/data") == 0 || + die "unable to create zfs $zfspoolname/data volume\n"; + } syscmd ("zfs create $zfspoolname/ROOT/$zfsrootvolname") == 0 || die "unable to create zfs $zfspoolname/ROOT/$zfsrootvolname volume\n"; @@ -910,7 +916,7 @@ sub partition_bootable_disk { # ZFS has this use_whole_disk concept, so we try to partition the same # way as zfs does by default. There is room at start of disk to insert -# a grub boot partition. But adding a EFI ESP is not possible. +# a grub boot partition. But adding a EFI ESP is not possible. # # Note: zfs people think this is just a waste of space an not # required. Instead, you should put the ESP on another disk (log, @@ -927,7 +933,7 @@ sub partition_bootable_zfs_disk { my $hdgb = int($hdsize/(1024*1024)); die "hardisk '$target_dev' too small (${hdsize}GB)\n" if $hdgb < 8; - # 1 - GRUB boot partition: 1M + # 1 - GRUB boot partition: 1M # 2 - OS/Data partition # 9 - ZFS reserved partition @@ -944,9 +950,9 @@ sub partition_bootable_zfs_disk { $pnum = 2; push @$pcmd, "-n$pnum:2048:0", "-t$pnum:BF01", '-c', "$pnum:zfs"; - + push @$pcmd, $target_dev; - + my $os_size = $hdsize - 1024 - 1024*8; syscmd($pcmd) == 0 || @@ -966,7 +972,7 @@ sub create_lvm_volumes { my $rootdev = "/dev/$vgname/root"; my $datadev = "/dev/$vgname/data"; - my $swapfile = "/dev/$vgname/swap"; + my $swapfile; # we use --metadatasize 250k, which results in "pe_start = 512" # so pe_start is aligned on a 128k boundary (advantage for SSDs) @@ -978,48 +984,78 @@ sub create_lvm_volumes { my $hdgb = int($os_size/(1024*1024)); my $space = (($hdgb > 128) ? 16 : ($hdgb/8))*1024*1024; - my $maxroot; - if ($config_options->{maxroot}) { - $maxroot = $config_options->{maxroot}; - } else { - $maxroot = 96; - } + my $rootsize; + my $datasize; - my $rootsize = (($hdgb > ($maxroot*4)) ? $maxroot : $hdgb/4)*1024*1024; + if ($setup->{product} eq 'pve') { - my $rest = $os_size - $swap_size - $rootsize; # in KB + my $maxroot; + if ($config_options->{maxroot}) { + $maxroot = $config_options->{maxroot}; + } else { + $maxroot = 96; + } + + $rootsize = (($hdgb > ($maxroot*4)) ? $maxroot : $hdgb/4)*1024*1024; + + my $rest = $os_size - $swap_size - $rootsize; # in KB + + my $minfree; + if ($config_options->{minfree}) { + $minfree = (($config_options->{minfree}*1024*1024) >= $rest ) ? $space : + $config_options->{minfree}*1024*1024 ; + } else { + $minfree = $space; + } + + $rest = $rest - $minfree; + + if (defined($config_options->{maxvz})) { + $rest = (($config_options->{maxvz}*1024*1024) <= $rest) ? + $config_options->{maxvz}*1024*1024 : $rest; + } + + $datasize = $rest; - my $minfree; - if ($config_options->{minfree}) { - $minfree = (($config_options->{minfree}*1024*1024) >= $rest ) ? $space : - $config_options->{minfree}*1024*1024 ; } else { - $minfree = $space; + my $minfree = $config_options->{minfree} ? $config_options->{minfree}*1024*1024 : $space; + $rootsize = $os_size - $minfree - $swap_size; # in KB } - $rest = $rest - $minfree; + if ($swap_size) { + syscmd ("/sbin/lvcreate -L${swap_size}K -nswap $vgname") == 0 || + die "unable to create swap volume\n"; - if ($config_options->{maxvz}) { - $rest = (($config_options->{maxvz}*1024*1024) <= $rest) ? - $config_options->{maxvz}*1024*1024 : $rest; + $swapfile = "/dev/$vgname/swap"; } - syscmd ("/sbin/lvcreate -L${swap_size}K -nswap $vgname") == 0 || - die "unable to create swap volume\n"; - syscmd ("/sbin/lvcreate -L${rootsize}K -nroot $vgname") == 0 || die "unable to create root volume\n"; - syscmd ("/sbin/lvcreate -L${rest}K -ndata $vgname") == 0 || - die "unable to create data volume\n"; + if ($datasize > 4*1024*1024) { + my $metadatasize = $datasize/100; # default 1% of data + $metadatasize = 1024*1024 if $metadatasize < 1024*1024; # but at least 1G + $metadatasize = 16*1024*1024 if $metadatasize > 16*1024*1024; # but at most 16G + + # otherwise the metadata is taken out of $minfree + $datasize -= 2*$metadatasize; + + # 1 4MB PE to allow for rounding + $datasize -= 4*1024; + + syscmd ("/sbin/lvcreate -L${datasize}K -ndata $vgname") == 0 || + die "unable to create data volume\n"; - syscmd ("/sbin/lvconvert --yes --type thin-pool $vgname/data") == 0 || - die "unable to create data thin-pool\n"; + syscmd ("/sbin/lvconvert --yes --type thin-pool --poolmetadatasize ${metadatasize}K $vgname/data") == 0 || + die "unable to create data thin-pool\n"; + } else { + $datadev = undef; + } syscmd ("/sbin/vgchange -a y $vgname") == 0 || die "unable to activate volume group\n"; - return ($rootdev, $datadev, $swapfile); + return ($rootdev, $swapfile, $datadev); } sub compute_swapsize { @@ -1028,7 +1064,7 @@ sub compute_swapsize { my $hdgb = int($hdsize/(1024*1024)); my $swapsize; - if ($config_options->{swapsize}) { + if (defined($config_options->{swapsize})) { $swapsize = $config_options->{swapsize}*1024*1024; } else { my $ss = int ($total_memory / 1024); @@ -1051,7 +1087,6 @@ sub extract_data { my $bootdevinfo = []; - my $datadev; my $swapfile; my $rootdev; @@ -1068,7 +1103,7 @@ sub extract_data { $target_hd = undef; # do not use this config $use_btrfs = 1; } - + if ($use_zfs) { my $i; for ($i = 5; $i > 0; $i--) { @@ -1096,7 +1131,7 @@ sub extract_data { if ($use_btrfs) { - die "unsupported btrfs mode (for testing environment)\n" + die "unsupported btrfs mode (for testing environment)\n" if $filesys ne 'btrfs (RAID0)'; btrfs_create([$rootdev], 'single'); @@ -1109,7 +1144,7 @@ sub extract_data { syscmd ("zpool destroy $zfstestpool"); zfs_create_rpool($rootdev); - + } else { # nothing to do @@ -1159,7 +1194,7 @@ sub extract_data { foreach my $di (@$bootdevinfo) { 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}; @@ -1169,9 +1204,9 @@ sub extract_data { } zfs_create_rpool($vdev); - + my $swap_size = compute_swapsize($disksize); - $swapfile = zfs_create_swap($swap_size); + $swapfile = zfs_create_swap($swap_size) if $swap_size; } else { @@ -1185,18 +1220,18 @@ sub extract_data { &$clean_disk($target_hd); - my ($os_size, $osdev, $efidev); - ($os_size, $osdev, $efidev) = + my ($os_size, $osdev, $efidev); + ($os_size, $osdev, $efidev) = partition_bootable_disk($target_hd, $maxhdsize, '8E00'); &$udevadm_trigger_block(); my $by_id = find_stable_path ("/dev/disk/by-id", $target_hd); - push @$bootdevinfo, { esp => $efidev, devname => $target_hd, + push @$bootdevinfo, { esp => $efidev, devname => $target_hd, osdev => $osdev, by_id => $by_id }; my $swap_size = compute_swapsize($os_size); - ($rootdev, $datadev, $swapfile) = + ($rootdev, $swapfile) = create_lvm_volumes($osdev, $os_size, $swap_size); # trigger udev to create /dev/disk/by-uuid @@ -1219,7 +1254,7 @@ sub extract_data { foreach my $di (@$bootdevinfo) { next if !$di->{esp}; - syscmd ("mkfs.vfat -F32 $di->{esp}") == 0 || + syscmd ("mkfs.vfat -F32 $di->{esp}") == 0 || die "unable to initialize EFI ESP on device $di->{esp}\n"; } @@ -1389,7 +1424,7 @@ sub extract_data { 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"; } } @@ -1424,7 +1459,7 @@ sub extract_data { # Note: keyboard-configuration/xbkb-keymap is used by console-setup my $xkmap = $cmap->{kmap}->{$keymap}->{x11} // 'us'; - + debconfig_set ($targetdir, <<_EOD); locales locales/default_environment_locale select en_US.UTF-8 locales locales/locales_to_be_generated select en_US.UTF-8 UTF-8 @@ -1527,7 +1562,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"; - + } diversion_remove ($targetdir, "/usr/sbin/update-grub"); @@ -1664,7 +1699,7 @@ _EOD syscmd ("zfs set mountpoint=/ $zfspoolname/ROOT/$zfsrootvolname") == 0 || die "zfs set mountpoint failed\n"; - + syscmd ("zpool set bootfs=$zfspoolname/ROOT/$zfsrootvolname $zfspoolname") == 0 || die "zfs set bootfs failed\n"; syscmd ("zpool export $zfspoolname"); @@ -1739,7 +1774,8 @@ sub create_main_window { my $vbox = Gtk3::VBox->new (0, 0); - my $image = Gtk3::Image->new_from_file ("${proxmox_libdir}/proxlogo.png"); + my $logofn = "$setup->{product}-banner.png"; + my $image = Gtk3::Image->new_from_file("${proxmox_libdir}/$logofn"); $vbox->pack_start ($image, 0, 0, 0); my $hbox = Gtk3::HBox->new (0, 0); @@ -1769,7 +1805,7 @@ sub create_main_window { $htmlview = Gtk3::WebKit::WebView->new(); my $scrolls = Gtk3::ScrolledWindow->new(); $scrolls->add($htmlview); - + my $hbox2 = Gtk3::HBox->new (0, 0); $hbox2->pack_start ($scrolls, 1, 1, 0); @@ -1790,10 +1826,10 @@ sub create_main_window { $window->realize (); } -sub cleanup_view { +sub cleanup_view { $inbox->foreach(sub { my $child = shift; - $inbox->remove ($child); + $inbox->remove ($child); }); } @@ -2002,7 +2038,7 @@ sub create_ipconf_view { my $hn = $ipconf->{domain} ? "$setup->{product}.$ipconf->{domain}" : "$setup->{product}.example.invalid"; - + my ($hostbox, $hostentry) = create_text_input ($hn, 'Hostname (FQDN):'); $vbox2->pack_start ($hostbox, 0, 0, 2); @@ -2031,7 +2067,7 @@ sub create_ipconf_view { set_next (undef, sub { # verify hostname - + my $text = $hostentry->get_text(); $text =~ s/^\s+//; @@ -2065,7 +2101,7 @@ sub create_ipconf_view { $ipaddress = $text; $ipversion = 4; } elsif ($text =~ m!^($IPV6RE)$!) { - $ipaddress = $text; + $ipaddress = $text; $ipversion = 6; } else { display_message ("IP address is not valid."); @@ -2098,7 +2134,7 @@ sub create_ipconf_view { $ipconf_entry_gw->grab_focus(); return; } - + $text = $ipconf_entry_dns->get_text(); $text =~ s/^\s+//; $text =~ s/\s+$//; @@ -2111,9 +2147,9 @@ sub create_ipconf_view { $ipconf_entry_dns->grab_focus(); return; } - + #print "TEST $ipaddress $netmask $gateway $dnsserver\n"; - + create_extract_view (); }); @@ -2361,7 +2397,7 @@ sub create_country_view { if ($val == Gtk3::Gdk::KEY_Tab) { my $cc = $countryhash->{lc($text)}; - + my $found = 0; my $compl; @@ -2398,7 +2434,7 @@ sub create_country_view { return undef; }); - + my $ls = Gtk3::ListStore->new('Glib::String'); foreach my $cc (sort {$ctr->{$a}->{name} cmp $ctr->{$b}->{name} } keys %$ctr) { my $iter = $ls->append(); @@ -2604,7 +2640,7 @@ sub create_hdoption_view { my $grid = Gtk3::Grid->new(); $grid->set_column_spacing(10); $grid->set_row_spacing(10); - + $hbox2->pack_start($grid, 1, 0, 10); my $row = 0; @@ -2614,7 +2650,7 @@ sub create_hdoption_view { my $label0 = Gtk3::Label->new ("Filesystem"); $label0->set_alignment (1, 0.5); $grid->attach($label0, 0, $row, 1, 1); - + my $fstypecb = Gtk3::ComboBoxText->new(); my $fstype = ['ext3', 'ext4', 'xfs', @@ -2662,14 +2698,16 @@ sub create_hdoption_view { my $entry_swapsize = Gtk3::Entry->new(); $entry_swapsize->set_tooltip_text("maximum SWAP size (GB)"); $entry_swapsize->signal_connect (key_press_event => \&check_float); - $entry_swapsize->set_text($config_options->{swapsize}) if $config_options->{swapsize}; + $entry_swapsize->set_text($config_options->{swapsize}) if defined($config_options->{swapsize}); push @$hdsize_labeled_widgets, "swapsize", $entry_swapsize; my $entry_maxroot = Gtk3::Entry->new(); - $entry_maxroot->set_tooltip_text("maximum size (GB) for LVM root volume"); - $entry_maxroot->signal_connect (key_press_event => \&check_float); - $entry_maxroot->set_text($config_options->{maxroot}) if $config_options->{maxroot}; - push @$hdsize_labeled_widgets, "maxroot", $entry_maxroot; + if ($setup->{product} eq 'pve') { + $entry_maxroot->set_tooltip_text("maximum size (GB) for LVM root volume"); + $entry_maxroot->signal_connect (key_press_event => \&check_float); + $entry_maxroot->set_text($config_options->{maxroot}) if $config_options->{maxroot}; + push @$hdsize_labeled_widgets, "maxroot", $entry_maxroot; + } my $entry_minfree = Gtk3::Entry->new(); $entry_minfree->set_tooltip_text("minimum free LVM space (GB, required for LVM snapshots)"); @@ -2677,11 +2715,14 @@ sub create_hdoption_view { $entry_minfree->set_text($config_options->{minfree}) if $config_options->{minfree}; push @$hdsize_labeled_widgets, "minfree", $entry_minfree; - my $entry_maxvz = Gtk3::Entry->new(); - $entry_maxvz->set_tooltip_text("maximum size (GB) for LVM data volume"); - $entry_maxvz->signal_connect (key_press_event => \&check_float); - $entry_maxvz->set_text($config_options->{maxvz}) if $config_options->{maxvz}; - push @$hdsize_labeled_widgets, "maxvz", $entry_maxvz; + my $entry_maxvz; + if ($setup->{product} eq 'pve') { + $entry_maxvz = Gtk3::Entry->new(); + $entry_maxvz->set_tooltip_text("maximum size (GB) for LVM data volume"); + $entry_maxvz->signal_connect (key_press_event => \&check_float); + $entry_maxvz->set_text($config_options->{maxvz}) if defined($config_options->{maxvz}); + push @$hdsize_labeled_widgets, "maxvz", $entry_maxvz; + } my $options_stack = Gtk3::Stack->new(); $options_stack->set_visible(1); @@ -2773,7 +2814,7 @@ sub create_hdoption_view { delete $config_options->{minfree}; } - if (defined($tmp = &$get_float($entry_maxvz))) { + if ($entry_maxvz && defined($tmp = &$get_float($entry_maxvz))) { $config_options->{maxvz} = $tmp; } else { delete $config_options->{maxvz}; @@ -2790,7 +2831,7 @@ my $get_raid_devlist = sub { for (my $i = 0; $i < @$hds; $i++) { if (my $hd = $config_options->{"disksel$i"}) { my ($disk, $devname, $size, $model) = @$hd; - die "device '$devname' is used more than once\n" + die "device '$devname' is used more than once\n" if $dev_name_hash->{$devname}; $dev_name_hash->{$devname} = $hd; push @$devlist, $hd; @@ -2837,7 +2878,7 @@ sub get_zfs_raid_setup { } elsif ($filesys eq 'zfs (RAID10)') { die "zfs (RAID10) needs at least 4 device\n" if $diskcount < 4; die "zfs (RAID10) needs an even number of devices\n" if $diskcount & 1; - + push @$bootdevlist, @$devlist[0], @$devlist[1]; for (my $i = 0; $i < $diskcount; $i+=2) { @@ -2924,7 +2965,7 @@ sub create_hdsel_view { my ($disk, $devname) = @{@$hds[$a]}; $target_hd = $devname; }); - + $hbox->pack_start ($target_hd_combo, 0, 0, 10); my $options = Gtk3::Button->new ('_Options');