]>
git.proxmox.com Git - pve-installer.git/blob - proxinstall
3 $ENV{DEBIAN_FRONTEND
} = 'noninteractive';
16 use String
::ShellQuote
;
23 my $kapi = `uname -r`;
28 if (!$ENV{G_SLICE
} || $ENV{G_SLICE
} ne "always-malloc") {
29 die "do not use slice allocator (run with 'G_SLICE=always-malloc ./proxinstall ...')\n";
32 if (!GetOptions
('testmode=s' => \
$opt_testmode)) {
37 my $zfstestpool = "test_rpool";
38 my $zfspoolname = $opt_testmode ?
$zfstestpool : 'rpool';
40 my $storage_cfg_zfs = <<__EOD__;
43 content iso,vztmpl,backup
46 pool $zfspoolname/data
48 content images,rootdir
51 my $storage_cfg_btrfs = <<__EOD__;
54 content iso,vztmpl,backup
58 path /var/lib/pve/local-btrfs
59 content iso,vztmpl,backup,images,rootdir
62 my $storage_cfg_lvmthin = <<__EOD__;
65 content iso,vztmpl,backup
70 content rootdir,images
74 sub file_read_firstline
{
77 my $fh = IO
::File-
>new ($filename, "r");
85 my $logfd = IO
::File-
>new (">/tmp/install.log");
87 my $proxmox_dir = $opt_testmode ? Cwd
::cwd
() : "/var/lib/pve-installer";
89 my $grub_plattform = "pc"; # pc, efi-amd64 or efi-ia32
91 $grub_plattform = "efi-amd64" if -d
"/sys/firmware/efi";
93 my $IPV4OCTET = "(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9])?[0-9])";
94 my $IPV4RE = "(?:(?:$IPV4OCTET\\.){3}$IPV4OCTET)";
95 my $IPV6H16 = "(?:[0-9a-fA-F]{1,4})";
96 my $IPV6LS32 = "(?:(?:$IPV4RE|$IPV6H16:$IPV6H16))";
99 "(?:(?:" . "(?:$IPV6H16:){6})$IPV6LS32)|" .
100 "(?:(?:" . "::(?:$IPV6H16:){5})$IPV6LS32)|" .
101 "(?:(?:(?:" . "$IPV6H16)?::(?:$IPV6H16:){4})$IPV6LS32)|" .
102 "(?:(?:(?:(?:$IPV6H16:){0,1}$IPV6H16)?::(?:$IPV6H16:){3})$IPV6LS32)|" .
103 "(?:(?:(?:(?:$IPV6H16:){0,2}$IPV6H16)?::(?:$IPV6H16:){2})$IPV6LS32)|" .
104 "(?:(?:(?:(?:$IPV6H16:){0,3}$IPV6H16)?::(?:$IPV6H16:){1})$IPV6LS32)|" .
105 "(?:(?:(?:(?:$IPV6H16:){0,4}$IPV6H16)?::" . ")$IPV6LS32)|" .
106 "(?:(?:(?:(?:$IPV6H16:){0,5}$IPV6H16)?::" . ")$IPV6H16)|" .
107 "(?:(?:(?:(?:$IPV6H16:){0,6}$IPV6H16)?::" . ")))";
109 my $IPRE = "(?:$IPV4RE|$IPV6RE)";
112 my $ipv4_mask_hash = {
129 '255.255.128.0' => 17,
130 '255.255.192.0' => 18,
131 '255.255.224.0' => 19,
132 '255.255.240.0' => 20,
133 '255.255.248.0' => 21,
134 '255.255.252.0' => 22,
135 '255.255.254.0' => 23,
136 '255.255.255.0' => 24,
137 '255.255.255.128' => 25,
138 '255.255.255.192' => 26,
139 '255.255.255.224' => 27,
140 '255.255.255.240' => 28,
141 '255.255.255.248' => 29,
142 '255.255.255.252' => 30
145 my ($window, $cmdbox, $inbox, $htmlview);
146 my ($next, $next_fctn, $target_hd);
147 my ($progress, $progress_status);
148 my ($ipversion, $ipaddress, $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';
160 my $keymap = 'en-us';
163 # parse command line args
165 my $config_options = {};
167 if ($cmdline =~ m/\s(ext3|ext4|xfs)(\s.*)?$/) {
168 $config_options->{filesys
} = $1;
170 $config_options->{filesys
} = 'ext4';
173 if ($cmdline =~ m/hdsize=(\d+(\.\d+)?)[\s\n]/i) {
174 $config_options->{hdsize
} = $1;
177 if ($cmdline =~ m/swapsize=(\d+(\.\d+)?)[\s\n]/i) {
178 $config_options->{swapsize
} = $1;
181 if ($cmdline =~ m/maxroot=(\d+(\.\d+)?)[\s\n]/i) {
182 $config_options->{maxroot
} = $1;
185 if ($cmdline =~ m/minfree=(\d+(\.\d+)?)[\s\n]/i) {
186 $config_options->{minfree
} = $1;
189 if ($cmdline =~ m/maxvz=(\d+(\.\d+)?)[\s\n]/i) {
190 $config_options->{maxvz
} = $1;
193 my $postfix_main_cf = <<_EOD;
194 # See /usr/share/postfix/main.cf.dist for a commented, more complete version
198 smtpd_banner = \$myhostname ESMTP \$mail_name (Debian/GNU)
201 # appending .domain is the MUA's job.
202 append_dot_mydomain = no
204 # Uncomment the next line to generate "delayed mail" warnings
205 #delay_warning_time = 4h
207 alias_maps = hash:/etc/aliases
208 alias_database = hash:/etc/aliases
209 mydestination = \$myhostname, localhost.\$mydomain, localhost
211 mynetworks = 127.0.0.0/8
212 inet_interfaces = loopback-only
213 recipient_delimiter = +
220 return String
::ShellQuote
::shell_quote
($str);
226 die "no arguments" if !$cmd;
228 return $cmd if !ref($cmd);
231 foreach my $arg (@$cmd) { push @qa, shellquote
($arg); }
233 return join (' ', @qa);
239 return run_command
($cmd, undef, undef, 1);
243 my ($cmd, $func, $input, $noout) = @_;
249 # see 'man bash' for option pipefail
250 $cmd = [ '/bin/bash', '-c', "set -o pipefail && $cmd" ];
255 $cmdstr = cmd2string
($cmd);
259 if ($input && ($cmdstr !~ m/chpasswd/)) {
260 $cmdtxt = "# $cmdstr <<EOD\n$input";
262 $cmdtxt .= "\nEOD\n";
264 $cmdtxt = "# $cmdstr\n";
272 print $logfd $cmdtxt;
274 my $reader = IO
::File-
>new();
275 my $writer = IO
::File-
>new();
276 my $error = IO
::File-
>new();
282 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
288 if ($orig_pid != $$) {
295 print $writer $input if defined $input;
298 my $select = new IO
::Select
;
299 $select->add ($reader);
300 $select->add ($error);
302 my ($ostream, $logout) = ('', '', '');
304 while ($select->count) {
305 my @handles = $select->can_read (0.2);
307 Gtk3
::main_iteration
() while Gtk3
::events_pending
();
309 next if !scalar (@handles); # timeout
311 foreach my $h (@handles) {
313 my $count = sysread ($h, $buf, 4096);
314 if (!defined ($count)) {
318 die "command '$cmd' failed: $err";
320 $select->remove ($h) if !$count;
322 $ostream .= $buf if !($noout || $func);
324 while ($logout =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
326 &$func($line) if $func;
329 } elsif ($h eq $error) {
330 $ostream .= $buf if !($noout || $func);
338 &$func($logout) if $func;
340 my $rv = waitpid ($pid, 0);
342 return $? if $noout; # behave like standard system();
347 die "command '$cmdstr' failed with exit code $ec";
355 print "trying to detect country...\n";
356 my $cpid = open2
(\
*TMP
, undef, "traceroute -N 1 -q 1 -n 8.8.8.8");
357 return undef if !$cpid;
361 my $previous_alarm = alarm (10);
363 local $SIG{ALRM
} = sub { die "timed out!\n" };
365 while (defined ($line = <TMP
>)) {
366 print $logfd "DC TRACEROUTE: $line";
367 if ($line =~ m/\s*\d+\s+(\d+\.\d+\.\d+\.\d+)\s/) {
368 my $geoip = `geoiplookup $1`;
369 print $logfd "DC GEOIP: $geoip";
370 if ($geoip =~ m/GeoIP Country Edition:\s*([A-Z]+),/) {
372 print $logfd "DC FOUND: $country\n";
381 alarm ($previous_alarm);
386 print "unable to detect country - $err\n";
388 print "detected country: " . uc($country) . "\n";
390 print "unable to detect country\n";
398 open (MEMINFO, "/proc/meminfo");
400 my $res = 512; # default to 512 if something goes wrong
401 while (my $line = <MEMINFO>) {
402 if ($line =~ m/^MemTotal:\s+(\d+)\s*kB/i) {
403 $res = int ($1 / 1024);
412 my $total_memory = get_memtotal();
415 my ($src, $dest) = @_;
417 my ($dev1,$ino1) = stat ($src);
418 my ($dev2,$ino2) = stat ($dest);
420 return 0 if !($dev1 && $dev2 && $ino1 && $ino2);
422 return $ino1 == $ino2 && $dev1 == $dev2;
425 sub find_stable_path {
426 my ($stabledir, $bdev) = @_;
428 foreach my $path (<$stabledir/*>) {
429 if (link_points_to ($path, $bdev)) {
430 return wantarray ? ($path, basename($path)) : $path;
435 sub find_dev_by_uuid {
438 my ($full_path, $name) = find_stable_path ("/dev/disk/by-uuid", $bdev);
448 push @$res, [-1, $opt_testmode, int((-s $opt_testmode)/512), "TESTDISK"];
454 foreach my $bd (</sys/block/*>) {
455 next if $bd =~ m|^/sys/block/ram\d+$|;
456 next if $bd =~ m|^/sys/block/loop\d+$|;
457 next if $bd =~ m|^/sys/block/md\d+$|;
458 next if $bd =~ m|^/sys/block/dm-.*$|;
459 next if $bd =~ m|^/sys/block/fd\d+$|;
460 next if $bd =~ m|^/sys/block/sr\d+$|;
462 my $dev = file_read_firstline("$bd/dev");
467 my $info = `udevadm info
--path
$bd --query all
`;
470 next if $info !~ m/^E: DEVTYPE=disk$/m;
472 next if $info =~ m/^E: ID_CDROM/m;
474 my ($name) = $info =~ m/^N: (\S+)$/m;
477 my $real_name = "/dev/$name";
479 my $size = file_read_firstline("$bd/size");
481 $size = undef if !($size && $size =~ m/^\d+$/);
483 my $model = file_read_firstline("$bd/device/model") || '';
486 if (length ($model) > 30) {
487 $model = substr ($model, 0, 30);
489 push @$res, [$count++, $real_name, $size, $model] if $size;
491 print STDERR "ERROR: unable to map device $dev ($bd)\n";
499 my $countryfn = $opt_testmode ? "/usr/share/pve-manager/country.dat" :
500 "/cdrom/proxmox/country.dat";
501 open (TMP, "<$countryfn") || die "unable to open '$countryfn' - $!\n";
504 my $countryhash = {};
507 while (defined ($line = <TMP>)) {
508 if ($line =~ m|^map:([^\s:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]*):$|) {
516 $kmaphash->{$2} = $1;
517 } elsif ($line =~ m|^([a-z]{2}):([^:]+):([^:]*):([^:]*):$|) {
523 $countryhash->{lc($2)} = $1;
525 warn "unable to parse 'country.dat' line: $line";
532 my $zonefn = "/usr/share/zoneinfo/zone.tab";
533 open (TMP, "<$zonefn") || die "unable to open '$zonefn' - $!\n";
534 while (defined ($line = <TMP>)) {
535 next if $line =~ m/^\#/;
536 next if $line =~ m/^\s*$/;
537 if ($line =~ m|^([A-Z][A-Z])\s+\S+\s+(([^/]+)/\S+)\s|) {
539 $cczones->{$cc}->{$2} = 1;
540 $country->{$cc}->{zone} = $2 if !defined ($country->{$cc}->{zone});
551 countryhash => $countryhash,
553 kmaphash => $kmaphash,
557 # search for Harddisks
558 my $hds = hd_list ();
563 foreach my $hd (@$hds) {
564 my ($disk, $devname, $size, $model) = @$hd;
565 return int($size/2) if $devname eq $dev;
568 die "no such device '$dev'\n";
571 sub get_partition_dev {
572 my ($dev, $partnum) = @_;
574 if ($dev =~ m|^/dev/[hxsev]d[a-z]$|) {
575 return "${dev}$partnum";
576 } elsif ($dev =~ m|^/dev/[^/]+/c\d+d\d+$|) {
577 return "${dev}p$partnum";
578 } elsif ($dev =~ m|^/dev/[^/]+/d\d+$|) {
579 return "${dev}p$partnum";
580 } elsif ($dev =~ m|^/dev/[^/]+/hd[a-z]$|) {
581 return "${dev}$partnum";
582 } elsif ($dev =~ m|^/dev/nvme\d+n\d+$|) {
583 return "${dev}p$partnum";
585 die "unable to get device for partition $partnum on device $dev\n";
590 sub file_get_contents {
591 my ($filename, $max) = @_;
593 my $fh = IO::File->new($filename, "r") ||
594 die "can't open '$filename' - $!\n";
596 local $/; # slurp mode
606 my ($text, $filename) = @_;
608 my $fd = IO::File->new (">$filename") ||
609 die "unable to open file '$filename' - $!\n";
614 sub update_progress {
615 my ($frac, $start, $end, $text) = @_;
617 my $part = $end - $start;
618 my $res = $start + $frac*$part;
620 $progress->set_fraction ($res);
621 $progress->set_text (sprintf ("%d%%", int ($res*100)));
622 $progress_status->set_text ($text) if defined ($text);
624 Gtk3::main_iteration() while Gtk3::events_pending();
629 mkfs => 'mkfs.ext3 -F',
631 mkfs_data_opt => '-m 0',
632 root_mountopt => 'errors=remount-ro',
635 mkfs => 'mkfs.ext4 -F',
637 mkfs_data_opt => '-m 0',
638 root_mountopt => 'errors=remount-ro',
641 mkfs => 'mkfs.xfs -f',
648 sub create_filesystem {
649 my ($dev, $name, $type, $start, $end, $fs, $fe) = @_;
651 my $range = $end - $start;
652 my $rs = $start + $range*$fs;
653 my $re = $start + $range*$fe;
656 my $fsdata = $fssetup->{$type} || die "internal error - unknown file system '$type'";
657 my $opts = $name eq 'root' ? $fsdata->{mkfs_root_opt} : $fsdata->{mkfs_data_opt};
659 update_progress (0, $rs, $re, "creating $name filesystem");
661 run_command ("$fsdata->{mkfs} $opts $dev", sub {
664 if ($line =~ m/Writing inode tables:\s+(\d+)\/(\d+)/) {
666 } elsif ($max && $line =~ m/(\d+)\/$max/) {
667 update_progress (($1/$max)*0.9, $rs, $re);
668 } elsif ($line =~ m/Creating journal.*done/) {
669 update_progress (0.95, $rs, $re);
670 } elsif ($line =~ m/Writing superblocks and filesystem.*done/) {
671 update_progress (1, $rs, $re);
677 my ($targetdir, $dcdata) = @_;
679 my $cfgfile = "/tmp/debconf.txt";
680 write_config ($dcdata, "$targetdir/$cfgfile");
681 syscmd ("chroot $targetdir debconf-set-selections $cfgfile");
682 unlink "$targetdir/$cfgfile";
686 my ($targetdir, $cmd, $new_cmd) = @_;
688 syscmd ("chroot $targetdir dpkg-divert --package proxmox " .
689 "--add --rename $cmd") == 0 ||
690 die "unable to exec dpkg-divert\n";
692 syscmd ("ln -sf ${new_cmd} $targetdir/$cmd") == 0 ||
693 die "unable to link diversion to ${new_cmd}\n";
696 sub diversion_remove {
697 my ($targetdir, $cmd) = @_;
699 syscmd ("mv $targetdir/${cmd}.distrib $targetdir/${cmd};") == 0 ||
700 die "unable to remove $cmd diversion\n";
702 syscmd ("chroot $targetdir dpkg-divert --remove $cmd") == 0 ||
703 die "unable to remove $cmd diversion\n";
707 my ($partitions, $mode) = @_;
709 die "unknown btrfs mode '$mode'"
710 if !($mode eq 'single' || $mode eq 'raid0' ||
711 $mode eq 'raid1' || $mode eq 'raid10');
713 my $cmd = ['mkfs.btrfs', '-f'];
715 push @$cmd, '-d', $mode, '-m', $mode;
717 push @$cmd, @$partitions;
722 sub zfs_create_rpool {
725 syscmd ("zpool create -f -o ashift=12 -o cachefile=none $zfspoolname $vdev") == 0 ||
726 die "unable to create zfs root pool\n";
728 syscmd ("zfs create $zfspoolname/ROOT") == 0 ||
729 die "unable to create zfs $zfspoolname/ROOT volume\n";
731 syscmd ("zfs create $zfspoolname/data") == 0 ||
732 die "unable to create zfs $zfspoolname/data volume\n";
734 syscmd ("zfs create $zfspoolname/ROOT/pve-1") == 0 ||
735 die "unable to create zfs $zfspoolname/ROOT/pve-1 volume\n";
737 # disable atime during insatll
738 syscmd ("zfs set atime=off $zfspoolname") == 0 ||
739 die "unable to set zfs properties\n";
740 syscmd ("zfs set compression=lz4 $zfspoolname") == 0 ||
741 die "unable to set zfs properties\n";
744 sub zfs_create_swap {
747 syscmd ("zfs create -V ${swapsize}K -b 4K $zfspoolname/swap") == 0 ||
748 die "unable to create zfs swap device\n";
750 syscmd ("zfs set com.sun:auto-snapshot=false $zfspoolname/swap") == 0 ||
751 die "unable to set zfs properties\n";
753 # reduces memory pressure
754 syscmd ("zfs set sync=always $zfspoolname/swap") == 0 ||
755 die "unable to set zfs properties\n";
757 return "/dev/zvol/$zfspoolname/swap";
760 sub partition_bootable_disk {
761 my ($target_dev, $maxhdsize, $ptype) = @_;
763 die "too dangerous" if $opt_testmode;
765 die "unknown partition type '$ptype'"
766 if !($ptype eq '8E00' || $ptype eq '8300');
768 syscmd("sgdisk -Z ${target_dev}");
769 my $hdsize = hd_size($target_dev); # size in blocks (1024 bytes)
771 my $restricted_hdsize_mb = 0; # 0 ==> end of partition
772 if ($maxhdsize && ($maxhdsize < $hdsize)) {
773 $hdsize = $maxhdsize;
774 $restricted_hdsize_mb = int($hdsize/1024) . 'M';
777 my $hdgb = int($hdsize/(1024*1024));
778 die "hardisk '$target_dev' too small (${hdsize}GB)\n" if $hdgb < 8;
780 # 1 - GRUB boot partition: 1M
782 # 3 - OS/Data partition
784 my $grubbootdev = get_partition_dev($target_dev, 1);
785 my $efibootdev = get_partition_dev($target_dev, 2);
786 my $osdev = get_partition_dev ($target_dev, 3);
788 my $pcmd = ['sgdisk', '-a1'];
791 push @$pcmd, "-n$pnum:34:2047", "-t$pnum:EF02";
794 # Note: from sector 2048 to 128M
795 my $endsec = 128*1024*2 - 1;
796 push @$pcmd, "-n$pnum:2048:$endsec", "-t$pnum:EF00";
799 # Note: from 128M to end
800 push @$pcmd, "-n$pnum:128M:${restricted_hdsize_mb}", "-t$pnum:$ptype";
802 push @$pcmd, $target_dev;
804 my $os_size = $hdsize - 128*1024;
806 syscmd($pcmd) == 0 ||
807 die "unable to partition harddisk '${target_dev}'\n";
809 return ($os_size, $osdev, $efibootdev);
812 # ZFS has this use_whole_disk concept, so we try to partition the same
813 # way as zfs does by default. There is room at start of disk to insert
814 # a grub boot partition. But adding a EFI ESP is not possible.
816 # Note: zfs people think this is just a waste of space an not
817 # required. Instead, you should put the ESP on another disk (log,
820 sub partition_bootable_zfs_disk {
821 my ($target_dev) = @_;
823 die "too dangerous" if $opt_testmode;
825 syscmd("sgdisk -Z ${target_dev}");
826 my $hdsize = hd_size($target_dev); # size in blocks (1024 bytes)
828 my $hdgb = int($hdsize/(1024*1024));
829 die "hardisk '$target_dev' too small (${hdsize}GB)\n" if $hdgb < 8;
831 # 1 - GRUB boot partition: 1M
832 # 2 - OS/Data partition
833 # 9 - ZFS reserved partition
835 my $grubbootdev = get_partition_dev($target_dev, 1);
836 my $osdev = get_partition_dev ($target_dev, 2);
838 my $pcmd = ['sgdisk', '-a1'];
841 push @$pcmd, "-n$pnum:34:2047", "-t$pnum:EF02";
844 push @$pcmd, "-n$pnum:-8M:0", "-t$pnum:BF07";
847 push @$pcmd, "-n$pnum:2048:0", "-t$pnum:BF01", '-c', "$pnum:zfs";
849 push @$pcmd, $target_dev;
851 my $os_size = $hdsize - 1024 - 1024*8;
853 syscmd($pcmd) == 0 ||
854 die "unable to partition harddisk '${target_dev}'\n";
856 return ($os_size, $osdev);
859 sub create_lvm_volumes {
860 my ($lvmdev, $os_size, $swap_size) = @_;
862 my $rootdev = '/dev/pve/root';
863 my $datadev = '/dev/pve/data';
864 my $swapfile = '/dev/pve/swap';
866 # we use --metadatasize 250k, which reseults in "pe_start = 512"
867 # so pe_start is aligned on a 128k boundary (advantage for SSDs)
868 syscmd ("/sbin/pvcreate --metadatasize 250k -y -ff $lvmdev") == 0 ||
869 die "unable to initialize physical volume $lvmdev\n";
870 syscmd ("/sbin/vgcreate pve $lvmdev") == 0 ||
871 die "unable to create volume group 'pve'\n";
873 my $hdgb = int($os_size/(1024*1024));
874 my $space = (($hdgb > 128) ? 16 : ($hdgb/8))*1024*1024;
877 if ($config_options->{maxroot}) {
878 $maxroot = $config_options->{maxroot};
883 my $rootsize = (($hdgb > ($maxroot*4)) ? $maxroot : $hdgb/4)*1024*1024;
885 my $rest = $os_size - $swap_size - $rootsize; # in KB
888 if ($config_options->{minfree}) {
889 $minfree = (($config_options->{minfree}*1024*1024) >= $rest ) ? $space :
890 $config_options->{minfree}*1024*1024 ;
895 $rest = $rest - $minfree;
897 if ($config_options->{maxvz}) {
898 $rest = (($config_options->{maxvz}*1024*1024) <= $rest) ?
899 $config_options->{maxvz}*1024*1024 : $rest;
902 syscmd ("/sbin/lvcreate -L${swap_size}K -nswap pve") == 0 ||
903 die "unable to create swap volume\n";
905 syscmd ("/sbin/lvcreate -L${rootsize}K -nroot pve") == 0 ||
906 die "unable to create root volume\n";
908 syscmd ("/sbin/lvcreate -L${rest}K -ndata pve") == 0 ||
909 die "unable to create data volume\n";
911 syscmd ("/sbin/lvconvert --yes --type thin-pool pve/data") == 0 ||
912 die "unable to create data thin-pool\n";
914 syscmd ("/sbin/vgchange -a y pve") == 0 ||
915 die "unable to activate volume group\n";
917 return ($rootdev, $datadev, $swapfile);
920 sub compute_swapsize {
923 my $hdgb = int($hdsize/(1024*1024));
926 if ($config_options->{swapsize}) {
927 $swapsize = $config_options->{swapsize}*1024*1024;
929 my $ss = int ($total_memory / 1024);
931 $ss = ($hdgb/8) if $ss > ($hdgb/8);
933 $swapsize = $ss*1024*1024;
937 my $udevadm_trigger_block = sub {
940 sleep(1) if !$nowait; # give kernel time to reread part table
942 # trigger udev to create /dev/disk/by-uuid
943 syscmd ("udevadm trigger --subsystem-match block");
944 syscmd ("udevadm settle --timeout 10");
948 my ($basefile, $targetdir) = @_;
950 die "target '$targetdir' does not exist\n" if ! -d $targetdir;
952 my $starttime = [Time::HiRes::gettimeofday];
954 my $bootdevinfo = [];
963 my $filesys = $config_options->{filesys};
965 if ($filesys =~ m/zfs/) {
966 $target_hd = undef; # do not use this config
968 $targetdir = "/$zfspoolname/ROOT/pve-1";
969 } elsif ($filesys =~ m/btrfs/) {
970 $target_hd = undef; # do not use this config
976 for ($i = 5; $i > 0; $i--) {
977 syscmd("modprobe zfs");
978 last if -c "/dev/zfs";
982 die "unable to load zfs kernel module\n" if !$i;
990 update_progress (0, 0, $maxper, "create partitions");
994 $rootdev = abs_path($opt_testmode);
995 syscmd("umount $rootdev");
999 die "unsupported btrfs mode (for testing environment)\n"
1000 if $filesys ne 'btrfs (RAID0)';
1002 btrfs_create([$rootdev], 'single');
1004 } elsif ($use_zfs) {
1006 die "unsupported zfs mode (for testing environment)\n"
1007 if $filesys ne 'zfs (RAID0)';
1009 syscmd ("zpool destroy $zfstestpool");
1011 zfs_create_rpool($rootdev);
1018 } elsif ($use_btrfs) {
1020 my ($devlist, $btrfs_mode) = get_btrfs_raid_setup();
1021 my $btrfs_partitions = [];
1023 foreach my $hd (@$devlist) {
1024 my $devname = @$hd[1];
1025 my ($size, $osdev, $efidev) =
1026 partition_bootable_disk($devname, undef, '8300');
1027 $rootdev = $osdev if !defined($rootdev); # simply point to first disk
1028 my $by_id = find_stable_path("/dev/disk/by-id", $devname);
1029 push @$bootdevinfo, { esp => $efidev, devname => $devname,
1030 osdev => $osdev, by_id => $by_id };
1031 push @$btrfs_partitions, $osdev;
1035 &$udevadm_trigger_block();
1037 btrfs_create($btrfs_partitions, $btrfs_mode);
1039 } elsif ($use_zfs) {
1041 my ($devlist, $bootdevlist, $vdev) = get_zfs_raid_setup();
1044 foreach my $hd (@$bootdevlist) {
1045 my $devname = @$hd[1];
1046 my ($size, $osdev) =
1047 partition_bootable_zfs_disk($devname);
1048 die "unable to mirror disks with different sizes!\n"
1049 if $disksize && ($size != $disksize);
1050 push @$bootdevinfo, { devname => $devname, osdev => $osdev};
1054 &$udevadm_trigger_block();
1056 foreach my $di (@$bootdevinfo) {
1057 my $devname = $di->{devname};
1058 $di->{by_id} = find_stable_path ("/dev/disk/by-id", $devname);
1060 # Note: using /dev/disk/by-id/ does not work for unknown reason, we get
1061 # cannot create 'rpool': no such pool or dataset
1062 #my $osdev = find_stable_path ("/dev/disk/by-id", $di->{osdev}) || $di->{osdev};
1064 my $osdev = $di->{osdev};
1065 $vdev =~ s/ $devname/ $osdev/;
1068 zfs_create_rpool($vdev);
1070 my $swap_size = compute_swapsize($disksize);
1071 $swapfile = zfs_create_swap($swap_size);
1075 die "target '$target_hd' is not a valid block device\n" if ! -b $target_hd;
1078 if ($config_options->{hdsize}) {
1079 # max hdsize passed on cmdline (GB)
1080 $maxhdsize = $config_options->{hdsize}*1024*1024;
1083 my ($os_size, $osdev, $efidev);
1084 ($os_size, $osdev, $efidev) =
1085 partition_bootable_disk($target_hd, $maxhdsize, '8E00');
1087 &$udevadm_trigger_block();
1089 my $by_id = find_stable_path ("/dev/disk/by-id", $target_hd);
1090 push @$bootdevinfo, { esp => $efidev, devname => $target_hd,
1091 osdev => $osdev, by_id => $by_id };
1093 my $swap_size = compute_swapsize($os_size);
1094 ($rootdev, $datadev, $swapfile) =
1095 create_lvm_volumes($osdev, $os_size, $swap_size);
1097 # trigger udev to create /dev/disk/by-uuid
1098 &$udevadm_trigger_block(1);
1102 # to be fast during installation
1103 syscmd ("zfs set sync=disabled $zfspoolname") == 0 ||
1104 die "unable to set zfs properties\n";
1107 update_progress (0.03, 0, $maxper, "create swap space");
1109 syscmd ("mkswap -f $swapfile") == 0 ||
1110 die "unable to create swap space\n";
1113 update_progress (0.05, 0, $maxper, "creating filesystems");
1115 foreach my $di (@$bootdevinfo) {
1116 next if !$di->{esp};
1117 syscmd ("mkfs.vfat -F32 $di->{esp}") == 0 ||
1118 die "unable to initialize EFI ESP on device $di->{esp}\n";
1123 } elsif ($use_btrfs) {
1126 create_filesystem ($rootdev, 'root', $filesys, 0.05, $maxper, 0, 1);
1129 update_progress (1, 0.05, $maxper, "mounting target $rootdev");
1133 } elsif ($use_btrfs) {
1134 syscmd("mount -n $rootdev -o noatime,nobarrier $targetdir") == 0 ||
1135 die "unable to mount $rootdev\n";
1137 syscmd ("mount -n $rootdev -o noatime,barrier=0 $targetdir") == 0 ||
1138 die "unable to mount $rootdev\n";
1141 mkdir "$targetdir/boot";
1142 mkdir "$targetdir/boot/efi";
1144 mkdir "$targetdir/var";
1145 mkdir "$targetdir/var/lib";
1146 mkdir "$targetdir/var/lib/vz";
1147 mkdir "$targetdir/var/lib/pve";
1150 syscmd("btrfs subvolume create $targetdir/var/lib/pve/local-btrfs") == 0 ||
1151 die "unable to create btrfs subvolume\n";
1154 display_html ("extract2-rulesystem.htm");
1155 update_progress (1, 0.05, $maxper, "extracting base system");
1157 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = stat ($basefile);
1158 $ino || die "unable to open file '$basefile' - $!\n";
1161 if ($opt_testmode) {
1162 $files = file_read_firstline("/pve/$release/install/pve-base.cnt");
1164 $files = file_read_firstline("/cdrom/proxmox/pve-base.cnt");
1170 run_command ("unsquashfs -f -dest $targetdir -i $basefile", sub {
1172 return if $line !~ m/^$targetdir/;
1174 my $nper = int (($count *100)/$files);
1175 if ($nper != $per) {
1177 my $frac = $per > 100 ? 1 : $per/100;
1178 update_progress ($frac, $maxper, 0.5);
1182 syscmd ("mount -n -t tmpfs tmpfs $targetdir/tmp") == 0 ||
1183 die "unable to mount tmpfs on $targetdir/tmp\n";
1184 syscmd ("mount -n -t proc proc $targetdir/proc") == 0 ||
1185 die "unable to mount proc on $targetdir/proc\n";
1186 syscmd ("mount -n -t sysfs sysfs $targetdir/sys") == 0 ||
1187 die "unable to mount sysfs on $targetdir/sys\n";
1189 display_html ("extract3-spam.htm");
1190 update_progress (1, $maxper, 0.5, "configuring base system");
1195 "127.0.0.1 localhost.localdomain localhost\n" .
1196 "$ipaddress $hostname.$domain $hostname pvelocalhost\n\n" .
1197 "# The following lines are desirable for IPv6 capable hosts\n\n" .
1198 "::1 ip6-localhost ip6-loopback\n" .
1199 "fe00::0 ip6-localnet\n" .
1200 "ff00::0 ip6-mcastprefix\n" .
1201 "ff02::1 ip6-allnodes\n" .
1202 "ff02::2 ip6-allrouters\n" .
1203 "ff02::3 ip6-allhosts\n";
1205 write_config ($hosts, "$targetdir/etc/hosts");
1207 write_config ("$hostname\n", "$targetdir/etc/hostname");
1209 syscmd ("/bin/hostname $hostname") if !$opt_testmode;
1211 # configure interfaces
1213 my $ifaces = "auto lo\niface lo inet loopback\n\n";
1215 my $ntype = $ipversion == 4 ? 'inet' : 'inet6';
1218 "auto vmbr0\niface vmbr0 $ntype static\n" .
1219 "\taddress $ipaddress\n" .
1220 "\tnetmask $netmask\n" .
1221 "\tgateway $gateway\n" .
1222 "\tbridge_ports eth0\n" .
1223 "\tbridge_stp off\n" .
1226 write_config ($ifaces, "$targetdir/etc/network/interfaces");
1230 my $resolfconf = "search $domain\nnameserver $dnsserver\n";
1231 write_config ($resolfconf, "$targetdir/etc/resolv.conf");
1235 my $fstab = "# <file system> <mount point> <type> <options> <dump> <pass>\n";
1239 } elsif ($use_btrfs) {
1241 my $cmd = "blkid -u filesystem -t TYPE=btrfs -o export $rootdev";
1242 run_command($cmd, sub {
1245 if ($line =~ m/^UUID=([A-Fa-f0-9\-]+)$/) {
1250 die "unable to detect FS UUID" if !defined($fsuuid);
1252 $fstab .= "UUID=$fsuuid / btrfs defaults 0 1\n";
1254 my $root_mountopt = $fssetup->{$filesys}->{root_mountopt} || 'defaults';
1255 $fstab .= "$rootdev / $filesys ${root_mountopt} 0 1\n";
1259 # Note: this is required by current grub, but really dangerous, because
1260 # vfat does not have journaling, so it triggers manual fsck after each crash
1261 # so we only mount /boot/efi if really required (efi systems).
1262 if ($grub_plattform =~ m/^efi-/) {
1263 if (scalar(@$bootdevinfo)) {
1264 my $di = @$bootdevinfo[0]; # simply use first disk
1266 my $efi_boot_uuid = $di->{esp};
1267 if (my $uuid = find_dev_by_uuid ($di->{esp})) {
1268 $efi_boot_uuid = "UUID=$uuid";
1271 $fstab .= "${efi_boot_uuid} /boot/efi vfat defaults 0 1\n";
1277 $fstab .= "$swapfile none swap sw 0 0\n" if $swapfile;
1279 $fstab .= "proc /proc proc defaults 0 0\n";
1281 write_config ($fstab, "$targetdir/etc/fstab");
1282 write_config ("", "$targetdir/etc/mtab");
1284 syscmd ("cp ${proxmox_dir}/policy-disable-rc.d " .
1285 "$targetdir/usr/sbin/policy-rc.d") == 0 ||
1286 die "unable to copy policy-rc.d\n";
1287 syscmd ("cp ${proxmox_dir}/fake-start-stop-daemon " .
1288 "$targetdir/sbin/") == 0 ||
1289 die "unable to copy start-stop-daemon\n";
1291 diversion_add ($targetdir, "/sbin/start-stop-daemon", "/sbin/fake-start-stop-daemon");
1292 diversion_add ($targetdir, "/usr/sbin/update-grub", "/bin/true");
1293 diversion_add ($targetdir, "/usr/sbin/update-initramfs", "/bin/true");
1295 syscmd ("touch $targetdir/proxmox_install_mode");
1297 my $grub_install_devices_txt = '';
1298 foreach my $di (@$bootdevinfo) {
1299 $grub_install_devices_txt .= ', ' if $grub_install_devices_txt;
1300 $grub_install_devices_txt .= $di->{by_id} || $di->{devname};
1303 # Note: debian-installer/locale is used by console-setup
1305 debconfig_set ($targetdir, <<_EOD);
1306 locales locales/default_environment_locale select en_US.UTF-8
1307 locales locales/locales_to_be_generated select en_US.UTF-8 UTF-8
1308 samba-common samba-common/dhcp boolean false
1309 samba-common samba-common/workgroup string WORKGROUP
1310 postfix postfix/main_mailer_type select Local only
1311 keyboard-configuration keyboard-configuration/xkb-keymap select $keymap
1312 d-i debian-installer/locale select en_US.UTF-8
1313 grub-pc grub-pc/install_devices select $grub_install_devices_txt
1316 my $pkgdir = $opt_testmode ?
"packages" : "/cdrom/proxmox/packages";
1318 while (<$pkgdir/*.deb
>) { $pkg_count++ };
1320 # btrfs/dpkg is extremely slow without --force-unsafe-io
1321 my $dpkg_opts = $use_btrfs ?
"--force-unsafe-io" : "";
1324 while (<$pkgdir/*.deb
>) {
1327 my ($deb) = $path =~ m/$pkgdir\/(.*\
.deb
)/;
1328 # if ($deb =~ m/^grub-efi-/ && $deb !~ m/^grub-${grub_plattform}/) {
1332 update_progress
($count/$pkg_count, 0.5, 0.75, "extracting $deb");
1333 print "extracting: $deb\n";
1334 syscmd
("cp $path $targetdir/tmp/$deb") == 0 ||
1335 die "installation of package $deb failed\n";
1336 syscmd
("chroot $targetdir dpkg $dpkg_opts --force-depends --no-triggers --unpack /tmp/$deb") == 0 ||
1337 die "installation of package $deb failed\n";
1338 update_progress
((++$count)/$pkg_count, 0.5, 0.75);
1341 display_html
("extract4-virus.htm");
1343 my $cmd = "chroot $targetdir dpkg $dpkg_opts --force-confold --configure -a";
1345 run_command
($cmd, sub {
1347 if ($line =~ m/Setting up\s+(\S+)/) {
1348 update_progress
((++$count)/$pkg_count, 0.75, 0.95,
1353 debconfig_set
($targetdir, <<_EOD);
1354 postfix postfix/main_mailer_type select No configuration
1357 unlink "$targetdir/etc/mailname";
1358 $postfix_main_cf =~ s/__FQDN__/${hostname}.${domain}/;
1359 write_config
($postfix_main_cf, "$targetdir/etc/postfix/main.cf");
1361 # make sure we have all postfix directories
1362 syscmd
("chroot $targetdir /usr/sbin/postfix check");
1363 # cleanup mail queue
1364 syscmd
("chroot $targetdir /usr/sbin/postsuper -d ALL");
1366 # enable NTP (timedatectl set-ntp true does not work without DBUS)
1367 syscmd
("chroot $targetdir /bin/systemctl enable systemd-timesyncd.service");
1369 unlink "$targetdir/proxmox_install_mode";
1372 unlink ("$targetdir/etc/localtime");
1373 symlink ("/usr/share/zoneinfo/$timezone", "$targetdir/etc/localtime");
1374 write_config
("$timezone\n", "$targetdir/etc/timezone");
1377 if (my $mirror = $cmap->{country
}->{$country}->{mirror
}) {
1378 my $fn = "$targetdir/etc/apt/sources.list";
1379 syscmd
("sed -i 's/ftp\\.debian\\.org/$mirror/' '$fn'");
1382 # create extended_states for apt (avoid cron job warning if that
1383 # file does not exist)
1384 write_config
('', "$targetdir/var/lib/apt/extended_states");
1386 # allow ssh root login
1387 syscmd
("sed -i 's/^PermitRootLogin.*/PermitRootLogin yes/' '$targetdir/etc/ssh/sshd_config'");
1389 # save installer settings
1390 my $ucc = uc ($country);
1391 debconfig_set
($targetdir, <<_EOD);
1392 pve-manager pve-manager/country string $ucc
1395 update_progress
(0.8, 0.95, 1, "make system bootable");
1398 syscmd
("sed -i -e 's/^GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"root=ZFS=$zfspoolname\\/ROOT\\/pve-1 boot=zfs\"/' $targetdir/etc/default/grub") == 0 ||
1399 die "unable to update /etc/default/grub\n";
1403 diversion_remove
($targetdir, "/usr/sbin/update-grub");
1404 diversion_remove
($targetdir, "/usr/sbin/update-initramfs");
1406 if (!$opt_testmode) {
1408 unlink ("$targetdir/etc/mtab");
1409 symlink ("/proc/mounts", "$targetdir/etc/mtab");
1410 syscmd
("mount -n --bind /dev $targetdir/dev");
1412 syscmd
("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0 ||
1413 die "unable to install initramfs\n";
1415 foreach my $di (@$bootdevinfo) {
1416 my $dev = $di->{devname
};
1417 syscmd
("chroot $targetdir /usr/sbin/grub-install --target i386-pc --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
1418 die "unable to install the i386-pc boot loader on '$dev'\n";
1421 syscmd
("mount -n $di->{esp} $targetdir/boot/efi") == 0 ||
1422 die "unable to mount $di->{esp}\n";
1423 syscmd
("chroot $targetdir /usr/sbin/grub-install --target x86_64-efi --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
1424 die "unable to install the EFI boot loader on '$dev'\n";
1425 # also install fallback boot file (OVMF does not boot without)
1426 mkdir("$targetdir/boot/efi/EFI/BOOT");
1427 syscmd
("cp $targetdir/boot/efi/EFI/proxmox/grubx64.efi $targetdir/boot/efi/EFI/BOOT/BOOTx64.EFI") == 0 ||
1428 die "unable to copy efi boot loader\n";
1430 syscmd
("umount $targetdir/boot/efi") == 0 ||
1431 die "unable to umount $targetdir/boot/efi\n";
1435 syscmd
("chroot $targetdir /usr/sbin/update-grub") == 0 ||
1436 die "unable to update boot loader config\n";
1438 syscmd
("umount $targetdir/dev");
1443 # hack: remove dead.letter from sshd installation
1444 syscmd
("rm -rf $targetdir/dead.letter");
1446 unlink "$targetdir/usr/sbin/policy-rc.d";
1448 diversion_remove
($targetdir, "/sbin/start-stop-daemon");
1451 my $octets = encode
("utf-8", $password);
1452 run_command
("chroot $targetdir /usr/sbin/chpasswd", undef,
1457 my $tmpdir = "$targetdir/tmp/pve";
1460 # write vnc keymap to datacenter.cfg
1461 my $vnckmap = $cmap->{kmap
}->{$keymap}->{kvm
} || 'en-us';
1462 write_config
("keyboard: $vnckmap\n",
1463 "$tmpdir/datacenter.cfg");
1466 write_config
("user:root\@pam:1:0:::${mailto}::\n",
1467 "$tmpdir/user.cfg");
1470 my $strorage_cfg_fn = "$tmpdir/storage.cfg";
1472 write_config
($storage_cfg_zfs, $strorage_cfg_fn);
1473 } elsif ($use_btrfs) {
1474 write_config
($storage_cfg_btrfs, $strorage_cfg_fn);
1476 write_config
($storage_cfg_lvmthin, $strorage_cfg_fn);
1479 run_command
("chroot $targetdir /usr/bin/create_pmxcfs_db /tmp/pve /var/lib/pve-cluster/config.db");
1481 syscmd
("rm -rf $tmpdir");
1486 update_progress
(1, 0, 1, "");
1490 if ($opt_testmode) {
1491 my $elapsed = Time
::HiRes
::tv_interval
($starttime);
1492 print "Elapsed extract time: $elapsed\n";
1494 syscmd
("chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> pve-final.pkglist");
1497 syscmd
("umount $targetdir/var/lib/vz");
1498 syscmd
("umount $targetdir/tmp");
1499 syscmd
("umount $targetdir/proc");
1500 syscmd
("umount $targetdir/sys");
1503 syscmd
("zfs umount -a") == 0 ||
1504 die "unable to unmount zfs\n";
1506 syscmd
("umount -d $targetdir");
1509 if (!$err && $use_zfs) {
1510 syscmd
("zfs set sync=standard $zfspoolname") == 0 ||
1511 die "unable to set zfs properties\n";
1513 syscmd
("zfs set mountpoint=/ $zfspoolname/ROOT/pve-1") == 0 ||
1514 die "zfs set mountpoint failed\n";
1516 syscmd
("zpool set bootfs=$zfspoolname/ROOT/pve-1 $zfspoolname") == 0 ||
1517 die "zfs set bootfs failed\n";
1524 my ($filename) = @_;
1526 my $path = "${proxmox_dir}/html/$filename";
1527 my $url = "file://$path";
1529 my $data = file_get_contents
($path);
1531 if ($filename eq 'license.htm') {
1532 my $licensefn = -f
"/EULA" ?
"/EULA" :
1533 $opt_testmode ?
"./copyright" :
1534 "/usr/share/doc/pve-installer/copyright";
1535 my $license = decode
('utf8', file_get_contents
($licensefn));
1536 $license =~ m/^\s+(.+\n)/;
1537 my $title = $licensefn eq '/EULA' ?
"END USER LICENSE AGREEMENT (EULA)": $1;
1538 $data =~ s/__LICENSE__/$license/;
1539 $data =~ s/__LICENSE_TITLE__/$title/;
1542 $htmlview->load_html_string($data, $url);
1546 my ($text, $fctn) = @_;
1549 $text = "_Next" if !$text;
1550 $next->set_label ($text);
1552 $next->grab_focus ();
1556 my ($doc, $url, $stream) = @_;
1558 $stream->set_cancel_func (sub {}); # hack: avoid warning
1560 my $path = "${proxmox_dir}/html/$url";
1563 open (HTMLTMP
, $path) ||
1564 die "unable to open file '$path' - $!\n";
1566 while (my $i = read (HTMLTMP
, $buf, 4096)) {
1567 $stream->write ($buf);
1568 Gtk3
::main_iteration
() while Gtk3
::events_pending
();
1573 #$stream->close(); # hack: dont close - avoid crash
1576 sub create_main_window
{
1578 $window = Gtk3
::Window-
>new ();
1579 $window->set_default_size (1024, 768);
1580 $window->set_has_resize_grip(0);
1581 $window->set_decorated (0) if !$opt_testmode;
1583 my $vbox = Gtk3
::VBox-
>new (0, 0);
1585 my $image = Gtk3
::Image-
>new_from_file ("${proxmox_dir}/proxlogo.png");
1586 $vbox->pack_start ($image, 0, 0, 0);
1588 my $hbox = Gtk3
::HBox-
>new (0, 0);
1589 $vbox->pack_start ($hbox, 1, 1, 0);
1591 # my $f1 = Gtk3::Frame->new ('test');
1592 # $f1->set_shadow_type ('none');
1593 # $hbox->pack_start ($f1, 1, 1, 0);
1595 my $sep1 = Gtk3
::HSeparator-
>new;
1596 $vbox->pack_start ($sep1, 0, 0, 0);
1598 $cmdbox = Gtk3
::HBox-
>new ();
1599 $vbox->pack_start ($cmdbox, 0, 0, 10);
1601 $next = Gtk3
::Button-
>new ('_Next');
1602 $next->signal_connect (clicked
=> sub { &$next_fctn (); });
1603 $cmdbox->pack_end ($next, 0, 0, 10);
1604 my $abort = Gtk3
::Button-
>new ('_Abort');
1605 $abort->set_can_focus (0);
1606 $cmdbox->pack_start ($abort, 0, 0, 10);
1607 $abort->signal_connect (clicked
=> sub { exit (-1); });
1609 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1610 $hbox->add ($vbox2);
1612 $htmlview = Gtk3
::WebKit
::WebView-
>new();
1613 my $scrolls = Gtk3
::ScrolledWindow-
>new();
1614 $scrolls->add($htmlview);
1616 my $hbox2 = Gtk3
::HBox-
>new (0, 0);
1617 $hbox2->pack_start ($scrolls, 1, 1, 0);
1619 $vbox2->pack_start ($hbox2, 1, 1, 0);
1621 my $vbox3 = Gtk3
::VBox-
>new (0, 0);
1622 $vbox2->pack_start ($vbox3, 0, 0, 0);
1624 my $sep2 = Gtk3
::HSeparator-
>new;
1625 $vbox3->pack_start ($sep2, 0, 0, 0);
1627 $inbox = Gtk3
::HBox-
>new (0, 0);
1628 $vbox3->pack_start ($inbox, 0, 0, 0);
1630 $window->add ($vbox);
1633 $window->realize ();
1637 $inbox->foreach(sub {
1639 $inbox->remove ($child);
1643 # fixme: newer GTK3 has special properties to handle numbers with Entry
1644 # only allow floating point numbers with Gtk3::Entry
1646 my ($entry, $event) = @_;
1649 my $val = $event->get_keyval;
1651 if ($val == ord '.' ||
1652 $val == Gtk3
::Gdk
::KEY_ISO_Left_Tab
||
1653 $val == Gtk3
::Gdk
::KEY_Shift_L
||
1654 $val == Gtk3
::Gdk
::KEY_Tab
||
1655 $val == Gtk3
::Gdk
::KEY_Left
||
1656 $val == Gtk3
::Gdk
::KEY_Right
||
1657 $val == Gtk3
::Gdk
::KEY_BackSpace
||
1658 $val == Gtk3
::Gdk
::KEY_Delete
||
1659 ($val >= ord '0' && $val <= ord '9') ||
1660 ($val >= Gtk3
::Gdk
::KEY_KP_0
&&
1661 $val <= Gtk3
::Gdk
::KEY_KP_9
)) {
1668 sub create_text_input
{
1669 my ($default, $text) = @_;
1671 my $hbox = Gtk3
::HBox-
>new (0, 0);
1673 my $label = Gtk3
::Label-
>new ($text);
1674 $label->set_size_request (150, -1);
1675 $label->set_alignment (1, 0.5);
1676 $hbox->pack_start ($label, 0, 0, 10);
1677 my $e1 = Gtk3
::Entry-
>new ();
1678 $e1->set_width_chars (30);
1679 $hbox->pack_start ($e1, 0, 0, 0);
1680 $e1->set_text ($default);
1682 return ($hbox, $e1);
1687 my $ifconfig = `ifconfig eth0`;
1689 my ($addr) = $ifconfig =~ m/inet addr:(\S*)/m;
1690 my ($mask) = $ifconfig =~ m/Mask:(\S*)/m;
1692 my $route = `route -n`;
1693 my ($gateway) = $route =~ m/^0\.0\.0\.0\s+(\d+\.\d+\.\d+\.\d+)\s+/m;
1695 my $resolvconf = `cat /etc/resolv.conf`;
1696 my ($dnsserver) = $resolvconf =~ m/^nameserver\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/m;
1697 my ($domain) = $resolvconf =~ m/^domain\s+(\S+)$/m;
1702 gateway
=> $gateway,
1703 dnsserver
=> $dnsserver,
1708 sub display_message
{
1711 my $dialog = Gtk3
::MessageDialog-
>new ($window, 'modal',
1712 'info', 'ok', $msg);
1720 my $dialog = Gtk3
::MessageDialog-
>new ($window, 'modal',
1721 'error', 'ok', $msg);
1726 sub create_ipconf_view
{
1729 display_html
("ipconf.htm");
1731 my $vbox = Gtk3
::VBox-
>new (0, 0);
1732 $inbox->pack_start ($vbox, 1, 0, 0);
1733 my $hbox = Gtk3
::HBox-
>new (0, 0);
1734 $vbox->pack_start ($hbox, 0, 0, 10);
1735 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1736 $hbox->add ($vbox2);
1738 my $addr = $ipconf->{addr
} || '192.168.100.2';
1739 my $mask = $ipconf->{mask
} || '255.255.255.0';
1741 my $hn = $ipconf->{domain
} ?
"pve.$ipconf->{domain}" : 'pve.domain.tld';
1743 my ($hostbox, $hostentry) =
1744 create_text_input
($hn, 'Hostname (FQDN):');
1745 $vbox2->pack_start ($hostbox, 0, 0, 2);
1748 ($ipbox, $ipconf_entry_addr) =
1749 create_text_input
($addr, 'IP Address:');
1750 $vbox2->pack_start ($ipbox, 0, 0, 2);
1753 ($maskbox, $ipconf_entry_mask) =
1754 create_text_input
($mask, 'Netmask:');
1755 $vbox2->pack_start ($maskbox, 0, 0, 2);
1757 $gateway = $ipconf->{gateway
} || '192.168.100.1';
1760 ($gwbox, $ipconf_entry_gw) =
1761 create_text_input
($gateway, 'Gateway:');
1763 $vbox2->pack_start ($gwbox, 0, 0, 2);
1765 $dnsserver = $ipconf->{dnsserver
} || $gateway;
1768 ($dnsbox, $ipconf_entry_dns) =
1769 create_text_input
($dnsserver, 'DNS Server:');
1771 $vbox2->pack_start ($dnsbox, 0, 0, 0);
1774 set_next
(undef, sub {
1778 my $text = $hostentry->get_text();
1783 my $namere = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
1785 # Debian does not support purely numeric hostnames
1786 if ($text && $text =~ /^[0-9]+(?:\.|$)/) {
1787 display_message
("Purely numeric hostnames are not allowed.");
1788 $hostentry->grab_focus();
1792 if ($text && $text =~ m/^(${namere}\.)*${namere}$/ && $text !~ m/.domain.tld$/ &&
1793 $text =~ m/^([^\.]+)\.(\S+)$/) {
1797 display_message
("Hostname does not look like a fully qualified domain name.");
1798 $hostentry->grab_focus();
1804 $text = $ipconf_entry_addr->get_text();
1807 if ($text =~ m!^($IPV4RE)$!) {
1810 } elsif ($text =~ m!^($IPV6RE)$!) {
1814 display_message
("IP address is not valid.");
1815 $ipconf_entry_addr->grab_focus();
1819 $text = $ipconf_entry_mask->get_text();
1822 if (($ipversion == 6) && ($text =~ m/^(\d+)$/) && ($1 >= 8) && ($1 <= 126)) {
1824 } elsif (($ipversion == 4) && defined($ipv4_mask_hash->{$text})) {
1827 display_message
("Netmask is not valid.");
1828 $ipconf_entry_mask->grab_focus();
1832 $text = $ipconf_entry_gw->get_text();
1835 if (($ipversion == 4) && ($text =~ m!^($IPV4RE)$!)) {
1837 } elsif (($ipversion == 6) && ($text =~ m!^($IPV6RE)$!)) {
1840 display_message
("Gateway is not valid.");
1841 $ipconf_entry_gw->grab_focus();
1845 $text = $ipconf_entry_dns->get_text();
1848 if (($ipversion == 4) && ($text =~ m!^($IPV4RE)$!)) {
1850 } elsif (($ipversion == 6) && ($text =~ m!^($IPV6RE)$!)) {
1853 display_message
("DNS server is not valid.");
1854 $ipconf_entry_dns->grab_focus();
1858 #print "TEST $ipaddress $netmask $gateway $dnsserver\n";
1860 create_extract_view
();
1863 $hostentry->grab_focus();
1866 sub get_device_desc
{
1867 my ($devname, $size, $model) = @_;
1869 if ($size && ($size > 0)) {
1870 $size = int($size/2048); # size in MB
1872 my $text = "$devname (";
1873 if ($size >= 1024) {
1874 $size = int($size/1024); # size in GB
1875 $text .= "${size}GB";
1877 $text .= "${size}MB";
1880 $text .= ", $model" if $model;
1889 my ($cb, $kmap) = @_;
1894 my $kmaphash = $cmap->{kmaphash
};
1895 foreach my $layout (sort keys %$kmaphash) {
1896 $def = $i if $kmaphash->{$layout} eq 'en-us';
1897 $ind = $i if $kmap && $kmaphash->{$layout} eq $kmap;
1901 $cb->set_active ($ind || $def || 0);
1905 sub update_zonelist
{
1906 my ($box, $cc) = @_;
1908 my $cczones = $cmap->{cczones
};
1909 my $zones = $cmap->{zones
};
1913 $sel = $lastzonecb->get_active_text();
1914 $box->remove ($lastzonecb);
1916 $sel = $timezone; # used once to select default
1919 my $cb = $lastzonecb = Gtk3
::ComboBoxText-
>new();
1920 $cb->set_size_request (200, -1);
1922 $cb->signal_connect ('changed' => sub {
1923 $timezone = $cb->get_active_text();
1927 if ($cc && defined ($cczones->{$cc})) {
1928 @za = keys %{$cczones->{$cc}};
1934 foreach my $zone (sort @za) {
1935 $ind = $i if $sel && $zone eq $sel;
1936 $cb->append_text ($zone);
1940 $cb->set_active ($ind || 0);
1943 $box->pack_start ($cb, 0, 0, 0);
1946 sub create_password_view
{
1950 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1951 $inbox->pack_start ($vbox2, 1, 0, 0);
1952 my $vbox = Gtk3
::VBox-
>new (0, 0);
1953 $vbox2->pack_start ($vbox, 0, 0, 10);
1955 my $hbox1 = Gtk3
::HBox-
>new (0, 0);
1956 my $label = Gtk3
::Label-
>new ("Password");
1957 $label->set_size_request (150, -1);
1958 $label->set_alignment (1, 0.5);
1959 $hbox1->pack_start ($label, 0, 0, 10);
1960 my $pwe1 = Gtk3
::Entry-
>new ();
1961 $pwe1->set_visibility (0);
1962 $pwe1->set_size_request (200, -1);
1963 $hbox1->pack_start ($pwe1, 0, 0, 0);
1965 my $hbox2 = Gtk3
::HBox-
>new (0, 0);
1966 $label = Gtk3
::Label-
>new ("Confirm");
1967 $label->set_size_request (150, -1);
1968 $label->set_alignment (1, 0.5);
1969 $hbox2->pack_start ($label, 0, 0, 10);
1970 my $pwe2 = Gtk3
::Entry-
>new ();
1971 $pwe2->set_visibility (0);
1972 $pwe2->set_size_request (200, -1);
1973 $hbox2->pack_start ($pwe2, 0, 0, 0);
1975 my $hbox3 = Gtk3
::HBox-
>new (0, 0);
1976 $label = Gtk3
::Label-
>new ("E-Mail");
1977 $label->set_size_request (150, -1);
1978 $label->set_alignment (1, 0.5);
1979 $hbox3->pack_start ($label, 0, 0, 10);
1980 my $eme = Gtk3
::Entry-
>new ();
1981 $eme->set_size_request (200, -1);
1982 $hbox3->pack_start ($eme, 0, 0, 0);
1985 $vbox->pack_start ($hbox1, 0, 0, 5);
1986 $vbox->pack_start ($hbox2, 0, 0, 5);
1987 $vbox->pack_start ($hbox3, 0, 0, 15);
1991 display_html
("passwd.htm");
1993 set_next
(undef, sub {
1995 my $t1 = $pwe1->get_text;
1996 my $t2 = $pwe2->get_text;
1998 if (length ($t1) < 5) {
1999 display_message
("Password is too short.");
2000 $pwe1->grab_focus();
2005 display_message
("Password does not match.");
2006 $pwe1->grab_focus();
2010 my $t3 = $eme->get_text;
2011 if ($t3 !~ m/^\S+\@\S+\.\S+$/) {
2012 display_message
("E-Mail does not look like a vaild address" .
2013 " (user\@domain.tld)");
2022 create_ipconf_view
();
2025 $pwe1->grab_focus();
2029 sub create_country_view
{
2033 my $countryhash = $cmap->{countryhash
};
2034 my $ctr = $cmap->{country
};
2036 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
2037 $inbox->pack_start ($vbox2, 1, 0, 0);
2038 my $vbox = Gtk3
::VBox-
>new (0, 0);
2039 $vbox2->pack_start ($vbox, 0, 0, 10);
2041 my $w = Gtk3
::Entry-
>new ();
2042 $w->set_size_request (200, -1);
2044 my $c = Gtk3
::EntryCompletion-
>new ();
2045 $c->set_text_column (0);
2046 $c->set_minimum_key_length(0);
2047 $c->set_popup_set_width (1);
2048 $c->set_inline_completion (1);
2050 my $hbox2 = Gtk3
::HBox-
>new (0, 0);
2051 my $label = Gtk3
::Label-
>new ("Time zone");
2052 $label->set_size_request (150, -1);
2053 $label->set_alignment (1, 0.5);
2054 $hbox2->pack_start ($label, 0, 0, 10);
2055 update_zonelist
($hbox2);
2057 my $hbox3 = Gtk3
::HBox-
>new (0, 0);
2058 $label = Gtk3
::Label-
>new ("Keyboard Layout");
2059 $label->set_size_request (150, -1);
2060 $label->set_alignment (1, 0.5);
2061 $hbox3->pack_start ($label, 0, 0, 10);
2063 my $kmapcb = Gtk3
::ComboBoxText-
>new();
2064 $kmapcb->set_size_request (200, -1);
2065 foreach my $layout (sort keys %{$cmap->{kmaphash
}}) {
2066 $kmapcb->append_text ($layout);
2069 update_layout
($kmapcb);
2070 $hbox3->pack_start ($kmapcb, 0, 0, 0);
2072 $kmapcb->signal_connect ('changed' => sub {
2073 my $sel = $kmapcb->get_active_text();
2074 if (my $kmap = $cmap->{kmaphash
}->{$sel}) {
2075 my $xkmap = $cmap->{kmap
}->{$kmap}->{x11
};
2076 my $xvar = $cmap->{kmap
}->{$kmap}->{x11var
};
2077 syscmd
("setxkbmap $xkmap $xvar") if !$opt_testmode;
2082 $w->signal_connect ('changed' => sub {
2083 my ($entry, $event) = @_;
2084 my $text = $entry->get_text;
2086 if (my $cc = $countryhash->{lc($text)}) {
2087 update_zonelist
($hbox2, $cc);
2088 my $kmap = $ctr->{$cc}->{kmap
} || 'en-us';
2089 update_layout
($kmapcb, $kmap);
2093 $w->signal_connect (key_press_event
=> sub {
2094 my ($entry, $event) = @_;
2095 my $text = $entry->get_text;
2097 my $val = $event->get_keyval;
2099 if ($val == Gtk3
::Gdk
::KEY_Tab
) {
2100 my $cc = $countryhash->{lc($text)};
2107 $compl = $ctr->{$cc}->{name
};
2109 foreach my $cc (keys %$ctr) {
2110 my $ct = $ctr->{$cc}->{name
};
2111 if ($ct =~ m/^\Q$text\E.*$/i) {
2120 $entry->set_text($compl);
2125 print chr(7); # beep ?
2130 my $buf = $w->get_buffer();
2131 $buf->insert_text(-1, '', -1); # popup selection
2139 my $ls = Gtk3
::ListStore-
>new('Glib::String');
2140 foreach my $cc (sort {$ctr->{$a}->{name
} cmp $ctr->{$b}->{name
} } keys %$ctr) {
2141 my $iter = $ls->append();
2142 $ls->set ($iter, 0, $ctr->{$cc}->{name
});
2144 $c->set_model ($ls);
2146 $w->set_completion ($c);
2148 my $hbox = Gtk3
::HBox-
>new (0, 0);
2150 $label = Gtk3
::Label-
>new ("Country");
2151 $label->set_alignment (1, 0.5);
2152 $label->set_size_request (150, -1);
2153 $hbox->pack_start ($label, 0, 0, 10);
2154 $hbox->pack_start ($w, 0, 0, 0);
2156 $vbox->pack_start ($hbox, 0, 0, 5);
2157 $vbox->pack_start ($hbox2, 0, 0, 5);
2158 $vbox->pack_start ($hbox3, 0, 0, 5);
2161 $w->set_text ($ctr->{$country}->{name
});
2166 display_html
("country.htm");
2167 set_next
(undef, sub {
2169 my $text = $w->get_text;
2171 if (my $cc = $countryhash->{lc($text)}) {
2173 create_password_view
();
2176 display_message
("Please select a country first.");
2184 my $target_hd_combo;
2185 my $target_hd_label;
2187 my $hdopion_first_setup = 1;
2189 sub create_hdoption_view
{
2191 my $dialog = Gtk3
::Dialog-
>new();
2193 $dialog->set_title("Harddisk options");
2195 $dialog->add_button("_OK", 1);
2197 my $contarea = $dialog->get_content_area();
2199 my $hbox2 = Gtk3
::Box-
>new('horizontal', 0);
2200 $contarea->pack_start($hbox2, 1, 1, 10);
2202 my $grid = Gtk3
::Grid-
>new();
2203 $grid->set_column_spacing(10);
2204 $grid->set_row_spacing(10);
2206 $hbox2->pack_start($grid, 1, 0, 10);
2212 my $label0 = Gtk3
::Label-
>new ("Filesystem");
2213 $label0->set_alignment (1, 0.5);
2214 $grid->attach($label0, 0, $row, 1, 1);
2216 my $fstypecb = Gtk3
::ComboBoxText-
>new();
2218 my $fstype = ['ext3', 'ext4', 'xfs',
2219 'zfs (RAID0)', 'zfs (RAID1)',
2220 'zfs (RAID10)', 'zfs (RAIDZ-1)',
2221 'zfs (RAIDZ-2)', 'zfs (RAIDZ-3)',
2222 'btrfs (RAID0)', 'btrfs (RAID1)', 'btrfs (RAID10)'];
2225 foreach my $tmp (@$fstype) {
2226 $fstypecb->append_text($tmp);
2227 $fstypecb->set_active ($tcount)
2228 if $config_options->{filesys
} eq $tmp;
2232 $grid->attach($fstypecb, 1, $row, 1, 1);
2240 for (my $i = 0; $i < 8; $i++) {
2241 $disk_label[$i] = Gtk3
::Label-
>new ("Hardisk $i");
2242 $disk_label[$i]->set_alignment (1, 0.5);
2243 $grid->attach($disk_label[$i], 0, $row, 1, 1);
2244 $disk_selector[$i] = Gtk3
::ComboBoxText-
>new();
2245 $disk_selector[$i]->append_text("-- do not use --");
2246 $disk_selector[$i]->set_active(0);
2247 foreach my $hd (@$hds) {
2248 my ($disk, $devname, $size, $model) = @$hd;
2249 $disk_selector[$i]->append_text(get_device_desc
($devname, $size, $model));
2250 $disk_selector[$i]->{pve_disk_id
} = $i;
2251 $disk_selector[$i]->signal_connect (changed
=> sub {
2253 my $diskid = $w->{pve_disk_id
};
2254 my $a = $w->get_active - 1;
2255 $config_options->{"disksel${diskid}"} = ($a >= 0) ?
$hds->[$a] : undef;
2259 if ($hdopion_first_setup) {
2260 $disk_selector[$i]->set_active ($i+1) if $hds->[$i];
2263 if (my $cur_hd = $config_options->{"disksel$i"}) {
2264 foreach my $hd (@$hds) {
2265 if (@$hd[1] eq @$cur_hd[1]) {
2266 $disk_selector[$i]->set_active($hdind+1);
2275 $grid->attach($disk_selector[$i], 1, $row, 1, 1);
2280 $hdopion_first_setup = 0;
2282 my $label_hdsize = Gtk3
::Label-
>new ("hdsize");
2283 $label_hdsize->set_alignment (1, 0.5);
2284 $grid->attach($label_hdsize, 0, $row, 1, 1);
2288 if ( -b
$target_hd) {
2289 $hdsize = int(hd_size
($target_hd) / (1024*1024.0)); # size in GB
2290 } elsif ($target_hd) {
2291 $hdsize = int((-s
$target_hd) / (1024*1024*1024.0));
2294 my $hdsize_size_adj = Gtk3
::Adjustment-
>new($config_options->{hdsize
} || $hdsize, 0, $hdsize+1, 1, 1, 1);
2295 my $spinbutton_hdsize = Gtk3
::SpinButton-
>new($hdsize_size_adj, 1, 1);
2296 $spinbutton_hdsize->set_tooltip_text("only use specified size (GB) of the harddisk (rest left unpartitioned)");
2297 $grid->attach($spinbutton_hdsize, 1, $row, 1, 1);
2300 my $label_swapsize = Gtk3
::Label-
>new ("swapsize");
2301 $label_swapsize->set_alignment (1, 0.5);
2302 $grid->attach($label_swapsize, 0, $row, 1, 1);
2304 my $entry_swapsize = Gtk3
::Entry-
>new();
2305 $entry_swapsize->set_tooltip_text("maximum SWAP size (GB)");
2306 $entry_swapsize->signal_connect (key_press_event
=> \
&check_float
);
2307 $entry_swapsize->set_text($config_options->{swapsize
}) if $config_options->{swapsize
};
2308 $grid->attach($entry_swapsize, 1, $row, 1, 1);
2311 my $label_maxroot = Gtk3
::Label-
>new ("maxroot");
2312 $label_maxroot->set_alignment (1, 0.5);
2313 $grid->attach($label_maxroot, 0, $row, 1, 1);
2315 my $entry_maxroot = Gtk3
::Entry-
>new();
2316 $entry_maxroot->set_tooltip_text("maximum size (GB) for LVM root volume");
2317 $entry_maxroot->signal_connect (key_press_event
=> \
&check_float
);
2318 $entry_maxroot->set_text($config_options->{maxroot
}) if $config_options->{maxroot
};
2319 $grid->attach($entry_maxroot, 1, $row, 1, 1);
2322 my $label_minfree = Gtk3
::Label-
>new ("minfree");
2323 $label_minfree->set_alignment (1, 0.5);
2324 $grid->attach($label_minfree, 0, $row, 1, 1);
2326 my $entry_minfree = Gtk3
::Entry-
>new();
2327 $entry_minfree->set_tooltip_text("minumum free LVM space (GB, required for LVM snapshots)");
2328 $entry_minfree->signal_connect (key_press_event
=> \
&check_float
);
2329 $entry_minfree->set_text($config_options->{minfree
}) if $config_options->{minfree
};
2330 $grid->attach($entry_minfree, 1, $row, 1, 1);
2333 my $label_maxvz = Gtk3
::Label-
>new ("maxvz");
2334 $label_maxvz->set_alignment (1, 0.5);
2335 $grid->attach($label_maxvz, 0, $row, 1, 1);
2337 my $entry_maxvz = Gtk3
::Entry-
>new();
2338 $entry_maxvz->set_tooltip_text("maximum size (GB) for LVM data volume");
2339 $entry_maxvz->signal_connect (key_press_event
=> \
&check_float
);
2340 $entry_maxvz->set_text($config_options->{maxvz
}) if $config_options->{maxvz
};
2341 $grid->attach($entry_maxvz, 1, $row, 1, 1);
2344 my $set_sensitive_flag = sub {
2345 my $enable_size_hints = $config_options->{filesys
} !~ m/zfs|btrfs/;
2347 if ($config_options->{filesys
} =~ m/zfs|btrfs/) {
2348 $target_hd_combo->set_visible(0);
2349 $target_hd_label->set_text("Target: $config_options->{filesys} ");
2350 foreach my $w (@disk_selector) { $w->set_visible(1); }
2351 foreach my $w (@disk_label) { $w->set_visible(1); }
2353 $target_hd_combo->set_visible(1);
2354 foreach my $w (@disk_selector) { $w->set_visible(0); }
2355 foreach my $w (@disk_label) { $w->set_visible(0); }
2356 $target_hd_label->set_text("Target Harddisk: ");
2359 $spinbutton_hdsize->set_visible($enable_size_hints);
2360 $label_hdsize->set_visible($enable_size_hints);
2361 $entry_swapsize->set_visible($enable_size_hints);
2362 $label_swapsize->set_visible($enable_size_hints);
2363 $entry_maxroot->set_visible($enable_size_hints);
2364 $label_maxroot->set_visible($enable_size_hints);
2365 $entry_minfree->set_visible($enable_size_hints);
2366 $label_minfree->set_visible($enable_size_hints);
2367 $entry_maxvz->set_visible($enable_size_hints);
2368 $label_maxvz->set_visible($enable_size_hints);
2371 &$set_sensitive_flag();
2373 $fstypecb->signal_connect (changed
=> sub {
2374 $config_options->{filesys
} = $fstypecb->get_active_text();
2375 &$set_sensitive_flag();
2382 my $get_float = sub {
2385 my $text = $entry->get_text();
2386 return undef if !defined($text);
2391 return undef if $text !~ m/^\d+(\.\d+)?$/;
2398 if (($tmp = &$get_float($spinbutton_hdsize)) && ($tmp != $hdsize)) {
2399 $config_options->{hdsize
} = $tmp;
2401 delete $config_options->{hdsize
};
2404 if (defined($tmp = &$get_float($entry_swapsize))) {
2405 $config_options->{swapsize
} = $tmp;
2407 delete $config_options->{swapsize
};
2410 if (defined($tmp = &$get_float($entry_maxroot))) {
2411 $config_options->{maxroot
} = $tmp;
2413 delete $config_options->{maxroot
};
2416 if (defined($tmp = &$get_float($entry_minfree))) {
2417 $config_options->{minfree
} = $tmp;
2419 delete $config_options->{minfree
};
2422 if (defined($tmp = &$get_float($entry_maxvz))) {
2423 $config_options->{maxvz
} = $tmp;
2425 delete $config_options->{maxvz
};
2431 my $get_raid_devlist = sub {
2433 my $dev_name_hash = {};
2436 for (my $i = 0; $i < 8; $i++) {
2437 if (my $hd = $config_options->{"disksel$i"}) {
2438 my ($disk, $devname, $size, $model) = @$hd;
2439 die "device '$devname' is used more than once\n"
2440 if $dev_name_hash->{$devname};
2441 $dev_name_hash->{$devname} = $hd;
2442 push @$devlist, $hd;
2449 sub get_zfs_raid_setup
{
2451 my $filesys = $config_options->{filesys
};
2453 my $devlist = &$get_raid_devlist();
2455 my $diskcount = scalar(@$devlist);
2456 die "$filesys need at least one device\n" if $diskcount < 1;
2458 my $bootdevlist = [];
2461 if ($filesys eq 'zfs (RAID0)') {
2462 push @$bootdevlist, @$devlist[0];
2463 foreach my $hd (@$devlist) {
2466 } elsif ($filesys eq 'zfs (RAID1)') {
2467 die "zfs (RAID1) need at least 2 device\n" if $diskcount < 2;
2469 my $hd = @$devlist[0];
2470 my $expected_size = @$hd[2]; # all disks needs same size
2471 foreach $hd (@$devlist) {
2472 die "mirrored disks must have same size\n" if @$hd[2] != $expected_size;
2474 push @$bootdevlist, $hd;
2476 } elsif ($filesys eq 'zfs (RAID10)') {
2477 my $half = int($diskcount/2);
2478 die "zfs (RAID10) need at least 4 device\n" if $diskcount < 4;
2479 die "zfs (RAID10) need at an even numver of devices\n" if $half*2 != $diskcount;
2481 push @$bootdevlist, @$devlist[0], @$devlist[1];
2483 for (my $i = 0; $i < $diskcount; $i+=2) {
2484 my $hd1 = @$devlist[$i];
2485 my $hd2 = @$devlist[$i+1];
2486 die "mirrored disks must have same size\n" if @$hd1[2] != @$hd2[2];
2487 $cmd .= ' mirror ' . @$hd1[1] . ' ' . @$hd2[1];
2490 } elsif ($filesys =~ m/^zfs \(RAIDZ-([123])\)$/) {
2492 my $mindisks = 2 + $level;
2493 die "zfs (RAIDZ-$level) need at least $mindisks devices\n" if scalar(@$devlist) < $mindisks;
2494 my $hd = @$devlist[0];
2495 my $expected_size = @$hd[2]; # all disks needs same size
2496 $cmd .= " raidz$level";
2497 foreach $hd (@$devlist) {
2498 die "mirrored disks must have same size\n" if @$hd[2] != $expected_size;
2500 push @$bootdevlist, $hd;
2503 die "unknown zfs mode '$filesys'\n";
2506 return ($devlist, $bootdevlist, $cmd);
2509 sub get_btrfs_raid_setup
{
2511 my $filesys = $config_options->{filesys
};
2513 my $devlist = &$get_raid_devlist();
2515 my $diskcount = scalar(@$devlist);
2516 die "$filesys need at least one device\n" if $diskcount < 1;
2520 if ($diskcount == 1) {
2523 if ($filesys eq 'btrfs (RAID0)') {
2525 } elsif ($filesys eq 'btrfs (RAID1)') {
2526 die "btrfs (RAID1) need at least 2 device\n" if $diskcount < 2;
2528 } elsif ($filesys eq 'btrfs (RAID10)') {
2529 die "btrfs (RAID10) need at least 4 device\n" if $diskcount < 4;
2532 die "unknown zfs mode '$filesys'\n";
2536 return ($devlist, $mode);
2539 sub create_hdsel_view
{
2543 my $vbox = Gtk3
::VBox-
>new (0, 0);
2544 $inbox->pack_start ($vbox, 1, 0, 0);
2545 my $hbox = Gtk3
::HBox-
>new (0, 0);
2546 $vbox->pack_start ($hbox, 0, 0, 10);
2548 my ($disk, $devname, $size, $model) = @{@$hds[0]};
2549 $target_hd = $devname;
2551 $target_hd_label = Gtk3
::Label-
>new ("Target Harddisk: ");
2552 $hbox->pack_start ($target_hd_label, 0, 0, 0);
2554 $target_hd_combo = Gtk3
::ComboBoxText-
>new();
2556 foreach my $hd (@$hds) {
2557 ($disk, $devname, $size, $model) = @$hd;
2558 $target_hd_combo->append_text (get_device_desc
($devname, $size, $model));
2561 $target_hd_combo->set_active (0);
2562 $target_hd_combo->signal_connect (changed
=> sub {
2563 $a = shift-
>get_active;
2564 my ($disk, $devname) = @{@$hds[$a]};
2565 $target_hd = $devname;
2568 $hbox->pack_start ($target_hd_combo, 0, 0, 10);
2570 my $options = Gtk3
::Button-
>new ('_Options');
2571 $options->signal_connect (clicked
=> \
&create_hdoption_view
);
2572 $hbox->pack_start ($options, 0, 0, 0);
2577 display_html
("page1.htm");
2579 set_next
(undef, sub {
2581 if ($config_options->{filesys
} =~ m/zfs/) {
2582 eval { get_zfs_raid_setup
(); };
2584 display_message
("Warning: $err\n" .
2585 "Please fix ZFS setup first.");
2587 create_country_view
();
2589 } elsif ($config_options->{filesys
} =~ m/btrfs/) {
2590 eval { get_btrfs_raid_setup
(); };
2592 display_message
("Warning: $err\n" .
2593 "Please fix BTRFS setup first.");
2595 create_country_view
();
2598 create_country_view
();
2603 sub create_extract_view
{
2607 display_html
("extract1-license.htm");
2608 $next->set_sensitive (0);
2610 my $vbox = Gtk3
::VBox-
>new (0, 0);
2611 $inbox->pack_start ($vbox, 1, 0, 0);
2612 my $hbox = Gtk3
::HBox-
>new (0, 0);
2613 $vbox->pack_start ($hbox, 0, 0, 10);
2615 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
2616 $hbox->pack_start ($vbox2, 0, 0, 0);
2618 $progress_status = Gtk3
::Label-
>new ('');
2619 $vbox2->pack_start ($progress_status, 1, 1, 0);
2621 $progress = Gtk3
::ProgressBar-
>new;
2622 $progress->set_show_text(1);
2623 $progress->set_size_request (600, -1);
2625 $vbox2->pack_start ($progress, 0, 0, 0);
2629 my $tdir = $opt_testmode ?
"target" : "/target";
2631 my $base = $opt_testmode ?
"/pve/$release/install/pve-base.squashfs" : "/cdrom/pve-base.squashfs";
2633 eval { extract_data
($base, $tdir); };
2636 $next->set_sensitive (1);
2638 set_next
("_Reboot", sub { exit (0); } );
2641 display_html
("fail.htm");
2642 display_error
($err);
2645 display_html
("success.htm");
2649 sub create_intro_view
{
2653 display_html
("license.htm");
2655 set_next
("I a_gree", \
&create_hdsel_view
);
2658 $ipconf = get_ip_config
();
2660 $country = detect_country
() if $ipconf->{addr
} || $opt_testmode;;
2662 # read country, kmap and timezone infos
2663 $cmap = read_cmap
();
2665 create_main_window
();
2667 if (!defined ($hds) || (scalar (@$hds) <= 0)) {
2668 print "no hardisks found\n";
2669 display_html
("nohds.htm");
2670 set_next
("Reboot", sub { exit (0); } );
2673 foreach my $hd (@$hds) {
2674 my ($disk, $devname) = @$hd;
2675 next if $devname =~ m
|^/dev/md\d
+$|;
2676 print "found Disk$disk N:$devname\n";
2679 create_intro_view
();