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);
30 if (!$ENV{G_SLICE
} || $ENV{G_SLICE
} ne "always-malloc") {
31 die "do not use slice allocator (run with 'G_SLICE=always-malloc ./proxinstall ...')\n";
37 'test-image|t=s' => \
$test_image
38 ) or die "usage error\n";
40 Proxmox
::Install
::ISOEnv
::set_test_image
($test_image) if $test_image;
43 $ENV{'LVM_SUPPRESS_FD_WARNINGS'} = '1';
45 my $env = Proxmox
::Install
::ISOEnv
::setup
();
47 my $zfstestpool = "test_rpool";
48 my $zfspoolname = is_test_mode
() ?
$zfstestpool : 'rpool';
49 my $zfsrootvolname = "$env->{product}-1";
51 my $storage_cfg_zfs = <<__EOD__;
54 content iso,vztmpl,backup
57 pool $zfspoolname/data
59 content images,rootdir
62 my $storage_cfg_btrfs = <<__EOD__;
65 content iso,vztmpl,backup
69 path /var/lib/pve/local-btrfs
70 content iso,vztmpl,backup,images,rootdir
73 my $storage_cfg_lvmthin = <<__EOD__;
76 content iso,vztmpl,backup
81 content rootdir,images
84 my $storage_cfg_local = <<__EOD__;
87 content iso,vztmpl,backup,rootdir,images
90 Proxmox
::Log
::init
("/tmp/install.log");
92 my $proxmox_libdir = $env->{locations
}->{lib
};
93 my $proxmox_cddir = $env->{locations
}->{iso
};
94 my $proxmox_pkgdir = "${proxmox_cddir}/proxmox/packages/";
96 my $boot_type = -d
'/sys/firmware/efi' ?
'efi' : 'bios';
98 my $step_number = 0; # Init number for global function list
103 html
=> 'license.htm',
104 next_button
=> 'I a_gree',
105 function
=> \
&create_intro_view
,
110 function
=> \
&create_hdsel_view
,
114 html
=> 'country.htm',
115 function
=> \
&create_country_view
,
119 html
=> 'passwd.htm',
120 function
=> \
&create_password_view
,
124 html
=> 'ipconf.htm',
125 function
=> \
&create_ipconf_view
,
130 next_button
=> '_Install',
131 function
=> \
&create_ack_view
,
135 next_button
=> '_Reboot',
136 function
=> \
&create_extract_view
,
140 # GUI global variables
141 my ($window, $cmdbox, $inbox, $htmlview);
143 my ($next, $next_fctn, $target_hd);
144 my ($progress, $progress_status);
146 my ($ipversion, $ipaddress, $cidr, $ipconf_entry_addr);
147 my ($netmask, $ipconf_entry_mask);
148 my ($gateway, $ipconf_entry_gw);
149 my ($dnsserver, $ipconf_entry_dns);
150 my $hostname = 'proxmox';
151 my $domain = 'domain.tld';
152 my $cmdline = file_read_firstline
("/proc/cmdline");
155 my $timezone = 'Europe/Vienna';
156 my $keymap = 'en-us';
158 my $mailto = 'mail@example.invalid';
159 my $autoreboot_seconds = 5;
162 # TODO: add all the user-provided options for previous button
164 timezone
=> $timezone,
167 password
=> $password,
171 hostname
=> $hostname,
178 # parse command line args
180 my $config_options = {
184 if ($cmdline =~ m/\s(ext4|xfs)(\s.*)?$/) {
185 $config_options->{filesys
} = $1;
187 $config_options->{filesys
} = 'ext4';
190 if ($cmdline =~ m/hdsize=(\d+(\.\d+)?)[\s\n]/i) {
191 $config_options->{hdsize
} = $1;
194 if ($cmdline =~ m/swapsize=(\d+(\.\d+)?)[\s\n]/i) {
195 $config_options->{swapsize
} = $1;
198 if ($cmdline =~ m/maxroot=(\d+(\.\d+)?)[\s\n]/i) {
199 $config_options->{maxroot
} = $1;
202 if ($cmdline =~ m/minfree=(\d+(\.\d+)?)[\s\n]/i) {
203 $config_options->{minfree
} = $1;
206 if ($env->{product
} eq 'pve') {
207 if ($cmdline =~ m/maxvz=(\d+(\.\d+)?)[\s\n]/i) {
208 $config_options->{maxvz
} = $1;
212 my $postfix_main_cf = <<_EOD;
213 # See /usr/share/postfix/main.cf.dist for a commented, more complete version
217 smtpd_banner = \$myhostname ESMTP \$mail_name (Debian/GNU)
220 # appending .domain is the MUA's job.
221 append_dot_mydomain = no
223 # Uncomment the next line to generate "delayed mail" warnings
224 #delay_warning_time = 4h
226 alias_maps = hash:/etc/aliases
227 alias_database = hash:/etc/aliases
228 mydestination = \$myhostname, localhost.\$mydomain, localhost
230 mynetworks = 127.0.0.0/8
231 inet_interfaces = loopback-only
232 recipient_delimiter = +
234 compatibility_level = 2
240 my ($exit_code) = @_;
242 Gtk3-
>main_quit() if Gtk3-
>main_level() > 0;
244 # reap left over zombie processes
245 while ((my $child = waitpid(-1, POSIX
::WNOHANG
)) > 0) {
246 print "reaped child $child\n";
252 print "trying to detect country...\n";
253 my $cpid = open2
(my $TRACEROUTE_FH, undef, "traceroute -N 1 -q 1 -n 8.8.8.8");
254 return undef if !$cpid;
258 my $previous_alarm = alarm (10);
260 local $SIG{ALRM
} = sub { die "timed out!\n" };
262 while (defined ($line = <$TRACEROUTE_FH>)) {
263 log_debug
("DC TRACEROUTE: $line");
264 if ($line =~ m/\s*\d+\s+(\d+\.\d+\.\d+\.\d+)\s/) {
265 my $geoip = `geoiplookup $1`;
266 log_debug("DC GEOIP: $geoip");
267 if ($geoip =~ m/GeoIP Country Edition:\s*([A-Z]+),/) {
269 log_info("DC FOUND: $country\n");
276 alarm ($previous_alarm);
278 close($TRACEROUTE_FH);
281 print "unable to detect country - $err\n";
283 print "detected country: " . uc($country) . "\n";
285 print "unable to detect country\n";
293 open (my $MEMINFO, '<', '/proc/meminfo');
295 my $res = 512; # default to 512 if something goes wrong
296 while (my $line = <$MEMINFO>) {
297 if ($line =~ m/^MemTotal:\s+(\d+)\s*kB/i) {
298 $res = int ($1 / 1024);
307 my $total_memory = get_memtotal();
309 sub update_progress {
310 my ($frac, $start, $end, $text) = @_;
312 my $part = $end - $start;
313 my $res = $start + $frac * $part;
315 $progress->set_fraction ($res);
316 $progress->set_text (sprintf ("%d%%", int ($res*100)));
317 $progress_status->set_text ($text) if defined ($text);
319 display_info() if $res < 0.9;
321 Gtk3::main_iteration() while Gtk3::events_pending();
326 mkfs => 'mkfs.ext4 -F',
328 mkfs_data_opt => '-m 0',
329 root_mountopt => 'errors=remount-ro',
332 mkfs => 'mkfs.xfs -f',
339 sub create_filesystem {
340 my ($dev, $name, $type, $start, $end, $fs, $fe) = @_;
342 my $range = $end - $start;
343 my $rs = $start + $range*$fs;
344 my $re = $start + $range*$fe;
347 my $fsdata = $fssetup->{$type} || die "internal error - unknown file system '$type'";
348 my $opts = $name eq 'root' ? $fsdata->{mkfs_root_opt} : $fsdata->{mkfs_data_opt};
350 update_progress(0, $rs, $re, "creating $name filesystem");
352 run_command("$fsdata->{mkfs} $opts $dev", sub {
355 if ($line =~ m/Writing inode tables:\s+(\d+)\/(\d+)/) {
357 } elsif ($max && $line =~ m/(\d+)\/$max/) {
358 update_progress(($1/$max)*0.9, $rs, $re);
359 } elsif ($line =~ m/Creating journal.*done/) {
360 update_progress(0.95, $rs, $re);
361 } elsif ($line =~ m/Writing superblocks and filesystem.*done/) {
362 update_progress(1, $rs, $re);
368 my ($targetdir, $dcdata) = @_;
370 my $cfgfile = "/tmp/debconf.txt";
371 file_write_all("$targetdir/$cfgfile", $dcdata);
372 syscmd("chroot $targetdir debconf-set-selections $cfgfile");
373 unlink "$targetdir/$cfgfile";
377 my ($targetdir, $cmd, $new_cmd) = @_;
379 syscmd("chroot $targetdir dpkg-divert --package proxmox --add --rename $cmd") == 0
380 || die "unable to exec dpkg-divert\n";
382 syscmd("ln -sf ${new_cmd} $targetdir/$cmd") == 0
383 || die "unable to link diversion to ${new_cmd}\n";
386 sub diversion_remove {
387 my ($targetdir, $cmd) = @_;
389 syscmd("mv $targetdir/${cmd}.distrib $targetdir/${cmd};") == 0
390 || die "unable to remove $cmd diversion\n";
392 syscmd("chroot $targetdir dpkg-divert --remove $cmd") == 0
393 || die "unable to remove $cmd diversion\n";
397 my ($partitions, $mode) = @_;
399 die "unknown btrfs mode '$mode'"
400 if !($mode eq 'single' || $mode eq 'raid0' || $mode eq 'raid1' || $mode eq 'raid10');
402 my $cmd = ['mkfs.btrfs', '-f'];
404 push @$cmd, '-d', $mode, '-m', $mode;
406 push @$cmd, @$partitions;
411 sub zfs_create_rpool {
414 my $cmd = "zpool create -f -o cachefile=none";
416 $cmd .= " -o ashift=$config_options->{ashift}"
417 if defined($config_options->{ashift});
419 syscmd("$cmd $zfspoolname $vdev") == 0 ||
420 die "unable to create zfs root pool\n";
422 syscmd("zfs create $zfspoolname/ROOT") == 0 ||
423 die "unable to create zfs $zfspoolname/ROOT volume\n";
425 if ($env->{product} eq 'pve') {
426 syscmd("zfs create $zfspoolname/data") == 0 ||
427 die "unable to create zfs $zfspoolname/data volume\n";
430 syscmd("zfs create $zfspoolname/ROOT/$zfsrootvolname") == 0 ||
431 die "unable to create zfs $zfspoolname/ROOT/$zfsrootvolname volume\n";
433 # default to `relatime
` on, fast enough for the installer and production
434 syscmd("zfs set atime=on relatime=on $zfspoolname") == 0 ||
435 die "unable to set zfs properties\n";
437 my $value = $config_options->{compress};
438 syscmd("zfs set compression=$value $zfspoolname")
439 if defined($value) && $value ne 'off';
441 $value = $config_options->{checksum};
442 syscmd("zfs set checksum=$value $zfspoolname")
443 if defined($value) && $value ne 'on';
445 $value = $config_options->{copies};
446 syscmd("zfs set copies=$value $zfspoolname")
447 if defined($value) && $value != 1;
450 sub get_pv_list_from_vgname {
460 my ($pv, $vg_uuid) = split(/\s+/, $line);
462 if (!defined($res->{$vg_uuid}->{pvs})) {
463 $res->{$vg_uuid}->{pvs} = "$pv";
465 $res->{$vg_uuid}->{pvs} .= ", $pv";
468 run_command("pvs --noheadings -o pv_name,vg_uuid -S vg_name='$vgname'", $parser, undef, 1);
473 sub ask_existing_vg_rename_or_abort {
476 # this normally only happens if one put a disk with a PVE installation in
477 # this server and that disk is not the installation target.
478 my $duplicate_vgs = get_pv_list_from_vgname($vgname);
479 return if !$duplicate_vgs;
481 my $message = "Detected existing '$vgname' Volume Group(s)! Do you want to:\n";
483 for my $vg_uuid (keys %$duplicate_vgs) {
484 my $vg = $duplicate_vgs->{$vg_uuid};
486 # no high randomnes properties, but this is only for the cases where
487 # we either have multiple "$vgname" vgs from multiple old PVE disks, or
488 # we have a disk with both a "$vgname" and "$vgname-old"...
489 my $short_uid = sprintf "%08X", rand(0xffffffff);
490 $vg->{new_vgname} = "$vgname-OLD-$short_uid";
492 $message .= "rename VG backed by PV '$vg->{pvs}' to '$vg->{new_vgname}'\n";
494 $message .= "or cancel the installation?";
496 my $response = display_prompt($message);
498 if ($response eq 'ok') {
499 for my $vg_uuid (keys %$duplicate_vgs) {
500 my $vg = $duplicate_vgs->{$vg_uuid};
501 my $new_vgname = $vg->{new_vgname};
503 syscmd("vgrename $vg_uuid $new_vgname") == 0 ||
504 die "could not rename VG from '$vg->{pvs}' ($vg_uuid) to '$new_vgname'!\n";
507 set_next("_Reboot", sub { app_quit(0); } );
508 display_html("fail.htm");
509 die "Cancled installation by user, due to already existing volume group '$vgname'\n";
513 sub create_lvm_volumes {
514 my ($lvmdev, $os_size, $swap_size) = @_;
516 my $vgname = $env->{product};
518 ask_existing_vg_rename_or_abort($vgname);
520 my $rootdev = "/dev/$vgname/root";
521 my $datadev = "/dev/$vgname/data";
524 # we use --metadatasize 250k, which results in "pe_start = 512"
525 # so pe_start is aligned on a 128k boundary (advantage for SSDs)
526 syscmd("/sbin/pvcreate --metadatasize 250k -y -ff $lvmdev") == 0 ||
527 die "unable to initialize physical volume $lvmdev\n";
528 syscmd("/sbin/vgcreate $vgname $lvmdev") == 0 ||
529 die "unable to create volume group '$vgname'\n";
531 my $hdgb = int($os_size / (1024 * 1024));
533 # always leave some space at the end to avoid roudning issues with LVM's physical extent (PE)
535 my $space = $hdgb <= 32 ? 4 * 1024 : (($hdgb > 128 ? 16 : $hdgb / 8) * 1024 * 1024);
540 if ($env->{product} eq 'pve') {
543 if ($config_options->{maxroot}) {
544 $maxroot_mb = $config_options->{maxroot} * 1024;
546 $maxroot_mb = 96 * 1024;
549 my $rest = $os_size - $swap_size;
550 my $rest_mb = int($rest / 1024);
553 if ($rest_mb < 12 * 1024) {
554 # no point in wasting space, try to get us actually installed and align down to 4 MB
555 $rootsize_mb = ($rest_mb - 0.1) & ~3;
556 } elsif ($rest_mb < 48 * 1024) {
557 my $masked = int($rest_mb / 2) & ~3; # align down to 4 MB
558 $rootsize_mb = $masked;
560 $rootsize_mb = $rest_mb / 4 + 12 * 1024;
563 $rootsize_mb = $maxroot_mb if $rootsize_mb > $maxroot_mb;
564 $rootsize = int($rootsize_mb * 1024);
566 $rest -= $rootsize; # in KB
568 my $minfree = $space;
569 if (defined(my $cfg_minfree = $config_options->{minfree})) {
570 $minfree = $cfg_minfree * 1024 * 1024 >= $rest ? $space : $cfg_minfree * 1024 * 1024;
573 $rest = int($rest - $minfree) & ~0xFFF; # align down to 4 MB boundaries
575 if (defined(my $maxvz = $config_options->{maxvz})) {
576 $rest = $maxvz * 1024 * 1024 <= $rest ? $maxvz * 1024 * 1024 : $rest;
582 my $minfree = defined($config_options->{minfree}) ? $config_options->{minfree}*1024*1024 : $space;
583 $rootsize = int($os_size - $minfree - $swap_size); # in KB
584 $rootsize &= ~0xFFF; # align down to 4 MB boundaries
588 syscmd("/sbin/lvcreate -Wy --yes -L${swap_size}K -nswap $vgname") == 0 ||
589 die "unable to create swap volume\n";
591 $swapfile = "/dev/$vgname/swap";
594 syscmd("/sbin/lvcreate -Wy --yes -L${rootsize}K -nroot $vgname") == 0 ||
595 die "unable to create root volume\n";
597 if ($datasize > 4 * 1024 * 1024) {
598 my $metadatasize = $datasize/100; # default 1% of data
599 $metadatasize = 1024*1024 if $metadatasize < 1024*1024; # but at least 1G
600 $metadatasize = 16*1024*1024 if $metadatasize > 16*1024*1024; # but at most 16G
602 # otherwise the metadata is taken out of $minfree
603 $datasize -= 2 * $metadatasize;
605 # 1 4MB PE to allow for rounding
606 $datasize -= 4 * 1024;
608 syscmd("/sbin/lvcreate -Wy --yes -L${datasize}K -ndata $vgname") == 0 ||
609 die "unable to create data volume\n";
611 syscmd("/sbin/lvconvert --yes --type thin-pool --poolmetadatasize ${metadatasize}K $vgname/data") == 0 ||
612 die "unable to create data thin-pool\n";
614 if ($env->{product} eq 'pve' && !defined($config_options->{maxvz})) {
615 display_message("Skipping auto-creation of LVM thinpool for guest data due to low space.");
620 syscmd("/sbin/vgchange -a y $vgname") == 0 ||
621 die "unable to activate volume group\n";
623 return ($rootdev, $swapfile, $datadev);
626 sub compute_swapsize {
629 my $hdgb = int($hdsize/(1024*1024));
632 if (defined($config_options->{swapsize})) {
633 $swapsize_kb = $config_options->{swapsize} * 1024 * 1024;
635 my $ss = int($total_memory);
636 $ss = 4096 if $ss < 4096 && $hdgb >= 64;
637 $ss = 2048 if $ss < 2048 && $hdgb >= 32;
638 $ss = 1024 if $ss >= 2048 && $hdgb <= 16;
639 $ss = 512 if $ss < 512;
640 $ss = int($hdgb * 128) if $ss > $hdgb * 128;
641 $ss = 8192 if $ss > 8192;
642 $swapsize_kb = int($ss * 1024) & ~0xFFF; # align to 4 MB to avoid all to odd SWAP size
648 my sub chroot_chown {
649 my ($root, $path, %param) = @_;
651 my $recursive = $param{recursive} ? ' -R' : '';
652 my $user = $param{user};
653 die "can not chown without user parameter\n" if !defined($user);
654 my $group = $param{group} // $user;
656 syscmd("chroot $root /bin/chown $user:$group $recursive $path") == 0 ||
657 die "chroot: unable to change owner for '$path'\n";
660 my sub chroot_chmod {
661 my ($root, $path, %param) = @_;
663 my $recursive = $param{recursive} ? ' -R' : '';
664 my $mode = $param{mode};
665 die "can not chmod without mode parameter\n" if !defined($mode);
667 syscmd("chroot $root /bin/chmod $mode $recursive $path") == 0 ||
668 die "chroot: unable to change permission mode for '$path'\n";
671 sub prepare_proxmox_boot_esp {
672 my ($espdev, $targetdir) = @_;
674 syscmd("chroot $targetdir proxmox-boot-tool init $espdev") == 0 ||
675 die "unable to init ESP and install proxmox-boot loader on '$espdev'\n";
678 sub prepare_grub_efi_boot_esp {
679 my ($dev, $espdev, $targetdir) = @_;
681 syscmd("mount -n $espdev -t vfat $targetdir/boot/efi") == 0 ||
682 die "unable to mount $espdev\n";
685 my $rc = syscmd("chroot $targetdir /usr/sbin/grub-install --target x86_64-efi --no-floppy --bootloader-id='proxmox' $dev");
687 if ($boot_type eq 'efi') {
688 die "unable to install the EFI boot loader on '$dev'\n";
690 warn "unable to install the EFI boot loader on '$dev', ignoring (not booted using UEFI)\n";
693 # also install fallback boot file (OVMF does not boot without)
694 mkdir("$targetdir/boot/efi/EFI/BOOT");
695 syscmd("cp $targetdir/boot/efi/EFI/proxmox/grubx64.efi $targetdir/boot/efi/EFI/BOOT/BOOTx64.EFI") == 0 ||
696 die "unable to copy efi boot loader\n";
701 syscmd("umount $targetdir/boot/efi") == 0 ||
702 die "unable to umount $targetdir/boot/efi\n";
706 die "failed to prepare EFI boot using Grub on '$espdev': $err" if $err;
710 my ($basefile, $targetdir) = @_;
712 die "target '$targetdir' does not exist\n" if ! -d $targetdir;
714 my $starttime = [Time::HiRes::gettimeofday];
716 my $bootdevinfo = [];
718 my ($swapfile, $rootdev, $datadev);
719 my ($use_zfs, $use_btrfs) = (0, 0);
721 my $filesys = $config_options->{filesys};
723 if ($filesys =~ m/zfs/) {
724 $target_hd = undef; # do not use this config
726 $targetdir = "/$zfspoolname/ROOT/$zfsrootvolname";
727 } elsif ($filesys =~ m/btrfs/) {
728 $target_hd = undef; # do not use this config
734 for ($i = 5; $i > 0; $i--) {
735 syscmd("modprobe zfs");
736 last if -c "/dev/zfs";
740 die "unable to load zfs kernel module\n" if !$i;
748 update_progress(0, 0, $maxper, "cleanup root-disks");
750 syscmd("vgchange -an") if !is_test_mode(); # deactivate all detected VGs
752 if (is_test_mode()) {
754 my $test_images = Proxmox::Install::ISOEnv::get_test_images();
755 $rootdev = abs_path($test_images->[0]); # FIXME: use all selected for test too!
756 syscmd("umount $rootdev");
760 die "unsupported btrfs mode (for testing environment)\n"
761 if $filesys ne 'btrfs (RAID0)';
763 btrfs_create([$rootdev], 'single');
767 die "unsupported zfs mode (for testing environment)\n"
768 if $filesys ne 'zfs (RAID0)';
770 syscmd("zpool destroy $zfstestpool");
772 zfs_create_rpool($rootdev);
779 } elsif ($use_btrfs) {
781 my ($devlist, $btrfs_mode) = get_btrfs_raid_setup();
783 foreach my $hd (@$devlist) {
787 update_progress(0, 0.02, $maxper, "create partitions");
789 my $btrfs_partitions = [];
790 foreach my $hd (@$devlist) {
791 my $devname = @$hd[1];
792 my $logical_bsize = @$hd[4];
794 my ($size, $osdev, $efidev) = partition_bootable_disk(
795 $devname, $config_options->{hdsize}, '8300');
796 $rootdev = $osdev if !defined($rootdev); # simply point to first disk
797 my $by_id = Proxmox::Sys::Block::get_disk_by_id_path($devname);
798 push @$bootdevinfo, {
803 logical_bsize => $logical_bsize,
805 push @$btrfs_partitions, $osdev;
808 Proxmox::Sys::Block::udevadm_trigger_block();
810 update_progress(0, 0.03, $maxper, "create btrfs");
812 btrfs_create($btrfs_partitions, $btrfs_mode);
816 my ($devlist, $vdev) = get_zfs_raid_setup();
818 foreach my $hd (@$devlist) {
822 update_progress(0, 0.02, $maxper, "create partitions");
824 # install esp/boot part on all, we can only win!
825 for my $hd (@$devlist) {
826 my $devname = @$hd[1];
827 my $logical_bsize = @$hd[4];
829 my ($size, $osdev, $efidev) =
830 partition_bootable_disk($devname, $config_options->{hdsize}, 'BF01');
832 push @$bootdevinfo, {
836 logical_bsize => $logical_bsize,
840 Proxmox::Sys::Block::udevadm_trigger_block();
842 foreach my $di (@$bootdevinfo) {
843 my $devname = $di->{devname};
844 $di->{by_id} = Proxmox::Sys::Block::get_disk_by_id_path($devname);
846 my $osdev = Proxmox::Sys::Block::get_disk_by_id_path($di->{osdev}) || $di->{osdev};
848 $vdev =~ s/ $devname/ $osdev/;
851 foreach my $hd (@$devlist) {
852 my $devname = @$hd[1];
853 my $by_id = Proxmox::Sys::Block::get_disk_by_id_path($devname);
855 $vdev =~ s/ $devname/ $by_id/ if $by_id;
858 update_progress(0, 0.03, $maxper, "create rpool");
860 zfs_create_rpool($vdev);
864 die "target '$target_hd' is not a valid block device\n" if ! -b $target_hd;
866 wipe_disk($target_hd);
868 update_progress(0, 0.02, $maxper, "create partitions");
870 my $logical_bsize = Proxmox::Sys::Block::logical_blocksize($target_hd);
872 my ($os_size, $osdev, $efidev) =
873 partition_bootable_disk($target_hd, $config_options->{hdsize}, '8E00');
875 Proxmox::Sys::Block::udevadm_trigger_block();
877 my $by_id = Proxmox::Sys::Block::get_disk_by_id_path($target_hd);
878 push @$bootdevinfo, {
880 devname => $target_hd,
883 logical_bsize => $logical_bsize,
886 update_progress(0, 0.03, $maxper, "create LVs");
888 my $swap_size = compute_swapsize($os_size);
889 ($rootdev, $swapfile, $datadev) =
890 create_lvm_volumes($osdev, $os_size, $swap_size);
892 # trigger udev to create /dev/disk/by-uuid
893 Proxmox::Sys::Block::udevadm_trigger_block(1);
897 # to be fast during installation
898 syscmd("zfs set sync=disabled $zfspoolname") == 0 ||
899 die "unable to set zfs properties\n";
902 update_progress(0.04, 0, $maxper, "create swap space");
904 syscmd("mkswap -f $swapfile") == 0 ||
905 die "unable to create swap space\n";
908 update_progress(0.045, 0, $maxper, "creating root filesystems");
910 foreach my $di (@$bootdevinfo) {
912 # FIXME remove '-s1' once https://github.com/dosfstools/dosfstools/issues/111 is fixed
913 my $vfat_extra_opts = ($di->{logical_bsize} == 4096) ? '-s1' : '';
914 syscmd("mkfs.vfat $vfat_extra_opts -F32 $di->{esp}") == 0 ||
915 die "unable to initialize EFI ESP on device $di->{esp}\n";
920 } elsif ($use_btrfs) {
923 create_filesystem($rootdev, 'root', $filesys, 0.05, $maxper, 0, 1);
926 update_progress(1, 0.05, $maxper, "mounting target $rootdev");
931 my $mount_opts = 'noatime';
932 $mount_opts .= ',nobarrier'
933 if $use_btrfs || $filesys =~ /^ext\d$/;
935 syscmd("mount -n $rootdev -o $mount_opts $targetdir") == 0 ||
936 die "unable to mount $rootdev\n";
939 mkdir "$targetdir/boot";
940 mkdir "$targetdir/boot/efi";
942 mkdir "$targetdir/var";
943 mkdir "$targetdir/var/lib";
945 if ($env->{product} eq 'pve') {
946 mkdir "$targetdir/var/lib/vz";
947 mkdir "$targetdir/var/lib/pve";
950 syscmd("btrfs subvolume create $targetdir/var/lib/pve/local-btrfs") == 0 ||
951 die "unable to create btrfs subvolume\n";
955 mkdir "$targetdir/mnt";
956 mkdir "$targetdir/mnt/hostrun";
957 syscmd("mount --bind /run $targetdir/mnt/hostrun") == 0 ||
958 die "unable to bindmount run on $targetdir/mnt/hostrun\n";
960 update_progress(1, 0.05, $maxper, "extracting base system");
962 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = stat ($basefile);
963 $ino || die "unable to open file '$basefile' - $!\n";
965 my $files = file_read_firstline("${proxmox_cddir}/proxmox/$env->{product}-base.cnt") ||
966 die "unable to read base file count\n";
971 run_command("unsquashfs -f -dest $targetdir -i $basefile", sub {
973 return if $line !~ m/^$targetdir/;
975 my $nper = int (($count *100)/$files);
978 my $frac = $per > 100 ? 1 : $per/100;
979 update_progress($frac, $maxper, 0.5);
983 syscmd("mount -n -t tmpfs tmpfs $targetdir/tmp") == 0 || die "unable to mount tmpfs on $targetdir/tmp\n";
985 mkdir "$targetdir/tmp/pkg";
986 syscmd("mount -n --bind '$proxmox_pkgdir' '$targetdir/tmp/pkg'") == 0
987 || die "unable to bind-mount packages on $targetdir/tmp/pkg\n";
988 syscmd("mount -n -t proc proc $targetdir/proc") == 0 || die "unable to mount proc on $targetdir/proc\n";
989 syscmd("mount -n -t sysfs sysfs $targetdir/sys") == 0 || die "unable to mount sysfs on $targetdir/sys\n";
990 if ($boot_type eq 'efi') {
991 syscmd("mount -n -t efivarfs efivarfs $targetdir/sys/firmware/efi/efivars") == 0 ||
992 die "unable to mount efivarfs on $targetdir/sys/firmware/efi/efivars: $!\n";
994 syscmd("chroot $targetdir mount --bind /mnt/hostrun /run") == 0 ||
995 die "unable to re-bindmount hostrun on /run in chroot\n";
997 update_progress(1, $maxper, 0.5, "configuring base system");
1002 "127.0.0.1 localhost.localdomain localhost\n" .
1003 "$ipaddress $hostname.$domain $hostname\n\n" .
1004 "# The following lines are desirable for IPv6 capable hosts\n\n" .
1005 "::1 ip6-localhost ip6-loopback\n" .
1006 "fe00::0 ip6-localnet\n" .
1007 "ff00::0 ip6-mcastprefix\n" .
1008 "ff02::1 ip6-allnodes\n" .
1009 "ff02::2 ip6-allrouters\n" .
1010 "ff02::3 ip6-allhosts\n";
1012 file_write_all("$targetdir/etc/hosts", $hosts);
1014 file_write_all("$targetdir/etc/hostname", "$hostname\n");
1016 syscmd("/bin/hostname $hostname") if !is_test_mode();
1018 # configure interfaces
1020 my $ifaces = "auto lo\niface lo inet loopback\n\n";
1022 my $ntype = $ipversion == 4 ? 'inet' : 'inet6';
1024 my $ethdev = $ipconf->{ifaces}->{$ipconf->{selected}}->{name};
1026 if ($env->{cfg}->{bridged_network}) {
1027 $ifaces .= "iface $ethdev $ntype manual\n";
1030 "\nauto vmbr0\niface vmbr0 $ntype static\n" .
1031 "\taddress $cidr\n" .
1032 "\tgateway $gateway\n" .
1033 "\tbridge-ports $ethdev\n" .
1034 "\tbridge-stp off\n" .
1037 $ifaces .= "auto $ethdev\n" .
1038 "iface $ethdev $ntype static\n" .
1039 "\taddress $cidr\n" .
1040 "\tgateway $gateway\n";
1043 foreach my $iface (sort keys %{$ipconf->{ifaces}}) {
1044 my $name = $ipconf->{ifaces}->{$iface}->{name};
1045 next if $name eq $ethdev;
1047 $ifaces .= "\niface $name $ntype manual\n";
1050 file_write_all("$targetdir/etc/network/interfaces", $ifaces);
1054 my $resolvconf = "search $domain\nnameserver $dnsserver\n";
1055 file_write_all("$targetdir/etc/resolv.conf", $resolvconf);
1059 my $fstab = "# <file system> <mount point> <type> <options> <dump> <pass>\n";
1063 } elsif ($use_btrfs) {
1065 my $cmd = "blkid -u filesystem -t TYPE=btrfs -o export $rootdev";
1066 run_command($cmd, sub {
1069 if ($line =~ m/^UUID=([A-Fa-f0-9\-]+)$/) {
1074 die "unable to detect FS UUID" if !defined($fsuuid);
1076 $fstab .= "UUID=$fsuuid / btrfs defaults 0 1\n";
1078 my $root_mountopt = $fssetup->{$filesys}->{root_mountopt} || 'defaults';
1079 $fstab .= "$rootdev / $filesys ${root_mountopt} 0 1\n";
1083 # Note: this is required by current grub, but really dangerous, because
1084 # vfat does not have journaling, so it triggers manual fsck after each crash
1085 # so we only mount /boot/efi if really required (efi systems).
1086 if ($boot_type eq 'efi' && !$use_zfs) {
1087 if (scalar(@$bootdevinfo)) {
1088 my $di = @$bootdevinfo[0]; # simply use first disk
1091 my $efi_boot_uuid = $di->{esp};
1092 if (my $uuid = Proxmox::Sys::Block::get_dev_uuid($di->{esp})) {
1093 $efi_boot_uuid = "UUID=$uuid";
1096 $fstab .= "${efi_boot_uuid} /boot/efi vfat defaults 0 1\n";
1102 $fstab .= "$swapfile none swap sw 0 0\n" if $swapfile;
1104 $fstab .= "proc /proc proc defaults 0 0\n";
1106 file_write_all("$targetdir/etc/fstab", $fstab);
1107 file_write_all("$targetdir/etc/mtab", "");
1109 syscmd("cp ${proxmox_libdir}/policy-disable-rc.d $targetdir/usr/sbin/policy-rc.d") == 0 ||
1110 die "unable to copy policy-rc.d\n";
1111 syscmd("cp ${proxmox_libdir}/fake-start-stop-daemon $targetdir/sbin/") == 0 ||
1112 die "unable to copy start-stop-daemon\n";
1114 diversion_add($targetdir, "/sbin/start-stop-daemon", "/sbin/fake-start-stop-daemon");
1115 diversion_add($targetdir, "/usr/sbin/update-grub", "/bin/true");
1116 diversion_add($targetdir, "/usr/sbin/update-initramfs", "/bin/true");
1118 my $machine_id = run_command("systemd-id128 new");
1119 die "unable to create a new machine-id\n" if ! $machine_id;
1120 file_write_all("$targetdir/etc/machine-id", $machine_id);
1122 syscmd("cp /etc/hostid $targetdir/etc/") == 0 ||
1123 die "unable to copy hostid\n";
1125 syscmd("touch $targetdir/proxmox_install_mode");
1127 my $grub_install_devices_txt = '';
1128 foreach my $di (@$bootdevinfo) {
1129 $grub_install_devices_txt .= ', ' if $grub_install_devices_txt;
1130 $grub_install_devices_txt .= $di->{by_id} || $di->{devname};
1133 # Note: keyboard-configuration/xbkb-keymap is used by console-setup
1134 my $xkmap = $env->{locales}->{kmap}->{$keymap}->{x11} // 'us';
1136 debconfig_set ($targetdir, <<_EOD);
1137 locales locales/default_environment_locale select en_US.UTF-8
1138 locales locales/locales_to_be_generated select en_US.UTF-8 UTF-8
1139 samba-common samba-common/dhcp boolean false
1140 samba-common samba-common/workgroup string WORKGROUP
1141 postfix postfix/main_mailer_type select No configuration
1142 keyboard-configuration keyboard-configuration/xkb-keymap select $xkmap
1143 d-i debian-installer/locale select en_US.UTF-8
1144 grub-pc grub-pc/install_devices select $grub_install_devices_txt
1148 while (<${proxmox_pkgdir
}/*.deb
>) { $pkg_count++ };
1150 # btrfs/dpkg is extremely slow without --force-unsafe-io
1151 my $dpkg_opts = $use_btrfs ?
"--force-unsafe-io" : "";
1154 while (<${proxmox_pkgdir
}/*.deb
>) {
1157 my ($deb) = $path =~ m/${proxmox_pkgdir}\/(.*\
.deb
)/;
1158 update_progress
($count/$pkg_count, 0.5, 0.75, "extracting $deb");
1159 print "extracting: $deb\n";
1160 syscmd
("chroot $targetdir dpkg $dpkg_opts --force-depends --no-triggers --unpack /tmp/pkg/$deb") == 0
1161 || die "installation of package $deb failed\n";
1162 update_progress
((++$count)/$pkg_count, 0.5, 0.75);
1165 # needed for postfix postinst in case no other NIC is active
1166 syscmd
("chroot $targetdir ifup lo");
1168 my $cmd = "chroot $targetdir dpkg $dpkg_opts --force-confold --configure -a";
1170 run_command
($cmd, sub {
1172 if ($line =~ m/Setting up\s+(\S+)/) {
1173 update_progress
((++$count)/$pkg_count, 0.75, 0.95, "configuring $1");
1177 unlink "$targetdir/etc/mailname";
1178 $postfix_main_cf =~ s/__FQDN__/${hostname}.${domain}/;
1179 file_write_all
("$targetdir/etc/postfix/main.cf", $postfix_main_cf);
1181 # make sure we have all postfix directories
1182 syscmd
("chroot $targetdir /usr/sbin/postfix check");
1183 # cleanup mail queue
1184 syscmd
("chroot $targetdir /usr/sbin/postsuper -d ALL");
1185 # create /etc/aliases.db (/etc/aliases is shipped in the base squashfs)
1186 syscmd
("chroot $targetdir /usr/bin/newaliases");
1188 unlink "$targetdir/proxmox_install_mode";
1191 unlink ("$targetdir/etc/localtime");
1192 symlink ("/usr/share/zoneinfo/$timezone", "$targetdir/etc/localtime");
1193 file_write_all
("$targetdir/etc/timezone", "$timezone\n");
1196 if (my $mirror = $env->{locales
}->{country
}->{$country}->{mirror
}) {
1197 my $fn = "$targetdir/etc/apt/sources.list";
1198 syscmd
("sed -i 's/ftp\\.debian\\.org/$mirror/' '$fn'");
1201 # create extended_states for apt (avoid cron job warning if that
1202 # file does not exist)
1203 file_write_all
("$targetdir/var/lib/apt/extended_states", '');
1205 # allow ssh root login
1206 syscmd
(['sed', '-i', 's/^#\?PermitRootLogin.*/PermitRootLogin yes/', "$targetdir/etc/ssh/sshd_config"]);
1208 if ($env->{product
} eq 'pmg') {
1209 # install initial clamav DB
1210 my $srcdir = "${proxmox_cddir}/proxmox/clamav";
1211 foreach my $fn ("main.cvd", "bytecode.cvd", "daily.cvd", "safebrowsing.cvd") {
1212 syscmd
("cp \"$srcdir/$fn\" \"$targetdir/var/lib/clamav\"") == 0 ||
1213 die "installation of clamav db file '$fn' failed\n";
1215 syscmd
("chroot $targetdir /bin/chown clamav:clamav -R /var/lib/clamav") == 0 ||
1216 die "unable to set owner for clamav database files\n";
1219 if ($env->{product
} eq 'pve') {
1220 # save installer settings
1221 my $ucc = uc ($country);
1222 debconfig_set
($targetdir, "pve-manager pve-manager/country string $ucc\n");
1225 update_progress
(0.8, 0.95, 1, "make system bootable");
1228 # add ZFS options while preserving existing kernel cmdline
1229 my $zfs_snippet = "GRUB_CMDLINE_LINUX=\"\$GRUB_CMDLINE_LINUX root=ZFS=$zfspoolname/ROOT/$zfsrootvolname boot=zfs\"";
1230 file_write_all
("$targetdir/etc/default/grub.d/zfs.cfg", $zfs_snippet);
1232 file_write_all
("$targetdir/etc/kernel/cmdline", "root=ZFS=$zfspoolname/ROOT/$zfsrootvolname boot=zfs\n");
1236 diversion_remove
($targetdir, "/usr/sbin/update-grub");
1237 diversion_remove
($targetdir, "/usr/sbin/update-initramfs");
1240 foreach my $fn (<$targetdir/lib/modules/*>) {
1241 if ($fn =~ m!/(\d+\.\d+\.\d+-\d+-pve)$!) {
1242 die "found multiple kernels\n" if defined($kapi);
1246 die "unable to detect kernel version\n" if !defined($kapi);
1248 if (!is_test_mode
()) {
1250 unlink ("$targetdir/etc/mtab");
1251 symlink ("/proc/mounts", "$targetdir/etc/mtab");
1252 syscmd
("mount -n --bind /dev $targetdir/dev");
1254 my $bootloader_err_list = [];
1256 syscmd
("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0 ||
1257 die "unable to install initramfs\n";
1259 my $native_4k_disk_bootable = 0;
1260 foreach my $di (@$bootdevinfo) {
1261 $native_4k_disk_bootable |= ($di->{logical_bsize
} == 4096);
1264 foreach my $di (@$bootdevinfo) {
1265 my $dev = $di->{devname
};
1267 prepare_proxmox_boot_esp
($di->{esp
}, $targetdir);
1269 if (!$native_4k_disk_bootable) {
1271 syscmd
("chroot $targetdir /usr/sbin/grub-install --target i386-pc --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
1272 die "unable to install the i386-pc boot loader on '$dev'\n";
1274 push @$bootloader_err_list, $@ if $@;
1277 if (my $esp = $di->{esp
}) {
1278 eval { prepare_grub_efi_boot_esp
($dev, $esp, $targetdir) };
1279 push @$bootloader_err_list, $@ if $@;
1284 syscmd
("chroot $targetdir /usr/sbin/update-grub") == 0 ||
1285 die "unable to update boot loader config\n";
1287 push @$bootloader_err_list, $@ if $@;
1289 if (scalar(@$bootloader_err_list) > 0) {
1290 $bootloader_err = "bootloader setup errors:\n";
1291 map { $bootloader_err .= "- $_" } @$bootloader_err_list;
1292 warn $bootloader_err;
1295 syscmd
("umount $targetdir/dev");
1300 unlink "$targetdir/usr/sbin/policy-rc.d";
1302 diversion_remove
($targetdir, "/sbin/start-stop-daemon");
1305 my $octets = encode
("utf-8", $password);
1306 run_command
("chroot $targetdir /usr/sbin/chpasswd", undef,
1309 if ($env->{product
} eq 'pmg') {
1311 file_write_all
("$targetdir/etc/pmg/pmg.conf", "section: admin\n\temail ${mailto}\n");
1313 } elsif ($env->{product
} eq 'pve') {
1317 my $tmpdir = "$targetdir/tmp/pve";
1320 # write vnc keymap to datacenter.cfg
1321 my $vnckmap = $env->{locales
}->{kmap
}->{$keymap}->{kvm
} || 'en-us';
1322 file_write_all
("$tmpdir/datacenter.cfg", "keyboard: $vnckmap\n");
1325 file_write_all
("$tmpdir/user.cfg", "user:root\@pam:1:0:::${mailto}::\n");
1330 $storage_cfg = $storage_cfg_zfs;
1331 } elsif ($use_btrfs) {
1332 $storage_cfg = $storage_cfg_btrfs;
1333 } elsif ($datadev) {
1334 $storage_cfg = $storage_cfg_lvmthin;
1336 $storage_cfg = $storage_cfg_local;
1338 file_write_all
("$tmpdir/storage.cfg", $storage_cfg);
1340 run_command
("chroot $targetdir /usr/bin/create_pmxcfs_db /tmp/pve /var/lib/pve-cluster/config.db");
1342 syscmd
("rm -rf $tmpdir");
1343 } elsif ($env->{product
} eq 'pbs') {
1344 my $base_cfg_path = "/etc/proxmox-backup";
1345 mkdir "$targetdir/$base_cfg_path";
1347 chroot_chown
($targetdir, $base_cfg_path, user
=> 'backup', recursive
=> 1);
1348 chroot_chmod
($targetdir, $base_cfg_path, mode
=> '0700');
1350 my $user_cfg_fn = "$base_cfg_path/user.cfg";
1351 file_write_all
("$targetdir/$user_cfg_fn", "user: root\@pam\n\temail ${mailto}\n");
1352 chroot_chown
($targetdir, $user_cfg_fn, user
=> 'root', group
=> 'backup');
1353 chroot_chmod
($targetdir, $user_cfg_fn, mode
=> '0640');
1359 update_progress
(1, 0, 1, "");
1363 if (is_test_mode
()) {
1364 my $elapsed = Time
::HiRes
::tv_interval
($starttime);
1365 print "Elapsed extract time: $elapsed\n";
1367 syscmd
("chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> final.pkglist");
1370 syscmd
("umount $targetdir/run");
1371 syscmd
("umount $targetdir/mnt/hostrun");
1372 syscmd
("umount $targetdir/tmp/pkg");
1373 syscmd
("umount $targetdir/tmp");
1374 syscmd
("umount $targetdir/proc");
1375 syscmd
("umount $targetdir/sys/firmware/efi/efivars");
1376 syscmd
("umount $targetdir/sys");
1377 rmdir("$targetdir/mnt/hostrun");
1380 syscmd
("zfs umount -a") == 0 ||
1381 die "unable to unmount zfs\n";
1383 syscmd
("umount -d $targetdir");
1386 if (!$err && $use_zfs) {
1387 syscmd
("zfs set sync=standard $zfspoolname") == 0 ||
1388 die "unable to set zfs properties\n";
1390 syscmd
("zfs set mountpoint=/ $zfspoolname/ROOT/$zfsrootvolname") == 0 ||
1391 die "zfs set mountpoint failed\n";
1393 syscmd
("zpool set bootfs=$zfspoolname/ROOT/$zfsrootvolname $zfspoolname") == 0 ||
1394 die "zpool set bootfs failed\n";
1395 syscmd
("zpool export $zfspoolname");
1398 if ($bootloader_err) {
1399 $err = $err ?
"$err\n$bootloader_err" : $bootloader_err;
1405 my $last_display_change = 0;
1407 my $display_info_counter = 0;
1409 my $display_info_items = [
1410 "extract1-license.htm",
1411 "extract2-rulesystem.htm",
1412 "extract3-spam.htm",
1413 "extract4-virus.htm",
1418 my $min_display_time = 15;
1422 return if ($ctime - $last_display_change) < $min_display_time;
1424 my $page = $display_info_items->[$display_info_counter % scalar(@$display_info_items)];
1426 $display_info_counter++;
1428 display_html
($page);
1432 my ($filename) = @_;
1434 $filename = $steps[$step_number]->{html
} if !$filename;
1436 my $htmldir = "${proxmox_libdir}/html";
1438 if (-f
"$htmldir/$env->{product}/$filename") {
1439 $path = "$htmldir/$env->{product}/$filename";
1441 $path = "$htmldir/$filename";
1444 my $data = file_read_all
($path);
1446 if ($filename eq 'license.htm') {
1447 my $license = eval { decode
('utf8', file_read_all
("${proxmox_cddir}/EULA")) };
1449 die $err if !is_test_mode
();
1450 $license = "TESTMODE: Ignore non existent EULA...\n";
1452 my $title = "END USER LICENSE AGREEMENT (EULA)";
1453 $data =~ s/__LICENSE__/$license/;
1454 $data =~ s/__LICENSE_TITLE__/$title/;
1455 } elsif ($filename eq 'success.htm') {
1456 my $addr = $ipversion == 6 ?
"[${ipaddress}]" : "$ipaddress";
1457 $data =~ s/__IPADDR__/$addr/g;
1458 $data =~ s/__PORT__/$env->{cfg}->{port}/g;
1460 my $autoreboot_msg = $config_options->{autoreboot
}
1461 ?
"Automatic reboot scheduled in $autoreboot_seconds seconds."
1463 $data =~ s/__AUTOREBOOT_MSG__/$autoreboot_msg/;
1465 $data =~ s/__FULL_PRODUCT_NAME__/$env->{cfg}->{fullname}/g;
1467 # always set base-path to common path, all resources are accesible from there.
1468 $htmlview->load_html($data, "file://$htmldir/");
1470 $last_display_change = time();
1475 my ($text, $fctn) = @_;
1477 $fctn = $step_number if !$fctn;
1478 $text = "_Previous" if !$text;
1479 $prev_btn->set_label ($text);
1482 $steps[$step_number]->{function
}();
1484 $prev_btn->grab_focus();
1488 my ($text, $fctn) = @_;
1491 my $step = $steps[$step_number];
1492 $text //= $steps[$step_number]->{next_button
} // '_Next';
1493 $next->set_label($text);
1495 $next->grab_focus();
1498 sub create_main_window
{
1500 $window = Gtk3
::Window-
>new();
1501 $window->set_default_size(1024, 768);
1502 $window->signal_connect(map => sub { $window->set_resizable(0); });
1503 $window->fullscreen() if !is_test_mode
();
1504 $window->set_decorated(0) if !is_test_mode
();
1505 $window->signal_connect(destroy
=> sub { Gtk3-
>main_quit(); });
1507 my $vbox = Gtk3
::Box-
>new('vertical', 0);
1509 my $logofn = "$env->{product}-banner.png";
1510 my $image = Gtk3
::Image-
>new_from_file("${proxmox_libdir}/$logofn");
1512 my $provider = Gtk3
::CssProvider-
>new();
1513 my $theming = "* {\nbackground: #171717;\n}";
1514 $provider->load_from_data ([map ord, split //, $theming]);
1515 my $context = $image->get_style_context();
1516 $context->add_provider($provider, 600);
1518 $vbox->pack_start($image, 0, 0, 0);
1520 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
1521 $vbox->pack_start($hbox, 1, 1, 0);
1523 # my $f1 = Gtk3::Frame->new ('test');
1524 # $f1->set_shadow_type ('none');
1525 # $hbox->pack_start ($f1, 1, 1, 0);
1527 my $sep1 = Gtk3
::Separator-
>new('horizontal');
1528 $vbox->pack_start($sep1, 0, 0, 0);
1530 $cmdbox = Gtk3
::Box-
>new('horizontal', 0);
1531 $vbox->pack_start($cmdbox, 0, 0, 10);
1533 $next = Gtk3
::Button-
>new('_Next');
1534 $next->signal_connect(clicked
=> sub { $last_display_change = 0; &$next_fctn (); });
1535 $cmdbox->pack_end($next, 0, 0, 10);
1538 $prev_btn = Gtk3
::Button-
>new('_Previous');
1539 $prev_btn->signal_connect(clicked
=> sub { $last_display_change = 0; &prev_function
(); });
1540 $cmdbox->pack_end($prev_btn, 0, 0, 10);
1543 my $abort = Gtk3
::Button-
>new('_Abort');
1544 $abort->set_can_focus(0);
1545 $cmdbox->pack_start($abort, 0, 0, 10);
1546 $abort->signal_connect(clicked
=> sub { app_quit
(-1); });
1548 my $vbox2 = Gtk3
::Box-
>new('vertical', 0);
1551 $htmlview = Gtk3
::WebKit2
::WebView-
>new();
1552 $htmlview->set_hexpand(1);
1553 my $scrolls = Gtk3
::ScrolledWindow-
>new();
1554 $scrolls->add($htmlview);
1556 my $hbox2 = Gtk3
::Box-
>new('horizontal', 0);
1557 $hbox2->pack_start($scrolls, 1, 1, 0);
1559 $vbox2->pack_start($hbox2, 1, 1, 0);
1561 my $vbox3 = Gtk3
::Box-
>new('vertical', 0);
1562 $vbox2->pack_start($vbox3, 0, 0, 0);
1564 my $sep2 = Gtk3
::Separator-
>new('horizontal');
1565 $vbox3->pack_start($sep2, 0, 0, 0);
1567 $inbox = Gtk3
::Box-
>new('horizontal', 0);
1568 $vbox3->pack_start($inbox, 0, 0, 0);
1570 $window->add($vbox);
1572 Proxmox
::UI
::init_gtk
({ window
=> $window });
1579 $inbox->foreach(sub {
1581 $inbox->remove ($child);
1585 # fixme: newer GTK3 has special properties to handle numbers with Entry
1586 # only allow floating point numbers with Gtk3::Entry
1589 my ($entry, $event) = @_;
1591 return check_number
($entry, $event, 1);
1595 my ($entry, $event) = @_;
1597 return check_number
($entry, $event, 0);
1601 my ($entry, $event, $float) = @_;
1603 my $val = $event->get_keyval;
1605 if (($float && $val == ord '.') ||
1606 $val == Gtk3
::Gdk
::KEY_ISO_Left_Tab
||
1607 $val == Gtk3
::Gdk
::KEY_Shift_L
||
1608 $val == Gtk3
::Gdk
::KEY_Tab
||
1609 $val == Gtk3
::Gdk
::KEY_Left
||
1610 $val == Gtk3
::Gdk
::KEY_Right
||
1611 $val == Gtk3
::Gdk
::KEY_BackSpace
||
1612 $val == Gtk3
::Gdk
::KEY_Delete
||
1613 ($val >= ord '0' && $val <= ord '9') ||
1614 ($val >= Gtk3
::Gdk
::KEY_KP_0
&&
1615 $val <= Gtk3
::Gdk
::KEY_KP_9
)) {
1622 sub create_text_input
{
1623 my ($default, $text) = @_;
1625 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
1627 my $label = Gtk3
::Label-
>new($text);
1628 $label->set_size_request(150, -1);
1629 $label->set_xalign(1.0);
1630 $hbox->pack_start($label, 0, 0, 10);
1631 my $e1 = Gtk3
::Entry-
>new();
1632 $e1->set_width_chars(35);
1633 $hbox->pack_start($e1, 0, 0, 0);
1634 $e1->set_text($default);
1636 return ($hbox, $e1);
1638 sub create_cidr_inputs
{
1639 my ($default_ip, $default_mask) = @_;
1641 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
1643 my $label = Gtk3
::Label-
>new('IP Address (CIDR)');
1644 $label->set_size_request(150, -1);
1645 $label->set_xalign(1.0);
1646 $hbox->pack_start($label, 0, 0, 10);
1648 my $ip_el = Gtk3
::Entry-
>new();
1649 $ip_el->set_width_chars(28);
1650 $hbox->pack_start($ip_el, 0, 0, 0);
1651 $ip_el->set_text($default_ip);
1653 $label = Gtk3
::Label-
>new('/');
1654 $label->set_size_request(10, -1);
1655 $hbox->pack_start($label, 0, 0, 2);
1657 my $cidr_el = Gtk3
::Entry-
>new();
1658 $cidr_el->set_width_chars(3);
1659 $hbox->pack_start($cidr_el, 0, 0, 0);
1660 $cidr_el->set_text($default_mask);
1662 return ($hbox, $ip_el, $cidr_el);
1665 sub display_message
{
1668 my $dialog = Gtk3
::MessageDialog-
>new($window, 'modal', 'info', 'ok', $msg);
1676 my $dialog = Gtk3
::MessageDialog-
>new($window, 'modal', 'error', 'ok', $msg);
1681 sub display_prompt
{
1684 my $dialog = Gtk3
::MessageDialog-
>new($window, 'modal', 'question', 'ok-cancel', $query);
1685 my $response = $dialog->run();
1691 my $ipconf_first_view = 1;
1693 sub create_ipconf_view
{
1698 my $vcontainer = Gtk3
::Box-
>new('vertical', 0);
1699 $inbox->pack_start($vcontainer, 1, 0, 0);
1700 my $hcontainer = Gtk3
::Box-
>new('horizontal', 0);
1701 $vcontainer->pack_start($hcontainer, 0, 0, 10);
1702 my $vbox = Gtk3
::Box-
>new('vertical', 0);
1703 $hcontainer->add($vbox);
1705 my $ipaddr_text = $config->{ipaddress
} // "192.168.100.2";
1706 my $netmask_text = $config->{netmask
} // "24";
1708 ($cidr_box, $ipconf_entry_addr, $ipconf_entry_mask) =
1709 create_cidr_inputs
($ipaddr_text, $netmask_text);
1711 my $device_cb = Gtk3
::ComboBoxText-
>new();
1712 $device_cb->set_active(0);
1713 $device_cb->set_visible(1);
1715 my $get_device_desc = sub {
1717 return "$iface->{name} - $iface->{mac} ($iface->{driver})";
1720 my $device_active_map = {};
1721 my $device_active_reverse_map = {};
1723 my $device_change_handler = sub {
1724 my $current = shift;
1726 my $new = $device_active_map->{$current->get_active()};
1727 return if defined($ipconf->{selected
}) && $new eq $ipconf->{selected
};
1729 $ipconf->{selected
} = $new;
1730 my $iface = $ipconf->{ifaces
}->{$ipconf->{selected
}};
1731 $config->{mngmt_nic
} = $iface->{name
};
1732 $ipconf_entry_addr->set_text($iface->{inet
}->{addr
} || $iface->{inet6
}->{addr
})
1733 if $iface->{inet
}->{addr
} || $iface->{inet6
}->{addr
};
1734 $ipconf_entry_mask->set_text($iface->{inet
}->{prefix
} || $iface->{inet6
}->{prefix
})
1735 if $iface->{inet
}->{prefix
} || $iface->{inet6
}->{prefix
};
1739 foreach my $index (sort keys %{$ipconf->{ifaces
}}) {
1740 $device_cb->append_text(&$get_device_desc($ipconf->{ifaces
}->{$index}));
1741 $device_active_map->{$i} = $index;
1742 $device_active_reverse_map->{$ipconf->{ifaces
}->{$index}->{name
}} = $i;
1743 if ($ipconf_first_view && $index == $ipconf->{default}) {
1744 $device_cb->set_active($i);
1745 &$device_change_handler($device_cb);
1746 $ipconf_first_view = 0;
1748 $device_cb->signal_connect('changed' => $device_change_handler);
1752 if (my $nic = $config->{mngmt_nic
}) {
1753 $device_cb->set_active($device_active_reverse_map->{$nic} // 0);
1755 $device_cb->set_active(0);
1758 my $devicebox = Gtk3
::Box-
>new('horizontal', 0);
1759 my $label = Gtk3
::Label-
>new("Management Interface:");
1760 $label->set_size_request(150, -1);
1761 $label->set_xalign(1.0);
1762 $devicebox->pack_start($label, 0, 0, 10);
1763 $devicebox->pack_start($device_cb, 0, 0, 0);
1765 $vbox->pack_start($devicebox, 0, 0, 2);
1767 my $hn = $config->{fqdn
} // "$env->{product}." . ($ipconf->{domain
} // "example.invalid");
1769 my ($hostbox, $hostentry) = create_text_input
($hn, 'Hostname (FQDN):');
1770 $vbox->pack_start($hostbox, 0, 0, 2);
1772 $vbox->pack_start($cidr_box, 0, 0, 2);
1774 $gateway = $config->{gateway
} // $ipconf->{gateway
} || '192.168.100.1';
1777 ($gwbox, $ipconf_entry_gw) =
1778 create_text_input
($gateway, 'Gateway:');
1780 $vbox->pack_start($gwbox, 0, 0, 2);
1782 $dnsserver = $config->{dnsserver
} // $ipconf->{dnsserver
} || $gateway;
1785 ($dnsbox, $ipconf_entry_dns) =
1786 create_text_input
($dnsserver, 'DNS Server:');
1788 $vbox->pack_start($dnsbox, 0, 0, 0);
1791 set_next
(undef, sub {
1795 my $text = $hostentry->get_text();
1800 $config->{fqdn
} = $text;
1802 my $namere = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
1804 # Debian does not support purely numeric hostnames
1805 if ($text && $text =~ /^[0-9]+(?:\.|$)/) {
1806 display_message
("Purely numeric hostnames are not allowed.");
1807 $hostentry->grab_focus();
1811 if ($text && $text =~ m/^(${namere}\.)*${namere}$/ && $text !~ m/.example.invalid$/ &&
1812 $text =~ m/^([^\.]+)\.(\S+)$/) {
1816 display_message
("Hostname does not look like a fully qualified domain name.");
1817 $hostentry->grab_focus();
1822 $text = $ipconf_entry_addr->get_text();
1823 ($ipaddress, $ipversion) = parse_ip_address
($text);
1824 if (!defined($ipaddress)) {
1825 display_message
("IP address is not valid.");
1826 $ipconf_entry_addr->grab_focus();
1829 $config->{ipaddress
} = $ipaddress;
1831 $text = $ipconf_entry_mask->get_text();
1832 $netmask = parse_ip_mask
($text, $ipversion);
1833 if (!defined($netmask)) {
1834 display_message
("Netmask is not valid.");
1835 $ipconf_entry_mask->grab_focus();
1838 $cidr = "$ipaddress/$netmask";
1839 $config->{netmask
} = $netmask;
1841 $text = $ipconf_entry_gw->get_text();
1842 my ($gateway_ip, $gateway_ip_version) = parse_ip_address
($text);
1843 if (!defined($gateway_ip) || $gateway_ip_version != $ipversion) {
1844 my $msg = defined($gateway_ip)
1845 ?
"Gateway and host IP version must not differ (IPv$gateway_ip_version != IPv$ipversion)."
1846 : "Gateway is not valid.";
1847 display_message
($msg);
1848 $ipconf_entry_gw->grab_focus();
1851 $config->{gateway
} = $gateway = $gateway_ip;
1853 $text = $ipconf_entry_dns->get_text();
1854 my ($dns_ip, $dns_ip_version) = parse_ip_address
($text);
1855 if (!defined($dns_ip) || $dns_ip_version != $ipversion) {
1856 my $msg = defined($gateway_ip)
1857 ?
"DNS and host IP version must not differ (IPv$gateway_ip_version != IPv$ipversion)."
1858 : "DNS IP is not valid.";
1859 display_message
($msg);
1860 $ipconf_entry_dns->grab_focus();
1863 $config->{dnsserver
} = $dnsserver = $dns_ip;
1865 #print "TEST $ipaddress $netmask $gateway $dnsserver\n";
1871 $hostentry->grab_focus();
1874 sub create_ack_view
{
1878 my $vbox = Gtk3
::Box-
>new('vertical', 0);
1879 $inbox->pack_start($vbox, 1, 0, 0);
1881 my $reboot_checkbox = Gtk3
::CheckButton-
>new('Automatically reboot after successful installation');
1882 $reboot_checkbox->set_active(1);
1883 $reboot_checkbox->signal_connect ("toggled" => sub {
1885 $config_options->{autoreboot
} = $cb->get_active();
1887 $vbox->pack_start($reboot_checkbox, 0, 0, 2);
1889 my $ack_template = "${proxmox_libdir}/html/ack_template.htm";
1890 my $ack_html = "${proxmox_libdir}/html/$env->{product}/$steps[$step_number]->{html}";
1891 my $html_data = file_read_all
($ack_template);
1893 my %config_values = (
1894 __target_hd__
=> join(' | ', @{$config_options->{target_hds
}}),
1895 __target_fs__
=> $config_options->{filesys
},
1896 __country__
=> $env->{locales
}->{country
}->{$country}->{name
},
1897 __timezone__
=> $timezone,
1898 __keymap__
=> $keymap,
1899 __mailto__
=> $mailto,
1900 __interface__
=> $ipconf->{ifaces
}->{$ipconf->{selected
}}->{name
},
1901 __hostname__
=> $hostname,
1902 __ip__
=> $ipaddress,
1904 __netmask__
=> $netmask,
1905 __gateway__
=> $gateway,
1906 __dnsserver__
=> $dnsserver,
1909 while (my ($k, $v) = each %config_values) {
1910 $html_data =~ s/$k/$v/g;
1913 file_write_all
($ack_html, $html_data);
1919 set_next
(undef, sub {
1921 create_extract_view
();
1925 sub get_device_desc
{
1926 my ($devname, $size, $model) = @_;
1928 if ($size && ($size > 0)) {
1929 $size = int($size/2048); # size in MiB, from 512B "sectors"
1931 my $text = "$devname (";
1932 if ($size >= 1024) {
1933 $size = $size/1024; # size in GiB
1934 if ($size >= 1024) {
1935 $size = $size/1024; # size in TiB
1936 $text .= sprintf("%.2f", $size) . "TiB";
1938 $text .= sprintf("%.2f", $size) . "GiB";
1941 $text .= "${size}MiB";
1944 $text .= ", $model" if $model;
1956 my ($cb, $kmap) = @_;
1961 my $kmaphash = $env->{locales
}->{kmaphash
};
1962 foreach my $layout (sort keys %$kmaphash) {
1963 $def = $i if $kmaphash->{$layout} eq 'en-us';
1964 $ind = $i if $kmap && $kmaphash->{$layout} eq $kmap;
1968 my $val = $ind || $def || 0;
1970 if (!defined($kmap)) {
1971 $last_layout //= $val;
1972 } elsif (!defined($country_layout) || $country_layout != $val) {
1973 $last_layout = $country_layout = $val;
1975 $cb->set_active($last_layout);
1979 sub update_zonelist
{
1980 my ($box, $cc) = @_;
1982 my $sel = $timezone; # initial default
1984 $sel = $lastzonecb->get_active_text();
1985 $box->remove($lastzonecb);
1988 my $cb = $lastzonecb = Gtk3
::ComboBoxText-
>new();
1989 $cb->set_size_request(200, -1);
1990 $cb->signal_connect('changed' => sub {
1991 $timezone = $cb->get_active_text();
1994 my ($cczones, $zones) = $env->{locales
}->@{'cczones', 'zones'};
1995 my @available_zones = $cc && defined($cczones->{$cc}) ?
keys %{$cczones->{$cc}} : keys %$zones;
1997 my ($i, $selected_index) = (0, undef);
1998 for my $zone (sort @available_zones) {
1999 $selected_index = $i if $sel && $zone eq $sel;
2000 $cb->append_text($zone);
2004 # Append UTC here, so it is always the last item and never the default for any country.
2005 $cb->append_text('UTC');
2007 $cb->set_active($selected_index || 0);
2010 $box->pack_start($cb, 0, 0, 0);
2013 sub create_password_view
{
2017 my $vbox2 = Gtk3
::Box-
>new('vertical', 0);
2018 $inbox->pack_start($vbox2, 1, 0, 0);
2019 my $vbox = Gtk3
::Box-
>new('vertical', 0);
2020 $vbox2->pack_start($vbox, 0, 0, 10);
2022 my $hbox1 = Gtk3
::Box-
>new('horizontal', 0);
2023 my $label = Gtk3
::Label-
>new("Password");
2024 $label->set_size_request(150, -1);
2025 $label->set_xalign(1.0);
2026 $hbox1->pack_start($label, 0, 0, 10);
2027 my $pwe1 = Gtk3
::Entry-
>new();
2028 $pwe1->set_visibility(0);
2029 $pwe1->set_text($password) if $password;
2030 $pwe1->set_size_request(200, -1);
2031 $hbox1->pack_start($pwe1, 0, 0, 0);
2033 my $hbox2 = Gtk3
::Box-
>new('horizontal', 0);
2034 $label = Gtk3
::Label-
>new("Confirm");
2035 $label->set_size_request(150, -1);
2036 $label->set_xalign(1.0);
2037 $hbox2->pack_start($label, 0, 0, 10);
2038 my $pwe2 = Gtk3
::Entry-
>new();
2039 $pwe2->set_visibility(0);
2040 $pwe2->set_text($password) if $password;
2041 $pwe2->set_size_request(200, -1);
2042 $hbox2->pack_start($pwe2, 0, 0, 0);
2044 my $hbox3 = Gtk3
::Box-
>new('horizontal', 0);
2045 $label = Gtk3
::Label-
>new("Email");
2046 $label->set_size_request(150, -1);
2047 $label->set_xalign(1.0);
2048 $hbox3->pack_start($label, 0, 0, 10);
2049 my $eme = Gtk3
::Entry-
>new();
2050 $eme->set_size_request(200, -1);
2051 $eme->set_text($mailto);
2052 $hbox3->pack_start($eme, 0, 0, 0);
2055 $vbox->pack_start($hbox1, 0, 0, 5);
2056 $vbox->pack_start($hbox2, 0, 0, 5);
2057 $vbox->pack_start($hbox3, 0, 0, 15);
2063 set_next
(undef, sub {
2065 my $t1 = $pwe1->get_text;
2066 my $t2 = $pwe2->get_text;
2068 if (length ($t1) < 5) {
2069 display_message
("Password is too short.");
2070 $pwe1->grab_focus();
2075 display_message
("Password does not match.");
2076 $pwe1->grab_focus();
2080 my $t3 = $eme->get_text;
2081 if ($t3 !~ m/^[\w\+\-\~]+(\.[\w\+\-\~]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*$/) {
2082 display_message
("Email does not look like a valid address" .
2083 " (user\@domain.tld)");
2088 if ($t3 eq 'mail@example.invalid') {
2089 display_message
("Please enter a valid Email address");
2098 create_ipconf_view
();
2101 $pwe1->grab_focus();
2106 sub create_country_view
{
2110 my $locales = $env->{locales
};
2112 my $vbox2 = Gtk3
::Box-
>new('vertical', 0);
2113 $inbox->pack_start($vbox2, 1, 0, 0);
2114 my $vbox = Gtk3
::Box-
>new('vertical', 0);
2115 $vbox2->pack_start($vbox, 0, 0, 10);
2117 my $w = Gtk3
::Entry-
>new();
2118 $w->set_size_request(200, -1);
2120 my $c = Gtk3
::EntryCompletion-
>new();
2121 $c->set_text_column(0);
2122 $c->set_minimum_key_length(0);
2123 $c->set_popup_set_width(1);
2124 $c->set_inline_completion(1);
2126 my $hbox2 = Gtk3
::Box-
>new('horizontal', 0);
2127 my $label = Gtk3
::Label-
>new("Time zone");
2128 $label->set_size_request(150, -1);
2129 $label->set_xalign(1.0);
2130 $hbox2->pack_start($label, 0, 0, 10);
2131 update_zonelist
($hbox2);
2133 my $hbox3 = Gtk3
::Box-
>new('horizontal', 0);
2134 $label = Gtk3
::Label-
>new("Keyboard Layout");
2135 $label->set_size_request(150, -1);
2136 $label->set_xalign(1.0);
2137 $hbox3->pack_start($label, 0, 0, 10);
2139 my $kmapcb = Gtk3
::ComboBoxText-
>new();
2140 $kmapcb->set_size_request (200, -1);
2141 for my $layout (sort keys %{$locales->{kmaphash
}}) {
2142 $kmapcb->append_text($layout);
2145 update_layout
($kmapcb);
2146 $hbox3->pack_start ($kmapcb, 0, 0, 0);
2148 $kmapcb->signal_connect ('changed' => sub {
2149 my $sel = $kmapcb->get_active_text();
2150 $last_layout = $kmapcb->get_active();
2151 if (my $kmap = $locales->{kmaphash
}->{$sel}) {
2152 my $xkmap = $locales->{kmap
}->{$kmap}->{x11
};
2153 my $xvar = $locales->{kmap
}->{$kmap}->{x11var
};
2156 return if (defined($installer_kmap) && $installer_kmap eq $kmap);
2158 $installer_kmap = $keymap;
2160 if (!is_test_mode
()) {
2161 syscmd
("setxkbmap $xkmap $xvar");
2163 my $kbd_config = qq{
2168 $kbd_config =~ s/^\s+//gm;
2170 Proxmox
::Sys
::Command
::run_in_background
(sub {
2171 file_write_all
('/etc/default/keyboard', $kbd_config);
2178 $w->signal_connect ('changed' => sub {
2179 my ($entry, $event) = @_;
2180 my $text = $entry->get_text;
2182 if (my $cc = $locales->{countryhash
}->{lc($text)}) {
2183 update_zonelist
($hbox2, $cc);
2184 my $kmap = $locales->{country
}->{$cc}->{kmap
} || 'en-us';
2185 update_layout
($kmapcb, $kmap);
2189 $w->signal_connect (key_press_event
=> sub {
2190 my ($entry, $event) = @_;
2191 my $text = $entry->get_text;
2193 my $val = $event->get_keyval;
2195 if ($val == Gtk3
::Gdk
::KEY_Tab
) {
2196 my $cc = $locales->{countryhash
}->{lc($text)};
2203 $compl = $locales->{country
}->{$cc}->{name
};
2205 for my $country (values $locales->{country
}->%*) {
2206 if ($country->{name
} =~ m/^\Q$text\E.*$/i) {
2208 $compl = $country->{name
};
2215 $entry->set_text($compl);
2220 print chr(7); # beep ?
2225 my $buf = $w->get_buffer();
2226 $buf->insert_text(-1, '', -1); # popup selection
2234 my $country_store = Gtk3
::ListStore-
>new('Glib::String');
2235 my $countries = $locales->{country
};
2236 for my $cc (sort { $countries->{$a}->{name
} cmp $countries->{$b}->{name
} } keys %$countries) {
2237 my $iter = $country_store->append();
2238 $country_store->set($iter, 0, $countries->{$cc}->{name
});
2240 $c->set_model($country_store);
2242 $w->set_completion ($c);
2244 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
2246 $label = Gtk3
::Label-
>new("Country");
2247 $label->set_xalign(1.0);
2248 $label->set_size_request(150, -1);
2249 $hbox->pack_start($label, 0, 0, 10);
2250 $hbox->pack_start($w, 0, 0, 0);
2252 $vbox->pack_start($hbox, 0, 0, 5);
2253 $vbox->pack_start($hbox2, 0, 0, 5);
2254 $vbox->pack_start($hbox3, 0, 0, 5);
2256 if ($country && (my $entry = $locales->{country
}->{$country})) {
2257 $w->set_text($entry->{name
});
2263 set_next
(undef, sub {
2265 my $text = $w->get_text;
2267 if (my $cc = $locales->{countryhash
}->{lc($text)}) {
2270 create_password_view
();
2273 display_message
("Please select a country first.");
2281 my $target_hd_combo;
2282 my $target_hd_label;
2284 my $hdoption_first_setup = 1;
2286 my $create_basic_grid = sub {
2287 my $grid = Gtk3
::Grid-
>new();
2288 $grid->set_visible(1);
2289 $grid->set_column_spacing(10);
2290 $grid->set_row_spacing(10);
2291 $grid->set_hexpand(1);
2293 $grid->set_margin_start(10);
2294 $grid->set_margin_end(20);
2295 $grid->set_margin_top(5);
2296 $grid->set_margin_bottom(5);
2301 my $create_label_widget_grid = sub {
2302 my ($labeled_widgets) = @_;
2304 my $grid = &$create_basic_grid();
2307 for (my $i = 0; $i < @$labeled_widgets; $i += 2) {
2308 my $widget = @$labeled_widgets[$i+1];
2309 my $label = Gtk3
::Label-
>new(@$labeled_widgets[$i]);
2310 $label->set_visible(1);
2311 $label->set_xalign(1.0);
2312 $grid->attach($label, 0, $row, 1, 1);
2313 $widget->set_visible(1);
2314 $grid->attach($widget, 1, $row, 1, 1);
2321 # only relevant for raid with its multipl diskX to diskY mappings.
2322 my $get_selected_hdsize = sub {
2324 return $hdsize if defined($hdsize);
2326 # compute the smallest disk size of the actually selected disks
2327 my $cached_disks = get_cached_disks
();
2328 my $disk_count = scalar(@$cached_disks);
2329 for (my $i = 0; $i < $disk_count; $i++) {
2330 my $cur_hd = $config_options->{"disksel$i"} // next;
2331 my $disksize = int(@$cur_hd[2] / (2 * 1024 * 1024.0)); # size in GB
2332 $hdsize //= $disksize;
2333 $hdsize = $disksize if $disksize < $hdsize;
2336 if (my $cfg_hdsize = $config_options->{hdsize
}) {
2337 # had the dialog open previously and set an even lower size than the disk selection allows
2338 $hdsize = $cfg_hdsize if $cfg_hdsize < $hdsize;
2340 return $hdsize // 0; # fall back to zero, e.g., if none is selected hdsize cannot be any size
2343 my sub update_hdsize_adjustment
{
2344 my ($adjustment, $hdsize) = @_;
2346 $hdsize = $get_selected_hdsize->($hdsize);
2347 # expect that lower = 0 and step increments = 1 still are valid
2348 $adjustment->set_upper($hdsize + 1);
2349 $adjustment->set_value($hdsize);
2352 my sub create_hdsize_adjustment
{
2354 $hdsize = $get_selected_hdsize->($hdsize);
2355 # params are: initial value, lower, upper, step increment, page increment, page size
2356 return Gtk3
::Adjustment-
>new($config_options->{hdsize
} || $hdsize, 0, $hdsize+1, 1, 1, 1);
2359 my sub get_hdsize_spin_button
{
2362 my $hdsize_entry_buffer = Gtk3
::EntryBuffer-
>new(undef, 1);
2363 my $hdsize_size_adj = create_hdsize_adjustment
($hdsize);
2365 my $spinbutton_hdsize = Gtk3
::SpinButton-
>new($hdsize_size_adj, 1, 1);
2366 $spinbutton_hdsize->set_buffer($hdsize_entry_buffer);
2367 $spinbutton_hdsize->set_adjustment($hdsize_size_adj);
2368 $spinbutton_hdsize->set_tooltip_text("only use specified size (GB) of the harddisk (rest left unpartitioned)");
2369 return $spinbutton_hdsize;
2372 my $create_raid_disk_grid = sub {
2373 my ($hdsize_buttons) = @_;
2375 my $cached_disks = get_cached_disks
();
2376 my $disk_count = scalar(@$cached_disks);
2377 my $disk_labeled_widgets = [];
2378 for (my $i = 0; $i < $disk_count; $i++) {
2379 my $disk_selector = Gtk3
::ComboBoxText-
>new();
2380 $disk_selector->append_text("-- do not use --");
2381 $disk_selector->set_active(0);
2382 $disk_selector->set_visible(1);
2384 for my $hd (@$cached_disks) {
2385 my ($disk, $devname, $size, $model, $logical_bsize) = @$hd;
2386 $disk_selector->append_text(get_device_desc
($devname, $size, $model));
2389 $disk_selector->{pve_disk_id
} = $i;
2390 $disk_selector->signal_connect(changed
=> sub {
2392 my $diskid = $w->{pve_disk_id
};
2393 my $a = $w->get_active - 1;
2394 $config_options->{"disksel${diskid}"} = ($a >= 0) ?
$cached_disks->[$a] : undef;
2395 for my $btn (@$hdsize_buttons) {
2396 update_hdsize_adjustment
($btn->get_adjustment());
2400 if ($hdoption_first_setup) {
2401 $disk_selector->set_active ($i+1) if $cached_disks->[$i];
2404 if (my $cur_hd = $config_options->{"disksel$i"}) {
2405 foreach my $hd (@$cached_disks) {
2406 if (@$hd[1] eq @$cur_hd[1]) {
2407 $disk_selector->set_active($hdind+1);
2415 push @$disk_labeled_widgets, "Harddisk $i", $disk_selector;
2418 my $clear_all_button = Gtk3
::Button-
>new('_Deselect All');
2419 if ($disk_count > 3) {
2420 $clear_all_button->signal_connect('clicked', sub {
2422 for my $disk_selector (@$disk_labeled_widgets) {
2423 $disk_selector->set_active(0) if $is_widget;
2427 $clear_all_button->set_visible(1);
2430 my $scrolled_window = Gtk3
::ScrolledWindow-
>new();
2431 $scrolled_window->set_hexpand(1);
2432 $scrolled_window->set_propagate_natural_height(1) if $disk_count > 4;
2434 my $diskgrid = $create_label_widget_grid->($disk_labeled_widgets);
2436 $scrolled_window->add($diskgrid);
2437 $scrolled_window->set_policy('never', 'automatic');
2438 $scrolled_window->set_visible(1);
2439 $scrolled_window->set_min_content_height(190);
2441 my $vbox = Gtk3
::Box-
>new('vertical', 0);
2442 $vbox->pack_start($scrolled_window, 1, 1, 10);
2444 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
2445 $hbox->pack_end($clear_all_button, 0, 0, 20);
2446 $hbox->set_visible(1);
2447 $vbox->pack_end($hbox, 0, 0, 0);
2452 my $create_raid_advanced_grid = sub {
2453 my ($hdsize_btn) = @_;
2454 my $labeled_widgets = [];
2455 my $spinbutton_ashift = Gtk3
::SpinButton-
>new_with_range(9, 13, 1);
2456 $spinbutton_ashift->set_tooltip_text("zpool ashift property (pool sector size, default 2^12)");
2457 $spinbutton_ashift->signal_connect ("value-changed" => sub {
2459 $config_options->{ashift
} = $w->get_value_as_int();
2461 $config_options->{ashift
} = 12 if ! defined($config_options->{ashift
});
2462 $spinbutton_ashift->set_value($config_options->{ashift
});
2463 push @$labeled_widgets, "ashift";
2464 push @$labeled_widgets, $spinbutton_ashift;
2466 my $combo_compress = Gtk3
::ComboBoxText-
>new();
2467 $combo_compress->set_tooltip_text("zfs compression algorithm for rpool dataset");
2468 my $comp_opts = ["on","off","lzjb","lz4", "zle", "gzip", "zstd"];
2469 foreach my $opt (@$comp_opts) {
2470 $combo_compress->append($opt, $opt);
2472 $config_options->{compress
} = "on" if !defined($config_options->{compress
});
2473 $combo_compress->set_active_id($config_options->{compress
});
2474 $combo_compress->signal_connect (changed
=> sub {
2476 $config_options->{compress
} = $w->get_active_text();
2478 push @$labeled_widgets, "compress";
2479 push @$labeled_widgets, $combo_compress;
2481 my $combo_checksum = Gtk3
::ComboBoxText-
>new();
2482 $combo_checksum->set_tooltip_text("zfs checksum algorithm for rpool dataset");
2483 my $csum_opts = ["on", "off","fletcher2", "fletcher4", "sha256"];
2484 foreach my $opt (@$csum_opts) {
2485 $combo_checksum->append($opt, $opt);
2487 $config_options->{checksum
} = "on" if !($config_options->{checksum
});
2488 $combo_checksum->set_active_id($config_options->{checksum
});
2489 $combo_checksum->signal_connect (changed
=> sub {
2491 $config_options->{checksum
} = $w->get_active_text();
2493 push @$labeled_widgets, "checksum";
2494 push @$labeled_widgets, $combo_checksum;
2496 my $spinbutton_copies = Gtk3
::SpinButton-
>new_with_range(1,3,1);
2497 $spinbutton_copies->set_tooltip_text("zfs copies property for rpool dataset (in addition to RAID redundancy!)");
2498 $spinbutton_copies->signal_connect ("value-changed" => sub {
2500 $config_options->{copies
} = $w->get_value_as_int();
2502 $config_options->{copies
} = 1 if !defined($config_options->{copies
});
2503 $spinbutton_copies->set_value($config_options->{copies
});
2504 push @$labeled_widgets, "copies", $spinbutton_copies;
2506 push @$labeled_widgets, "hdsize", $hdsize_btn;
2507 return $create_label_widget_grid->($labeled_widgets);;
2510 my $create_btrfs_raid_advanced_grid = sub {
2511 my ($hdsize_btn) = @_;
2512 my $labeled_widgets = [];
2513 push @$labeled_widgets, "hdsize", $hdsize_btn;
2514 return $create_label_widget_grid->($labeled_widgets);;
2517 sub create_hdoption_view
{
2518 my $dialog = Gtk3
::Dialog-
>new();
2520 $dialog->set_title("Harddisk options");
2522 $dialog->add_button("_OK", 1);
2524 my $contarea = $dialog->get_content_area();
2526 my $hbox2 = Gtk3
::Box-
>new('horizontal', 0);
2527 $contarea->pack_start($hbox2, 1, 1, 5);
2529 my $grid = Gtk3
::Grid-
>new();
2530 $grid->set_column_spacing(10);
2531 $grid->set_row_spacing(10);
2533 $hbox2->pack_start($grid, 1, 0, 5);
2538 my $label0 = Gtk3
::Label-
>new("Filesystem");
2539 $label0->set_xalign(1.0);
2540 $grid->attach($label0, 0, $row, 1, 1);
2542 my $fstypecb = Gtk3
::ComboBoxText-
>new();
2553 push @$fstype, 'btrfs (RAID0)', 'btrfs (RAID1)', 'btrfs (RAID10)'
2554 if $env->{cfg
}->{enable_btrfs
};
2557 foreach my $tmp (@$fstype) {
2558 $fstypecb->append_text($tmp);
2559 $fstypecb->set_active ($tcount) if $config_options->{filesys
} eq $tmp;
2563 $grid->attach($fstypecb, 1, $row, 1, 1);
2569 my $sep = Gtk3
::Separator-
>new('horizontal');
2570 $sep->set_visible(1);
2571 $grid->attach($sep, 0, $row, 2, 1);
2574 my $hw_raid_note = Gtk3
::Label-
>new(""); # text will be set below, before making it visible
2575 $hw_raid_note->set_line_wrap(1);
2576 $hw_raid_note->set_max_width_chars(30);
2577 $hw_raid_note->set_visible(0);
2578 $grid->attach($hw_raid_note, 0, $row++, 2, 1);
2580 my $hdsize_labeled_widgets = [];
2584 if ( -b
$target_hd) {
2585 $hdsize = int(Proxmox
::Sys
::Block
::hd_size
($target_hd) / (1024 * 1024.0)); # size in GB
2586 } elsif ($target_hd) {
2587 $hdsize = int((-s
$target_hd) / (1024 * 1024 * 1024.0));
2590 my $spinbutton_hdsize_nonraid = get_hdsize_spin_button
($hdsize);
2591 push @$hdsize_labeled_widgets, "hdsize", $spinbutton_hdsize_nonraid;
2592 my $spinbutton_hdsize = $spinbutton_hdsize_nonraid;
2594 my $entry_swapsize = Gtk3
::Entry-
>new();
2595 $entry_swapsize->set_tooltip_text("maximum SWAP size (GB)");
2596 $entry_swapsize->signal_connect (key_press_event
=> \
&check_float
);
2597 $entry_swapsize->set_text($config_options->{swapsize
}) if defined($config_options->{swapsize
});
2598 push @$hdsize_labeled_widgets, "swapsize", $entry_swapsize;
2600 my $entry_maxroot = Gtk3
::Entry-
>new();
2601 if ($env->{product
} eq 'pve') {
2602 $entry_maxroot->set_tooltip_text("maximum size (GB) for LVM root volume");
2603 $entry_maxroot->signal_connect (key_press_event
=> \
&check_float
);
2604 $entry_maxroot->set_text($config_options->{maxroot
}) if $config_options->{maxroot
};
2605 push @$hdsize_labeled_widgets, "maxroot", $entry_maxroot;
2608 my $entry_minfree = Gtk3
::Entry-
>new();
2609 $entry_minfree->set_tooltip_text("minimum free LVM space (GB, required for LVM snapshots)");
2610 $entry_minfree->signal_connect (key_press_event
=> \
&check_float
);
2611 $entry_minfree->set_text($config_options->{minfree
}) if defined($config_options->{minfree
});
2612 push @$hdsize_labeled_widgets, "minfree", $entry_minfree;
2615 if ($env->{product
} eq 'pve') {
2616 $entry_maxvz = Gtk3
::Entry-
>new();
2617 $entry_maxvz->set_tooltip_text("maximum size (GB) for LVM data volume");
2618 $entry_maxvz->signal_connect (key_press_event
=> \
&check_float
);
2619 $entry_maxvz->set_text($config_options->{maxvz
}) if defined($config_options->{maxvz
});
2620 push @$hdsize_labeled_widgets, "maxvz", $entry_maxvz;
2623 my $spinbutton_hdsize_zfs = get_hdsize_spin_button
($hdsize);
2624 my $spinbutton_hdsize_btrfs = get_hdsize_spin_button
($hdsize);
2625 my $hdsize_buttons = [ $spinbutton_hdsize_zfs, $spinbutton_hdsize_btrfs ];
2626 my $options_stack = Gtk3
::Stack-
>new();
2627 $options_stack->set_visible(1);
2628 $options_stack->set_hexpand(1);
2629 $options_stack->set_vexpand(1);
2630 $options_stack->add_titled(&$create_raid_disk_grid($hdsize_buttons), "raiddisk", "Disk Setup");
2631 $options_stack->add_titled(&$create_label_widget_grid($hdsize_labeled_widgets), "hdsize", "Size Options");
2632 $options_stack->add_titled(&$create_raid_advanced_grid($spinbutton_hdsize_zfs), "raidzfsadvanced", "Advanced Options");
2633 $options_stack->add_titled(&$create_btrfs_raid_advanced_grid($spinbutton_hdsize_btrfs), "raidbtrfsadvanced", "Advanced Options");
2634 $options_stack->set_visible_child_name("raiddisk");
2635 my $options_stack_switcher = Gtk3
::StackSwitcher-
>new();
2636 $options_stack_switcher->set_halign('center');
2637 $options_stack_switcher->set_stack($options_stack);
2638 $grid->attach($options_stack_switcher, 0, $row, 2, 1);
2640 $grid->attach($options_stack, 0, $row, 2, 1);
2643 $hdoption_first_setup = 0;
2645 my $switch_view = sub {
2646 my $raid = $config_options->{filesys
} =~ m/zfs|btrfs/;
2647 my $is_zfs = $config_options->{filesys
} =~ m/zfs/;
2649 $target_hd_combo->set_visible(!$raid);
2650 $options_stack->get_child_by_name("hdsize")->set_visible(!$raid);
2651 $options_stack->get_child_by_name("raiddisk")->set_visible($raid);
2654 my $msg = "<b>Note</b>: " . ($is_zfs
2655 ?
"ZFS is not compatible with hardware RAID controllers, for details see the documentation."
2656 : "BTRFS integration in $env->{cfg}->{fullname} is a technology preview!"
2658 $hw_raid_note->set_markup($msg);
2660 $hw_raid_note->set_visible($raid);
2661 $options_stack_switcher->set_visible($raid);
2662 $options_stack->get_child_by_name("raidzfsadvanced")->set_visible($is_zfs);
2663 $options_stack->get_child_by_name("raidbtrfsadvanced")->set_visible(!$is_zfs);
2665 $target_hd_label->set_text("Target: $config_options->{filesys} ");
2666 $options_stack->set_visible_child_name("raiddisk");
2668 $target_hd_label->set_text("Target Harddisk: ");
2672 $spinbutton_hdsize = $is_zfs ?
$spinbutton_hdsize_zfs : $spinbutton_hdsize_btrfs;
2674 $spinbutton_hdsize = $spinbutton_hdsize_nonraid;
2677 my (undef, $pref_width) = $dialog->get_preferred_width();
2678 my (undef, $pref_height) = $dialog->get_preferred_height();
2679 $pref_height = 750 if $pref_height > 750;
2680 $dialog->resize($pref_width, $pref_height);
2685 $fstypecb->signal_connect (changed
=> sub {
2686 $config_options->{filesys
} = $fstypecb->get_active_text();
2690 my $sep2 = Gtk3
::Separator-
>new('horizontal');
2691 $sep2->set_visible(1);
2692 $contarea->pack_end($sep2, 1, 1, 10);
2698 my $get_float = sub {
2701 my $text = $entry->get_text();
2702 return undef if !defined($text);
2707 return undef if $text !~ m/^\d+(\.\d+)?$/;
2714 if (($tmp = &$get_float($spinbutton_hdsize)) && ($tmp != $hdsize)) {
2715 $config_options->{hdsize
} = $tmp;
2717 delete $config_options->{hdsize
};
2720 if (defined($tmp = &$get_float($entry_swapsize))) {
2721 $config_options->{swapsize
} = $tmp;
2723 delete $config_options->{swapsize
};
2726 if (defined($tmp = &$get_float($entry_maxroot))) {
2727 $config_options->{maxroot
} = $tmp;
2729 delete $config_options->{maxroot
};
2732 if (defined($tmp = &$get_float($entry_minfree))) {
2733 $config_options->{minfree
} = $tmp;
2735 delete $config_options->{minfree
};
2738 if ($entry_maxvz && defined($tmp = &$get_float($entry_maxvz))) {
2739 $config_options->{maxvz
} = $tmp;
2741 delete $config_options->{maxvz
};
2747 my $get_raid_devlist = sub {
2749 my $dev_name_hash = {};
2751 my $cached_disks = get_cached_disks
();
2753 for (my $i = 0; $i < @$cached_disks; $i++) {
2754 if (my $hd = $config_options->{"disksel$i"}) {
2755 my ($disk, $devname, $size, $model, $logical_bsize) = @$hd;
2756 die "device '$devname' is used more than once\n"
2757 if $dev_name_hash->{$devname};
2758 $dev_name_hash->{$devname} = $hd;
2759 push @$devlist, $hd;
2766 sub zfs_mirror_size_check
{
2767 my ($expected, $actual) = @_;
2769 die "mirrored disks must have same size\n"
2770 if abs($expected - $actual) > $expected / 10;
2773 sub legacy_bios_4k_check
{
2775 die "Booting from 4kn drive in legacy BIOS mode is not supported.\n"
2776 if $boot_type ne 'efi' && $lbs == 4096;
2779 sub get_zfs_raid_setup
{
2780 my $filesys = $config_options->{filesys
};
2782 my $devlist = &$get_raid_devlist();
2784 my $diskcount = scalar(@$devlist);
2785 die "$filesys needs at least one device\n" if $diskcount < 1;
2788 if ($filesys eq 'zfs (RAID0)') {
2789 foreach my $hd (@$devlist) {
2790 legacy_bios_4k_check
(@$hd[4]);
2793 } elsif ($filesys eq 'zfs (RAID1)') {
2794 die "zfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
2796 my $hd = @$devlist[0];
2797 my $expected_size = @$hd[2]; # all disks need approximately same size
2798 foreach my $hd (@$devlist) {
2799 zfs_mirror_size_check
($expected_size, @$hd[2]);
2800 legacy_bios_4k_check
(@$hd[4]);
2803 } elsif ($filesys eq 'zfs (RAID10)') {
2804 die "zfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
2805 die "zfs (RAID10) needs an even number of devices\n" if $diskcount & 1;
2807 for (my $i = 0; $i < $diskcount; $i+=2) {
2808 my $hd1 = @$devlist[$i];
2809 my $hd2 = @$devlist[$i+1];
2810 zfs_mirror_size_check
(@$hd1[2], @$hd2[2]); # pairs need approximately same size
2811 legacy_bios_4k_check
(@$hd1[4]);
2812 legacy_bios_4k_check
(@$hd2[4]);
2813 $cmd .= ' mirror ' . @$hd1[1] . ' ' . @$hd2[1];
2816 } elsif ($filesys =~ m/^zfs \(RAIDZ-([123])\)$/) {
2818 my $mindisks = 2 + $level;
2819 die "zfs (RAIDZ-$level) needs at least $mindisks devices\n" if scalar(@$devlist) < $mindisks;
2820 my $hd = @$devlist[0];
2821 my $expected_size = @$hd[2]; # all disks need approximately same size
2822 $cmd .= " raidz$level";
2823 foreach my $hd (@$devlist) {
2824 zfs_mirror_size_check
($expected_size, @$hd[2]);
2825 legacy_bios_4k_check
(@$hd[4]);
2829 die "unknown zfs mode '$filesys'\n";
2832 return ($devlist, $cmd);
2835 sub get_btrfs_raid_setup
{
2837 my $filesys = $config_options->{filesys
};
2839 my $devlist = &$get_raid_devlist();
2841 my $diskcount = scalar(@$devlist);
2842 die "$filesys needs at least one device\n" if $diskcount < 1;
2846 if ($diskcount == 1) {
2849 if ($filesys eq 'btrfs (RAID0)') {
2851 } elsif ($filesys eq 'btrfs (RAID1)') {
2852 die "btrfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
2854 } elsif ($filesys eq 'btrfs (RAID10)') {
2855 die "btrfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
2858 die "unknown btrfs mode '$filesys'\n";
2862 return ($devlist, $mode);
2865 my $last_hd_selected = 0;
2866 sub create_hdsel_view
{
2868 $prev_btn->set_sensitive(1); # enable previous button at this point
2872 my $vbox = Gtk3
::Box-
>new('vertical', 0);
2873 $inbox->pack_start($vbox, 1, 0, 0);
2874 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
2875 $vbox->pack_start($hbox, 0, 0, 10);
2877 my $cached_disks = get_cached_disks
();
2878 my ($disk, $devname, $size, $model, $logical_bsize) = $cached_disks->[0]->@*;
2879 $target_hd = $devname if !defined($target_hd);
2881 $target_hd_label = Gtk3
::Label-
>new("Target Harddisk: ");
2882 $hbox->pack_start($target_hd_label, 0, 0, 0);
2884 $target_hd_combo = Gtk3
::ComboBoxText-
>new();
2886 foreach my $hd ($cached_disks->@*) {
2887 ($disk, $devname, $size, $model, $logical_bsize) = @$hd;
2888 $target_hd_combo->append_text(get_device_desc
($devname, $size, $model));
2891 my $raid = $config_options->{filesys
} =~ m/zfs|btrfs/;
2893 $target_hd_label->set_text("Target: $config_options->{filesys} ");
2894 $target_hd_combo->set_visible(0);
2895 $target_hd_combo->set_no_show_all(1);
2897 $target_hd_combo->set_active($last_hd_selected);
2898 $target_hd_combo->signal_connect(changed
=> sub {
2899 $a = shift-
>get_active;
2900 my ($disk, $devname) = @{@$cached_disks[$a]};
2901 $last_hd_selected = $a;
2902 $target_hd = $devname;
2905 $hbox->pack_start($target_hd_combo, 0, 0, 10);
2907 my $options = Gtk3
::Button-
>new('_Options');
2908 $options->signal_connect (clicked
=> \
&create_hdoption_view
);
2909 $hbox->pack_start ($options, 0, 0, 0);
2916 set_next
(undef, sub {
2918 if ($config_options->{filesys
} =~ m/zfs/) {
2919 my ($devlist) = eval { get_zfs_raid_setup
() };
2921 display_message
("Warning: $err\nPlease fix ZFS setup first.");
2924 $config_options->{target_hds
} = [ map { $_->[1] } @$devlist ];
2925 } elsif ($config_options->{filesys
} =~ m/btrfs/) {
2926 my ($devlist) = eval { get_btrfs_raid_setup
() };
2928 display_message
("Warning: $err\nPlease fix BTRFS setup first.");
2931 $config_options->{target_hds
} = [ map { $_->[1] } @$devlist ];
2934 my $target_block_size = Proxmox
::Sys
::Block
::logical_blocksize
($target_hd);
2935 legacy_bios_4k_check
($target_block_size);
2938 display_message
("Warning: $err\n");
2941 $config_options->{target_hds
} = [ $target_hd ];
2945 create_country_view
();
2949 sub create_extract_view
{
2955 $next->set_sensitive(0);
2956 $prev_btn->set_sensitive(0);
2959 my $vbox = Gtk3
::Box-
>new('vertical', 0);
2960 $inbox->pack_start ($vbox, 1, 0, 0);
2961 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
2962 $vbox->pack_start ($hbox, 0, 0, 10);
2964 my $vbox2 = Gtk3
::Box-
>new('vertical', 0);
2965 $hbox->pack_start ($vbox2, 0, 0, 0);
2967 $progress_status = Gtk3
::Label-
>new('');
2968 $vbox2->pack_start ($progress_status, 1, 1, 0);
2970 $progress = Gtk3
::ProgressBar-
>new;
2971 $progress->set_show_text(1);
2972 $progress->set_size_request (600, -1);
2974 $vbox2->pack_start($progress, 0, 0, 0);
2978 my $tdir = is_test_mode
() ?
"target" : "/target";
2980 my $base = "${proxmox_cddir}/$env->{product}-base.squashfs";
2982 eval { extract_data
($base, $tdir); };
2985 $next->set_sensitive(1);
2987 set_next
("_Reboot", sub { app_quit
(0); } );
2990 display_html
("fail.htm");
2991 display_error
($err);
2994 display_html
("success.htm");
2996 if ($config_options->{autoreboot
}) {
2997 Glib
::Timeout-
>add(1000, sub {
2998 if ($autoreboot_seconds > 0) {
2999 $autoreboot_seconds--;
3000 display_html
("success.htm");
3009 sub create_intro_view
{
3011 $prev_btn->set_sensitive(0);
3015 if (int($total_memory) < 1024) {
3016 display_error
("Less than 1 GiB of usable memory detected, installation will probably fail.\n\n".
3017 "See 'System Requirements' in the $env->{cfg}->{fullname} documentation.");
3020 if ($env->{product
} eq 'pve') {
3021 my $cpuinfo = eval { file_read_all
('/proc/cpuinfo') };
3022 if (!$cpuinfo || $cpuinfo !~ /^flags\s*:.*(vmx|svm)/m) {
3024 "No support for hardware-accelerated KVM virtualization detected.\n\n"
3025 ."Check BIOS settings for Intel VT / AMD-V / SVM."
3033 set_next
("I a_gree", \
&create_hdsel_view
);
3036 $ipconf = Proxmox
::Sys
::Net
::get_ip_config
();
3038 $country = detect_country
() if $ipconf->{default} || is_test_mode
();
3040 if (!defined($env->{locales
}->{country
}->{$country})) {
3041 log_warn
("ignoring detected country '$country', invalid or unknown\n");
3047 create_main_window
();
3049 my $initial_error = 0;
3052 my $cached_disks = get_cached_disks
();
3053 if (!defined($cached_disks) || (scalar (@$cached_disks) <= 0)) {
3054 print "no harddisks found\n";
3056 display_html
("nohds.htm");
3057 set_next
("Reboot", sub { app_quit
(0); } );
3059 foreach my $hd (@$cached_disks) {
3060 my ($disk, $devname) = @$hd;
3061 next if $devname =~ m
|^/dev/md\d
+$|;
3062 print "found Disk$disk N:$devname\n";
3067 if (!$initial_error && (scalar keys %{ $ipconf->{ifaces
} } == 0)) {
3068 print "no network interfaces found\n";
3070 display_html
("nonics.htm");
3071 set_next
("Reboot", sub { app_quit
(0); } );
3074 create_intro_view
() if !$initial_error;