6 $ENV{DEBIAN_FRONTEND
} = 'noninteractive';
20 use POSIX
":sys_wait_h";
22 use Proxmox
::Install
::Env
;
24 use Proxmox
::Sys
::Block
qw(get_cached_disks);
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
::Env
::set_test_image
($test_image) if $test_image;
42 $ENV{'LVM_SUPPRESS_FD_WARNINGS'} = '1';
44 my $env = Proxmox
::Install
::Env
::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 = is_test_mode
()
92 ? Cwd
::cwd
() . "/testdir/var/lib/proxmox-installer"
93 : "/var/lib/proxmox-installer"
95 my $proxmox_cddir = is_test_mode
() ?
"../pve-cd-builder/tmp/data-gz/" : "/cdrom";
96 my $proxmox_pkgdir = "${proxmox_cddir}/proxmox/packages/";
98 my $boot_type = -d
'/sys/firmware/efi' ?
'efi' : 'bios';
100 my $step_number = 0; # Init number for global function list
105 html
=> 'license.htm',
106 next_button
=> 'I a_gree',
107 function
=> \
&create_intro_view
,
112 function
=> \
&create_hdsel_view
,
116 html
=> 'country.htm',
117 function
=> \
&create_country_view
,
121 html
=> 'passwd.htm',
122 function
=> \
&create_password_view
,
126 html
=> 'ipconf.htm',
127 function
=> \
&create_ipconf_view
,
132 next_button
=> '_Install',
133 function
=> \
&create_ack_view
,
137 next_button
=> '_Reboot',
138 function
=> \
&create_extract_view
,
142 # GUI global variables
143 my ($window, $cmdbox, $inbox, $htmlview);
145 my ($next, $next_fctn, $target_hd);
146 my ($progress, $progress_status);
148 my ($ipversion, $ipaddress, $cidr, $ipconf_entry_addr);
149 my ($netmask, $ipconf_entry_mask);
150 my ($gateway, $ipconf_entry_gw);
151 my ($dnsserver, $ipconf_entry_dns);
152 my $hostname = 'proxmox';
153 my $domain = 'domain.tld';
154 my $cmdline = file_read_firstline
("/proc/cmdline");
157 my $timezone = 'Europe/Vienna';
158 my $keymap = 'en-us';
160 my $mailto = 'mail@example.invalid';
162 my $autoreboot_seconds = 5;
165 # TODO: add all the user-provided options for previous button
167 timezone
=> $timezone,
170 password
=> $password,
174 hostname
=> $hostname,
181 # parse command line args
183 my $config_options = {
187 if ($cmdline =~ m/\s(ext4|xfs)(\s.*)?$/) {
188 $config_options->{filesys
} = $1;
190 $config_options->{filesys
} = 'ext4';
193 if ($cmdline =~ m/hdsize=(\d+(\.\d+)?)[\s\n]/i) {
194 $config_options->{hdsize
} = $1;
197 if ($cmdline =~ m/swapsize=(\d+(\.\d+)?)[\s\n]/i) {
198 $config_options->{swapsize
} = $1;
201 if ($cmdline =~ m/maxroot=(\d+(\.\d+)?)[\s\n]/i) {
202 $config_options->{maxroot
} = $1;
205 if ($cmdline =~ m/minfree=(\d+(\.\d+)?)[\s\n]/i) {
206 $config_options->{minfree
} = $1;
209 if ($env->{product
} eq 'pve') {
210 if ($cmdline =~ m/maxvz=(\d+(\.\d+)?)[\s\n]/i) {
211 $config_options->{maxvz
} = $1;
215 my $postfix_main_cf = <<_EOD;
216 # See /usr/share/postfix/main.cf.dist for a commented, more complete version
220 smtpd_banner = \$myhostname ESMTP \$mail_name (Debian/GNU)
223 # appending .domain is the MUA's job.
224 append_dot_mydomain = no
226 # Uncomment the next line to generate "delayed mail" warnings
227 #delay_warning_time = 4h
229 alias_maps = hash:/etc/aliases
230 alias_database = hash:/etc/aliases
231 mydestination = \$myhostname, localhost.\$mydomain, localhost
233 mynetworks = 127.0.0.0/8
234 inet_interfaces = loopback-only
235 recipient_delimiter = +
237 compatibility_level = 2
244 print "trying to detect country...\n";
245 my $cpid = open2
(\
*TMP
, undef, "traceroute -N 1 -q 1 -n 8.8.8.8");
246 return undef if !$cpid;
250 my $previous_alarm = alarm (10);
252 local $SIG{ALRM
} = sub { die "timed out!\n" };
254 while (defined ($line = <TMP
>)) {
255 log_debug
("DC TRACEROUTE: $line");
256 if ($line =~ m/\s*\d+\s+(\d+\.\d+\.\d+\.\d+)\s/) {
257 my $geoip = `geoiplookup $1`;
258 log_debug("DC GEOIP: $geoip");
259 if ($geoip =~ m/GeoIP Country Edition:\s*([A-Z]+),/) {
261 log_info("DC FOUND: $country\n");
270 alarm ($previous_alarm);
275 print "unable to detect country - $err\n";
277 print "detected country: " . uc($country) . "\n";
279 print "unable to detect country\n";
287 open (my $MEMINFO, '<', '/proc/meminfo');
289 my $res = 512; # default to 512 if something goes wrong
290 while (my $line = <$MEMINFO>) {
291 if ($line =~ m/^MemTotal:\s+(\d+)\s*kB/i) {
292 $res = int ($1 / 1024);
301 my $total_memory = get_memtotal();
304 my $countryfn = "${proxmox_libdir}/country.dat";
305 open (my $TMP, "<:encoding(utf8)", "$countryfn") || die "unable to open '$countryfn' - $!\n";
306 my ($country, $countryhash, $kmap, $kmaphash) = ({}, {}, {}, {});
307 while (defined (my $line = <$TMP>)) {
308 if ($line =~ m|^map:([^\s:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]*):$|) {
316 $kmaphash->{$2} = $1;
317 } elsif ($line =~ m|^([a-z]{2}):([^:]+):([^:]*):([^:]*):$|) {
323 $countryhash->{lc($2)} = $1;
325 warn "unable to parse 'country.dat' line: $line";
333 my $zonefn = "/usr/share/zoneinfo/zone.tab";
334 open ($TMP, '<', "$zonefn") || die "unable to open '$zonefn' - $!\n";
335 while (defined (my $line = <$TMP>)) {
336 next if $line =~ m/^\#/;
337 next if $line =~ m/^\s*$/;
338 if ($line =~ m|^([A-Z][A-Z])\s+\S+\s+(([^/]+)/\S+)\s|) {
340 $cczones->{$cc}->{$2} = 1;
341 $country->{$cc}->{zone} = $2 if !defined ($country->{$cc}->{zone});
352 countryhash => $countryhash,
354 kmaphash => $kmaphash,
358 sub update_progress {
359 my ($frac, $start, $end, $text) = @_;
361 my $part = $end - $start;
362 my $res = $start + $frac * $part;
364 $progress->set_fraction ($res);
365 $progress->set_text (sprintf ("%d%%", int ($res*100)));
366 $progress_status->set_text ($text) if defined ($text);
368 display_info() if $res < 0.9;
370 Gtk3::main_iteration() while Gtk3::events_pending();
375 mkfs => 'mkfs.ext4 -F',
377 mkfs_data_opt => '-m 0',
378 root_mountopt => 'errors=remount-ro',
381 mkfs => 'mkfs.xfs -f',
388 sub create_filesystem {
389 my ($dev, $name, $type, $start, $end, $fs, $fe) = @_;
391 my $range = $end - $start;
392 my $rs = $start + $range*$fs;
393 my $re = $start + $range*$fe;
396 my $fsdata = $fssetup->{$type} || die "internal error - unknown file system '$type'";
397 my $opts = $name eq 'root' ? $fsdata->{mkfs_root_opt} : $fsdata->{mkfs_data_opt};
399 update_progress(0, $rs, $re, "creating $name filesystem");
401 run_command("$fsdata->{mkfs} $opts $dev", sub {
404 if ($line =~ m/Writing inode tables:\s+(\d+)\/(\d+)/) {
406 } elsif ($max && $line =~ m/(\d+)\/$max/) {
407 update_progress(($1/$max)*0.9, $rs, $re);
408 } elsif ($line =~ m/Creating journal.*done/) {
409 update_progress(0.95, $rs, $re);
410 } elsif ($line =~ m/Writing superblocks and filesystem.*done/) {
411 update_progress(1, $rs, $re);
417 my ($targetdir, $dcdata) = @_;
419 my $cfgfile = "/tmp/debconf.txt";
420 file_write_all("$targetdir/$cfgfile", $dcdata);
421 syscmd("chroot $targetdir debconf-set-selections $cfgfile");
422 unlink "$targetdir/$cfgfile";
426 my ($targetdir, $cmd, $new_cmd) = @_;
428 syscmd("chroot $targetdir dpkg-divert --package proxmox --add --rename $cmd") == 0
429 || die "unable to exec dpkg-divert\n";
431 syscmd("ln -sf ${new_cmd} $targetdir/$cmd") == 0
432 || die "unable to link diversion to ${new_cmd}\n";
435 sub diversion_remove {
436 my ($targetdir, $cmd) = @_;
438 syscmd("mv $targetdir/${cmd}.distrib $targetdir/${cmd};") == 0
439 || die "unable to remove $cmd diversion\n";
441 syscmd("chroot $targetdir dpkg-divert --remove $cmd") == 0
442 || die "unable to remove $cmd diversion\n";
446 my ($partitions, $mode) = @_;
448 die "unknown btrfs mode '$mode'"
449 if !($mode eq 'single' || $mode eq 'raid0' || $mode eq 'raid1' || $mode eq 'raid10');
451 my $cmd = ['mkfs.btrfs', '-f'];
453 push @$cmd, '-d', $mode, '-m', $mode;
455 push @$cmd, @$partitions;
460 sub zfs_create_rpool {
463 my $cmd = "zpool create -f -o cachefile=none";
465 $cmd .= " -o ashift=$config_options->{ashift}"
466 if defined($config_options->{ashift});
468 syscmd("$cmd $zfspoolname $vdev") == 0 ||
469 die "unable to create zfs root pool\n";
471 syscmd("zfs create $zfspoolname/ROOT") == 0 ||
472 die "unable to create zfs $zfspoolname/ROOT volume\n";
474 if ($env->{product} eq 'pve') {
475 syscmd("zfs create $zfspoolname/data") == 0 ||
476 die "unable to create zfs $zfspoolname/data volume\n";
479 syscmd("zfs create $zfspoolname/ROOT/$zfsrootvolname") == 0 ||
480 die "unable to create zfs $zfspoolname/ROOT/$zfsrootvolname volume\n";
482 # default to `relatime
` on, fast enough for the installer and production
483 syscmd("zfs set atime=on relatime=on $zfspoolname") == 0 ||
484 die "unable to set zfs properties\n";
486 my $value = $config_options->{compress};
487 syscmd("zfs set compression=$value $zfspoolname")
488 if defined($value) && $value ne 'off';
490 $value = $config_options->{checksum};
491 syscmd("zfs set checksum=$value $zfspoolname")
492 if defined($value) && $value ne 'on';
494 $value = $config_options->{copies};
495 syscmd("zfs set copies=$value $zfspoolname")
496 if defined($value) && $value != 1;
499 sub get_pv_list_from_vgname {
509 my ($pv, $vg_uuid) = split(/\s+/, $line);
511 if (!defined($res->{$vg_uuid}->{pvs})) {
512 $res->{$vg_uuid}->{pvs} = "$pv";
514 $res->{$vg_uuid}->{pvs} .= ", $pv";
517 run_command("pvs --noheadings -o pv_name,vg_uuid -S vg_name='$vgname'", $parser, undef, 1);
522 sub ask_existing_vg_rename_or_abort {
525 # this normally only happens if one put a disk with a PVE installation in
526 # this server and that disk is not the installation target.
527 my $duplicate_vgs = get_pv_list_from_vgname($vgname);
528 return if !$duplicate_vgs;
530 my $message = "Detected existing '$vgname' Volume Group(s)! Do you want to:\n";
532 for my $vg_uuid (keys %$duplicate_vgs) {
533 my $vg = $duplicate_vgs->{$vg_uuid};
535 # no high randomnes properties, but this is only for the cases where
536 # we either have multiple "$vgname" vgs from multiple old PVE disks, or
537 # we have a disk with both a "$vgname" and "$vgname-old"...
538 my $short_uid = sprintf "%08X", rand(0xffffffff);
539 $vg->{new_vgname} = "$vgname-OLD-$short_uid";
541 $message .= "rename VG backed by PV '$vg->{pvs}' to '$vg->{new_vgname}'\n";
543 $message .= "or cancel the installation?";
545 my $response = display_prompt($message);
547 if ($response eq 'ok') {
548 for my $vg_uuid (keys %$duplicate_vgs) {
549 my $vg = $duplicate_vgs->{$vg_uuid};
550 my $new_vgname = $vg->{new_vgname};
552 syscmd("vgrename $vg_uuid $new_vgname") == 0 ||
553 die "could not rename VG from '$vg->{pvs}' ($vg_uuid) to '$new_vgname'!\n";
556 set_next("_Reboot", sub { exit (0); } );
557 display_html("fail.htm");
558 die "Cancled installation by user, due to already existing volume group '$vgname'\n";
562 sub create_lvm_volumes {
563 my ($lvmdev, $os_size, $swap_size) = @_;
565 my $vgname = $env->{product};
567 ask_existing_vg_rename_or_abort($vgname);
569 my $rootdev = "/dev/$vgname/root";
570 my $datadev = "/dev/$vgname/data";
573 # we use --metadatasize 250k, which results in "pe_start = 512"
574 # so pe_start is aligned on a 128k boundary (advantage for SSDs)
575 syscmd("/sbin/pvcreate --metadatasize 250k -y -ff $lvmdev") == 0 ||
576 die "unable to initialize physical volume $lvmdev\n";
577 syscmd("/sbin/vgcreate $vgname $lvmdev") == 0 ||
578 die "unable to create volume group '$vgname'\n";
580 my $hdgb = int($os_size / (1024 * 1024));
582 # always leave some space at the end to avoid roudning issues with LVM's physical extent (PE)
584 my $space = $hdgb <= 32 ? 4 * 1024 : (($hdgb > 128 ? 16 : $hdgb / 8) * 1024 * 1024);
589 if ($env->{product} eq 'pve') {
592 if ($config_options->{maxroot}) {
593 $maxroot_mb = $config_options->{maxroot} * 1024;
595 $maxroot_mb = 96 * 1024;
598 my $rest = $os_size - $swap_size;
599 my $rest_mb = int($rest / 1024);
602 if ($rest_mb < 12 * 1024) {
603 # no point in wasting space, try to get us actually installed and align down to 4 MB
604 $rootsize_mb = ($rest_mb - 0.1) & ~3;
605 } elsif ($rest_mb < 48 * 1024) {
606 my $masked = int($rest_mb / 2) & ~3; # align down to 4 MB
607 $rootsize_mb = $masked;
609 $rootsize_mb = $rest_mb / 4 + 12 * 1024;
612 $rootsize_mb = $maxroot_mb if $rootsize_mb > $maxroot_mb;
613 $rootsize = int($rootsize_mb * 1024);
615 $rest -= $rootsize; # in KB
617 my $minfree = $space;
618 if (defined(my $cfg_minfree = $config_options->{minfree})) {
619 $minfree = $cfg_minfree * 1024 * 1024 >= $rest ? $space : $cfg_minfree * 1024 * 1024;
622 $rest = int($rest - $minfree) & ~0xFFF; # align down to 4 MB boundaries
624 if (defined(my $maxvz = $config_options->{maxvz})) {
625 $rest = $maxvz * 1024 * 1024 <= $rest ? $maxvz * 1024 * 1024 : $rest;
631 my $minfree = defined($config_options->{minfree}) ? $config_options->{minfree}*1024*1024 : $space;
632 $rootsize = int($os_size - $minfree - $swap_size); # in KB
633 $rootsize &= ~0xFFF; # align down to 4 MB boundaries
637 syscmd("/sbin/lvcreate -Wy --yes -L${swap_size}K -nswap $vgname") == 0 ||
638 die "unable to create swap volume\n";
640 $swapfile = "/dev/$vgname/swap";
643 syscmd("/sbin/lvcreate -Wy --yes -L${rootsize}K -nroot $vgname") == 0 ||
644 die "unable to create root volume\n";
646 if ($datasize > 4 * 1024 * 1024) {
647 my $metadatasize = $datasize/100; # default 1% of data
648 $metadatasize = 1024*1024 if $metadatasize < 1024*1024; # but at least 1G
649 $metadatasize = 16*1024*1024 if $metadatasize > 16*1024*1024; # but at most 16G
651 # otherwise the metadata is taken out of $minfree
652 $datasize -= 2 * $metadatasize;
654 # 1 4MB PE to allow for rounding
655 $datasize -= 4 * 1024;
657 syscmd("/sbin/lvcreate -Wy --yes -L${datasize}K -ndata $vgname") == 0 ||
658 die "unable to create data volume\n";
660 syscmd("/sbin/lvconvert --yes --type thin-pool --poolmetadatasize ${metadatasize}K $vgname/data") == 0 ||
661 die "unable to create data thin-pool\n";
663 if ($env->{product} eq 'pve' && !defined($config_options->{maxvz})) {
664 display_message("Skipping auto-creation of LVM thinpool for guest data due to low space.");
669 syscmd("/sbin/vgchange -a y $vgname") == 0 ||
670 die "unable to activate volume group\n";
672 return ($rootdev, $swapfile, $datadev);
675 sub compute_swapsize {
678 my $hdgb = int($hdsize/(1024*1024));
681 if (defined($config_options->{swapsize})) {
682 $swapsize_kb = $config_options->{swapsize} * 1024 * 1024;
684 my $ss = int($total_memory);
685 $ss = 4096 if $ss < 4096 && $hdgb >= 64;
686 $ss = 2048 if $ss < 2048 && $hdgb >= 32;
687 $ss = 1024 if $ss >= 2048 && $hdgb <= 16;
688 $ss = 512 if $ss < 512;
689 $ss = int($hdgb * 128) if $ss > $hdgb * 128;
690 $ss = 8192 if $ss > 8192;
691 $swapsize_kb = int($ss * 1024) & ~0xFFF; # align to 4 MB to avoid all to odd SWAP size
697 my sub chroot_chown {
698 my ($root, $path, %param) = @_;
700 my $recursive = $param{recursive} ? ' -R' : '';
701 my $user = $param{user};
702 die "can not chown without user parameter\n" if !defined($user);
703 my $group = $param{group} // $user;
705 syscmd("chroot $root /bin/chown $user:$group $recursive $path") == 0 ||
706 die "chroot: unable to change owner for '$path'\n";
709 my sub chroot_chmod {
710 my ($root, $path, %param) = @_;
712 my $recursive = $param{recursive} ? ' -R' : '';
713 my $mode = $param{mode};
714 die "can not chmod without mode parameter\n" if !defined($mode);
716 syscmd("chroot $root /bin/chmod $mode $recursive $path") == 0 ||
717 die "chroot: unable to change permission mode for '$path'\n";
720 sub prepare_proxmox_boot_esp {
721 my ($espdev, $targetdir) = @_;
723 syscmd("chroot $targetdir proxmox-boot-tool init $espdev") == 0 ||
724 die "unable to init ESP and install proxmox-boot loader on '$espdev'\n";
727 sub prepare_grub_efi_boot_esp {
728 my ($dev, $espdev, $targetdir) = @_;
730 syscmd("mount -n $espdev -t vfat $targetdir/boot/efi") == 0 ||
731 die "unable to mount $espdev\n";
734 my $rc = syscmd("chroot $targetdir /usr/sbin/grub-install --target x86_64-efi --no-floppy --bootloader-id='proxmox' $dev");
736 if ($boot_type eq 'efi') {
737 die "unable to install the EFI boot loader on '$dev'\n";
739 warn "unable to install the EFI boot loader on '$dev', ignoring (not booted using UEFI)\n";
742 # also install fallback boot file (OVMF does not boot without)
743 mkdir("$targetdir/boot/efi/EFI/BOOT");
744 syscmd("cp $targetdir/boot/efi/EFI/proxmox/grubx64.efi $targetdir/boot/efi/EFI/BOOT/BOOTx64.EFI") == 0 ||
745 die "unable to copy efi boot loader\n";
750 syscmd("umount $targetdir/boot/efi") == 0 ||
751 die "unable to umount $targetdir/boot/efi\n";
755 die "failed to prepare EFI boot using Grub on '$espdev': $err" if $err;
759 my ($basefile, $targetdir) = @_;
761 die "target '$targetdir' does not exist\n" if ! -d $targetdir;
763 my $starttime = [Time::HiRes::gettimeofday];
765 my $bootdevinfo = [];
774 my $filesys = $config_options->{filesys};
776 if ($filesys =~ m/zfs/) {
777 $target_hd = undef; # do not use this config
779 $targetdir = "/$zfspoolname/ROOT/$zfsrootvolname";
780 } elsif ($filesys =~ m/btrfs/) {
781 $target_hd = undef; # do not use this config
787 for ($i = 5; $i > 0; $i--) {
788 syscmd("modprobe zfs");
789 last if -c "/dev/zfs";
793 die "unable to load zfs kernel module\n" if !$i;
801 update_progress(0, 0, $maxper, "cleanup root-disks");
803 syscmd("vgchange -an") if !is_test_mode(); # deactivate all detected VGs
805 if (is_test_mode()) {
807 my $test_images = Proxmox::Install::Env::get_test_images();
808 $rootdev = abs_path($test_images->[0]); # FIXME: use all selected for test too!
809 syscmd("umount $rootdev");
813 die "unsupported btrfs mode (for testing environment)\n"
814 if $filesys ne 'btrfs (RAID0)';
816 btrfs_create([$rootdev], 'single');
820 die "unsupported zfs mode (for testing environment)\n"
821 if $filesys ne 'zfs (RAID0)';
823 syscmd("zpool destroy $zfstestpool");
825 zfs_create_rpool($rootdev);
832 } elsif ($use_btrfs) {
834 my ($devlist, $btrfs_mode) = get_btrfs_raid_setup();
836 foreach my $hd (@$devlist) {
840 update_progress(0, 0.02, $maxper, "create partitions");
842 my $btrfs_partitions = [];
843 foreach my $hd (@$devlist) {
844 my $devname = @$hd[1];
845 my $logical_bsize = @$hd[4];
847 my ($size, $osdev, $efidev) = partition_bootable_disk(
848 $devname, $config_options->{hdsize}, '8300');
849 $rootdev = $osdev if !defined($rootdev); # simply point to first disk
850 my $by_id = Proxmox::Sys::Block::get_disk_by_id_path($devname);
851 push @$bootdevinfo, {
856 logical_bsize => $logical_bsize,
858 push @$btrfs_partitions, $osdev;
861 Proxmox::Sys::Block::udevadm_trigger_block();
863 update_progress(0, 0.03, $maxper, "create btrfs");
865 btrfs_create($btrfs_partitions, $btrfs_mode);
869 my ($devlist, $vdev) = get_zfs_raid_setup();
871 foreach my $hd (@$devlist) {
875 update_progress(0, 0.02, $maxper, "create partitions");
877 # install esp/boot part on all, we can only win!
878 for my $hd (@$devlist) {
879 my $devname = @$hd[1];
880 my $logical_bsize = @$hd[4];
882 my ($size, $osdev, $efidev) =
883 partition_bootable_disk($devname, $config_options->{hdsize}, 'BF01');
885 push @$bootdevinfo, {
889 logical_bsize => $logical_bsize,
893 Proxmox::Sys::Block::udevadm_trigger_block();
895 foreach my $di (@$bootdevinfo) {
896 my $devname = $di->{devname};
897 $di->{by_id} = Proxmox::Sys::Block::get_disk_by_id_path($devname);
899 my $osdev = Proxmox::Sys::Block::get_disk_by_id_path($di->{osdev}) || $di->{osdev};
901 $vdev =~ s/ $devname/ $osdev/;
904 foreach my $hd (@$devlist) {
905 my $devname = @$hd[1];
906 my $by_id = Proxmox::Sys::Block::get_disk_by_id_path($devname);
908 $vdev =~ s/ $devname/ $by_id/ if $by_id;
911 update_progress(0, 0.03, $maxper, "create rpool");
913 zfs_create_rpool($vdev);
917 die "target '$target_hd' is not a valid block device\n" if ! -b $target_hd;
919 wipe_disk($target_hd);
921 update_progress(0, 0.02, $maxper, "create partitions");
923 my $logical_bsize = logical_blocksize($target_hd);
925 my ($os_size, $osdev, $efidev) =
926 partition_bootable_disk($target_hd, $config_options->{hdsize}, '8E00');
928 Proxmox::Sys::Block::udevadm_trigger_block();
930 my $by_id = Proxmox::Sys::Block::get_disk_by_id_path($target_hd);
931 push @$bootdevinfo, {
933 devname => $target_hd,
936 logical_bsize => $logical_bsize,
939 update_progress(0, 0.03, $maxper, "create LVs");
941 my $swap_size = compute_swapsize($os_size);
942 ($rootdev, $swapfile, $datadev) =
943 create_lvm_volumes($osdev, $os_size, $swap_size);
945 # trigger udev to create /dev/disk/by-uuid
946 Proxmox::Sys::Block::udevadm_trigger_block(1);
950 # to be fast during installation
951 syscmd("zfs set sync=disabled $zfspoolname") == 0 ||
952 die "unable to set zfs properties\n";
955 update_progress(0.04, 0, $maxper, "create swap space");
957 syscmd("mkswap -f $swapfile") == 0 ||
958 die "unable to create swap space\n";
961 update_progress(0.045, 0, $maxper, "creating root filesystems");
963 foreach my $di (@$bootdevinfo) {
965 # FIXME remove '-s1' once https://github.com/dosfstools/dosfstools/issues/111 is fixed
966 my $vfat_extra_opts = ($di->{logical_bsize} == 4096) ? '-s1' : '';
967 syscmd("mkfs.vfat $vfat_extra_opts -F32 $di->{esp}") == 0 ||
968 die "unable to initialize EFI ESP on device $di->{esp}\n";
973 } elsif ($use_btrfs) {
976 create_filesystem($rootdev, 'root', $filesys, 0.05, $maxper, 0, 1);
979 update_progress(1, 0.05, $maxper, "mounting target $rootdev");
984 my $mount_opts = 'noatime';
985 $mount_opts .= ',nobarrier'
986 if $use_btrfs || $filesys =~ /^ext\d$/;
988 syscmd("mount -n $rootdev -o $mount_opts $targetdir") == 0 ||
989 die "unable to mount $rootdev\n";
992 mkdir "$targetdir/boot";
993 mkdir "$targetdir/boot/efi";
995 mkdir "$targetdir/var";
996 mkdir "$targetdir/var/lib";
998 if ($env->{product} eq 'pve') {
999 mkdir "$targetdir/var/lib/vz";
1000 mkdir "$targetdir/var/lib/pve";
1003 syscmd("btrfs subvolume create $targetdir/var/lib/pve/local-btrfs") == 0 ||
1004 die "unable to create btrfs subvolume\n";
1008 mkdir "$targetdir/mnt";
1009 mkdir "$targetdir/mnt/hostrun";
1010 syscmd("mount --bind /run $targetdir/mnt/hostrun") == 0 ||
1011 die "unable to bindmount run on $targetdir/mnt/hostrun\n";
1013 update_progress(1, 0.05, $maxper, "extracting base system");
1015 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = stat ($basefile);
1016 $ino || die "unable to open file '$basefile' - $!\n";
1018 my $files = file_read_firstline("${proxmox_cddir}/proxmox/$env->{product}-base.cnt") ||
1019 die "unable to read base file count\n";
1024 run_command("unsquashfs -f -dest $targetdir -i $basefile", sub {
1026 return if $line !~ m/^$targetdir/;
1028 my $nper = int (($count *100)/$files);
1029 if ($nper != $per) {
1031 my $frac = $per > 100 ? 1 : $per/100;
1032 update_progress($frac, $maxper, 0.5);
1036 syscmd("mount -n -t tmpfs tmpfs $targetdir/tmp") == 0 || die "unable to mount tmpfs on $targetdir/tmp\n";
1038 mkdir "$targetdir/tmp/pkg";
1039 syscmd("mount -n --bind '$proxmox_pkgdir' '$targetdir/tmp/pkg'") == 0
1040 || die "unable to bind-mount packages on $targetdir/tmp/pkg\n";
1041 syscmd("mount -n -t proc proc $targetdir/proc") == 0 || die "unable to mount proc on $targetdir/proc\n";
1042 syscmd("mount -n -t sysfs sysfs $targetdir/sys") == 0 || die "unable to mount sysfs on $targetdir/sys\n";
1043 if ($boot_type eq 'efi') {
1044 syscmd("mount -n -t efivarfs efivarfs $targetdir/sys/firmware/efi/efivars") == 0 ||
1045 die "unable to mount efivarfs on $targetdir/sys/firmware/efi/efivars: $!\n";
1047 syscmd("chroot $targetdir mount --bind /mnt/hostrun /run") == 0 ||
1048 die "unable to re-bindmount hostrun on /run in chroot\n";
1050 update_progress(1, $maxper, 0.5, "configuring base system");
1055 "127.0.0.1 localhost.localdomain localhost\n" .
1056 "$ipaddress $hostname.$domain $hostname\n\n" .
1057 "# The following lines are desirable for IPv6 capable hosts\n\n" .
1058 "::1 ip6-localhost ip6-loopback\n" .
1059 "fe00::0 ip6-localnet\n" .
1060 "ff00::0 ip6-mcastprefix\n" .
1061 "ff02::1 ip6-allnodes\n" .
1062 "ff02::2 ip6-allrouters\n" .
1063 "ff02::3 ip6-allhosts\n";
1065 file_write_all("$targetdir/etc/hosts", $hosts);
1067 file_write_all("$targetdir/etc/hostname", "$hostname\n");
1069 syscmd("/bin/hostname $hostname") if !is_test_mode();
1071 # configure interfaces
1073 my $ifaces = "auto lo\niface lo inet loopback\n\n";
1075 my $ntype = $ipversion == 4 ? 'inet' : 'inet6';
1077 my $ethdev = $ipconf->{ifaces}->{$ipconf->{selected}}->{name};
1079 if ($env->{cfg}->{bridged_network}) {
1080 $ifaces .= "iface $ethdev $ntype manual\n";
1083 "\nauto vmbr0\niface vmbr0 $ntype static\n" .
1084 "\taddress $cidr\n" .
1085 "\tgateway $gateway\n" .
1086 "\tbridge-ports $ethdev\n" .
1087 "\tbridge-stp off\n" .
1090 $ifaces .= "auto $ethdev\n" .
1091 "iface $ethdev $ntype static\n" .
1092 "\taddress $cidr\n" .
1093 "\tgateway $gateway\n";
1096 foreach my $iface (sort keys %{$ipconf->{ifaces}}) {
1097 my $name = $ipconf->{ifaces}->{$iface}->{name};
1098 next if $name eq $ethdev;
1100 $ifaces .= "\niface $name $ntype manual\n";
1103 file_write_all("$targetdir/etc/network/interfaces", $ifaces);
1107 my $resolvconf = "search $domain\nnameserver $dnsserver\n";
1108 file_write_all("$targetdir/etc/resolv.conf", $resolvconf);
1112 my $fstab = "# <file system> <mount point> <type> <options> <dump> <pass>\n";
1116 } elsif ($use_btrfs) {
1118 my $cmd = "blkid -u filesystem -t TYPE=btrfs -o export $rootdev";
1119 run_command($cmd, sub {
1122 if ($line =~ m/^UUID=([A-Fa-f0-9\-]+)$/) {
1127 die "unable to detect FS UUID" if !defined($fsuuid);
1129 $fstab .= "UUID=$fsuuid / btrfs defaults 0 1\n";
1131 my $root_mountopt = $fssetup->{$filesys}->{root_mountopt} || 'defaults';
1132 $fstab .= "$rootdev / $filesys ${root_mountopt} 0 1\n";
1136 # Note: this is required by current grub, but really dangerous, because
1137 # vfat does not have journaling, so it triggers manual fsck after each crash
1138 # so we only mount /boot/efi if really required (efi systems).
1139 if ($boot_type eq 'efi' && !$use_zfs) {
1140 if (scalar(@$bootdevinfo)) {
1141 my $di = @$bootdevinfo[0]; # simply use first disk
1144 my $efi_boot_uuid = $di->{esp};
1145 if (my $uuid = Proxmox::Sys::Block::get_dev_uuid($di->{esp})) {
1146 $efi_boot_uuid = "UUID=$uuid";
1149 $fstab .= "${efi_boot_uuid} /boot/efi vfat defaults 0 1\n";
1155 $fstab .= "$swapfile none swap sw 0 0\n" if $swapfile;
1157 $fstab .= "proc /proc proc defaults 0 0\n";
1159 file_write_all("$targetdir/etc/fstab", $fstab);
1160 file_write_all("$targetdir/etc/mtab", "");
1162 syscmd("cp ${proxmox_libdir}/policy-disable-rc.d " .
1163 "$targetdir/usr/sbin/policy-rc.d") == 0 ||
1164 die "unable to copy policy-rc.d\n";
1165 syscmd("cp ${proxmox_libdir}/fake-start-stop-daemon " .
1166 "$targetdir/sbin/") == 0 ||
1167 die "unable to copy start-stop-daemon\n";
1169 diversion_add($targetdir, "/sbin/start-stop-daemon", "/sbin/fake-start-stop-daemon");
1170 diversion_add($targetdir, "/usr/sbin/update-grub", "/bin/true");
1171 diversion_add($targetdir, "/usr/sbin/update-initramfs", "/bin/true");
1173 my $machine_id = run_command("systemd-id128 new");
1174 die "unable to create a new machine-id\n" if ! $machine_id;
1175 file_write_all("$targetdir/etc/machine-id", $machine_id);
1177 syscmd("cp /etc/hostid $targetdir/etc/") == 0 ||
1178 die "unable to copy hostid\n";
1180 syscmd("touch $targetdir/proxmox_install_mode");
1182 my $grub_install_devices_txt = '';
1183 foreach my $di (@$bootdevinfo) {
1184 $grub_install_devices_txt .= ', ' if $grub_install_devices_txt;
1185 $grub_install_devices_txt .= $di->{by_id} || $di->{devname};
1188 # Note: keyboard-configuration/xbkb-keymap is used by console-setup
1189 my $xkmap = $cmap->{kmap}->{$keymap}->{x11} // 'us';
1191 debconfig_set ($targetdir, <<_EOD);
1192 locales locales/default_environment_locale select en_US.UTF-8
1193 locales locales/locales_to_be_generated select en_US.UTF-8 UTF-8
1194 samba-common samba-common/dhcp boolean false
1195 samba-common samba-common/workgroup string WORKGROUP
1196 postfix postfix/main_mailer_type select No configuration
1197 keyboard-configuration keyboard-configuration/xkb-keymap select $xkmap
1198 d-i debian-installer/locale select en_US.UTF-8
1199 grub-pc grub-pc/install_devices select $grub_install_devices_txt
1203 while (<${proxmox_pkgdir
}/*.deb
>) { $pkg_count++ };
1205 # btrfs/dpkg is extremely slow without --force-unsafe-io
1206 my $dpkg_opts = $use_btrfs ?
"--force-unsafe-io" : "";
1209 while (<${proxmox_pkgdir
}/*.deb
>) {
1212 my ($deb) = $path =~ m/${proxmox_pkgdir}\/(.*\
.deb
)/;
1213 update_progress
($count/$pkg_count, 0.5, 0.75, "extracting $deb");
1214 print "extracting: $deb\n";
1215 syscmd
("chroot $targetdir dpkg $dpkg_opts --force-depends --no-triggers --unpack /tmp/pkg/$deb") == 0
1216 || die "installation of package $deb failed\n";
1217 update_progress
((++$count)/$pkg_count, 0.5, 0.75);
1220 # needed for postfix postinst in case no other NIC is active
1221 syscmd
("chroot $targetdir ifup lo");
1223 my $cmd = "chroot $targetdir dpkg $dpkg_opts --force-confold --configure -a";
1225 run_command
($cmd, sub {
1227 if ($line =~ m/Setting up\s+(\S+)/) {
1228 update_progress
((++$count)/$pkg_count, 0.75, 0.95, "configuring $1");
1232 unlink "$targetdir/etc/mailname";
1233 $postfix_main_cf =~ s/__FQDN__/${hostname}.${domain}/;
1234 file_write_all
("$targetdir/etc/postfix/main.cf", $postfix_main_cf);
1236 # make sure we have all postfix directories
1237 syscmd
("chroot $targetdir /usr/sbin/postfix check");
1238 # cleanup mail queue
1239 syscmd
("chroot $targetdir /usr/sbin/postsuper -d ALL");
1240 # create /etc/aliases.db (/etc/aliases is shipped in the base squashfs)
1241 syscmd
("chroot $targetdir /usr/bin/newaliases");
1243 unlink "$targetdir/proxmox_install_mode";
1246 unlink ("$targetdir/etc/localtime");
1247 symlink ("/usr/share/zoneinfo/$timezone", "$targetdir/etc/localtime");
1248 file_write_all
("$targetdir/etc/timezone", "$timezone\n");
1251 if (my $mirror = $cmap->{country
}->{$country}->{mirror
}) {
1252 my $fn = "$targetdir/etc/apt/sources.list";
1253 syscmd
("sed -i 's/ftp\\.debian\\.org/$mirror/' '$fn'");
1256 # create extended_states for apt (avoid cron job warning if that
1257 # file does not exist)
1258 file_write_all
("$targetdir/var/lib/apt/extended_states", '');
1260 # allow ssh root login
1261 syscmd
(['sed', '-i', 's/^#\?PermitRootLogin.*/PermitRootLogin yes/', "$targetdir/etc/ssh/sshd_config"]);
1263 if ($env->{product
} eq 'pmg') {
1264 # install initial clamav DB
1265 my $srcdir = "${proxmox_cddir}/proxmox/clamav";
1266 foreach my $fn ("main.cvd", "bytecode.cvd", "daily.cvd", "safebrowsing.cvd") {
1267 syscmd
("cp \"$srcdir/$fn\" \"$targetdir/var/lib/clamav\"") == 0 ||
1268 die "installation of clamav db file '$fn' failed\n";
1270 syscmd
("chroot $targetdir /bin/chown clamav:clamav -R /var/lib/clamav") == 0 ||
1271 die "unable to set owner for clamav database files\n";
1274 if ($env->{product
} eq 'pve') {
1275 # save installer settings
1276 my $ucc = uc ($country);
1277 debconfig_set
($targetdir, "pve-manager pve-manager/country string $ucc\n");
1280 update_progress
(0.8, 0.95, 1, "make system bootable");
1283 # add ZFS options while preserving existing kernel cmdline
1284 my $zfs_snippet = "GRUB_CMDLINE_LINUX=\"\$GRUB_CMDLINE_LINUX root=ZFS=$zfspoolname/ROOT/$zfsrootvolname boot=zfs\"";
1285 file_write_all
("$targetdir/etc/default/grub.d/zfs.cfg", $zfs_snippet);
1287 file_write_all
("$targetdir/etc/kernel/cmdline", "root=ZFS=$zfspoolname/ROOT/$zfsrootvolname boot=zfs\n");
1291 diversion_remove
($targetdir, "/usr/sbin/update-grub");
1292 diversion_remove
($targetdir, "/usr/sbin/update-initramfs");
1295 foreach my $fn (<$targetdir/lib/modules/*>) {
1296 if ($fn =~ m!/(\d+\.\d+\.\d+-\d+-pve)$!) {
1297 die "found multiple kernels\n" if defined($kapi);
1301 die "unable to detect kernel version\n" if !defined($kapi);
1303 if (!is_test_mode
()) {
1305 unlink ("$targetdir/etc/mtab");
1306 symlink ("/proc/mounts", "$targetdir/etc/mtab");
1307 syscmd
("mount -n --bind /dev $targetdir/dev");
1309 my $bootloader_err_list = [];
1311 syscmd
("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0 ||
1312 die "unable to install initramfs\n";
1314 my $native_4k_disk_bootable = 0;
1315 foreach my $di (@$bootdevinfo) {
1316 $native_4k_disk_bootable |= ($di->{logical_bsize
} == 4096);
1319 foreach my $di (@$bootdevinfo) {
1320 my $dev = $di->{devname
};
1322 prepare_proxmox_boot_esp
($di->{esp
}, $targetdir);
1324 if (!$native_4k_disk_bootable) {
1326 syscmd
("chroot $targetdir /usr/sbin/grub-install --target i386-pc --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
1327 die "unable to install the i386-pc boot loader on '$dev'\n";
1329 push @$bootloader_err_list, $@ if $@;
1333 if (my $esp = $di->{esp
}) {
1334 prepare_grub_efi_boot_esp
($dev, $esp, $targetdir);
1338 push @$bootloader_err_list, $@ if $@;
1341 syscmd
("chroot $targetdir /usr/sbin/update-grub") == 0 ||
1342 die "unable to update boot loader config\n";
1344 push @$bootloader_err_list, $@ if $@;
1346 if (scalar(@$bootloader_err_list) > 0) {
1347 $bootloader_err = "bootloader setup errors:\n";
1348 map { $bootloader_err .= "- $_" } @$bootloader_err_list;
1349 warn $bootloader_err;
1352 syscmd
("umount $targetdir/dev");
1357 unlink "$targetdir/usr/sbin/policy-rc.d";
1359 diversion_remove
($targetdir, "/sbin/start-stop-daemon");
1362 my $octets = encode
("utf-8", $password);
1363 run_command
("chroot $targetdir /usr/sbin/chpasswd", undef,
1366 if ($env->{product
} eq 'pmg') {
1368 file_write_all
("$targetdir/etc/pmg/pmg.conf", "section: admin\n\temail ${mailto}\n");
1370 } elsif ($env->{product
} eq 'pve') {
1374 my $tmpdir = "$targetdir/tmp/pve";
1377 # write vnc keymap to datacenter.cfg
1378 my $vnckmap = $cmap->{kmap
}->{$keymap}->{kvm
} || 'en-us';
1379 file_write_all
("$tmpdir/datacenter.cfg", "keyboard: $vnckmap\n");
1382 file_write_all
("$tmpdir/user.cfg", "user:root\@pam:1:0:::${mailto}::\n");
1387 $storage_cfg = $storage_cfg_zfs;
1388 } elsif ($use_btrfs) {
1389 $storage_cfg = $storage_cfg_btrfs;
1390 } elsif ($datadev) {
1391 $storage_cfg = $storage_cfg_lvmthin;
1393 $storage_cfg = $storage_cfg_local;
1395 file_write_all
("$tmpdir/storage.cfg", $storage_cfg);
1397 run_command
("chroot $targetdir /usr/bin/create_pmxcfs_db /tmp/pve /var/lib/pve-cluster/config.db");
1399 syscmd
("rm -rf $tmpdir");
1400 } elsif ($env->{product
} eq 'pbs') {
1401 my $base_cfg_path = "/etc/proxmox-backup";
1402 mkdir "$targetdir/$base_cfg_path";
1404 chroot_chown
($targetdir, $base_cfg_path, user
=> 'backup', recursive
=> 1);
1405 chroot_chmod
($targetdir, $base_cfg_path, mode
=> '0700');
1407 my $user_cfg_fn = "$base_cfg_path/user.cfg";
1408 file_write_all
("$targetdir/$user_cfg_fn", "user: root\@pam\n\temail ${mailto}\n");
1409 chroot_chown
($targetdir, $user_cfg_fn, user
=> 'root', group
=> 'backup');
1410 chroot_chmod
($targetdir, $user_cfg_fn, mode
=> '0640');
1416 update_progress
(1, 0, 1, "");
1420 if (is_test_mode
()) {
1421 my $elapsed = Time
::HiRes
::tv_interval
($starttime);
1422 print "Elapsed extract time: $elapsed\n";
1424 syscmd
("chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> final.pkglist");
1427 syscmd
("umount $targetdir/run");
1428 syscmd
("umount $targetdir/mnt/hostrun");
1429 syscmd
("umount $targetdir/tmp/pkg");
1430 syscmd
("umount $targetdir/tmp");
1431 syscmd
("umount $targetdir/proc");
1432 syscmd
("umount $targetdir/sys/firmware/efi/efivars");
1433 syscmd
("umount $targetdir/sys");
1434 rmdir("$targetdir/mnt/hostrun");
1437 syscmd
("zfs umount -a") == 0 ||
1438 die "unable to unmount zfs\n";
1440 syscmd
("umount -d $targetdir");
1443 if (!$err && $use_zfs) {
1444 syscmd
("zfs set sync=standard $zfspoolname") == 0 ||
1445 die "unable to set zfs properties\n";
1447 syscmd
("zfs set mountpoint=/ $zfspoolname/ROOT/$zfsrootvolname") == 0 ||
1448 die "zfs set mountpoint failed\n";
1450 syscmd
("zpool set bootfs=$zfspoolname/ROOT/$zfsrootvolname $zfspoolname") == 0 ||
1451 die "zpool set bootfs failed\n";
1452 syscmd
("zpool export $zfspoolname");
1455 if ($bootloader_err) {
1456 $err = $err ?
"$err\n$bootloader_err" : $bootloader_err;
1462 my $last_display_change = 0;
1464 my $display_info_counter = 0;
1466 my $display_info_items = [
1467 "extract1-license.htm",
1468 "extract2-rulesystem.htm",
1469 "extract3-spam.htm",
1470 "extract4-virus.htm",
1475 my $min_display_time = 15;
1479 return if ($ctime - $last_display_change) < $min_display_time;
1481 my $page = $display_info_items->[$display_info_counter % scalar(@$display_info_items)];
1483 $display_info_counter++;
1485 display_html
($page);
1489 my ($filename) = @_;
1491 $filename = $steps[$step_number]->{html
} if !$filename;
1493 my $htmldir = "${proxmox_libdir}/html";
1495 if (-f
"$htmldir/$env->{product}/$filename") {
1496 $path = "$htmldir/$env->{product}/$filename";
1498 $path = "$htmldir/$filename";
1501 my $data = file_read_all
($path);
1503 if ($filename eq 'license.htm') {
1504 my $license = eval { decode
('utf8', file_read_all
("${proxmox_cddir}/EULA")) };
1506 die $err if !is_test_mode
();
1507 $license = "TESTMODE: Ignore non existent EULA...\n";
1509 my $title = "END USER LICENSE AGREEMENT (EULA)";
1510 $data =~ s/__LICENSE__/$license/;
1511 $data =~ s/__LICENSE_TITLE__/$title/;
1512 } elsif ($filename eq 'success.htm') {
1513 my $addr = $ipversion == 6 ?
"[${ipaddress}]" : "$ipaddress";
1514 $data =~ s/__IPADDR__/$addr/g;
1515 $data =~ s/__PORT__/$env->{cfg}->{port}/g;
1517 my $autoreboot_msg = $config_options->{autoreboot
}
1518 ?
"Automatic reboot scheduled in $autoreboot_seconds seconds."
1520 $data =~ s/__AUTOREBOOT_MSG__/$autoreboot_msg/;
1522 $data =~ s/__FULL_PRODUCT_NAME__/$env->{cfg}->{fullname}/g;
1524 # always set base-path to common path, all resources are accesible from there.
1525 $htmlview->load_html($data, "file://$htmldir/");
1527 $last_display_change = time();
1532 my ($text, $fctn) = @_;
1534 $fctn = $step_number if !$fctn;
1535 $text = "_Previous" if !$text;
1536 $prev_btn->set_label ($text);
1539 $steps[$step_number]->{function
}();
1541 $prev_btn->grab_focus();
1545 my ($text, $fctn) = @_;
1548 my $step = $steps[$step_number];
1549 $text //= $steps[$step_number]->{next_button
} // '_Next';
1550 $next->set_label($text);
1552 $next->grab_focus();
1555 sub create_main_window
{
1557 $window = Gtk3
::Window-
>new();
1558 $window->set_default_size(1024, 768);
1559 $window->set_has_resize_grip(0);
1560 $window->fullscreen() if !is_test_mode
();
1561 $window->set_decorated(0) if !is_test_mode
();
1563 my $vbox = Gtk3
::VBox-
>new(0, 0);
1565 my $logofn = "$env->{product}-banner.png";
1566 my $image = Gtk3
::Image-
>new_from_file("${proxmox_libdir}/$logofn");
1568 my $provider = Gtk3
::CssProvider-
>new();
1569 my $theming = "* {\nbackground: #171717;\n}";
1570 $provider->load_from_data ([map ord, split //, $theming]);
1571 my $context = $image->get_style_context();
1572 $context->add_provider($provider, 600);
1574 $vbox->pack_start($image, 0, 0, 0);
1576 my $hbox = Gtk3
::HBox-
>new(0, 0);
1577 $vbox->pack_start($hbox, 1, 1, 0);
1579 # my $f1 = Gtk3::Frame->new ('test');
1580 # $f1->set_shadow_type ('none');
1581 # $hbox->pack_start ($f1, 1, 1, 0);
1583 my $sep1 = Gtk3
::HSeparator-
>new();
1584 $vbox->pack_start($sep1, 0, 0, 0);
1586 $cmdbox = Gtk3
::HBox-
>new();
1587 $vbox->pack_start($cmdbox, 0, 0, 10);
1589 $next = Gtk3
::Button-
>new('_Next');
1590 $next->signal_connect(clicked
=> sub { $last_display_change = 0; &$next_fctn (); });
1591 $cmdbox->pack_end($next, 0, 0, 10);
1594 $prev_btn = Gtk3
::Button-
>new('_Previous');
1595 $prev_btn->signal_connect(clicked
=> sub { $last_display_change = 0; &prev_function
(); });
1596 $cmdbox->pack_end($prev_btn, 0, 0, 10);
1599 my $abort = Gtk3
::Button-
>new('_Abort');
1600 $abort->set_can_focus(0);
1601 $cmdbox->pack_start($abort, 0, 0, 10);
1602 $abort->signal_connect(clicked
=> sub { exit (-1); });
1604 my $vbox2 = Gtk3
::VBox-
>new(0, 0);
1607 $htmlview = Gtk3
::WebKit2
::WebView-
>new();
1608 my $scrolls = Gtk3
::ScrolledWindow-
>new();
1609 $scrolls->add($htmlview);
1611 my $hbox2 = Gtk3
::HBox-
>new(0, 0);
1612 $hbox2->pack_start($scrolls, 1, 1, 0);
1614 $vbox2->pack_start($hbox2, 1, 1, 0);
1616 my $vbox3 = Gtk3
::VBox-
>new(0, 0);
1617 $vbox2->pack_start($vbox3, 0, 0, 0);
1619 my $sep2 = Gtk3
::HSeparator-
>new;
1620 $vbox3->pack_start($sep2, 0, 0, 0);
1622 $inbox = Gtk3
::HBox-
>new(0, 0);
1623 $vbox3->pack_start($inbox, 0, 0, 0);
1625 $window->add($vbox);
1632 $inbox->foreach(sub {
1634 $inbox->remove ($child);
1638 # fixme: newer GTK3 has special properties to handle numbers with Entry
1639 # only allow floating point numbers with Gtk3::Entry
1642 my ($entry, $event) = @_;
1644 return check_number
($entry, $event, 1);
1648 my ($entry, $event) = @_;
1650 return check_number
($entry, $event, 0);
1654 my ($entry, $event, $float) = @_;
1656 my $val = $event->get_keyval;
1658 if (($float && $val == ord '.') ||
1659 $val == Gtk3
::Gdk
::KEY_ISO_Left_Tab
||
1660 $val == Gtk3
::Gdk
::KEY_Shift_L
||
1661 $val == Gtk3
::Gdk
::KEY_Tab
||
1662 $val == Gtk3
::Gdk
::KEY_Left
||
1663 $val == Gtk3
::Gdk
::KEY_Right
||
1664 $val == Gtk3
::Gdk
::KEY_BackSpace
||
1665 $val == Gtk3
::Gdk
::KEY_Delete
||
1666 ($val >= ord '0' && $val <= ord '9') ||
1667 ($val >= Gtk3
::Gdk
::KEY_KP_0
&&
1668 $val <= Gtk3
::Gdk
::KEY_KP_9
)) {
1675 sub create_text_input
{
1676 my ($default, $text) = @_;
1678 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
1680 my $label = Gtk3
::Label-
>new($text);
1681 $label->set_size_request(150, -1);
1682 $label->set_alignment(1, 0.5);
1683 $hbox->pack_start($label, 0, 0, 10);
1684 my $e1 = Gtk3
::Entry-
>new();
1685 $e1->set_width_chars(35);
1686 $hbox->pack_start($e1, 0, 0, 0);
1687 $e1->set_text($default);
1689 return ($hbox, $e1);
1691 sub create_cidr_inputs
{
1692 my ($default_ip, $default_mask) = @_;
1694 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
1696 my $label = Gtk3
::Label-
>new('IP Address (CIDR)');
1697 $label->set_size_request(150, -1);
1698 $label->set_alignment(1, 0.5);
1699 $hbox->pack_start($label, 0, 0, 10);
1701 my $ip_el = Gtk3
::Entry-
>new();
1702 $ip_el->set_width_chars(28);
1703 $hbox->pack_start($ip_el, 0, 0, 0);
1704 $ip_el->set_text($default_ip);
1706 $label = Gtk3
::Label-
>new('/');
1707 $label->set_size_request(10, -1);
1708 $label->set_alignment(0.5, 0.5);
1709 $hbox->pack_start($label, 0, 0, 2);
1711 my $cidr_el = Gtk3
::Entry-
>new();
1712 $cidr_el->set_width_chars(3);
1713 $hbox->pack_start($cidr_el, 0, 0, 0);
1714 $cidr_el->set_text($default_mask);
1716 return ($hbox, $ip_el, $cidr_el);
1719 sub display_message
{
1722 my $dialog = Gtk3
::MessageDialog-
>new($window, 'modal', 'info', 'ok', $msg);
1730 my $dialog = Gtk3
::MessageDialog-
>new($window, 'modal', 'error', 'ok', $msg);
1735 sub display_prompt
{
1738 my $dialog = Gtk3
::MessageDialog-
>new($window, 'modal', 'question', 'ok-cancel', $query);
1739 my $response = $dialog->run();
1745 my $ipconf_first_view = 1;
1747 sub create_ipconf_view
{
1752 my $vcontainer = Gtk3
::Box-
>new('vertical', 0);
1753 $inbox->pack_start($vcontainer, 1, 0, 0);
1754 my $hcontainer = Gtk3
::Box-
>new('horizontal', 0);
1755 $vcontainer->pack_start($hcontainer, 0, 0, 10);
1756 my $vbox = Gtk3
::Box-
>new('vertical', 0);
1757 $hcontainer->add($vbox);
1759 my $ipaddr_text = $config->{ipaddress
} // "192.168.100.2";
1760 my $netmask_text = $config->{netmask
} // "24";
1762 ($cidr_box, $ipconf_entry_addr, $ipconf_entry_mask) =
1763 create_cidr_inputs
($ipaddr_text, $netmask_text);
1765 my $device_cb = Gtk3
::ComboBoxText-
>new();
1766 $device_cb->set_active(0);
1767 $device_cb->set_visible(1);
1769 my $get_device_desc = sub {
1771 return "$iface->{name} - $iface->{mac} ($iface->{driver})";
1774 my $device_active_map = {};
1775 my $device_active_reverse_map = {};
1777 my $device_change_handler = sub {
1778 my $current = shift;
1780 my $new = $device_active_map->{$current->get_active()};
1781 return if defined($ipconf->{selected
}) && $new eq $ipconf->{selected
};
1783 $ipconf->{selected
} = $new;
1784 my $iface = $ipconf->{ifaces
}->{$ipconf->{selected
}};
1785 $config->{mngmt_nic
} = $iface->{name
};
1786 $ipconf_entry_addr->set_text($iface->{inet
}->{addr
} || $iface->{inet6
}->{addr
})
1787 if $iface->{inet
}->{addr
} || $iface->{inet6
}->{addr
};
1788 $ipconf_entry_mask->set_text($iface->{inet
}->{prefix
} || $iface->{inet6
}->{prefix
})
1789 if $iface->{inet
}->{prefix
} || $iface->{inet6
}->{prefix
};
1793 foreach my $index (sort keys %{$ipconf->{ifaces
}}) {
1794 $device_cb->append_text(&$get_device_desc($ipconf->{ifaces
}->{$index}));
1795 $device_active_map->{$i} = $index;
1796 $device_active_reverse_map->{$ipconf->{ifaces
}->{$index}->{name
}} = $i;
1797 if ($ipconf_first_view && $index == $ipconf->{default}) {
1798 $device_cb->set_active($i);
1799 &$device_change_handler($device_cb);
1800 $ipconf_first_view = 0;
1802 $device_cb->signal_connect('changed' => $device_change_handler);
1806 if (my $nic = $config->{mngmt_nic
}) {
1807 $device_cb->set_active($device_active_reverse_map->{$nic} // 0);
1809 $device_cb->set_active(0);
1812 my $devicebox = Gtk3
::HBox-
>new(0, 0);
1813 my $label = Gtk3
::Label-
>new("Management Interface:");
1814 $label->set_size_request(150, -1);
1815 $label->set_alignment(1, 0.5);
1816 $devicebox->pack_start($label, 0, 0, 10);
1817 $devicebox->pack_start($device_cb, 0, 0, 0);
1819 $vbox->pack_start($devicebox, 0, 0, 2);
1821 my $hn = $config->{fqdn
} // "$env->{product}." . ($ipconf->{domain
} // "example.invalid");
1823 my ($hostbox, $hostentry) = create_text_input
($hn, 'Hostname (FQDN):');
1824 $vbox->pack_start($hostbox, 0, 0, 2);
1826 $vbox->pack_start($cidr_box, 0, 0, 2);
1828 $gateway = $config->{gateway
} // $ipconf->{gateway
} || '192.168.100.1';
1831 ($gwbox, $ipconf_entry_gw) =
1832 create_text_input
($gateway, 'Gateway:');
1834 $vbox->pack_start($gwbox, 0, 0, 2);
1836 $dnsserver = $config->{dnsserver
} // $ipconf->{dnsserver
} || $gateway;
1839 ($dnsbox, $ipconf_entry_dns) =
1840 create_text_input
($dnsserver, 'DNS Server:');
1842 $vbox->pack_start($dnsbox, 0, 0, 0);
1845 set_next
(undef, sub {
1849 my $text = $hostentry->get_text();
1854 $config->{fqdn
} = $text;
1856 my $namere = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
1858 # Debian does not support purely numeric hostnames
1859 if ($text && $text =~ /^[0-9]+(?:\.|$)/) {
1860 display_message
("Purely numeric hostnames are not allowed.");
1861 $hostentry->grab_focus();
1865 if ($text && $text =~ m/^(${namere}\.)*${namere}$/ && $text !~ m/.example.invalid$/ &&
1866 $text =~ m/^([^\.]+)\.(\S+)$/) {
1870 display_message
("Hostname does not look like a fully qualified domain name.");
1871 $hostentry->grab_focus();
1876 $text = $ipconf_entry_addr->get_text();
1877 ($ipaddress, $ipversion) = parse_ip_address
($text);
1878 if (!defined($ipaddress)) {
1879 display_message
("IP address is not valid.");
1880 $ipconf_entry_addr->grab_focus();
1883 $config->{ipaddress
} = $ipaddress;
1885 $text = $ipconf_entry_mask->get_text();
1886 $netmask = parse_ip_mask
($text, $ipversion);
1887 if (!defined($netmask)) {
1888 display_message
("Netmask is not valid.");
1889 $ipconf_entry_mask->grab_focus();
1892 $cidr = "$ipaddress/$netmask";
1893 $config->{netmask
} = $netmask;
1895 $text = $ipconf_entry_gw->get_text();
1896 my ($gateway_ip, $gateway_ip_version) = parse_ip_address
($text);
1897 if (!defined($gateway_ip) || $gateway_ip_version != $ipversion) {
1898 my $msg = defined($gateway_ip)
1899 ?
"Gateway and host IP version must not differ (IPv$gateway_ip_version != IPv$ipversion)."
1900 : "Gateway is not valid.";
1901 display_message
($msg);
1902 $ipconf_entry_gw->grab_focus();
1905 $config->{gateway
} = $gateway = $gateway_ip;
1907 $text = $ipconf_entry_dns->get_text();
1908 my ($dns_ip, $dns_ip_version) = parse_ip_address
($text);
1909 if (!defined($dns_ip) || $dns_ip_version != $ipversion) {
1910 my $msg = defined($gateway_ip)
1911 ?
"DNS and host IP version must not differ (IPv$gateway_ip_version != IPv$ipversion)."
1912 : "DNS IP is not valid.";
1913 display_message
($msg);
1914 $ipconf_entry_dns->grab_focus();
1917 $config->{dnsserver
} = $dnsserver = $dns_ip;
1919 #print "TEST $ipaddress $netmask $gateway $dnsserver\n";
1925 $hostentry->grab_focus();
1928 sub create_ack_view
{
1932 my $vbox = Gtk3
::VBox-
>new(0, 0);
1933 $inbox->pack_start($vbox, 1, 0, 0);
1935 my $reboot_checkbox = Gtk3
::CheckButton-
>new('Automatically reboot after successful installation');
1936 $reboot_checkbox->set_active(1);
1937 $reboot_checkbox->signal_connect ("toggled" => sub {
1939 $config_options->{autoreboot
} = $cb->get_active();
1941 $vbox->pack_start($reboot_checkbox, 0, 0, 2);
1943 my $ack_template = "${proxmox_libdir}/html/ack_template.htm";
1944 my $ack_html = "${proxmox_libdir}/html/$env->{product}/$steps[$step_number]->{html}";
1945 my $html_data = file_read_all
($ack_template);
1947 my %config_values = (
1948 __target_hd__
=> join(' | ', @{$config_options->{target_hds
}}),
1949 __target_fs__
=> $config_options->{filesys
},
1950 __country__
=> $cmap->{country
}->{$country}->{name
},
1951 __timezone__
=> $timezone,
1952 __keymap__
=> $keymap,
1953 __mailto__
=> $mailto,
1954 __interface__
=> $ipconf->{ifaces
}->{$ipconf->{selected
}}->{name
},
1955 __hostname__
=> $hostname,
1956 __ip__
=> $ipaddress,
1958 __netmask__
=> $netmask,
1959 __gateway__
=> $gateway,
1960 __dnsserver__
=> $dnsserver,
1963 while (my ($k, $v) = each %config_values) {
1964 $html_data =~ s/$k/$v/g;
1967 file_write_all
($ack_html, $html_data);
1973 set_next
(undef, sub {
1975 create_extract_view
();
1979 sub get_device_desc
{
1980 my ($devname, $size, $model) = @_;
1982 if ($size && ($size > 0)) {
1983 $size = int($size/2048); # size in MiB, from 512B "sectors"
1985 my $text = "$devname (";
1986 if ($size >= 1024) {
1987 $size = $size/1024; # size in GiB
1988 if ($size >= 1024) {
1989 $size = $size/1024; # size in TiB
1990 $text .= sprintf("%.2f", $size) . "TiB";
1992 $text .= sprintf("%.2f", $size) . "GiB";
1995 $text .= "${size}MiB";
1998 $text .= ", $model" if $model;
2010 my ($cb, $kmap) = @_;
2015 my $kmaphash = $cmap->{kmaphash
};
2016 foreach my $layout (sort keys %$kmaphash) {
2017 $def = $i if $kmaphash->{$layout} eq 'en-us';
2018 $ind = $i if $kmap && $kmaphash->{$layout} eq $kmap;
2022 my $val = $ind || $def || 0;
2024 if (!defined($kmap)) {
2025 $last_layout //= $val;
2026 } elsif (!defined($country_layout) || $country_layout != $val) {
2027 $last_layout = $country_layout = $val;
2029 $cb->set_active($last_layout);
2033 sub update_zonelist
{
2034 my ($box, $cc) = @_;
2036 my $cczones = $cmap->{cczones
};
2037 my $zones = $cmap->{zones
};
2041 $sel = $lastzonecb->get_active_text();
2042 $box->remove ($lastzonecb);
2044 $sel = $timezone; # used once to select default
2047 my $cb = $lastzonecb = Gtk3
::ComboBoxText-
>new();
2048 $cb->set_size_request(200, -1);
2050 $cb->signal_connect('changed' => sub {
2051 $timezone = $cb->get_active_text();
2055 if ($cc && defined ($cczones->{$cc})) {
2056 @za = keys %{$cczones->{$cc}};
2062 foreach my $zone (sort @za) {
2063 $ind = $i if $sel && $zone eq $sel;
2064 $cb->append_text($zone);
2068 # Append UTC here, so it is always the last item and never the default for any country.
2069 $cb->append_text('UTC');
2071 $cb->set_active($ind || 0);
2074 $box->pack_start($cb, 0, 0, 0);
2077 sub create_password_view
{
2081 my $vbox2 = Gtk3
::VBox-
>new(0, 0);
2082 $inbox->pack_start($vbox2, 1, 0, 0);
2083 my $vbox = Gtk3
::VBox-
>new(0, 0);
2084 $vbox2->pack_start($vbox, 0, 0, 10);
2086 my $hbox1 = Gtk3
::HBox-
>new(0, 0);
2087 my $label = Gtk3
::Label-
>new("Password");
2088 $label->set_size_request(150, -1);
2089 $label->set_alignment(1, 0.5);
2090 $hbox1->pack_start($label, 0, 0, 10);
2091 my $pwe1 = Gtk3
::Entry-
>new();
2092 $pwe1->set_visibility(0);
2093 $pwe1->set_text($password) if $password;
2094 $pwe1->set_size_request(200, -1);
2095 $hbox1->pack_start($pwe1, 0, 0, 0);
2097 my $hbox2 = Gtk3
::HBox-
>new(0, 0);
2098 $label = Gtk3
::Label-
>new("Confirm");
2099 $label->set_size_request(150, -1);
2100 $label->set_alignment(1, 0.5);
2101 $hbox2->pack_start($label, 0, 0, 10);
2102 my $pwe2 = Gtk3
::Entry-
>new();
2103 $pwe2->set_visibility(0);
2104 $pwe2->set_text($password) if $password;
2105 $pwe2->set_size_request(200, -1);
2106 $hbox2->pack_start($pwe2, 0, 0, 0);
2108 my $hbox3 = Gtk3
::HBox-
>new(0, 0);
2109 $label = Gtk3
::Label-
>new("Email");
2110 $label->set_size_request(150, -1);
2111 $label->set_alignment(1, 0.5);
2112 $hbox3->pack_start($label, 0, 0, 10);
2113 my $eme = Gtk3
::Entry-
>new();
2114 $eme->set_size_request(200, -1);
2115 $eme->set_text($mailto);
2116 $hbox3->pack_start($eme, 0, 0, 0);
2119 $vbox->pack_start($hbox1, 0, 0, 5);
2120 $vbox->pack_start($hbox2, 0, 0, 5);
2121 $vbox->pack_start($hbox3, 0, 0, 15);
2127 set_next
(undef, sub {
2129 my $t1 = $pwe1->get_text;
2130 my $t2 = $pwe2->get_text;
2132 if (length ($t1) < 5) {
2133 display_message
("Password is too short.");
2134 $pwe1->grab_focus();
2139 display_message
("Password does not match.");
2140 $pwe1->grab_focus();
2144 my $t3 = $eme->get_text;
2145 if ($t3 !~ m/^[\w\+\-\~]+(\.[\w\+\-\~]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*$/) {
2146 display_message
("Email does not look like a valid address" .
2147 " (user\@domain.tld)");
2152 if ($t3 eq 'mail@example.invalid') {
2153 display_message
("Please enter a valid Email address");
2162 create_ipconf_view
();
2165 $pwe1->grab_focus();
2170 sub create_country_view
{
2174 my $countryhash = $cmap->{countryhash
};
2175 my $ctr = $cmap->{country
};
2177 my $vbox2 = Gtk3
::VBox-
>new(0, 0);
2178 $inbox->pack_start($vbox2, 1, 0, 0);
2179 my $vbox = Gtk3
::VBox-
>new(0, 0);
2180 $vbox2->pack_start($vbox, 0, 0, 10);
2182 my $w = Gtk3
::Entry-
>new();
2183 $w->set_size_request(200, -1);
2185 my $c = Gtk3
::EntryCompletion-
>new();
2186 $c->set_text_column(0);
2187 $c->set_minimum_key_length(0);
2188 $c->set_popup_set_width(1);
2189 $c->set_inline_completion(1);
2191 my $hbox2 = Gtk3
::HBox-
>new(0, 0);
2192 my $label = Gtk3
::Label-
>new("Time zone");
2193 $label->set_size_request(150, -1);
2194 $label->set_alignment(1, 0.5);
2195 $hbox2->pack_start($label, 0, 0, 10);
2196 update_zonelist
($hbox2);
2198 my $hbox3 = Gtk3
::HBox-
>new(0, 0);
2199 $label = Gtk3
::Label-
>new("Keyboard Layout");
2200 $label->set_size_request(150, -1);
2201 $label->set_alignment(1, 0.5);
2202 $hbox3->pack_start($label, 0, 0, 10);
2204 my $kmapcb = Gtk3
::ComboBoxText-
>new();
2205 $kmapcb->set_size_request (200, -1);
2206 foreach my $layout (sort keys %{$cmap->{kmaphash
}}) {
2207 $kmapcb->append_text ($layout);
2210 update_layout
($kmapcb);
2211 $hbox3->pack_start ($kmapcb, 0, 0, 0);
2213 $kmapcb->signal_connect ('changed' => sub {
2214 my $sel = $kmapcb->get_active_text();
2215 $last_layout = $kmapcb->get_active();
2216 if (my $kmap = $cmap->{kmaphash
}->{$sel}) {
2217 my $xkmap = $cmap->{kmap
}->{$kmap}->{x11
};
2218 my $xvar = $cmap->{kmap
}->{$kmap}->{x11var
};
2221 return if (defined($installer_kmap) && $installer_kmap eq $kmap);
2223 $installer_kmap = $keymap;
2225 if (!is_test_mode
()) {
2226 syscmd
("setxkbmap $xkmap $xvar");
2228 my $kbd_config = qq{
2233 $kbd_config =~ s/^\s+//gm;
2235 Proxmox
::Sys
::Command
::run_in_background
(sub {
2236 file_write_all
('/etc/default/keyboard', $kbd_config);
2243 $w->signal_connect ('changed' => sub {
2244 my ($entry, $event) = @_;
2245 my $text = $entry->get_text;
2247 if (my $cc = $countryhash->{lc($text)}) {
2248 update_zonelist
($hbox2, $cc);
2249 my $kmap = $ctr->{$cc}->{kmap
} || 'en-us';
2250 update_layout
($kmapcb, $kmap);
2254 $w->signal_connect (key_press_event
=> sub {
2255 my ($entry, $event) = @_;
2256 my $text = $entry->get_text;
2258 my $val = $event->get_keyval;
2260 if ($val == Gtk3
::Gdk
::KEY_Tab
) {
2261 my $cc = $countryhash->{lc($text)};
2268 $compl = $ctr->{$cc}->{name
};
2270 foreach my $cc (keys %$ctr) {
2271 my $ct = $ctr->{$cc}->{name
};
2272 if ($ct =~ m/^\Q$text\E.*$/i) {
2281 $entry->set_text($compl);
2286 print chr(7); # beep ?
2291 my $buf = $w->get_buffer();
2292 $buf->insert_text(-1, '', -1); # popup selection
2300 my $ls = Gtk3
::ListStore-
>new('Glib::String');
2301 foreach my $cc (sort {$ctr->{$a}->{name
} cmp $ctr->{$b}->{name
} } keys %$ctr) {
2302 my $iter = $ls->append();
2303 $ls->set ($iter, 0, $ctr->{$cc}->{name
});
2305 $c->set_model ($ls);
2307 $w->set_completion ($c);
2309 my $hbox = Gtk3
::HBox-
>new(0, 0);
2311 $label = Gtk3
::Label-
>new("Country");
2312 $label->set_alignment(1, 0.5);
2313 $label->set_size_request(150, -1);
2314 $hbox->pack_start($label, 0, 0, 10);
2315 $hbox->pack_start($w, 0, 0, 0);
2317 $vbox->pack_start($hbox, 0, 0, 5);
2318 $vbox->pack_start($hbox2, 0, 0, 5);
2319 $vbox->pack_start($hbox3, 0, 0, 5);
2321 if ($country && $ctr->{$country}) {
2322 $w->set_text ($ctr->{$country}->{name
});
2328 set_next
(undef, sub {
2330 my $text = $w->get_text;
2332 if (my $cc = $countryhash->{lc($text)}) {
2335 create_password_view
();
2338 display_message
("Please select a country first.");
2346 my $target_hd_combo;
2347 my $target_hd_label;
2349 my $hdoption_first_setup = 1;
2351 my $create_basic_grid = sub {
2352 my $grid = Gtk3
::Grid-
>new();
2353 $grid->set_visible(1);
2354 $grid->set_column_spacing(10);
2355 $grid->set_row_spacing(10);
2356 $grid->set_hexpand(1);
2358 $grid->set_margin_start(10);
2359 $grid->set_margin_end(20);
2360 $grid->set_margin_top(5);
2361 $grid->set_margin_bottom(5);
2366 my $create_label_widget_grid = sub {
2367 my ($labeled_widgets) = @_;
2369 my $grid = &$create_basic_grid();
2372 for (my $i = 0; $i < @$labeled_widgets; $i += 2) {
2373 my $widget = @$labeled_widgets[$i+1];
2374 my $label = Gtk3
::Label-
>new(@$labeled_widgets[$i]);
2375 $label->set_visible(1);
2376 $label->set_alignment (1, 0.5);
2377 $grid->attach($label, 0, $row, 1, 1);
2378 $widget->set_visible(1);
2379 $grid->attach($widget, 1, $row, 1, 1);
2386 # only relevant for raid with its multipl diskX to diskY mappings.
2387 my $get_selected_hdsize = sub {
2389 return $hdsize if defined($hdsize);
2391 # compute the smallest disk size of the actually selected disks
2392 my $cached_disks = get_cached_disks
();
2393 my $disk_count = scalar(@$cached_disks);
2394 for (my $i = 0; $i < $disk_count; $i++) {
2395 my $cur_hd = $config_options->{"disksel$i"} // next;
2396 my $disksize = int(@$cur_hd[2] / (2 * 1024 * 1024.0)); # size in GB
2397 $hdsize //= $disksize;
2398 $hdsize = $disksize if $disksize < $hdsize;
2401 if (my $cfg_hdsize = $config_options->{hdsize
}) {
2402 # had the dialog open previously and set an even lower size than the disk selection allows
2403 $hdsize = $cfg_hdsize if $cfg_hdsize < $hdsize;
2405 return $hdsize // 0; # fall back to zero, e.g., if none is selected hdsize cannot be any size
2408 my sub update_hdsize_adjustment
{
2409 my ($adjustment, $hdsize) = @_;
2411 $hdsize = $get_selected_hdsize->($hdsize);
2412 # expect that lower = 0 and step increments = 1 still are valid
2413 $adjustment->set_upper($hdsize + 1);
2414 $adjustment->set_value($hdsize);
2417 my sub create_hdsize_adjustment
{
2419 $hdsize = $get_selected_hdsize->($hdsize);
2420 # params are: initial value, lower, upper, step increment, page increment, page size
2421 return Gtk3
::Adjustment-
>new($config_options->{hdsize
} || $hdsize, 0, $hdsize+1, 1, 1, 1);
2424 my sub get_hdsize_spin_button
{
2427 my $hdsize_entry_buffer = Gtk3
::EntryBuffer-
>new(undef, 1);
2428 my $hdsize_size_adj = create_hdsize_adjustment
($hdsize);
2430 my $spinbutton_hdsize = Gtk3
::SpinButton-
>new($hdsize_size_adj, 1, 1);
2431 $spinbutton_hdsize->set_buffer($hdsize_entry_buffer);
2432 $spinbutton_hdsize->set_adjustment($hdsize_size_adj);
2433 $spinbutton_hdsize->set_tooltip_text("only use specified size (GB) of the harddisk (rest left unpartitioned)");
2434 return $spinbutton_hdsize;
2437 my $create_raid_disk_grid = sub {
2438 my ($hdsize_buttons) = @_;
2440 my $cached_disks = get_cached_disks
();
2441 my $disk_count = scalar(@$cached_disks);
2442 my $disk_labeled_widgets = [];
2443 for (my $i = 0; $i < $disk_count; $i++) {
2444 my $disk_selector = Gtk3
::ComboBoxText-
>new();
2445 $disk_selector->append_text("-- do not use --");
2446 $disk_selector->set_active(0);
2447 $disk_selector->set_visible(1);
2449 for my $hd (@$cached_disks) {
2450 my ($disk, $devname, $size, $model, $logical_bsize) = @$hd;
2451 $disk_selector->append_text(get_device_desc
($devname, $size, $model));
2454 $disk_selector->{pve_disk_id
} = $i;
2455 $disk_selector->signal_connect(changed
=> sub {
2457 my $diskid = $w->{pve_disk_id
};
2458 my $a = $w->get_active - 1;
2459 $config_options->{"disksel${diskid}"} = ($a >= 0) ?
$cached_disks->[$a] : undef;
2460 for my $btn (@$hdsize_buttons) {
2461 update_hdsize_adjustment
($btn->get_adjustment());
2465 if ($hdoption_first_setup) {
2466 $disk_selector->set_active ($i+1) if $cached_disks->[$i];
2469 if (my $cur_hd = $config_options->{"disksel$i"}) {
2470 foreach my $hd (@$cached_disks) {
2471 if (@$hd[1] eq @$cur_hd[1]) {
2472 $disk_selector->set_active($hdind+1);
2480 push @$disk_labeled_widgets, "Harddisk $i", $disk_selector;
2483 my $clear_all_button = Gtk3
::Button-
>new('_Deselect All');
2484 if ($disk_count > 3) {
2485 $clear_all_button->signal_connect('clicked', sub {
2487 for my $disk_selector (@$disk_labeled_widgets) {
2488 $disk_selector->set_active(0) if $is_widget;
2492 $clear_all_button->set_visible(1);
2495 my $scrolled_window = Gtk3
::ScrolledWindow-
>new();
2496 $scrolled_window->set_hexpand(1);
2497 $scrolled_window->set_propagate_natural_height(1) if $disk_count > 4;
2499 my $diskgrid = $create_label_widget_grid->($disk_labeled_widgets);
2501 $scrolled_window->add($diskgrid);
2502 $scrolled_window->set_policy('never', 'automatic');
2503 $scrolled_window->set_visible(1);
2504 $scrolled_window->set_min_content_height(190);
2506 my $vbox = Gtk3
::Box-
>new('vertical', 0);
2507 $vbox->pack_start($scrolled_window, 1, 1, 10);
2509 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
2510 $hbox->pack_end($clear_all_button, 0, 0, 20);
2511 $hbox->set_visible(1);
2512 $vbox->pack_end($hbox, 0, 0, 0);
2517 my $create_raid_advanced_grid = sub {
2518 my ($hdsize_btn) = @_;
2519 my $labeled_widgets = [];
2520 my $spinbutton_ashift = Gtk3
::SpinButton-
>new_with_range(9, 13, 1);
2521 $spinbutton_ashift->set_tooltip_text("zpool ashift property (pool sector size, default 2^12)");
2522 $spinbutton_ashift->signal_connect ("value-changed" => sub {
2524 $config_options->{ashift
} = $w->get_value_as_int();
2526 $config_options->{ashift
} = 12 if ! defined($config_options->{ashift
});
2527 $spinbutton_ashift->set_value($config_options->{ashift
});
2528 push @$labeled_widgets, "ashift";
2529 push @$labeled_widgets, $spinbutton_ashift;
2531 my $combo_compress = Gtk3
::ComboBoxText-
>new();
2532 $combo_compress->set_tooltip_text("zfs compression algorithm for rpool dataset");
2533 my $comp_opts = ["on","off","lzjb","lz4", "zle", "gzip", "zstd"];
2534 foreach my $opt (@$comp_opts) {
2535 $combo_compress->append($opt, $opt);
2537 $config_options->{compress
} = "on" if !defined($config_options->{compress
});
2538 $combo_compress->set_active_id($config_options->{compress
});
2539 $combo_compress->signal_connect (changed
=> sub {
2541 $config_options->{compress
} = $w->get_active_text();
2543 push @$labeled_widgets, "compress";
2544 push @$labeled_widgets, $combo_compress;
2546 my $combo_checksum = Gtk3
::ComboBoxText-
>new();
2547 $combo_checksum->set_tooltip_text("zfs checksum algorithm for rpool dataset");
2548 my $csum_opts = ["on", "off","fletcher2", "fletcher4", "sha256"];
2549 foreach my $opt (@$csum_opts) {
2550 $combo_checksum->append($opt, $opt);
2552 $config_options->{checksum
} = "on" if !($config_options->{checksum
});
2553 $combo_checksum->set_active_id($config_options->{checksum
});
2554 $combo_checksum->signal_connect (changed
=> sub {
2556 $config_options->{checksum
} = $w->get_active_text();
2558 push @$labeled_widgets, "checksum";
2559 push @$labeled_widgets, $combo_checksum;
2561 my $spinbutton_copies = Gtk3
::SpinButton-
>new_with_range(1,3,1);
2562 $spinbutton_copies->set_tooltip_text("zfs copies property for rpool dataset (in addition to RAID redundancy!)");
2563 $spinbutton_copies->signal_connect ("value-changed" => sub {
2565 $config_options->{copies
} = $w->get_value_as_int();
2567 $config_options->{copies
} = 1 if !defined($config_options->{copies
});
2568 $spinbutton_copies->set_value($config_options->{copies
});
2569 push @$labeled_widgets, "copies", $spinbutton_copies;
2571 push @$labeled_widgets, "hdsize", $hdsize_btn;
2572 return $create_label_widget_grid->($labeled_widgets);;
2575 my $create_btrfs_raid_advanced_grid = sub {
2576 my ($hdsize_btn) = @_;
2577 my $labeled_widgets = [];
2578 push @$labeled_widgets, "hdsize", $hdsize_btn;
2579 return $create_label_widget_grid->($labeled_widgets);;
2582 sub create_hdoption_view
{
2583 my $dialog = Gtk3
::Dialog-
>new();
2585 $dialog->set_title("Harddisk options");
2587 $dialog->add_button("_OK", 1);
2589 my $contarea = $dialog->get_content_area();
2591 my $hbox2 = Gtk3
::Box-
>new('horizontal', 0);
2592 $contarea->pack_start($hbox2, 1, 1, 5);
2594 my $grid = Gtk3
::Grid-
>new();
2595 $grid->set_column_spacing(10);
2596 $grid->set_row_spacing(10);
2598 $hbox2->pack_start($grid, 1, 0, 5);
2603 my $label0 = Gtk3
::Label-
>new("Filesystem");
2604 $label0->set_alignment (1, 0.5);
2605 $grid->attach($label0, 0, $row, 1, 1);
2607 my $fstypecb = Gtk3
::ComboBoxText-
>new();
2618 push @$fstype, 'btrfs (RAID0)', 'btrfs (RAID1)', 'btrfs (RAID10)'
2619 if $env->{cfg
}->{enable_btrfs
};
2622 foreach my $tmp (@$fstype) {
2623 $fstypecb->append_text($tmp);
2624 $fstypecb->set_active ($tcount) if $config_options->{filesys
} eq $tmp;
2628 $grid->attach($fstypecb, 1, $row, 1, 1);
2634 my $sep = Gtk3
::HSeparator-
>new();
2635 $sep->set_visible(1);
2636 $grid->attach($sep, 0, $row, 2, 1);
2639 my $hw_raid_note = Gtk3
::Label-
>new(""); # text will be set below, before making it visible
2640 $hw_raid_note->set_line_wrap(1);
2641 $hw_raid_note->set_max_width_chars(30);
2642 $hw_raid_note->set_visible(0);
2643 $grid->attach($hw_raid_note, 0, $row++, 2, 1);
2645 my $hdsize_labeled_widgets = [];
2649 if ( -b
$target_hd) {
2650 $hdsize = int(hd_size
($target_hd) / (1024 * 1024.0)); # size in GB
2651 } elsif ($target_hd) {
2652 $hdsize = int((-s
$target_hd) / (1024 * 1024 * 1024.0));
2655 my $spinbutton_hdsize_nonraid = get_hdsize_spin_button
($hdsize);
2656 push @$hdsize_labeled_widgets, "hdsize", $spinbutton_hdsize_nonraid;
2657 my $spinbutton_hdsize = $spinbutton_hdsize_nonraid;
2659 my $entry_swapsize = Gtk3
::Entry-
>new();
2660 $entry_swapsize->set_tooltip_text("maximum SWAP size (GB)");
2661 $entry_swapsize->signal_connect (key_press_event
=> \
&check_float
);
2662 $entry_swapsize->set_text($config_options->{swapsize
}) if defined($config_options->{swapsize
});
2663 push @$hdsize_labeled_widgets, "swapsize", $entry_swapsize;
2665 my $entry_maxroot = Gtk3
::Entry-
>new();
2666 if ($env->{product
} eq 'pve') {
2667 $entry_maxroot->set_tooltip_text("maximum size (GB) for LVM root volume");
2668 $entry_maxroot->signal_connect (key_press_event
=> \
&check_float
);
2669 $entry_maxroot->set_text($config_options->{maxroot
}) if $config_options->{maxroot
};
2670 push @$hdsize_labeled_widgets, "maxroot", $entry_maxroot;
2673 my $entry_minfree = Gtk3
::Entry-
>new();
2674 $entry_minfree->set_tooltip_text("minimum free LVM space (GB, required for LVM snapshots)");
2675 $entry_minfree->signal_connect (key_press_event
=> \
&check_float
);
2676 $entry_minfree->set_text($config_options->{minfree
}) if defined($config_options->{minfree
});
2677 push @$hdsize_labeled_widgets, "minfree", $entry_minfree;
2680 if ($env->{product
} eq 'pve') {
2681 $entry_maxvz = Gtk3
::Entry-
>new();
2682 $entry_maxvz->set_tooltip_text("maximum size (GB) for LVM data volume");
2683 $entry_maxvz->signal_connect (key_press_event
=> \
&check_float
);
2684 $entry_maxvz->set_text($config_options->{maxvz
}) if defined($config_options->{maxvz
});
2685 push @$hdsize_labeled_widgets, "maxvz", $entry_maxvz;
2688 my $spinbutton_hdsize_zfs = get_hdsize_spin_button
($hdsize);
2689 my $spinbutton_hdsize_btrfs = get_hdsize_spin_button
($hdsize);
2690 my $hdsize_buttons = [ $spinbutton_hdsize_zfs, $spinbutton_hdsize_btrfs ];
2691 my $options_stack = Gtk3
::Stack-
>new();
2692 $options_stack->set_visible(1);
2693 $options_stack->set_hexpand(1);
2694 $options_stack->set_vexpand(1);
2695 $options_stack->add_titled(&$create_raid_disk_grid($hdsize_buttons), "raiddisk", "Disk Setup");
2696 $options_stack->add_titled(&$create_label_widget_grid($hdsize_labeled_widgets), "hdsize", "Size Options");
2697 $options_stack->add_titled(&$create_raid_advanced_grid($spinbutton_hdsize_zfs), "raidzfsadvanced", "Advanced Options");
2698 $options_stack->add_titled(&$create_btrfs_raid_advanced_grid($spinbutton_hdsize_btrfs), "raidbtrfsadvanced", "Advanced Options");
2699 $options_stack->set_visible_child_name("raiddisk");
2700 my $options_stack_switcher = Gtk3
::StackSwitcher-
>new();
2701 $options_stack_switcher->set_halign('center');
2702 $options_stack_switcher->set_stack($options_stack);
2703 $grid->attach($options_stack_switcher, 0, $row, 2, 1);
2705 $grid->attach($options_stack, 0, $row, 2, 1);
2708 $hdoption_first_setup = 0;
2710 my $switch_view = sub {
2711 my $raid = $config_options->{filesys
} =~ m/zfs|btrfs/;
2712 my $is_zfs = $config_options->{filesys
} =~ m/zfs/;
2714 $target_hd_combo->set_visible(!$raid);
2715 $options_stack->get_child_by_name("hdsize")->set_visible(!$raid);
2716 $options_stack->get_child_by_name("raiddisk")->set_visible($raid);
2719 my $msg = "<b>Note</b>: " . ($is_zfs
2720 ?
"ZFS is not compatible with hardware RAID controllers, for details see the documentation."
2721 : "BTRFS integration in $env->{cfg}->{fullname} is a technology preview!"
2723 $hw_raid_note->set_markup($msg);
2725 $hw_raid_note->set_visible($raid);
2726 $options_stack_switcher->set_visible($raid);
2727 $options_stack->get_child_by_name("raidzfsadvanced")->set_visible($is_zfs);
2728 $options_stack->get_child_by_name("raidbtrfsadvanced")->set_visible(!$is_zfs);
2730 $target_hd_label->set_text("Target: $config_options->{filesys} ");
2731 $options_stack->set_visible_child_name("raiddisk");
2733 $target_hd_label->set_text("Target Harddisk: ");
2737 $spinbutton_hdsize = $is_zfs ?
$spinbutton_hdsize_zfs : $spinbutton_hdsize_btrfs;
2739 $spinbutton_hdsize = $spinbutton_hdsize_nonraid;
2742 my (undef, $pref_width) = $dialog->get_preferred_width();
2743 my (undef, $pref_height) = $dialog->get_preferred_height();
2744 $pref_height = 750 if $pref_height > 750;
2745 $dialog->resize($pref_width, $pref_height);
2750 $fstypecb->signal_connect (changed
=> sub {
2751 $config_options->{filesys
} = $fstypecb->get_active_text();
2755 my $sep2 = Gtk3
::HSeparator-
>new();
2756 $sep2->set_visible(1);
2757 $contarea->pack_end($sep2, 1, 1, 10);
2763 my $get_float = sub {
2766 my $text = $entry->get_text();
2767 return undef if !defined($text);
2772 return undef if $text !~ m/^\d+(\.\d+)?$/;
2779 if (($tmp = &$get_float($spinbutton_hdsize)) && ($tmp != $hdsize)) {
2780 $config_options->{hdsize
} = $tmp;
2782 delete $config_options->{hdsize
};
2785 if (defined($tmp = &$get_float($entry_swapsize))) {
2786 $config_options->{swapsize
} = $tmp;
2788 delete $config_options->{swapsize
};
2791 if (defined($tmp = &$get_float($entry_maxroot))) {
2792 $config_options->{maxroot
} = $tmp;
2794 delete $config_options->{maxroot
};
2797 if (defined($tmp = &$get_float($entry_minfree))) {
2798 $config_options->{minfree
} = $tmp;
2800 delete $config_options->{minfree
};
2803 if ($entry_maxvz && defined($tmp = &$get_float($entry_maxvz))) {
2804 $config_options->{maxvz
} = $tmp;
2806 delete $config_options->{maxvz
};
2812 my $get_raid_devlist = sub {
2814 my $dev_name_hash = {};
2816 my $cached_disks = get_cached_disks
();
2818 for (my $i = 0; $i < @$cached_disks; $i++) {
2819 if (my $hd = $config_options->{"disksel$i"}) {
2820 my ($disk, $devname, $size, $model, $logical_bsize) = @$hd;
2821 die "device '$devname' is used more than once\n"
2822 if $dev_name_hash->{$devname};
2823 $dev_name_hash->{$devname} = $hd;
2824 push @$devlist, $hd;
2831 sub zfs_mirror_size_check
{
2832 my ($expected, $actual) = @_;
2834 die "mirrored disks must have same size\n"
2835 if abs($expected - $actual) > $expected / 10;
2838 sub legacy_bios_4k_check
{
2840 die "Booting from 4kn drive in legacy BIOS mode is not supported.\n"
2841 if (($boot_type ne 'efi') && ($lbs == 4096));
2844 sub get_zfs_raid_setup
{
2845 my $filesys = $config_options->{filesys
};
2847 my $devlist = &$get_raid_devlist();
2849 my $diskcount = scalar(@$devlist);
2850 die "$filesys needs at least one device\n" if $diskcount < 1;
2853 if ($filesys eq 'zfs (RAID0)') {
2854 foreach my $hd (@$devlist) {
2855 legacy_bios_4k_check
(@$hd[4]);
2858 } elsif ($filesys eq 'zfs (RAID1)') {
2859 die "zfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
2861 my $hd = @$devlist[0];
2862 my $expected_size = @$hd[2]; # all disks need approximately same size
2863 foreach my $hd (@$devlist) {
2864 zfs_mirror_size_check
($expected_size, @$hd[2]);
2865 legacy_bios_4k_check
(@$hd[4]);
2868 } elsif ($filesys eq 'zfs (RAID10)') {
2869 die "zfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
2870 die "zfs (RAID10) needs an even number of devices\n" if $diskcount & 1;
2872 for (my $i = 0; $i < $diskcount; $i+=2) {
2873 my $hd1 = @$devlist[$i];
2874 my $hd2 = @$devlist[$i+1];
2875 zfs_mirror_size_check
(@$hd1[2], @$hd2[2]); # pairs need approximately same size
2876 legacy_bios_4k_check
(@$hd1[4]);
2877 legacy_bios_4k_check
(@$hd2[4]);
2878 $cmd .= ' mirror ' . @$hd1[1] . ' ' . @$hd2[1];
2881 } elsif ($filesys =~ m/^zfs \(RAIDZ-([123])\)$/) {
2883 my $mindisks = 2 + $level;
2884 die "zfs (RAIDZ-$level) needs at least $mindisks devices\n" if scalar(@$devlist) < $mindisks;
2885 my $hd = @$devlist[0];
2886 my $expected_size = @$hd[2]; # all disks need approximately same size
2887 $cmd .= " raidz$level";
2888 foreach my $hd (@$devlist) {
2889 zfs_mirror_size_check
($expected_size, @$hd[2]);
2890 legacy_bios_4k_check
(@$hd[4]);
2894 die "unknown zfs mode '$filesys'\n";
2897 return ($devlist, $cmd);
2900 sub get_btrfs_raid_setup
{
2902 my $filesys = $config_options->{filesys
};
2904 my $devlist = &$get_raid_devlist();
2906 my $diskcount = scalar(@$devlist);
2907 die "$filesys needs at least one device\n" if $diskcount < 1;
2911 if ($diskcount == 1) {
2914 if ($filesys eq 'btrfs (RAID0)') {
2916 } elsif ($filesys eq 'btrfs (RAID1)') {
2917 die "btrfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
2919 } elsif ($filesys eq 'btrfs (RAID10)') {
2920 die "btrfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
2923 die "unknown btrfs mode '$filesys'\n";
2927 return ($devlist, $mode);
2930 my $last_hd_selected = 0;
2931 sub create_hdsel_view
{
2933 $prev_btn->set_sensitive(1); # enable previous button at this point
2937 my $vbox = Gtk3
::VBox-
>new(0, 0);
2938 $inbox->pack_start($vbox, 1, 0, 0);
2939 my $hbox = Gtk3
::HBox-
>new(0, 0);
2940 $vbox->pack_start($hbox, 0, 0, 10);
2942 my $cached_disks = get_cached_disks
();
2943 my ($disk, $devname, $size, $model, $logical_bsize) = $cached_disks->[0]->@*;
2944 $target_hd = $devname if !defined($target_hd);
2946 $target_hd_label = Gtk3
::Label-
>new("Target Harddisk: ");
2947 $hbox->pack_start($target_hd_label, 0, 0, 0);
2949 $target_hd_combo = Gtk3
::ComboBoxText-
>new();
2951 foreach my $hd ($cached_disks->@*) {
2952 ($disk, $devname, $size, $model, $logical_bsize) = @$hd;
2953 $target_hd_combo->append_text(get_device_desc
($devname, $size, $model));
2956 my $raid = $config_options->{filesys
} =~ m/zfs|btrfs/;
2958 $target_hd_label->set_text("Target: $config_options->{filesys} ");
2959 $target_hd_combo->set_visible(0);
2960 $target_hd_combo->set_no_show_all(1);
2962 $target_hd_combo->set_active($last_hd_selected);
2963 $target_hd_combo->signal_connect(changed
=> sub {
2964 $a = shift-
>get_active;
2965 my ($disk, $devname) = @{@$cached_disks[$a]};
2966 $last_hd_selected = $a;
2967 $target_hd = $devname;
2970 $hbox->pack_start($target_hd_combo, 0, 0, 10);
2972 my $options = Gtk3
::Button-
>new('_Options');
2973 $options->signal_connect (clicked
=> \
&create_hdoption_view
);
2974 $hbox->pack_start ($options, 0, 0, 0);
2981 set_next
(undef, sub {
2983 if ($config_options->{filesys
} =~ m/zfs/) {
2984 my ($devlist) = eval { get_zfs_raid_setup
() };
2986 display_message
("Warning: $err\nPlease fix ZFS setup first.");
2989 $config_options->{target_hds
} = [ map { $_->[1] } @$devlist ];
2990 } elsif ($config_options->{filesys
} =~ m/btrfs/) {
2991 my ($devlist) = eval { get_btrfs_raid_setup
() };
2993 display_message
("Warning: $err\nPlease fix BTRFS setup first.");
2996 $config_options->{target_hds
} = [ map { $_->[1] } @$devlist ];
2999 my $target_block_size = Proxmox
::Sys
::Block
::logical_blocksize
($target_hd);
3000 legacy_bios_4k_check
($target_block_size);
3003 display_message
("Warning: $err\n");
3006 $config_options->{target_hds
} = [ $target_hd ];
3010 create_country_view
();
3014 sub create_extract_view
{
3020 $next->set_sensitive(0);
3021 $prev_btn->set_sensitive(0);
3024 my $vbox = Gtk3
::VBox-
>new(0, 0);
3025 $inbox->pack_start ($vbox, 1, 0, 0);
3026 my $hbox = Gtk3
::HBox-
>new(0, 0);
3027 $vbox->pack_start ($hbox, 0, 0, 10);
3029 my $vbox2 = Gtk3
::VBox-
>new(0, 0);
3030 $hbox->pack_start ($vbox2, 0, 0, 0);
3032 $progress_status = Gtk3
::Label-
>new('');
3033 $vbox2->pack_start ($progress_status, 1, 1, 0);
3035 $progress = Gtk3
::ProgressBar-
>new;
3036 $progress->set_show_text(1);
3037 $progress->set_size_request (600, -1);
3039 $vbox2->pack_start($progress, 0, 0, 0);
3043 my $tdir = is_test_mode
() ?
"target" : "/target";
3045 my $base = "${proxmox_cddir}/$env->{product}-base.squashfs";
3047 eval { extract_data
($base, $tdir); };
3050 $next->set_sensitive(1);
3052 set_next
("_Reboot", sub { exit (0); } );
3055 display_html
("fail.htm");
3056 display_error
($err);
3059 display_html
("success.htm");
3061 if ($config_options->{autoreboot
}) {
3062 Glib
::Timeout-
>add(1000, sub {
3063 if ($autoreboot_seconds > 0) {
3064 $autoreboot_seconds--;
3065 display_html
("success.htm");
3074 sub create_intro_view
{
3076 $prev_btn->set_sensitive(0);
3080 if (int($total_memory) < 1024) {
3081 display_error
("Less than 1 GiB of usable memory detected, installation will probably fail.\n\n".
3082 "See 'System Requirements' in the $env->{cfg}->{fullname} documentation.");
3085 if ($env->{product
} eq 'pve') {
3086 my $cpuinfo = eval { file_read_all
('/proc/cpuinfo') };
3087 if (!$cpuinfo || $cpuinfo !~ /^flags\s*:.*(vmx|svm)/m) {
3089 "No support for hardware-accelerated KVM virtualization detected.\n\n"
3090 ."Check BIOS settings for Intel VT / AMD-V / SVM."
3098 set_next
("I a_gree", \
&create_hdsel_view
);
3101 $ipconf = Proxmox
::Sys
::Net
::get_ip_config
();
3103 $country = detect_country
() if $ipconf->{default} || is_test_mode
();
3105 # read country, kmap and timezone infos
3106 $cmap = read_cmap
();
3108 if (!defined($cmap->{country
}->{$country})) {
3109 log_warn
("ignoring detected country '$country', invalid or unknown\n");
3115 create_main_window
();
3117 my $initial_error = 0;
3120 my $cached_disks = get_cached_disks
();
3121 if (!defined($cached_disks) || (scalar (@$cached_disks) <= 0)) {
3122 print "no harddisks found\n";
3124 display_html
("nohds.htm");
3125 set_next
("Reboot", sub { exit(0); } );
3127 foreach my $hd (@$cached_disks) {
3128 my ($disk, $devname) = @$hd;
3129 next if $devname =~ m
|^/dev/md\d
+$|;
3130 print "found Disk$disk N:$devname\n";
3135 if (!$initial_error && (scalar keys %{ $ipconf->{ifaces
} } == 0)) {
3136 print "no network interfaces found\n";
3138 display_html
("nonics.htm");
3139 set_next
("Reboot", sub { exit(0); } );
3142 create_intro_view
() if !$initial_error;
3146 # reap left over zombie processes
3147 while ((my $child = waitpid(-1, POSIX
::WNOHANG
)) > 0) {
3148 print "reaped child $child\n";