6 $ENV{DEBIAN_FRONTEND
} = 'noninteractive';
20 use POSIX
":sys_wait_h";
22 use Proxmox
::Install
::ISOEnv
;
24 use Proxmox
::Sys
::Block
qw(get_cached_disks wipe_disk partition_bootable_disk);
25 use Proxmox
::Sys
::Command
qw(run_command syscmd);
26 use Proxmox
::Sys
::File
qw(file_read_firstline file_read_all file_write_all);
27 use Proxmox
::Sys
::Net
qw(parse_ip_address parse_ip_mask);
29 if (!$ENV{G_SLICE
} || $ENV{G_SLICE
} ne "always-malloc") {
30 die "do not use slice allocator (run with 'G_SLICE=always-malloc ./proxinstall ...')\n";
36 'test-image|t=s' => \
$test_image
37 ) or die "usage error\n";
39 Proxmox
::Install
::ISOEnv
::set_test_image
($test_image) if $test_image;
42 $ENV{'LVM_SUPPRESS_FD_WARNINGS'} = '1';
44 my $env = Proxmox
::Install
::ISOEnv
::setup
();
46 my $zfstestpool = "test_rpool";
47 my $zfspoolname = is_test_mode
() ?
$zfstestpool : 'rpool';
48 my $zfsrootvolname = "$env->{product}-1";
50 my $storage_cfg_zfs = <<__EOD__;
53 content iso,vztmpl,backup
56 pool $zfspoolname/data
58 content images,rootdir
61 my $storage_cfg_btrfs = <<__EOD__;
64 content iso,vztmpl,backup
68 path /var/lib/pve/local-btrfs
69 content iso,vztmpl,backup,images,rootdir
72 my $storage_cfg_lvmthin = <<__EOD__;
75 content iso,vztmpl,backup
80 content rootdir,images
83 my $storage_cfg_local = <<__EOD__;
86 content iso,vztmpl,backup,rootdir,images
89 Proxmox
::Log
::init
("/tmp/install.log");
91 my $proxmox_libdir = $env->{locations
}->{lib
};
92 my $proxmox_cddir = $env->{locations
}->{iso
};
93 my $proxmox_pkgdir = "${proxmox_cddir}/proxmox/packages/";
95 my $boot_type = -d
'/sys/firmware/efi' ?
'efi' : 'bios';
97 my $step_number = 0; # Init number for global function list
102 html
=> 'license.htm',
103 next_button
=> 'I a_gree',
104 function
=> \
&create_intro_view
,
109 function
=> \
&create_hdsel_view
,
113 html
=> 'country.htm',
114 function
=> \
&create_country_view
,
118 html
=> 'passwd.htm',
119 function
=> \
&create_password_view
,
123 html
=> 'ipconf.htm',
124 function
=> \
&create_ipconf_view
,
129 next_button
=> '_Install',
130 function
=> \
&create_ack_view
,
134 next_button
=> '_Reboot',
135 function
=> \
&create_extract_view
,
139 # GUI global variables
140 my ($window, $cmdbox, $inbox, $htmlview);
142 my ($next, $next_fctn, $target_hd);
143 my ($progress, $progress_status);
145 my ($ipversion, $ipaddress, $cidr, $ipconf_entry_addr);
146 my ($netmask, $ipconf_entry_mask);
147 my ($gateway, $ipconf_entry_gw);
148 my ($dnsserver, $ipconf_entry_dns);
149 my $hostname = 'proxmox';
150 my $domain = 'domain.tld';
151 my $cmdline = file_read_firstline
("/proc/cmdline");
154 my $timezone = 'Europe/Vienna';
155 my $keymap = 'en-us';
157 my $mailto = 'mail@example.invalid';
158 my $autoreboot_seconds = 5;
161 # TODO: add all the user-provided options for previous button
163 timezone
=> $timezone,
166 password
=> $password,
170 hostname
=> $hostname,
177 # parse command line args
179 my $config_options = {
183 if ($cmdline =~ m/\s(ext4|xfs)(\s.*)?$/) {
184 $config_options->{filesys
} = $1;
186 $config_options->{filesys
} = 'ext4';
189 if ($cmdline =~ m/hdsize=(\d+(\.\d+)?)[\s\n]/i) {
190 $config_options->{hdsize
} = $1;
193 if ($cmdline =~ m/swapsize=(\d+(\.\d+)?)[\s\n]/i) {
194 $config_options->{swapsize
} = $1;
197 if ($cmdline =~ m/maxroot=(\d+(\.\d+)?)[\s\n]/i) {
198 $config_options->{maxroot
} = $1;
201 if ($cmdline =~ m/minfree=(\d+(\.\d+)?)[\s\n]/i) {
202 $config_options->{minfree
} = $1;
205 if ($env->{product
} eq 'pve') {
206 if ($cmdline =~ m/maxvz=(\d+(\.\d+)?)[\s\n]/i) {
207 $config_options->{maxvz
} = $1;
211 my $postfix_main_cf = <<_EOD;
212 # See /usr/share/postfix/main.cf.dist for a commented, more complete version
216 smtpd_banner = \$myhostname ESMTP \$mail_name (Debian/GNU)
219 # appending .domain is the MUA's job.
220 append_dot_mydomain = no
222 # Uncomment the next line to generate "delayed mail" warnings
223 #delay_warning_time = 4h
225 alias_maps = hash:/etc/aliases
226 alias_database = hash:/etc/aliases
227 mydestination = \$myhostname, localhost.\$mydomain, localhost
229 mynetworks = 127.0.0.0/8
230 inet_interfaces = loopback-only
231 recipient_delimiter = +
233 compatibility_level = 2
239 print "trying to detect country...\n";
240 my $cpid = open2
(my $TRACEROUTE_FH, undef, "traceroute -N 1 -q 1 -n 8.8.8.8");
241 return undef if !$cpid;
245 my $previous_alarm = alarm (10);
247 local $SIG{ALRM
} = sub { die "timed out!\n" };
249 while (defined ($line = <$TRACEROUTE_FH>)) {
250 log_debug
("DC TRACEROUTE: $line");
251 if ($line =~ m/\s*\d+\s+(\d+\.\d+\.\d+\.\d+)\s/) {
252 my $geoip = `geoiplookup $1`;
253 log_debug("DC GEOIP: $geoip");
254 if ($geoip =~ m/GeoIP Country Edition:\s*([A-Z]+),/) {
256 log_info("DC FOUND: $country\n");
263 alarm ($previous_alarm);
265 close($TRACEROUTE_FH);
268 print "unable to detect country - $err\n";
270 print "detected country: " . uc($country) . "\n";
272 print "unable to detect country\n";
280 open (my $MEMINFO, '<', '/proc/meminfo');
282 my $res = 512; # default to 512 if something goes wrong
283 while (my $line = <$MEMINFO>) {
284 if ($line =~ m/^MemTotal:\s+(\d+)\s*kB/i) {
285 $res = int ($1 / 1024);
294 my $total_memory = get_memtotal();
296 sub update_progress {
297 my ($frac, $start, $end, $text) = @_;
299 my $part = $end - $start;
300 my $res = $start + $frac * $part;
302 $progress->set_fraction ($res);
303 $progress->set_text (sprintf ("%d%%", int ($res*100)));
304 $progress_status->set_text ($text) if defined ($text);
306 display_info() if $res < 0.9;
308 Gtk3::main_iteration() while Gtk3::events_pending();
313 mkfs => 'mkfs.ext4 -F',
315 mkfs_data_opt => '-m 0',
316 root_mountopt => 'errors=remount-ro',
319 mkfs => 'mkfs.xfs -f',
326 sub create_filesystem {
327 my ($dev, $name, $type, $start, $end, $fs, $fe) = @_;
329 my $range = $end - $start;
330 my $rs = $start + $range*$fs;
331 my $re = $start + $range*$fe;
334 my $fsdata = $fssetup->{$type} || die "internal error - unknown file system '$type'";
335 my $opts = $name eq 'root' ? $fsdata->{mkfs_root_opt} : $fsdata->{mkfs_data_opt};
337 update_progress(0, $rs, $re, "creating $name filesystem");
339 run_command("$fsdata->{mkfs} $opts $dev", sub {
342 if ($line =~ m/Writing inode tables:\s+(\d+)\/(\d+)/) {
344 } elsif ($max && $line =~ m/(\d+)\/$max/) {
345 update_progress(($1/$max)*0.9, $rs, $re);
346 } elsif ($line =~ m/Creating journal.*done/) {
347 update_progress(0.95, $rs, $re);
348 } elsif ($line =~ m/Writing superblocks and filesystem.*done/) {
349 update_progress(1, $rs, $re);
355 my ($targetdir, $dcdata) = @_;
357 my $cfgfile = "/tmp/debconf.txt";
358 file_write_all("$targetdir/$cfgfile", $dcdata);
359 syscmd("chroot $targetdir debconf-set-selections $cfgfile");
360 unlink "$targetdir/$cfgfile";
364 my ($targetdir, $cmd, $new_cmd) = @_;
366 syscmd("chroot $targetdir dpkg-divert --package proxmox --add --rename $cmd") == 0
367 || die "unable to exec dpkg-divert\n";
369 syscmd("ln -sf ${new_cmd} $targetdir/$cmd") == 0
370 || die "unable to link diversion to ${new_cmd}\n";
373 sub diversion_remove {
374 my ($targetdir, $cmd) = @_;
376 syscmd("mv $targetdir/${cmd}.distrib $targetdir/${cmd};") == 0
377 || die "unable to remove $cmd diversion\n";
379 syscmd("chroot $targetdir dpkg-divert --remove $cmd") == 0
380 || die "unable to remove $cmd diversion\n";
384 my ($partitions, $mode) = @_;
386 die "unknown btrfs mode '$mode'"
387 if !($mode eq 'single' || $mode eq 'raid0' || $mode eq 'raid1' || $mode eq 'raid10');
389 my $cmd = ['mkfs.btrfs', '-f'];
391 push @$cmd, '-d', $mode, '-m', $mode;
393 push @$cmd, @$partitions;
398 sub zfs_create_rpool {
401 my $cmd = "zpool create -f -o cachefile=none";
403 $cmd .= " -o ashift=$config_options->{ashift}"
404 if defined($config_options->{ashift});
406 syscmd("$cmd $zfspoolname $vdev") == 0 ||
407 die "unable to create zfs root pool\n";
409 syscmd("zfs create $zfspoolname/ROOT") == 0 ||
410 die "unable to create zfs $zfspoolname/ROOT volume\n";
412 if ($env->{product} eq 'pve') {
413 syscmd("zfs create $zfspoolname/data") == 0 ||
414 die "unable to create zfs $zfspoolname/data volume\n";
417 syscmd("zfs create $zfspoolname/ROOT/$zfsrootvolname") == 0 ||
418 die "unable to create zfs $zfspoolname/ROOT/$zfsrootvolname volume\n";
420 # default to `relatime
` on, fast enough for the installer and production
421 syscmd("zfs set atime=on relatime=on $zfspoolname") == 0 ||
422 die "unable to set zfs properties\n";
424 my $value = $config_options->{compress};
425 syscmd("zfs set compression=$value $zfspoolname")
426 if defined($value) && $value ne 'off';
428 $value = $config_options->{checksum};
429 syscmd("zfs set checksum=$value $zfspoolname")
430 if defined($value) && $value ne 'on';
432 $value = $config_options->{copies};
433 syscmd("zfs set copies=$value $zfspoolname")
434 if defined($value) && $value != 1;
437 sub get_pv_list_from_vgname {
447 my ($pv, $vg_uuid) = split(/\s+/, $line);
449 if (!defined($res->{$vg_uuid}->{pvs})) {
450 $res->{$vg_uuid}->{pvs} = "$pv";
452 $res->{$vg_uuid}->{pvs} .= ", $pv";
455 run_command("pvs --noheadings -o pv_name,vg_uuid -S vg_name='$vgname'", $parser, undef, 1);
460 sub ask_existing_vg_rename_or_abort {
463 # this normally only happens if one put a disk with a PVE installation in
464 # this server and that disk is not the installation target.
465 my $duplicate_vgs = get_pv_list_from_vgname($vgname);
466 return if !$duplicate_vgs;
468 my $message = "Detected existing '$vgname' Volume Group(s)! Do you want to:\n";
470 for my $vg_uuid (keys %$duplicate_vgs) {
471 my $vg = $duplicate_vgs->{$vg_uuid};
473 # no high randomnes properties, but this is only for the cases where
474 # we either have multiple "$vgname" vgs from multiple old PVE disks, or
475 # we have a disk with both a "$vgname" and "$vgname-old"...
476 my $short_uid = sprintf "%08X", rand(0xffffffff);
477 $vg->{new_vgname} = "$vgname-OLD-$short_uid";
479 $message .= "rename VG backed by PV '$vg->{pvs}' to '$vg->{new_vgname}'\n";
481 $message .= "or cancel the installation?";
483 my $response = display_prompt($message);
485 if ($response eq 'ok') {
486 for my $vg_uuid (keys %$duplicate_vgs) {
487 my $vg = $duplicate_vgs->{$vg_uuid};
488 my $new_vgname = $vg->{new_vgname};
490 syscmd("vgrename $vg_uuid $new_vgname") == 0 ||
491 die "could not rename VG from '$vg->{pvs}' ($vg_uuid) to '$new_vgname'!\n";
494 set_next("_Reboot", sub { exit (0); } );
495 display_html("fail.htm");
496 die "Cancled installation by user, due to already existing volume group '$vgname'\n";
500 sub create_lvm_volumes {
501 my ($lvmdev, $os_size, $swap_size) = @_;
503 my $vgname = $env->{product};
505 ask_existing_vg_rename_or_abort($vgname);
507 my $rootdev = "/dev/$vgname/root";
508 my $datadev = "/dev/$vgname/data";
511 # we use --metadatasize 250k, which results in "pe_start = 512"
512 # so pe_start is aligned on a 128k boundary (advantage for SSDs)
513 syscmd("/sbin/pvcreate --metadatasize 250k -y -ff $lvmdev") == 0 ||
514 die "unable to initialize physical volume $lvmdev\n";
515 syscmd("/sbin/vgcreate $vgname $lvmdev") == 0 ||
516 die "unable to create volume group '$vgname'\n";
518 my $hdgb = int($os_size / (1024 * 1024));
520 # always leave some space at the end to avoid roudning issues with LVM's physical extent (PE)
522 my $space = $hdgb <= 32 ? 4 * 1024 : (($hdgb > 128 ? 16 : $hdgb / 8) * 1024 * 1024);
527 if ($env->{product} eq 'pve') {
530 if ($config_options->{maxroot}) {
531 $maxroot_mb = $config_options->{maxroot} * 1024;
533 $maxroot_mb = 96 * 1024;
536 my $rest = $os_size - $swap_size;
537 my $rest_mb = int($rest / 1024);
540 if ($rest_mb < 12 * 1024) {
541 # no point in wasting space, try to get us actually installed and align down to 4 MB
542 $rootsize_mb = ($rest_mb - 0.1) & ~3;
543 } elsif ($rest_mb < 48 * 1024) {
544 my $masked = int($rest_mb / 2) & ~3; # align down to 4 MB
545 $rootsize_mb = $masked;
547 $rootsize_mb = $rest_mb / 4 + 12 * 1024;
550 $rootsize_mb = $maxroot_mb if $rootsize_mb > $maxroot_mb;
551 $rootsize = int($rootsize_mb * 1024);
553 $rest -= $rootsize; # in KB
555 my $minfree = $space;
556 if (defined(my $cfg_minfree = $config_options->{minfree})) {
557 $minfree = $cfg_minfree * 1024 * 1024 >= $rest ? $space : $cfg_minfree * 1024 * 1024;
560 $rest = int($rest - $minfree) & ~0xFFF; # align down to 4 MB boundaries
562 if (defined(my $maxvz = $config_options->{maxvz})) {
563 $rest = $maxvz * 1024 * 1024 <= $rest ? $maxvz * 1024 * 1024 : $rest;
569 my $minfree = defined($config_options->{minfree}) ? $config_options->{minfree}*1024*1024 : $space;
570 $rootsize = int($os_size - $minfree - $swap_size); # in KB
571 $rootsize &= ~0xFFF; # align down to 4 MB boundaries
575 syscmd("/sbin/lvcreate -Wy --yes -L${swap_size}K -nswap $vgname") == 0 ||
576 die "unable to create swap volume\n";
578 $swapfile = "/dev/$vgname/swap";
581 syscmd("/sbin/lvcreate -Wy --yes -L${rootsize}K -nroot $vgname") == 0 ||
582 die "unable to create root volume\n";
584 if ($datasize > 4 * 1024 * 1024) {
585 my $metadatasize = $datasize/100; # default 1% of data
586 $metadatasize = 1024*1024 if $metadatasize < 1024*1024; # but at least 1G
587 $metadatasize = 16*1024*1024 if $metadatasize > 16*1024*1024; # but at most 16G
589 # otherwise the metadata is taken out of $minfree
590 $datasize -= 2 * $metadatasize;
592 # 1 4MB PE to allow for rounding
593 $datasize -= 4 * 1024;
595 syscmd("/sbin/lvcreate -Wy --yes -L${datasize}K -ndata $vgname") == 0 ||
596 die "unable to create data volume\n";
598 syscmd("/sbin/lvconvert --yes --type thin-pool --poolmetadatasize ${metadatasize}K $vgname/data") == 0 ||
599 die "unable to create data thin-pool\n";
601 if ($env->{product} eq 'pve' && !defined($config_options->{maxvz})) {
602 display_message("Skipping auto-creation of LVM thinpool for guest data due to low space.");
607 syscmd("/sbin/vgchange -a y $vgname") == 0 ||
608 die "unable to activate volume group\n";
610 return ($rootdev, $swapfile, $datadev);
613 sub compute_swapsize {
616 my $hdgb = int($hdsize/(1024*1024));
619 if (defined($config_options->{swapsize})) {
620 $swapsize_kb = $config_options->{swapsize} * 1024 * 1024;
622 my $ss = int($total_memory);
623 $ss = 4096 if $ss < 4096 && $hdgb >= 64;
624 $ss = 2048 if $ss < 2048 && $hdgb >= 32;
625 $ss = 1024 if $ss >= 2048 && $hdgb <= 16;
626 $ss = 512 if $ss < 512;
627 $ss = int($hdgb * 128) if $ss > $hdgb * 128;
628 $ss = 8192 if $ss > 8192;
629 $swapsize_kb = int($ss * 1024) & ~0xFFF; # align to 4 MB to avoid all to odd SWAP size
635 my sub chroot_chown {
636 my ($root, $path, %param) = @_;
638 my $recursive = $param{recursive} ? ' -R' : '';
639 my $user = $param{user};
640 die "can not chown without user parameter\n" if !defined($user);
641 my $group = $param{group} // $user;
643 syscmd("chroot $root /bin/chown $user:$group $recursive $path") == 0 ||
644 die "chroot: unable to change owner for '$path'\n";
647 my sub chroot_chmod {
648 my ($root, $path, %param) = @_;
650 my $recursive = $param{recursive} ? ' -R' : '';
651 my $mode = $param{mode};
652 die "can not chmod without mode parameter\n" if !defined($mode);
654 syscmd("chroot $root /bin/chmod $mode $recursive $path") == 0 ||
655 die "chroot: unable to change permission mode for '$path'\n";
658 sub prepare_proxmox_boot_esp {
659 my ($espdev, $targetdir) = @_;
661 syscmd("chroot $targetdir proxmox-boot-tool init $espdev") == 0 ||
662 die "unable to init ESP and install proxmox-boot loader on '$espdev'\n";
665 sub prepare_grub_efi_boot_esp {
666 my ($dev, $espdev, $targetdir) = @_;
668 syscmd("mount -n $espdev -t vfat $targetdir/boot/efi") == 0 ||
669 die "unable to mount $espdev\n";
672 my $rc = syscmd("chroot $targetdir /usr/sbin/grub-install --target x86_64-efi --no-floppy --bootloader-id='proxmox' $dev");
674 if ($boot_type eq 'efi') {
675 die "unable to install the EFI boot loader on '$dev'\n";
677 warn "unable to install the EFI boot loader on '$dev', ignoring (not booted using UEFI)\n";
680 # also install fallback boot file (OVMF does not boot without)
681 mkdir("$targetdir/boot/efi/EFI/BOOT");
682 syscmd("cp $targetdir/boot/efi/EFI/proxmox/grubx64.efi $targetdir/boot/efi/EFI/BOOT/BOOTx64.EFI") == 0 ||
683 die "unable to copy efi boot loader\n";
688 syscmd("umount $targetdir/boot/efi") == 0 ||
689 die "unable to umount $targetdir/boot/efi\n";
693 die "failed to prepare EFI boot using Grub on '$espdev': $err" if $err;
697 my ($basefile, $targetdir) = @_;
699 die "target '$targetdir' does not exist\n" if ! -d $targetdir;
701 my $starttime = [Time::HiRes::gettimeofday];
703 my $bootdevinfo = [];
705 my ($swapfile, $rootdev, $datadev);
706 my ($use_zfs, $use_btrfs) = (0, 0);
708 my $filesys = $config_options->{filesys};
710 if ($filesys =~ m/zfs/) {
711 $target_hd = undef; # do not use this config
713 $targetdir = "/$zfspoolname/ROOT/$zfsrootvolname";
714 } elsif ($filesys =~ m/btrfs/) {
715 $target_hd = undef; # do not use this config
721 for ($i = 5; $i > 0; $i--) {
722 syscmd("modprobe zfs");
723 last if -c "/dev/zfs";
727 die "unable to load zfs kernel module\n" if !$i;
735 update_progress(0, 0, $maxper, "cleanup root-disks");
737 syscmd("vgchange -an") if !is_test_mode(); # deactivate all detected VGs
739 if (is_test_mode()) {
741 my $test_images = Proxmox::Install::ISOEnv::get_test_images();
742 $rootdev = abs_path($test_images->[0]); # FIXME: use all selected for test too!
743 syscmd("umount $rootdev");
747 die "unsupported btrfs mode (for testing environment)\n"
748 if $filesys ne 'btrfs (RAID0)';
750 btrfs_create([$rootdev], 'single');
754 die "unsupported zfs mode (for testing environment)\n"
755 if $filesys ne 'zfs (RAID0)';
757 syscmd("zpool destroy $zfstestpool");
759 zfs_create_rpool($rootdev);
766 } elsif ($use_btrfs) {
768 my ($devlist, $btrfs_mode) = get_btrfs_raid_setup();
770 foreach my $hd (@$devlist) {
774 update_progress(0, 0.02, $maxper, "create partitions");
776 my $btrfs_partitions = [];
777 foreach my $hd (@$devlist) {
778 my $devname = @$hd[1];
779 my $logical_bsize = @$hd[4];
781 my ($size, $osdev, $efidev) = partition_bootable_disk(
782 $devname, $config_options->{hdsize}, '8300');
783 $rootdev = $osdev if !defined($rootdev); # simply point to first disk
784 my $by_id = Proxmox::Sys::Block::get_disk_by_id_path($devname);
785 push @$bootdevinfo, {
790 logical_bsize => $logical_bsize,
792 push @$btrfs_partitions, $osdev;
795 Proxmox::Sys::Block::udevadm_trigger_block();
797 update_progress(0, 0.03, $maxper, "create btrfs");
799 btrfs_create($btrfs_partitions, $btrfs_mode);
803 my ($devlist, $vdev) = get_zfs_raid_setup();
805 foreach my $hd (@$devlist) {
809 update_progress(0, 0.02, $maxper, "create partitions");
811 # install esp/boot part on all, we can only win!
812 for my $hd (@$devlist) {
813 my $devname = @$hd[1];
814 my $logical_bsize = @$hd[4];
816 my ($size, $osdev, $efidev) =
817 partition_bootable_disk($devname, $config_options->{hdsize}, 'BF01');
819 push @$bootdevinfo, {
823 logical_bsize => $logical_bsize,
827 Proxmox::Sys::Block::udevadm_trigger_block();
829 foreach my $di (@$bootdevinfo) {
830 my $devname = $di->{devname};
831 $di->{by_id} = Proxmox::Sys::Block::get_disk_by_id_path($devname);
833 my $osdev = Proxmox::Sys::Block::get_disk_by_id_path($di->{osdev}) || $di->{osdev};
835 $vdev =~ s/ $devname/ $osdev/;
838 foreach my $hd (@$devlist) {
839 my $devname = @$hd[1];
840 my $by_id = Proxmox::Sys::Block::get_disk_by_id_path($devname);
842 $vdev =~ s/ $devname/ $by_id/ if $by_id;
845 update_progress(0, 0.03, $maxper, "create rpool");
847 zfs_create_rpool($vdev);
851 die "target '$target_hd' is not a valid block device\n" if ! -b $target_hd;
853 wipe_disk($target_hd);
855 update_progress(0, 0.02, $maxper, "create partitions");
857 my $logical_bsize = Proxmox::Sys::Block::logical_blocksize($target_hd);
859 my ($os_size, $osdev, $efidev) =
860 partition_bootable_disk($target_hd, $config_options->{hdsize}, '8E00');
862 Proxmox::Sys::Block::udevadm_trigger_block();
864 my $by_id = Proxmox::Sys::Block::get_disk_by_id_path($target_hd);
865 push @$bootdevinfo, {
867 devname => $target_hd,
870 logical_bsize => $logical_bsize,
873 update_progress(0, 0.03, $maxper, "create LVs");
875 my $swap_size = compute_swapsize($os_size);
876 ($rootdev, $swapfile, $datadev) =
877 create_lvm_volumes($osdev, $os_size, $swap_size);
879 # trigger udev to create /dev/disk/by-uuid
880 Proxmox::Sys::Block::udevadm_trigger_block(1);
884 # to be fast during installation
885 syscmd("zfs set sync=disabled $zfspoolname") == 0 ||
886 die "unable to set zfs properties\n";
889 update_progress(0.04, 0, $maxper, "create swap space");
891 syscmd("mkswap -f $swapfile") == 0 ||
892 die "unable to create swap space\n";
895 update_progress(0.045, 0, $maxper, "creating root filesystems");
897 foreach my $di (@$bootdevinfo) {
899 # FIXME remove '-s1' once https://github.com/dosfstools/dosfstools/issues/111 is fixed
900 my $vfat_extra_opts = ($di->{logical_bsize} == 4096) ? '-s1' : '';
901 syscmd("mkfs.vfat $vfat_extra_opts -F32 $di->{esp}") == 0 ||
902 die "unable to initialize EFI ESP on device $di->{esp}\n";
907 } elsif ($use_btrfs) {
910 create_filesystem($rootdev, 'root', $filesys, 0.05, $maxper, 0, 1);
913 update_progress(1, 0.05, $maxper, "mounting target $rootdev");
918 my $mount_opts = 'noatime';
919 $mount_opts .= ',nobarrier'
920 if $use_btrfs || $filesys =~ /^ext\d$/;
922 syscmd("mount -n $rootdev -o $mount_opts $targetdir") == 0 ||
923 die "unable to mount $rootdev\n";
926 mkdir "$targetdir/boot";
927 mkdir "$targetdir/boot/efi";
929 mkdir "$targetdir/var";
930 mkdir "$targetdir/var/lib";
932 if ($env->{product} eq 'pve') {
933 mkdir "$targetdir/var/lib/vz";
934 mkdir "$targetdir/var/lib/pve";
937 syscmd("btrfs subvolume create $targetdir/var/lib/pve/local-btrfs") == 0 ||
938 die "unable to create btrfs subvolume\n";
942 mkdir "$targetdir/mnt";
943 mkdir "$targetdir/mnt/hostrun";
944 syscmd("mount --bind /run $targetdir/mnt/hostrun") == 0 ||
945 die "unable to bindmount run on $targetdir/mnt/hostrun\n";
947 update_progress(1, 0.05, $maxper, "extracting base system");
949 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = stat ($basefile);
950 $ino || die "unable to open file '$basefile' - $!\n";
952 my $files = file_read_firstline("${proxmox_cddir}/proxmox/$env->{product}-base.cnt") ||
953 die "unable to read base file count\n";
958 run_command("unsquashfs -f -dest $targetdir -i $basefile", sub {
960 return if $line !~ m/^$targetdir/;
962 my $nper = int (($count *100)/$files);
965 my $frac = $per > 100 ? 1 : $per/100;
966 update_progress($frac, $maxper, 0.5);
970 syscmd("mount -n -t tmpfs tmpfs $targetdir/tmp") == 0 || die "unable to mount tmpfs on $targetdir/tmp\n";
972 mkdir "$targetdir/tmp/pkg";
973 syscmd("mount -n --bind '$proxmox_pkgdir' '$targetdir/tmp/pkg'") == 0
974 || die "unable to bind-mount packages on $targetdir/tmp/pkg\n";
975 syscmd("mount -n -t proc proc $targetdir/proc") == 0 || die "unable to mount proc on $targetdir/proc\n";
976 syscmd("mount -n -t sysfs sysfs $targetdir/sys") == 0 || die "unable to mount sysfs on $targetdir/sys\n";
977 if ($boot_type eq 'efi') {
978 syscmd("mount -n -t efivarfs efivarfs $targetdir/sys/firmware/efi/efivars") == 0 ||
979 die "unable to mount efivarfs on $targetdir/sys/firmware/efi/efivars: $!\n";
981 syscmd("chroot $targetdir mount --bind /mnt/hostrun /run") == 0 ||
982 die "unable to re-bindmount hostrun on /run in chroot\n";
984 update_progress(1, $maxper, 0.5, "configuring base system");
989 "127.0.0.1 localhost.localdomain localhost\n" .
990 "$ipaddress $hostname.$domain $hostname\n\n" .
991 "# The following lines are desirable for IPv6 capable hosts\n\n" .
992 "::1 ip6-localhost ip6-loopback\n" .
993 "fe00::0 ip6-localnet\n" .
994 "ff00::0 ip6-mcastprefix\n" .
995 "ff02::1 ip6-allnodes\n" .
996 "ff02::2 ip6-allrouters\n" .
997 "ff02::3 ip6-allhosts\n";
999 file_write_all("$targetdir/etc/hosts", $hosts);
1001 file_write_all("$targetdir/etc/hostname", "$hostname\n");
1003 syscmd("/bin/hostname $hostname") if !is_test_mode();
1005 # configure interfaces
1007 my $ifaces = "auto lo\niface lo inet loopback\n\n";
1009 my $ntype = $ipversion == 4 ? 'inet' : 'inet6';
1011 my $ethdev = $ipconf->{ifaces}->{$ipconf->{selected}}->{name};
1013 if ($env->{cfg}->{bridged_network}) {
1014 $ifaces .= "iface $ethdev $ntype manual\n";
1017 "\nauto vmbr0\niface vmbr0 $ntype static\n" .
1018 "\taddress $cidr\n" .
1019 "\tgateway $gateway\n" .
1020 "\tbridge-ports $ethdev\n" .
1021 "\tbridge-stp off\n" .
1024 $ifaces .= "auto $ethdev\n" .
1025 "iface $ethdev $ntype static\n" .
1026 "\taddress $cidr\n" .
1027 "\tgateway $gateway\n";
1030 foreach my $iface (sort keys %{$ipconf->{ifaces}}) {
1031 my $name = $ipconf->{ifaces}->{$iface}->{name};
1032 next if $name eq $ethdev;
1034 $ifaces .= "\niface $name $ntype manual\n";
1037 file_write_all("$targetdir/etc/network/interfaces", $ifaces);
1041 my $resolvconf = "search $domain\nnameserver $dnsserver\n";
1042 file_write_all("$targetdir/etc/resolv.conf", $resolvconf);
1046 my $fstab = "# <file system> <mount point> <type> <options> <dump> <pass>\n";
1050 } elsif ($use_btrfs) {
1052 my $cmd = "blkid -u filesystem -t TYPE=btrfs -o export $rootdev";
1053 run_command($cmd, sub {
1056 if ($line =~ m/^UUID=([A-Fa-f0-9\-]+)$/) {
1061 die "unable to detect FS UUID" if !defined($fsuuid);
1063 $fstab .= "UUID=$fsuuid / btrfs defaults 0 1\n";
1065 my $root_mountopt = $fssetup->{$filesys}->{root_mountopt} || 'defaults';
1066 $fstab .= "$rootdev / $filesys ${root_mountopt} 0 1\n";
1070 # Note: this is required by current grub, but really dangerous, because
1071 # vfat does not have journaling, so it triggers manual fsck after each crash
1072 # so we only mount /boot/efi if really required (efi systems).
1073 if ($boot_type eq 'efi' && !$use_zfs) {
1074 if (scalar(@$bootdevinfo)) {
1075 my $di = @$bootdevinfo[0]; # simply use first disk
1078 my $efi_boot_uuid = $di->{esp};
1079 if (my $uuid = Proxmox::Sys::Block::get_dev_uuid($di->{esp})) {
1080 $efi_boot_uuid = "UUID=$uuid";
1083 $fstab .= "${efi_boot_uuid} /boot/efi vfat defaults 0 1\n";
1089 $fstab .= "$swapfile none swap sw 0 0\n" if $swapfile;
1091 $fstab .= "proc /proc proc defaults 0 0\n";
1093 file_write_all("$targetdir/etc/fstab", $fstab);
1094 file_write_all("$targetdir/etc/mtab", "");
1096 syscmd("cp ${proxmox_libdir}/policy-disable-rc.d $targetdir/usr/sbin/policy-rc.d") == 0 ||
1097 die "unable to copy policy-rc.d\n";
1098 syscmd("cp ${proxmox_libdir}/fake-start-stop-daemon $targetdir/sbin/") == 0 ||
1099 die "unable to copy start-stop-daemon\n";
1101 diversion_add($targetdir, "/sbin/start-stop-daemon", "/sbin/fake-start-stop-daemon");
1102 diversion_add($targetdir, "/usr/sbin/update-grub", "/bin/true");
1103 diversion_add($targetdir, "/usr/sbin/update-initramfs", "/bin/true");
1105 my $machine_id = run_command("systemd-id128 new");
1106 die "unable to create a new machine-id\n" if ! $machine_id;
1107 file_write_all("$targetdir/etc/machine-id", $machine_id);
1109 syscmd("cp /etc/hostid $targetdir/etc/") == 0 ||
1110 die "unable to copy hostid\n";
1112 syscmd("touch $targetdir/proxmox_install_mode");
1114 my $grub_install_devices_txt = '';
1115 foreach my $di (@$bootdevinfo) {
1116 $grub_install_devices_txt .= ', ' if $grub_install_devices_txt;
1117 $grub_install_devices_txt .= $di->{by_id} || $di->{devname};
1120 # Note: keyboard-configuration/xbkb-keymap is used by console-setup
1121 my $xkmap = $env->{locales}->{kmap}->{$keymap}->{x11} // 'us';
1123 debconfig_set ($targetdir, <<_EOD);
1124 locales locales/default_environment_locale select en_US.UTF-8
1125 locales locales/locales_to_be_generated select en_US.UTF-8 UTF-8
1126 samba-common samba-common/dhcp boolean false
1127 samba-common samba-common/workgroup string WORKGROUP
1128 postfix postfix/main_mailer_type select No configuration
1129 keyboard-configuration keyboard-configuration/xkb-keymap select $xkmap
1130 d-i debian-installer/locale select en_US.UTF-8
1131 grub-pc grub-pc/install_devices select $grub_install_devices_txt
1135 while (<${proxmox_pkgdir
}/*.deb
>) { $pkg_count++ };
1137 # btrfs/dpkg is extremely slow without --force-unsafe-io
1138 my $dpkg_opts = $use_btrfs ?
"--force-unsafe-io" : "";
1141 while (<${proxmox_pkgdir
}/*.deb
>) {
1144 my ($deb) = $path =~ m/${proxmox_pkgdir}\/(.*\
.deb
)/;
1145 update_progress
($count/$pkg_count, 0.5, 0.75, "extracting $deb");
1146 print "extracting: $deb\n";
1147 syscmd
("chroot $targetdir dpkg $dpkg_opts --force-depends --no-triggers --unpack /tmp/pkg/$deb") == 0
1148 || die "installation of package $deb failed\n";
1149 update_progress
((++$count)/$pkg_count, 0.5, 0.75);
1152 # needed for postfix postinst in case no other NIC is active
1153 syscmd
("chroot $targetdir ifup lo");
1155 my $cmd = "chroot $targetdir dpkg $dpkg_opts --force-confold --configure -a";
1157 run_command
($cmd, sub {
1159 if ($line =~ m/Setting up\s+(\S+)/) {
1160 update_progress
((++$count)/$pkg_count, 0.75, 0.95, "configuring $1");
1164 unlink "$targetdir/etc/mailname";
1165 $postfix_main_cf =~ s/__FQDN__/${hostname}.${domain}/;
1166 file_write_all
("$targetdir/etc/postfix/main.cf", $postfix_main_cf);
1168 # make sure we have all postfix directories
1169 syscmd
("chroot $targetdir /usr/sbin/postfix check");
1170 # cleanup mail queue
1171 syscmd
("chroot $targetdir /usr/sbin/postsuper -d ALL");
1172 # create /etc/aliases.db (/etc/aliases is shipped in the base squashfs)
1173 syscmd
("chroot $targetdir /usr/bin/newaliases");
1175 unlink "$targetdir/proxmox_install_mode";
1178 unlink ("$targetdir/etc/localtime");
1179 symlink ("/usr/share/zoneinfo/$timezone", "$targetdir/etc/localtime");
1180 file_write_all
("$targetdir/etc/timezone", "$timezone\n");
1183 if (my $mirror = $env->{locales
}->{country
}->{$country}->{mirror
}) {
1184 my $fn = "$targetdir/etc/apt/sources.list";
1185 syscmd
("sed -i 's/ftp\\.debian\\.org/$mirror/' '$fn'");
1188 # create extended_states for apt (avoid cron job warning if that
1189 # file does not exist)
1190 file_write_all
("$targetdir/var/lib/apt/extended_states", '');
1192 # allow ssh root login
1193 syscmd
(['sed', '-i', 's/^#\?PermitRootLogin.*/PermitRootLogin yes/', "$targetdir/etc/ssh/sshd_config"]);
1195 if ($env->{product
} eq 'pmg') {
1196 # install initial clamav DB
1197 my $srcdir = "${proxmox_cddir}/proxmox/clamav";
1198 foreach my $fn ("main.cvd", "bytecode.cvd", "daily.cvd", "safebrowsing.cvd") {
1199 syscmd
("cp \"$srcdir/$fn\" \"$targetdir/var/lib/clamav\"") == 0 ||
1200 die "installation of clamav db file '$fn' failed\n";
1202 syscmd
("chroot $targetdir /bin/chown clamav:clamav -R /var/lib/clamav") == 0 ||
1203 die "unable to set owner for clamav database files\n";
1206 if ($env->{product
} eq 'pve') {
1207 # save installer settings
1208 my $ucc = uc ($country);
1209 debconfig_set
($targetdir, "pve-manager pve-manager/country string $ucc\n");
1212 update_progress
(0.8, 0.95, 1, "make system bootable");
1215 # add ZFS options while preserving existing kernel cmdline
1216 my $zfs_snippet = "GRUB_CMDLINE_LINUX=\"\$GRUB_CMDLINE_LINUX root=ZFS=$zfspoolname/ROOT/$zfsrootvolname boot=zfs\"";
1217 file_write_all
("$targetdir/etc/default/grub.d/zfs.cfg", $zfs_snippet);
1219 file_write_all
("$targetdir/etc/kernel/cmdline", "root=ZFS=$zfspoolname/ROOT/$zfsrootvolname boot=zfs\n");
1223 diversion_remove
($targetdir, "/usr/sbin/update-grub");
1224 diversion_remove
($targetdir, "/usr/sbin/update-initramfs");
1227 foreach my $fn (<$targetdir/lib/modules/*>) {
1228 if ($fn =~ m!/(\d+\.\d+\.\d+-\d+-pve)$!) {
1229 die "found multiple kernels\n" if defined($kapi);
1233 die "unable to detect kernel version\n" if !defined($kapi);
1235 if (!is_test_mode
()) {
1237 unlink ("$targetdir/etc/mtab");
1238 symlink ("/proc/mounts", "$targetdir/etc/mtab");
1239 syscmd
("mount -n --bind /dev $targetdir/dev");
1241 my $bootloader_err_list = [];
1243 syscmd
("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0 ||
1244 die "unable to install initramfs\n";
1246 my $native_4k_disk_bootable = 0;
1247 foreach my $di (@$bootdevinfo) {
1248 $native_4k_disk_bootable |= ($di->{logical_bsize
} == 4096);
1251 foreach my $di (@$bootdevinfo) {
1252 my $dev = $di->{devname
};
1254 prepare_proxmox_boot_esp
($di->{esp
}, $targetdir);
1256 if (!$native_4k_disk_bootable) {
1258 syscmd
("chroot $targetdir /usr/sbin/grub-install --target i386-pc --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
1259 die "unable to install the i386-pc boot loader on '$dev'\n";
1261 push @$bootloader_err_list, $@ if $@;
1264 if (my $esp = $di->{esp
}) {
1265 eval { prepare_grub_efi_boot_esp
($dev, $esp, $targetdir) };
1266 push @$bootloader_err_list, $@ if $@;
1271 syscmd
("chroot $targetdir /usr/sbin/update-grub") == 0 ||
1272 die "unable to update boot loader config\n";
1274 push @$bootloader_err_list, $@ if $@;
1276 if (scalar(@$bootloader_err_list) > 0) {
1277 $bootloader_err = "bootloader setup errors:\n";
1278 map { $bootloader_err .= "- $_" } @$bootloader_err_list;
1279 warn $bootloader_err;
1282 syscmd
("umount $targetdir/dev");
1287 unlink "$targetdir/usr/sbin/policy-rc.d";
1289 diversion_remove
($targetdir, "/sbin/start-stop-daemon");
1292 my $octets = encode
("utf-8", $password);
1293 run_command
("chroot $targetdir /usr/sbin/chpasswd", undef,
1296 if ($env->{product
} eq 'pmg') {
1298 file_write_all
("$targetdir/etc/pmg/pmg.conf", "section: admin\n\temail ${mailto}\n");
1300 } elsif ($env->{product
} eq 'pve') {
1304 my $tmpdir = "$targetdir/tmp/pve";
1307 # write vnc keymap to datacenter.cfg
1308 my $vnckmap = $env->{locales
}->{kmap
}->{$keymap}->{kvm
} || 'en-us';
1309 file_write_all
("$tmpdir/datacenter.cfg", "keyboard: $vnckmap\n");
1312 file_write_all
("$tmpdir/user.cfg", "user:root\@pam:1:0:::${mailto}::\n");
1317 $storage_cfg = $storage_cfg_zfs;
1318 } elsif ($use_btrfs) {
1319 $storage_cfg = $storage_cfg_btrfs;
1320 } elsif ($datadev) {
1321 $storage_cfg = $storage_cfg_lvmthin;
1323 $storage_cfg = $storage_cfg_local;
1325 file_write_all
("$tmpdir/storage.cfg", $storage_cfg);
1327 run_command
("chroot $targetdir /usr/bin/create_pmxcfs_db /tmp/pve /var/lib/pve-cluster/config.db");
1329 syscmd
("rm -rf $tmpdir");
1330 } elsif ($env->{product
} eq 'pbs') {
1331 my $base_cfg_path = "/etc/proxmox-backup";
1332 mkdir "$targetdir/$base_cfg_path";
1334 chroot_chown
($targetdir, $base_cfg_path, user
=> 'backup', recursive
=> 1);
1335 chroot_chmod
($targetdir, $base_cfg_path, mode
=> '0700');
1337 my $user_cfg_fn = "$base_cfg_path/user.cfg";
1338 file_write_all
("$targetdir/$user_cfg_fn", "user: root\@pam\n\temail ${mailto}\n");
1339 chroot_chown
($targetdir, $user_cfg_fn, user
=> 'root', group
=> 'backup');
1340 chroot_chmod
($targetdir, $user_cfg_fn, mode
=> '0640');
1346 update_progress
(1, 0, 1, "");
1350 if (is_test_mode
()) {
1351 my $elapsed = Time
::HiRes
::tv_interval
($starttime);
1352 print "Elapsed extract time: $elapsed\n";
1354 syscmd
("chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> final.pkglist");
1357 syscmd
("umount $targetdir/run");
1358 syscmd
("umount $targetdir/mnt/hostrun");
1359 syscmd
("umount $targetdir/tmp/pkg");
1360 syscmd
("umount $targetdir/tmp");
1361 syscmd
("umount $targetdir/proc");
1362 syscmd
("umount $targetdir/sys/firmware/efi/efivars");
1363 syscmd
("umount $targetdir/sys");
1364 rmdir("$targetdir/mnt/hostrun");
1367 syscmd
("zfs umount -a") == 0 ||
1368 die "unable to unmount zfs\n";
1370 syscmd
("umount -d $targetdir");
1373 if (!$err && $use_zfs) {
1374 syscmd
("zfs set sync=standard $zfspoolname") == 0 ||
1375 die "unable to set zfs properties\n";
1377 syscmd
("zfs set mountpoint=/ $zfspoolname/ROOT/$zfsrootvolname") == 0 ||
1378 die "zfs set mountpoint failed\n";
1380 syscmd
("zpool set bootfs=$zfspoolname/ROOT/$zfsrootvolname $zfspoolname") == 0 ||
1381 die "zpool set bootfs failed\n";
1382 syscmd
("zpool export $zfspoolname");
1385 if ($bootloader_err) {
1386 $err = $err ?
"$err\n$bootloader_err" : $bootloader_err;
1392 my $last_display_change = 0;
1394 my $display_info_counter = 0;
1396 my $display_info_items = [
1397 "extract1-license.htm",
1398 "extract2-rulesystem.htm",
1399 "extract3-spam.htm",
1400 "extract4-virus.htm",
1405 my $min_display_time = 15;
1409 return if ($ctime - $last_display_change) < $min_display_time;
1411 my $page = $display_info_items->[$display_info_counter % scalar(@$display_info_items)];
1413 $display_info_counter++;
1415 display_html
($page);
1419 my ($filename) = @_;
1421 $filename = $steps[$step_number]->{html
} if !$filename;
1423 my $htmldir = "${proxmox_libdir}/html";
1425 if (-f
"$htmldir/$env->{product}/$filename") {
1426 $path = "$htmldir/$env->{product}/$filename";
1428 $path = "$htmldir/$filename";
1431 my $data = file_read_all
($path);
1433 if ($filename eq 'license.htm') {
1434 my $license = eval { decode
('utf8', file_read_all
("${proxmox_cddir}/EULA")) };
1436 die $err if !is_test_mode
();
1437 $license = "TESTMODE: Ignore non existent EULA...\n";
1439 my $title = "END USER LICENSE AGREEMENT (EULA)";
1440 $data =~ s/__LICENSE__/$license/;
1441 $data =~ s/__LICENSE_TITLE__/$title/;
1442 } elsif ($filename eq 'success.htm') {
1443 my $addr = $ipversion == 6 ?
"[${ipaddress}]" : "$ipaddress";
1444 $data =~ s/__IPADDR__/$addr/g;
1445 $data =~ s/__PORT__/$env->{cfg}->{port}/g;
1447 my $autoreboot_msg = $config_options->{autoreboot
}
1448 ?
"Automatic reboot scheduled in $autoreboot_seconds seconds."
1450 $data =~ s/__AUTOREBOOT_MSG__/$autoreboot_msg/;
1452 $data =~ s/__FULL_PRODUCT_NAME__/$env->{cfg}->{fullname}/g;
1454 # always set base-path to common path, all resources are accesible from there.
1455 $htmlview->load_html($data, "file://$htmldir/");
1457 $last_display_change = time();
1462 my ($text, $fctn) = @_;
1464 $fctn = $step_number if !$fctn;
1465 $text = "_Previous" if !$text;
1466 $prev_btn->set_label ($text);
1469 $steps[$step_number]->{function
}();
1471 $prev_btn->grab_focus();
1475 my ($text, $fctn) = @_;
1478 my $step = $steps[$step_number];
1479 $text //= $steps[$step_number]->{next_button
} // '_Next';
1480 $next->set_label($text);
1482 $next->grab_focus();
1485 sub create_main_window
{
1487 $window = Gtk3
::Window-
>new();
1488 $window->set_default_size(1024, 768);
1489 $window->set_has_resize_grip(0);
1490 $window->fullscreen() if !is_test_mode
();
1491 $window->set_decorated(0) if !is_test_mode
();
1493 my $vbox = Gtk3
::Box-
>new('vertical', 0);
1495 my $logofn = "$env->{product}-banner.png";
1496 my $image = Gtk3
::Image-
>new_from_file("${proxmox_libdir}/$logofn");
1498 my $provider = Gtk3
::CssProvider-
>new();
1499 my $theming = "* {\nbackground: #171717;\n}";
1500 $provider->load_from_data ([map ord, split //, $theming]);
1501 my $context = $image->get_style_context();
1502 $context->add_provider($provider, 600);
1504 $vbox->pack_start($image, 0, 0, 0);
1506 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
1507 $vbox->pack_start($hbox, 1, 1, 0);
1509 # my $f1 = Gtk3::Frame->new ('test');
1510 # $f1->set_shadow_type ('none');
1511 # $hbox->pack_start ($f1, 1, 1, 0);
1513 my $sep1 = Gtk3
::Separator-
>new('horizontal');
1514 $vbox->pack_start($sep1, 0, 0, 0);
1516 $cmdbox = Gtk3
::Box-
>new('horizontal', 0);
1517 $vbox->pack_start($cmdbox, 0, 0, 10);
1519 $next = Gtk3
::Button-
>new('_Next');
1520 $next->signal_connect(clicked
=> sub { $last_display_change = 0; &$next_fctn (); });
1521 $cmdbox->pack_end($next, 0, 0, 10);
1524 $prev_btn = Gtk3
::Button-
>new('_Previous');
1525 $prev_btn->signal_connect(clicked
=> sub { $last_display_change = 0; &prev_function
(); });
1526 $cmdbox->pack_end($prev_btn, 0, 0, 10);
1529 my $abort = Gtk3
::Button-
>new('_Abort');
1530 $abort->set_can_focus(0);
1531 $cmdbox->pack_start($abort, 0, 0, 10);
1532 $abort->signal_connect(clicked
=> sub { exit (-1); });
1534 my $vbox2 = Gtk3
::Box-
>new('vertical', 0);
1537 $htmlview = Gtk3
::WebKit2
::WebView-
>new();
1538 $htmlview->set_hexpand(1);
1539 my $scrolls = Gtk3
::ScrolledWindow-
>new();
1540 $scrolls->add($htmlview);
1542 my $hbox2 = Gtk3
::Box-
>new('horizontal', 0);
1543 $hbox2->pack_start($scrolls, 1, 1, 0);
1545 $vbox2->pack_start($hbox2, 1, 1, 0);
1547 my $vbox3 = Gtk3
::Box-
>new('vertical', 0);
1548 $vbox2->pack_start($vbox3, 0, 0, 0);
1550 my $sep2 = Gtk3
::Separator-
>new('horizontal');
1551 $vbox3->pack_start($sep2, 0, 0, 0);
1553 $inbox = Gtk3
::Box-
>new('horizontal', 0);
1554 $vbox3->pack_start($inbox, 0, 0, 0);
1556 $window->add($vbox);
1563 $inbox->foreach(sub {
1565 $inbox->remove ($child);
1569 # fixme: newer GTK3 has special properties to handle numbers with Entry
1570 # only allow floating point numbers with Gtk3::Entry
1573 my ($entry, $event) = @_;
1575 return check_number
($entry, $event, 1);
1579 my ($entry, $event) = @_;
1581 return check_number
($entry, $event, 0);
1585 my ($entry, $event, $float) = @_;
1587 my $val = $event->get_keyval;
1589 if (($float && $val == ord '.') ||
1590 $val == Gtk3
::Gdk
::KEY_ISO_Left_Tab
||
1591 $val == Gtk3
::Gdk
::KEY_Shift_L
||
1592 $val == Gtk3
::Gdk
::KEY_Tab
||
1593 $val == Gtk3
::Gdk
::KEY_Left
||
1594 $val == Gtk3
::Gdk
::KEY_Right
||
1595 $val == Gtk3
::Gdk
::KEY_BackSpace
||
1596 $val == Gtk3
::Gdk
::KEY_Delete
||
1597 ($val >= ord '0' && $val <= ord '9') ||
1598 ($val >= Gtk3
::Gdk
::KEY_KP_0
&&
1599 $val <= Gtk3
::Gdk
::KEY_KP_9
)) {
1606 sub create_text_input
{
1607 my ($default, $text) = @_;
1609 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
1611 my $label = Gtk3
::Label-
>new($text);
1612 $label->set_size_request(150, -1);
1613 $label->set_xalign(1.0);
1614 $hbox->pack_start($label, 0, 0, 10);
1615 my $e1 = Gtk3
::Entry-
>new();
1616 $e1->set_width_chars(35);
1617 $hbox->pack_start($e1, 0, 0, 0);
1618 $e1->set_text($default);
1620 return ($hbox, $e1);
1622 sub create_cidr_inputs
{
1623 my ($default_ip, $default_mask) = @_;
1625 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
1627 my $label = Gtk3
::Label-
>new('IP Address (CIDR)');
1628 $label->set_size_request(150, -1);
1629 $label->set_xalign(1.0);
1630 $hbox->pack_start($label, 0, 0, 10);
1632 my $ip_el = Gtk3
::Entry-
>new();
1633 $ip_el->set_width_chars(28);
1634 $hbox->pack_start($ip_el, 0, 0, 0);
1635 $ip_el->set_text($default_ip);
1637 $label = Gtk3
::Label-
>new('/');
1638 $label->set_size_request(10, -1);
1639 $hbox->pack_start($label, 0, 0, 2);
1641 my $cidr_el = Gtk3
::Entry-
>new();
1642 $cidr_el->set_width_chars(3);
1643 $hbox->pack_start($cidr_el, 0, 0, 0);
1644 $cidr_el->set_text($default_mask);
1646 return ($hbox, $ip_el, $cidr_el);
1649 sub display_message
{
1652 my $dialog = Gtk3
::MessageDialog-
>new($window, 'modal', 'info', 'ok', $msg);
1660 my $dialog = Gtk3
::MessageDialog-
>new($window, 'modal', 'error', 'ok', $msg);
1665 sub display_prompt
{
1668 my $dialog = Gtk3
::MessageDialog-
>new($window, 'modal', 'question', 'ok-cancel', $query);
1669 my $response = $dialog->run();
1675 my $ipconf_first_view = 1;
1677 sub create_ipconf_view
{
1682 my $vcontainer = Gtk3
::Box-
>new('vertical', 0);
1683 $inbox->pack_start($vcontainer, 1, 0, 0);
1684 my $hcontainer = Gtk3
::Box-
>new('horizontal', 0);
1685 $vcontainer->pack_start($hcontainer, 0, 0, 10);
1686 my $vbox = Gtk3
::Box-
>new('vertical', 0);
1687 $hcontainer->add($vbox);
1689 my $ipaddr_text = $config->{ipaddress
} // "192.168.100.2";
1690 my $netmask_text = $config->{netmask
} // "24";
1692 ($cidr_box, $ipconf_entry_addr, $ipconf_entry_mask) =
1693 create_cidr_inputs
($ipaddr_text, $netmask_text);
1695 my $device_cb = Gtk3
::ComboBoxText-
>new();
1696 $device_cb->set_active(0);
1697 $device_cb->set_visible(1);
1699 my $get_device_desc = sub {
1701 return "$iface->{name} - $iface->{mac} ($iface->{driver})";
1704 my $device_active_map = {};
1705 my $device_active_reverse_map = {};
1707 my $device_change_handler = sub {
1708 my $current = shift;
1710 my $new = $device_active_map->{$current->get_active()};
1711 return if defined($ipconf->{selected
}) && $new eq $ipconf->{selected
};
1713 $ipconf->{selected
} = $new;
1714 my $iface = $ipconf->{ifaces
}->{$ipconf->{selected
}};
1715 $config->{mngmt_nic
} = $iface->{name
};
1716 $ipconf_entry_addr->set_text($iface->{inet
}->{addr
} || $iface->{inet6
}->{addr
})
1717 if $iface->{inet
}->{addr
} || $iface->{inet6
}->{addr
};
1718 $ipconf_entry_mask->set_text($iface->{inet
}->{prefix
} || $iface->{inet6
}->{prefix
})
1719 if $iface->{inet
}->{prefix
} || $iface->{inet6
}->{prefix
};
1723 foreach my $index (sort keys %{$ipconf->{ifaces
}}) {
1724 $device_cb->append_text(&$get_device_desc($ipconf->{ifaces
}->{$index}));
1725 $device_active_map->{$i} = $index;
1726 $device_active_reverse_map->{$ipconf->{ifaces
}->{$index}->{name
}} = $i;
1727 if ($ipconf_first_view && $index == $ipconf->{default}) {
1728 $device_cb->set_active($i);
1729 &$device_change_handler($device_cb);
1730 $ipconf_first_view = 0;
1732 $device_cb->signal_connect('changed' => $device_change_handler);
1736 if (my $nic = $config->{mngmt_nic
}) {
1737 $device_cb->set_active($device_active_reverse_map->{$nic} // 0);
1739 $device_cb->set_active(0);
1742 my $devicebox = Gtk3
::Box-
>new('horizontal', 0);
1743 my $label = Gtk3
::Label-
>new("Management Interface:");
1744 $label->set_size_request(150, -1);
1745 $label->set_xalign(1.0);
1746 $devicebox->pack_start($label, 0, 0, 10);
1747 $devicebox->pack_start($device_cb, 0, 0, 0);
1749 $vbox->pack_start($devicebox, 0, 0, 2);
1751 my $hn = $config->{fqdn
} // "$env->{product}." . ($ipconf->{domain
} // "example.invalid");
1753 my ($hostbox, $hostentry) = create_text_input
($hn, 'Hostname (FQDN):');
1754 $vbox->pack_start($hostbox, 0, 0, 2);
1756 $vbox->pack_start($cidr_box, 0, 0, 2);
1758 $gateway = $config->{gateway
} // $ipconf->{gateway
} || '192.168.100.1';
1761 ($gwbox, $ipconf_entry_gw) =
1762 create_text_input
($gateway, 'Gateway:');
1764 $vbox->pack_start($gwbox, 0, 0, 2);
1766 $dnsserver = $config->{dnsserver
} // $ipconf->{dnsserver
} || $gateway;
1769 ($dnsbox, $ipconf_entry_dns) =
1770 create_text_input
($dnsserver, 'DNS Server:');
1772 $vbox->pack_start($dnsbox, 0, 0, 0);
1775 set_next
(undef, sub {
1779 my $text = $hostentry->get_text();
1784 $config->{fqdn
} = $text;
1786 my $namere = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
1788 # Debian does not support purely numeric hostnames
1789 if ($text && $text =~ /^[0-9]+(?:\.|$)/) {
1790 display_message
("Purely numeric hostnames are not allowed.");
1791 $hostentry->grab_focus();
1795 if ($text && $text =~ m/^(${namere}\.)*${namere}$/ && $text !~ m/.example.invalid$/ &&
1796 $text =~ m/^([^\.]+)\.(\S+)$/) {
1800 display_message
("Hostname does not look like a fully qualified domain name.");
1801 $hostentry->grab_focus();
1806 $text = $ipconf_entry_addr->get_text();
1807 ($ipaddress, $ipversion) = parse_ip_address
($text);
1808 if (!defined($ipaddress)) {
1809 display_message
("IP address is not valid.");
1810 $ipconf_entry_addr->grab_focus();
1813 $config->{ipaddress
} = $ipaddress;
1815 $text = $ipconf_entry_mask->get_text();
1816 $netmask = parse_ip_mask
($text, $ipversion);
1817 if (!defined($netmask)) {
1818 display_message
("Netmask is not valid.");
1819 $ipconf_entry_mask->grab_focus();
1822 $cidr = "$ipaddress/$netmask";
1823 $config->{netmask
} = $netmask;
1825 $text = $ipconf_entry_gw->get_text();
1826 my ($gateway_ip, $gateway_ip_version) = parse_ip_address
($text);
1827 if (!defined($gateway_ip) || $gateway_ip_version != $ipversion) {
1828 my $msg = defined($gateway_ip)
1829 ?
"Gateway and host IP version must not differ (IPv$gateway_ip_version != IPv$ipversion)."
1830 : "Gateway is not valid.";
1831 display_message
($msg);
1832 $ipconf_entry_gw->grab_focus();
1835 $config->{gateway
} = $gateway = $gateway_ip;
1837 $text = $ipconf_entry_dns->get_text();
1838 my ($dns_ip, $dns_ip_version) = parse_ip_address
($text);
1839 if (!defined($dns_ip) || $dns_ip_version != $ipversion) {
1840 my $msg = defined($gateway_ip)
1841 ?
"DNS and host IP version must not differ (IPv$gateway_ip_version != IPv$ipversion)."
1842 : "DNS IP is not valid.";
1843 display_message
($msg);
1844 $ipconf_entry_dns->grab_focus();
1847 $config->{dnsserver
} = $dnsserver = $dns_ip;
1849 #print "TEST $ipaddress $netmask $gateway $dnsserver\n";
1855 $hostentry->grab_focus();
1858 sub create_ack_view
{
1862 my $vbox = Gtk3
::Box-
>new('vertical', 0);
1863 $inbox->pack_start($vbox, 1, 0, 0);
1865 my $reboot_checkbox = Gtk3
::CheckButton-
>new('Automatically reboot after successful installation');
1866 $reboot_checkbox->set_active(1);
1867 $reboot_checkbox->signal_connect ("toggled" => sub {
1869 $config_options->{autoreboot
} = $cb->get_active();
1871 $vbox->pack_start($reboot_checkbox, 0, 0, 2);
1873 my $ack_template = "${proxmox_libdir}/html/ack_template.htm";
1874 my $ack_html = "${proxmox_libdir}/html/$env->{product}/$steps[$step_number]->{html}";
1875 my $html_data = file_read_all
($ack_template);
1877 my %config_values = (
1878 __target_hd__
=> join(' | ', @{$config_options->{target_hds
}}),
1879 __target_fs__
=> $config_options->{filesys
},
1880 __country__
=> $env->{locales
}->{country
}->{$country}->{name
},
1881 __timezone__
=> $timezone,
1882 __keymap__
=> $keymap,
1883 __mailto__
=> $mailto,
1884 __interface__
=> $ipconf->{ifaces
}->{$ipconf->{selected
}}->{name
},
1885 __hostname__
=> $hostname,
1886 __ip__
=> $ipaddress,
1888 __netmask__
=> $netmask,
1889 __gateway__
=> $gateway,
1890 __dnsserver__
=> $dnsserver,
1893 while (my ($k, $v) = each %config_values) {
1894 $html_data =~ s/$k/$v/g;
1897 file_write_all
($ack_html, $html_data);
1903 set_next
(undef, sub {
1905 create_extract_view
();
1909 sub get_device_desc
{
1910 my ($devname, $size, $model) = @_;
1912 if ($size && ($size > 0)) {
1913 $size = int($size/2048); # size in MiB, from 512B "sectors"
1915 my $text = "$devname (";
1916 if ($size >= 1024) {
1917 $size = $size/1024; # size in GiB
1918 if ($size >= 1024) {
1919 $size = $size/1024; # size in TiB
1920 $text .= sprintf("%.2f", $size) . "TiB";
1922 $text .= sprintf("%.2f", $size) . "GiB";
1925 $text .= "${size}MiB";
1928 $text .= ", $model" if $model;
1940 my ($cb, $kmap) = @_;
1945 my $kmaphash = $env->{locales
}->{kmaphash
};
1946 foreach my $layout (sort keys %$kmaphash) {
1947 $def = $i if $kmaphash->{$layout} eq 'en-us';
1948 $ind = $i if $kmap && $kmaphash->{$layout} eq $kmap;
1952 my $val = $ind || $def || 0;
1954 if (!defined($kmap)) {
1955 $last_layout //= $val;
1956 } elsif (!defined($country_layout) || $country_layout != $val) {
1957 $last_layout = $country_layout = $val;
1959 $cb->set_active($last_layout);
1963 sub update_zonelist
{
1964 my ($box, $cc) = @_;
1966 my $sel = $timezone; # initial default
1968 $sel = $lastzonecb->get_active_text();
1969 $box->remove($lastzonecb);
1972 my $cb = $lastzonecb = Gtk3
::ComboBoxText-
>new();
1973 $cb->set_size_request(200, -1);
1974 $cb->signal_connect('changed' => sub {
1975 $timezone = $cb->get_active_text();
1978 my ($cczones, $zones) = $env->{locales
}->@{'cczones', 'zones'};
1979 my @available_zones = $cc && defined($cczones->{$cc}) ?
keys %{$cczones->{$cc}} : keys %$zones;
1981 my ($i, $selected_index) = (0, undef);
1982 for my $zone (sort @available_zones) {
1983 $selected_index = $i if $sel && $zone eq $sel;
1984 $cb->append_text($zone);
1988 # Append UTC here, so it is always the last item and never the default for any country.
1989 $cb->append_text('UTC');
1991 $cb->set_active($selected_index || 0);
1994 $box->pack_start($cb, 0, 0, 0);
1997 sub create_password_view
{
2001 my $vbox2 = Gtk3
::Box-
>new('vertical', 0);
2002 $inbox->pack_start($vbox2, 1, 0, 0);
2003 my $vbox = Gtk3
::Box-
>new('vertical', 0);
2004 $vbox2->pack_start($vbox, 0, 0, 10);
2006 my $hbox1 = Gtk3
::Box-
>new('horizontal', 0);
2007 my $label = Gtk3
::Label-
>new("Password");
2008 $label->set_size_request(150, -1);
2009 $label->set_xalign(1.0);
2010 $hbox1->pack_start($label, 0, 0, 10);
2011 my $pwe1 = Gtk3
::Entry-
>new();
2012 $pwe1->set_visibility(0);
2013 $pwe1->set_text($password) if $password;
2014 $pwe1->set_size_request(200, -1);
2015 $hbox1->pack_start($pwe1, 0, 0, 0);
2017 my $hbox2 = Gtk3
::Box-
>new('horizontal', 0);
2018 $label = Gtk3
::Label-
>new("Confirm");
2019 $label->set_size_request(150, -1);
2020 $label->set_xalign(1.0);
2021 $hbox2->pack_start($label, 0, 0, 10);
2022 my $pwe2 = Gtk3
::Entry-
>new();
2023 $pwe2->set_visibility(0);
2024 $pwe2->set_text($password) if $password;
2025 $pwe2->set_size_request(200, -1);
2026 $hbox2->pack_start($pwe2, 0, 0, 0);
2028 my $hbox3 = Gtk3
::Box-
>new('horizontal', 0);
2029 $label = Gtk3
::Label-
>new("Email");
2030 $label->set_size_request(150, -1);
2031 $label->set_xalign(1.0);
2032 $hbox3->pack_start($label, 0, 0, 10);
2033 my $eme = Gtk3
::Entry-
>new();
2034 $eme->set_size_request(200, -1);
2035 $eme->set_text($mailto);
2036 $hbox3->pack_start($eme, 0, 0, 0);
2039 $vbox->pack_start($hbox1, 0, 0, 5);
2040 $vbox->pack_start($hbox2, 0, 0, 5);
2041 $vbox->pack_start($hbox3, 0, 0, 15);
2047 set_next
(undef, sub {
2049 my $t1 = $pwe1->get_text;
2050 my $t2 = $pwe2->get_text;
2052 if (length ($t1) < 5) {
2053 display_message
("Password is too short.");
2054 $pwe1->grab_focus();
2059 display_message
("Password does not match.");
2060 $pwe1->grab_focus();
2064 my $t3 = $eme->get_text;
2065 if ($t3 !~ m/^[\w\+\-\~]+(\.[\w\+\-\~]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*$/) {
2066 display_message
("Email does not look like a valid address" .
2067 " (user\@domain.tld)");
2072 if ($t3 eq 'mail@example.invalid') {
2073 display_message
("Please enter a valid Email address");
2082 create_ipconf_view
();
2085 $pwe1->grab_focus();
2090 sub create_country_view
{
2094 my $locales = $env->{locales
};
2096 my $vbox2 = Gtk3
::Box-
>new('vertical', 0);
2097 $inbox->pack_start($vbox2, 1, 0, 0);
2098 my $vbox = Gtk3
::Box-
>new('vertical', 0);
2099 $vbox2->pack_start($vbox, 0, 0, 10);
2101 my $w = Gtk3
::Entry-
>new();
2102 $w->set_size_request(200, -1);
2104 my $c = Gtk3
::EntryCompletion-
>new();
2105 $c->set_text_column(0);
2106 $c->set_minimum_key_length(0);
2107 $c->set_popup_set_width(1);
2108 $c->set_inline_completion(1);
2110 my $hbox2 = Gtk3
::Box-
>new('horizontal', 0);
2111 my $label = Gtk3
::Label-
>new("Time zone");
2112 $label->set_size_request(150, -1);
2113 $label->set_xalign(1.0);
2114 $hbox2->pack_start($label, 0, 0, 10);
2115 update_zonelist
($hbox2);
2117 my $hbox3 = Gtk3
::Box-
>new('horizontal', 0);
2118 $label = Gtk3
::Label-
>new("Keyboard Layout");
2119 $label->set_size_request(150, -1);
2120 $label->set_xalign(1.0);
2121 $hbox3->pack_start($label, 0, 0, 10);
2123 my $kmapcb = Gtk3
::ComboBoxText-
>new();
2124 $kmapcb->set_size_request (200, -1);
2125 for my $layout (sort keys %{$locales->{kmaphash
}}) {
2126 $kmapcb->append_text($layout);
2129 update_layout
($kmapcb);
2130 $hbox3->pack_start ($kmapcb, 0, 0, 0);
2132 $kmapcb->signal_connect ('changed' => sub {
2133 my $sel = $kmapcb->get_active_text();
2134 $last_layout = $kmapcb->get_active();
2135 if (my $kmap = $locales->{kmaphash
}->{$sel}) {
2136 my $xkmap = $locales->{kmap
}->{$kmap}->{x11
};
2137 my $xvar = $locales->{kmap
}->{$kmap}->{x11var
};
2140 return if (defined($installer_kmap) && $installer_kmap eq $kmap);
2142 $installer_kmap = $keymap;
2144 if (!is_test_mode
()) {
2145 syscmd
("setxkbmap $xkmap $xvar");
2147 my $kbd_config = qq{
2152 $kbd_config =~ s/^\s+//gm;
2154 Proxmox
::Sys
::Command
::run_in_background
(sub {
2155 file_write_all
('/etc/default/keyboard', $kbd_config);
2162 $w->signal_connect ('changed' => sub {
2163 my ($entry, $event) = @_;
2164 my $text = $entry->get_text;
2166 if (my $cc = $locales->{countryhash
}->{lc($text)}) {
2167 update_zonelist
($hbox2, $cc);
2168 my $kmap = $locales->{country
}->{$cc}->{kmap
} || 'en-us';
2169 update_layout
($kmapcb, $kmap);
2173 $w->signal_connect (key_press_event
=> sub {
2174 my ($entry, $event) = @_;
2175 my $text = $entry->get_text;
2177 my $val = $event->get_keyval;
2179 if ($val == Gtk3
::Gdk
::KEY_Tab
) {
2180 my $cc = $locales->{countryhash
}->{lc($text)};
2187 $compl = $locales->{country
}->{$cc}->{name
};
2189 for my $country (values $locales->{country
}->%*) {
2190 if ($country->{name
} =~ m/^\Q$text\E.*$/i) {
2192 $compl = $country->{name
};
2199 $entry->set_text($compl);
2204 print chr(7); # beep ?
2209 my $buf = $w->get_buffer();
2210 $buf->insert_text(-1, '', -1); # popup selection
2218 my $country_store = Gtk3
::ListStore-
>new('Glib::String');
2219 my $countries = $locales->{country
};
2220 for my $cc (sort { $countries->{$a}->{name
} cmp $countries->{$b}->{name
} } keys %$countries) {
2221 my $iter = $country_store->append();
2222 $country_store->set($iter, 0, $countries->{$cc}->{name
});
2224 $c->set_model($country_store);
2226 $w->set_completion ($c);
2228 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
2230 $label = Gtk3
::Label-
>new("Country");
2231 $label->set_xalign(1.0);
2232 $label->set_size_request(150, -1);
2233 $hbox->pack_start($label, 0, 0, 10);
2234 $hbox->pack_start($w, 0, 0, 0);
2236 $vbox->pack_start($hbox, 0, 0, 5);
2237 $vbox->pack_start($hbox2, 0, 0, 5);
2238 $vbox->pack_start($hbox3, 0, 0, 5);
2240 if ($country && (my $entry = $locales->{country
}->{$country})) {
2241 $w->set_text($entry->{name
});
2247 set_next
(undef, sub {
2249 my $text = $w->get_text;
2251 if (my $cc = $locales->{countryhash
}->{lc($text)}) {
2254 create_password_view
();
2257 display_message
("Please select a country first.");
2265 my $target_hd_combo;
2266 my $target_hd_label;
2268 my $hdoption_first_setup = 1;
2270 my $create_basic_grid = sub {
2271 my $grid = Gtk3
::Grid-
>new();
2272 $grid->set_visible(1);
2273 $grid->set_column_spacing(10);
2274 $grid->set_row_spacing(10);
2275 $grid->set_hexpand(1);
2277 $grid->set_margin_start(10);
2278 $grid->set_margin_end(20);
2279 $grid->set_margin_top(5);
2280 $grid->set_margin_bottom(5);
2285 my $create_label_widget_grid = sub {
2286 my ($labeled_widgets) = @_;
2288 my $grid = &$create_basic_grid();
2291 for (my $i = 0; $i < @$labeled_widgets; $i += 2) {
2292 my $widget = @$labeled_widgets[$i+1];
2293 my $label = Gtk3
::Label-
>new(@$labeled_widgets[$i]);
2294 $label->set_visible(1);
2295 $label->set_xalign(1.0);
2296 $grid->attach($label, 0, $row, 1, 1);
2297 $widget->set_visible(1);
2298 $grid->attach($widget, 1, $row, 1, 1);
2305 # only relevant for raid with its multipl diskX to diskY mappings.
2306 my $get_selected_hdsize = sub {
2308 return $hdsize if defined($hdsize);
2310 # compute the smallest disk size of the actually selected disks
2311 my $cached_disks = get_cached_disks
();
2312 my $disk_count = scalar(@$cached_disks);
2313 for (my $i = 0; $i < $disk_count; $i++) {
2314 my $cur_hd = $config_options->{"disksel$i"} // next;
2315 my $disksize = int(@$cur_hd[2] / (2 * 1024 * 1024.0)); # size in GB
2316 $hdsize //= $disksize;
2317 $hdsize = $disksize if $disksize < $hdsize;
2320 if (my $cfg_hdsize = $config_options->{hdsize
}) {
2321 # had the dialog open previously and set an even lower size than the disk selection allows
2322 $hdsize = $cfg_hdsize if $cfg_hdsize < $hdsize;
2324 return $hdsize // 0; # fall back to zero, e.g., if none is selected hdsize cannot be any size
2327 my sub update_hdsize_adjustment
{
2328 my ($adjustment, $hdsize) = @_;
2330 $hdsize = $get_selected_hdsize->($hdsize);
2331 # expect that lower = 0 and step increments = 1 still are valid
2332 $adjustment->set_upper($hdsize + 1);
2333 $adjustment->set_value($hdsize);
2336 my sub create_hdsize_adjustment
{
2338 $hdsize = $get_selected_hdsize->($hdsize);
2339 # params are: initial value, lower, upper, step increment, page increment, page size
2340 return Gtk3
::Adjustment-
>new($config_options->{hdsize
} || $hdsize, 0, $hdsize+1, 1, 1, 1);
2343 my sub get_hdsize_spin_button
{
2346 my $hdsize_entry_buffer = Gtk3
::EntryBuffer-
>new(undef, 1);
2347 my $hdsize_size_adj = create_hdsize_adjustment
($hdsize);
2349 my $spinbutton_hdsize = Gtk3
::SpinButton-
>new($hdsize_size_adj, 1, 1);
2350 $spinbutton_hdsize->set_buffer($hdsize_entry_buffer);
2351 $spinbutton_hdsize->set_adjustment($hdsize_size_adj);
2352 $spinbutton_hdsize->set_tooltip_text("only use specified size (GB) of the harddisk (rest left unpartitioned)");
2353 return $spinbutton_hdsize;
2356 my $create_raid_disk_grid = sub {
2357 my ($hdsize_buttons) = @_;
2359 my $cached_disks = get_cached_disks
();
2360 my $disk_count = scalar(@$cached_disks);
2361 my $disk_labeled_widgets = [];
2362 for (my $i = 0; $i < $disk_count; $i++) {
2363 my $disk_selector = Gtk3
::ComboBoxText-
>new();
2364 $disk_selector->append_text("-- do not use --");
2365 $disk_selector->set_active(0);
2366 $disk_selector->set_visible(1);
2368 for my $hd (@$cached_disks) {
2369 my ($disk, $devname, $size, $model, $logical_bsize) = @$hd;
2370 $disk_selector->append_text(get_device_desc
($devname, $size, $model));
2373 $disk_selector->{pve_disk_id
} = $i;
2374 $disk_selector->signal_connect(changed
=> sub {
2376 my $diskid = $w->{pve_disk_id
};
2377 my $a = $w->get_active - 1;
2378 $config_options->{"disksel${diskid}"} = ($a >= 0) ?
$cached_disks->[$a] : undef;
2379 for my $btn (@$hdsize_buttons) {
2380 update_hdsize_adjustment
($btn->get_adjustment());
2384 if ($hdoption_first_setup) {
2385 $disk_selector->set_active ($i+1) if $cached_disks->[$i];
2388 if (my $cur_hd = $config_options->{"disksel$i"}) {
2389 foreach my $hd (@$cached_disks) {
2390 if (@$hd[1] eq @$cur_hd[1]) {
2391 $disk_selector->set_active($hdind+1);
2399 push @$disk_labeled_widgets, "Harddisk $i", $disk_selector;
2402 my $clear_all_button = Gtk3
::Button-
>new('_Deselect All');
2403 if ($disk_count > 3) {
2404 $clear_all_button->signal_connect('clicked', sub {
2406 for my $disk_selector (@$disk_labeled_widgets) {
2407 $disk_selector->set_active(0) if $is_widget;
2411 $clear_all_button->set_visible(1);
2414 my $scrolled_window = Gtk3
::ScrolledWindow-
>new();
2415 $scrolled_window->set_hexpand(1);
2416 $scrolled_window->set_propagate_natural_height(1) if $disk_count > 4;
2418 my $diskgrid = $create_label_widget_grid->($disk_labeled_widgets);
2420 $scrolled_window->add($diskgrid);
2421 $scrolled_window->set_policy('never', 'automatic');
2422 $scrolled_window->set_visible(1);
2423 $scrolled_window->set_min_content_height(190);
2425 my $vbox = Gtk3
::Box-
>new('vertical', 0);
2426 $vbox->pack_start($scrolled_window, 1, 1, 10);
2428 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
2429 $hbox->pack_end($clear_all_button, 0, 0, 20);
2430 $hbox->set_visible(1);
2431 $vbox->pack_end($hbox, 0, 0, 0);
2436 my $create_raid_advanced_grid = sub {
2437 my ($hdsize_btn) = @_;
2438 my $labeled_widgets = [];
2439 my $spinbutton_ashift = Gtk3
::SpinButton-
>new_with_range(9, 13, 1);
2440 $spinbutton_ashift->set_tooltip_text("zpool ashift property (pool sector size, default 2^12)");
2441 $spinbutton_ashift->signal_connect ("value-changed" => sub {
2443 $config_options->{ashift
} = $w->get_value_as_int();
2445 $config_options->{ashift
} = 12 if ! defined($config_options->{ashift
});
2446 $spinbutton_ashift->set_value($config_options->{ashift
});
2447 push @$labeled_widgets, "ashift";
2448 push @$labeled_widgets, $spinbutton_ashift;
2450 my $combo_compress = Gtk3
::ComboBoxText-
>new();
2451 $combo_compress->set_tooltip_text("zfs compression algorithm for rpool dataset");
2452 my $comp_opts = ["on","off","lzjb","lz4", "zle", "gzip", "zstd"];
2453 foreach my $opt (@$comp_opts) {
2454 $combo_compress->append($opt, $opt);
2456 $config_options->{compress
} = "on" if !defined($config_options->{compress
});
2457 $combo_compress->set_active_id($config_options->{compress
});
2458 $combo_compress->signal_connect (changed
=> sub {
2460 $config_options->{compress
} = $w->get_active_text();
2462 push @$labeled_widgets, "compress";
2463 push @$labeled_widgets, $combo_compress;
2465 my $combo_checksum = Gtk3
::ComboBoxText-
>new();
2466 $combo_checksum->set_tooltip_text("zfs checksum algorithm for rpool dataset");
2467 my $csum_opts = ["on", "off","fletcher2", "fletcher4", "sha256"];
2468 foreach my $opt (@$csum_opts) {
2469 $combo_checksum->append($opt, $opt);
2471 $config_options->{checksum
} = "on" if !($config_options->{checksum
});
2472 $combo_checksum->set_active_id($config_options->{checksum
});
2473 $combo_checksum->signal_connect (changed
=> sub {
2475 $config_options->{checksum
} = $w->get_active_text();
2477 push @$labeled_widgets, "checksum";
2478 push @$labeled_widgets, $combo_checksum;
2480 my $spinbutton_copies = Gtk3
::SpinButton-
>new_with_range(1,3,1);
2481 $spinbutton_copies->set_tooltip_text("zfs copies property for rpool dataset (in addition to RAID redundancy!)");
2482 $spinbutton_copies->signal_connect ("value-changed" => sub {
2484 $config_options->{copies
} = $w->get_value_as_int();
2486 $config_options->{copies
} = 1 if !defined($config_options->{copies
});
2487 $spinbutton_copies->set_value($config_options->{copies
});
2488 push @$labeled_widgets, "copies", $spinbutton_copies;
2490 push @$labeled_widgets, "hdsize", $hdsize_btn;
2491 return $create_label_widget_grid->($labeled_widgets);;
2494 my $create_btrfs_raid_advanced_grid = sub {
2495 my ($hdsize_btn) = @_;
2496 my $labeled_widgets = [];
2497 push @$labeled_widgets, "hdsize", $hdsize_btn;
2498 return $create_label_widget_grid->($labeled_widgets);;
2501 sub create_hdoption_view
{
2502 my $dialog = Gtk3
::Dialog-
>new();
2504 $dialog->set_title("Harddisk options");
2506 $dialog->add_button("_OK", 1);
2508 my $contarea = $dialog->get_content_area();
2510 my $hbox2 = Gtk3
::Box-
>new('horizontal', 0);
2511 $contarea->pack_start($hbox2, 1, 1, 5);
2513 my $grid = Gtk3
::Grid-
>new();
2514 $grid->set_column_spacing(10);
2515 $grid->set_row_spacing(10);
2517 $hbox2->pack_start($grid, 1, 0, 5);
2522 my $label0 = Gtk3
::Label-
>new("Filesystem");
2523 $label0->set_xalign(1.0);
2524 $grid->attach($label0, 0, $row, 1, 1);
2526 my $fstypecb = Gtk3
::ComboBoxText-
>new();
2537 push @$fstype, 'btrfs (RAID0)', 'btrfs (RAID1)', 'btrfs (RAID10)'
2538 if $env->{cfg
}->{enable_btrfs
};
2541 foreach my $tmp (@$fstype) {
2542 $fstypecb->append_text($tmp);
2543 $fstypecb->set_active ($tcount) if $config_options->{filesys
} eq $tmp;
2547 $grid->attach($fstypecb, 1, $row, 1, 1);
2553 my $sep = Gtk3
::Separator-
>new('horizontal');
2554 $sep->set_visible(1);
2555 $grid->attach($sep, 0, $row, 2, 1);
2558 my $hw_raid_note = Gtk3
::Label-
>new(""); # text will be set below, before making it visible
2559 $hw_raid_note->set_line_wrap(1);
2560 $hw_raid_note->set_max_width_chars(30);
2561 $hw_raid_note->set_visible(0);
2562 $grid->attach($hw_raid_note, 0, $row++, 2, 1);
2564 my $hdsize_labeled_widgets = [];
2568 if ( -b
$target_hd) {
2569 $hdsize = int(Proxmox
::Sys
::Block
::hd_size
($target_hd) / (1024 * 1024.0)); # size in GB
2570 } elsif ($target_hd) {
2571 $hdsize = int((-s
$target_hd) / (1024 * 1024 * 1024.0));
2574 my $spinbutton_hdsize_nonraid = get_hdsize_spin_button
($hdsize);
2575 push @$hdsize_labeled_widgets, "hdsize", $spinbutton_hdsize_nonraid;
2576 my $spinbutton_hdsize = $spinbutton_hdsize_nonraid;
2578 my $entry_swapsize = Gtk3
::Entry-
>new();
2579 $entry_swapsize->set_tooltip_text("maximum SWAP size (GB)");
2580 $entry_swapsize->signal_connect (key_press_event
=> \
&check_float
);
2581 $entry_swapsize->set_text($config_options->{swapsize
}) if defined($config_options->{swapsize
});
2582 push @$hdsize_labeled_widgets, "swapsize", $entry_swapsize;
2584 my $entry_maxroot = Gtk3
::Entry-
>new();
2585 if ($env->{product
} eq 'pve') {
2586 $entry_maxroot->set_tooltip_text("maximum size (GB) for LVM root volume");
2587 $entry_maxroot->signal_connect (key_press_event
=> \
&check_float
);
2588 $entry_maxroot->set_text($config_options->{maxroot
}) if $config_options->{maxroot
};
2589 push @$hdsize_labeled_widgets, "maxroot", $entry_maxroot;
2592 my $entry_minfree = Gtk3
::Entry-
>new();
2593 $entry_minfree->set_tooltip_text("minimum free LVM space (GB, required for LVM snapshots)");
2594 $entry_minfree->signal_connect (key_press_event
=> \
&check_float
);
2595 $entry_minfree->set_text($config_options->{minfree
}) if defined($config_options->{minfree
});
2596 push @$hdsize_labeled_widgets, "minfree", $entry_minfree;
2599 if ($env->{product
} eq 'pve') {
2600 $entry_maxvz = Gtk3
::Entry-
>new();
2601 $entry_maxvz->set_tooltip_text("maximum size (GB) for LVM data volume");
2602 $entry_maxvz->signal_connect (key_press_event
=> \
&check_float
);
2603 $entry_maxvz->set_text($config_options->{maxvz
}) if defined($config_options->{maxvz
});
2604 push @$hdsize_labeled_widgets, "maxvz", $entry_maxvz;
2607 my $spinbutton_hdsize_zfs = get_hdsize_spin_button
($hdsize);
2608 my $spinbutton_hdsize_btrfs = get_hdsize_spin_button
($hdsize);
2609 my $hdsize_buttons = [ $spinbutton_hdsize_zfs, $spinbutton_hdsize_btrfs ];
2610 my $options_stack = Gtk3
::Stack-
>new();
2611 $options_stack->set_visible(1);
2612 $options_stack->set_hexpand(1);
2613 $options_stack->set_vexpand(1);
2614 $options_stack->add_titled(&$create_raid_disk_grid($hdsize_buttons), "raiddisk", "Disk Setup");
2615 $options_stack->add_titled(&$create_label_widget_grid($hdsize_labeled_widgets), "hdsize", "Size Options");
2616 $options_stack->add_titled(&$create_raid_advanced_grid($spinbutton_hdsize_zfs), "raidzfsadvanced", "Advanced Options");
2617 $options_stack->add_titled(&$create_btrfs_raid_advanced_grid($spinbutton_hdsize_btrfs), "raidbtrfsadvanced", "Advanced Options");
2618 $options_stack->set_visible_child_name("raiddisk");
2619 my $options_stack_switcher = Gtk3
::StackSwitcher-
>new();
2620 $options_stack_switcher->set_halign('center');
2621 $options_stack_switcher->set_stack($options_stack);
2622 $grid->attach($options_stack_switcher, 0, $row, 2, 1);
2624 $grid->attach($options_stack, 0, $row, 2, 1);
2627 $hdoption_first_setup = 0;
2629 my $switch_view = sub {
2630 my $raid = $config_options->{filesys
} =~ m/zfs|btrfs/;
2631 my $is_zfs = $config_options->{filesys
} =~ m/zfs/;
2633 $target_hd_combo->set_visible(!$raid);
2634 $options_stack->get_child_by_name("hdsize")->set_visible(!$raid);
2635 $options_stack->get_child_by_name("raiddisk")->set_visible($raid);
2638 my $msg = "<b>Note</b>: " . ($is_zfs
2639 ?
"ZFS is not compatible with hardware RAID controllers, for details see the documentation."
2640 : "BTRFS integration in $env->{cfg}->{fullname} is a technology preview!"
2642 $hw_raid_note->set_markup($msg);
2644 $hw_raid_note->set_visible($raid);
2645 $options_stack_switcher->set_visible($raid);
2646 $options_stack->get_child_by_name("raidzfsadvanced")->set_visible($is_zfs);
2647 $options_stack->get_child_by_name("raidbtrfsadvanced")->set_visible(!$is_zfs);
2649 $target_hd_label->set_text("Target: $config_options->{filesys} ");
2650 $options_stack->set_visible_child_name("raiddisk");
2652 $target_hd_label->set_text("Target Harddisk: ");
2656 $spinbutton_hdsize = $is_zfs ?
$spinbutton_hdsize_zfs : $spinbutton_hdsize_btrfs;
2658 $spinbutton_hdsize = $spinbutton_hdsize_nonraid;
2661 my (undef, $pref_width) = $dialog->get_preferred_width();
2662 my (undef, $pref_height) = $dialog->get_preferred_height();
2663 $pref_height = 750 if $pref_height > 750;
2664 $dialog->resize($pref_width, $pref_height);
2669 $fstypecb->signal_connect (changed
=> sub {
2670 $config_options->{filesys
} = $fstypecb->get_active_text();
2674 my $sep2 = Gtk3
::Separator-
>new('horizontal');
2675 $sep2->set_visible(1);
2676 $contarea->pack_end($sep2, 1, 1, 10);
2682 my $get_float = sub {
2685 my $text = $entry->get_text();
2686 return undef if !defined($text);
2691 return undef if $text !~ m/^\d+(\.\d+)?$/;
2698 if (($tmp = &$get_float($spinbutton_hdsize)) && ($tmp != $hdsize)) {
2699 $config_options->{hdsize
} = $tmp;
2701 delete $config_options->{hdsize
};
2704 if (defined($tmp = &$get_float($entry_swapsize))) {
2705 $config_options->{swapsize
} = $tmp;
2707 delete $config_options->{swapsize
};
2710 if (defined($tmp = &$get_float($entry_maxroot))) {
2711 $config_options->{maxroot
} = $tmp;
2713 delete $config_options->{maxroot
};
2716 if (defined($tmp = &$get_float($entry_minfree))) {
2717 $config_options->{minfree
} = $tmp;
2719 delete $config_options->{minfree
};
2722 if ($entry_maxvz && defined($tmp = &$get_float($entry_maxvz))) {
2723 $config_options->{maxvz
} = $tmp;
2725 delete $config_options->{maxvz
};
2731 my $get_raid_devlist = sub {
2733 my $dev_name_hash = {};
2735 my $cached_disks = get_cached_disks
();
2737 for (my $i = 0; $i < @$cached_disks; $i++) {
2738 if (my $hd = $config_options->{"disksel$i"}) {
2739 my ($disk, $devname, $size, $model, $logical_bsize) = @$hd;
2740 die "device '$devname' is used more than once\n"
2741 if $dev_name_hash->{$devname};
2742 $dev_name_hash->{$devname} = $hd;
2743 push @$devlist, $hd;
2750 sub zfs_mirror_size_check
{
2751 my ($expected, $actual) = @_;
2753 die "mirrored disks must have same size\n"
2754 if abs($expected - $actual) > $expected / 10;
2757 sub legacy_bios_4k_check
{
2759 die "Booting from 4kn drive in legacy BIOS mode is not supported.\n"
2760 if $boot_type ne 'efi' && $lbs == 4096;
2763 sub get_zfs_raid_setup
{
2764 my $filesys = $config_options->{filesys
};
2766 my $devlist = &$get_raid_devlist();
2768 my $diskcount = scalar(@$devlist);
2769 die "$filesys needs at least one device\n" if $diskcount < 1;
2772 if ($filesys eq 'zfs (RAID0)') {
2773 foreach my $hd (@$devlist) {
2774 legacy_bios_4k_check
(@$hd[4]);
2777 } elsif ($filesys eq 'zfs (RAID1)') {
2778 die "zfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
2780 my $hd = @$devlist[0];
2781 my $expected_size = @$hd[2]; # all disks need approximately same size
2782 foreach my $hd (@$devlist) {
2783 zfs_mirror_size_check
($expected_size, @$hd[2]);
2784 legacy_bios_4k_check
(@$hd[4]);
2787 } elsif ($filesys eq 'zfs (RAID10)') {
2788 die "zfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
2789 die "zfs (RAID10) needs an even number of devices\n" if $diskcount & 1;
2791 for (my $i = 0; $i < $diskcount; $i+=2) {
2792 my $hd1 = @$devlist[$i];
2793 my $hd2 = @$devlist[$i+1];
2794 zfs_mirror_size_check
(@$hd1[2], @$hd2[2]); # pairs need approximately same size
2795 legacy_bios_4k_check
(@$hd1[4]);
2796 legacy_bios_4k_check
(@$hd2[4]);
2797 $cmd .= ' mirror ' . @$hd1[1] . ' ' . @$hd2[1];
2800 } elsif ($filesys =~ m/^zfs \(RAIDZ-([123])\)$/) {
2802 my $mindisks = 2 + $level;
2803 die "zfs (RAIDZ-$level) needs at least $mindisks devices\n" if scalar(@$devlist) < $mindisks;
2804 my $hd = @$devlist[0];
2805 my $expected_size = @$hd[2]; # all disks need approximately same size
2806 $cmd .= " raidz$level";
2807 foreach my $hd (@$devlist) {
2808 zfs_mirror_size_check
($expected_size, @$hd[2]);
2809 legacy_bios_4k_check
(@$hd[4]);
2813 die "unknown zfs mode '$filesys'\n";
2816 return ($devlist, $cmd);
2819 sub get_btrfs_raid_setup
{
2821 my $filesys = $config_options->{filesys
};
2823 my $devlist = &$get_raid_devlist();
2825 my $diskcount = scalar(@$devlist);
2826 die "$filesys needs at least one device\n" if $diskcount < 1;
2830 if ($diskcount == 1) {
2833 if ($filesys eq 'btrfs (RAID0)') {
2835 } elsif ($filesys eq 'btrfs (RAID1)') {
2836 die "btrfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
2838 } elsif ($filesys eq 'btrfs (RAID10)') {
2839 die "btrfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
2842 die "unknown btrfs mode '$filesys'\n";
2846 return ($devlist, $mode);
2849 my $last_hd_selected = 0;
2850 sub create_hdsel_view
{
2852 $prev_btn->set_sensitive(1); # enable previous button at this point
2856 my $vbox = Gtk3
::Box-
>new('vertical', 0);
2857 $inbox->pack_start($vbox, 1, 0, 0);
2858 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
2859 $vbox->pack_start($hbox, 0, 0, 10);
2861 my $cached_disks = get_cached_disks
();
2862 my ($disk, $devname, $size, $model, $logical_bsize) = $cached_disks->[0]->@*;
2863 $target_hd = $devname if !defined($target_hd);
2865 $target_hd_label = Gtk3
::Label-
>new("Target Harddisk: ");
2866 $hbox->pack_start($target_hd_label, 0, 0, 0);
2868 $target_hd_combo = Gtk3
::ComboBoxText-
>new();
2870 foreach my $hd ($cached_disks->@*) {
2871 ($disk, $devname, $size, $model, $logical_bsize) = @$hd;
2872 $target_hd_combo->append_text(get_device_desc
($devname, $size, $model));
2875 my $raid = $config_options->{filesys
} =~ m/zfs|btrfs/;
2877 $target_hd_label->set_text("Target: $config_options->{filesys} ");
2878 $target_hd_combo->set_visible(0);
2879 $target_hd_combo->set_no_show_all(1);
2881 $target_hd_combo->set_active($last_hd_selected);
2882 $target_hd_combo->signal_connect(changed
=> sub {
2883 $a = shift-
>get_active;
2884 my ($disk, $devname) = @{@$cached_disks[$a]};
2885 $last_hd_selected = $a;
2886 $target_hd = $devname;
2889 $hbox->pack_start($target_hd_combo, 0, 0, 10);
2891 my $options = Gtk3
::Button-
>new('_Options');
2892 $options->signal_connect (clicked
=> \
&create_hdoption_view
);
2893 $hbox->pack_start ($options, 0, 0, 0);
2900 set_next
(undef, sub {
2902 if ($config_options->{filesys
} =~ m/zfs/) {
2903 my ($devlist) = eval { get_zfs_raid_setup
() };
2905 display_message
("Warning: $err\nPlease fix ZFS setup first.");
2908 $config_options->{target_hds
} = [ map { $_->[1] } @$devlist ];
2909 } elsif ($config_options->{filesys
} =~ m/btrfs/) {
2910 my ($devlist) = eval { get_btrfs_raid_setup
() };
2912 display_message
("Warning: $err\nPlease fix BTRFS setup first.");
2915 $config_options->{target_hds
} = [ map { $_->[1] } @$devlist ];
2918 my $target_block_size = Proxmox
::Sys
::Block
::logical_blocksize
($target_hd);
2919 legacy_bios_4k_check
($target_block_size);
2922 display_message
("Warning: $err\n");
2925 $config_options->{target_hds
} = [ $target_hd ];
2929 create_country_view
();
2933 sub create_extract_view
{
2939 $next->set_sensitive(0);
2940 $prev_btn->set_sensitive(0);
2943 my $vbox = Gtk3
::Box-
>new('vertical', 0);
2944 $inbox->pack_start ($vbox, 1, 0, 0);
2945 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
2946 $vbox->pack_start ($hbox, 0, 0, 10);
2948 my $vbox2 = Gtk3
::Box-
>new('vertical', 0);
2949 $hbox->pack_start ($vbox2, 0, 0, 0);
2951 $progress_status = Gtk3
::Label-
>new('');
2952 $vbox2->pack_start ($progress_status, 1, 1, 0);
2954 $progress = Gtk3
::ProgressBar-
>new;
2955 $progress->set_show_text(1);
2956 $progress->set_size_request (600, -1);
2958 $vbox2->pack_start($progress, 0, 0, 0);
2962 my $tdir = is_test_mode
() ?
"target" : "/target";
2964 my $base = "${proxmox_cddir}/$env->{product}-base.squashfs";
2966 eval { extract_data
($base, $tdir); };
2969 $next->set_sensitive(1);
2971 set_next
("_Reboot", sub { exit (0); } );
2974 display_html
("fail.htm");
2975 display_error
($err);
2978 display_html
("success.htm");
2980 if ($config_options->{autoreboot
}) {
2981 Glib
::Timeout-
>add(1000, sub {
2982 if ($autoreboot_seconds > 0) {
2983 $autoreboot_seconds--;
2984 display_html
("success.htm");
2993 sub create_intro_view
{
2995 $prev_btn->set_sensitive(0);
2999 if (int($total_memory) < 1024) {
3000 display_error
("Less than 1 GiB of usable memory detected, installation will probably fail.\n\n".
3001 "See 'System Requirements' in the $env->{cfg}->{fullname} documentation.");
3004 if ($env->{product
} eq 'pve') {
3005 my $cpuinfo = eval { file_read_all
('/proc/cpuinfo') };
3006 if (!$cpuinfo || $cpuinfo !~ /^flags\s*:.*(vmx|svm)/m) {
3008 "No support for hardware-accelerated KVM virtualization detected.\n\n"
3009 ."Check BIOS settings for Intel VT / AMD-V / SVM."
3017 set_next
("I a_gree", \
&create_hdsel_view
);
3020 $ipconf = Proxmox
::Sys
::Net
::get_ip_config
();
3022 $country = detect_country
() if $ipconf->{default} || is_test_mode
();
3024 if (!defined($env->{locales
}->{country
}->{$country})) {
3025 log_warn
("ignoring detected country '$country', invalid or unknown\n");
3031 create_main_window
();
3033 my $initial_error = 0;
3036 my $cached_disks = get_cached_disks
();
3037 if (!defined($cached_disks) || (scalar (@$cached_disks) <= 0)) {
3038 print "no harddisks found\n";
3040 display_html
("nohds.htm");
3041 set_next
("Reboot", sub { exit(0); } );
3043 foreach my $hd (@$cached_disks) {
3044 my ($disk, $devname) = @$hd;
3045 next if $devname =~ m
|^/dev/md\d
+$|;
3046 print "found Disk$disk N:$devname\n";
3051 if (!$initial_error && (scalar keys %{ $ipconf->{ifaces
} } == 0)) {
3052 print "no network interfaces found\n";
3054 display_html
("nonics.htm");
3055 set_next
("Reboot", sub { exit(0); } );
3058 create_intro_view
() if !$initial_error;
3062 # reap left over zombie processes
3063 while ((my $child = waitpid(-1, POSIX
::WNOHANG
)) > 0) {
3064 print "reaped child $child\n";