]>
git.proxmox.com Git - pve-installer.git/blob - proxinstall
95683198f2ef31b17ce8d32bdd2c2842874aa83c
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 "/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 ($tgzfile, $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 ($tgzfile);
1158 $ino || die "unable to open file '$tgzfile' - $!\n";
1161 if ($opt_testmode) {
1162 $files = file_read_firstline("/pve/$release/install/pve-base.cnt");
1164 $files = file_read_firstline("/proxmox/pve-base.cnt");
1170 run_command ("tar xvf $tgzfile -C $targetdir", sub {
1173 my $nper = int (($count *100)/$files);
1174 if ($nper != $per) {
1176 my $frac = $per > 100 ? 100 : $per/100;
1177 update_progress ($frac, $maxper, 0.5);
1181 syscmd ("mount -n -t tmpfs tmpfs $targetdir/tmp") == 0 ||
1182 die "unable to mount tmpfs on $targetdir/tmp\n";
1183 syscmd ("mount -n -t proc proc $targetdir/proc") == 0 ||
1184 die "unable to mount proc on $targetdir/proc\n";
1185 syscmd ("mount -n -t sysfs sysfs $targetdir/sys") == 0 ||
1186 die "unable to mount sysfs on $targetdir/sys\n";
1188 display_html ("extract3-spam.htm");
1189 update_progress (1, $maxper, 0.5, "configuring base system");
1194 "127.0.0.1 localhost.localdomain localhost\n" .
1195 "$ipaddress $hostname.$domain $hostname pvelocalhost\n\n" .
1196 "# The following lines are desirable for IPv6 capable hosts\n\n" .
1197 "::1 ip6-localhost ip6-loopback\n" .
1198 "fe00::0 ip6-localnet\n" .
1199 "ff00::0 ip6-mcastprefix\n" .
1200 "ff02::1 ip6-allnodes\n" .
1201 "ff02::2 ip6-allrouters\n" .
1202 "ff02::3 ip6-allhosts\n";
1204 write_config ($hosts, "$targetdir/etc/hosts");
1206 write_config ("$hostname\n", "$targetdir/etc/hostname");
1208 syscmd ("/bin/hostname $hostname") if !$opt_testmode;
1210 # configure interfaces
1212 my $ifaces = "auto lo\niface lo inet loopback\n\n";
1214 my $ntype = $ipversion == 4 ? 'inet' : 'inet6';
1217 "auto vmbr0\niface vmbr0 $ntype static\n" .
1218 "\taddress $ipaddress\n" .
1219 "\tnetmask $netmask\n" .
1220 "\tgateway $gateway\n" .
1221 "\tbridge_ports eth0\n" .
1222 "\tbridge_stp off\n" .
1225 write_config ($ifaces, "$targetdir/etc/network/interfaces");
1229 my $resolfconf = "search $domain\nnameserver $dnsserver\n";
1230 write_config ($resolfconf, "$targetdir/etc/resolv.conf");
1234 my $fstab = "# <file system> <mount point> <type> <options> <dump> <pass>\n";
1238 } elsif ($use_btrfs) {
1240 my $cmd = "blkid -u filesystem -t TYPE=btrfs -o export $rootdev";
1241 run_command($cmd, sub {
1244 if ($line =~ m/^UUID=([A-Fa-f0-9\-]+)$/) {
1249 die "unable to detect FS UUID" if !defined($fsuuid);
1251 $fstab .= "UUID=$fsuuid / btrfs defaults 0 1\n";
1253 my $root_mountopt = $fssetup->{$filesys}->{root_mountopt} || 'defaults';
1254 $fstab .= "$rootdev / $filesys ${root_mountopt} 0 1\n";
1258 # Note: this is required by current grub, but really dangerous, because
1259 # vfat does not have journaling, so it triggers manual fsck after each crash
1260 # so we only mount /boot/efi if really required (efi systems).
1261 if ($grub_plattform =~ m/^efi-/) {
1262 if (scalar(@$bootdevinfo)) {
1263 my $di = @$bootdevinfo[0]; # simply use first disk
1265 my $efi_boot_uuid = $di->{esp};
1266 if (my $uuid = find_dev_by_uuid ($di->{esp})) {
1267 $efi_boot_uuid = "UUID=$uuid";
1270 $fstab .= "${efi_boot_uuid} /boot/efi vfat defaults 0 1\n";
1276 $fstab .= "$swapfile none swap sw 0 0\n" if $swapfile;
1278 $fstab .= "proc /proc proc defaults 0 0\n";
1280 write_config ($fstab, "$targetdir/etc/fstab");
1281 write_config ("", "$targetdir/etc/mtab");
1283 syscmd ("cp ${proxmox_dir}/policy-disable-rc.d " .
1284 "$targetdir/usr/sbin/policy-rc.d") == 0 ||
1285 die "unable to copy policy-rc.d\n";
1286 syscmd ("cp ${proxmox_dir}/fake-start-stop-daemon " .
1287 "$targetdir/sbin/") == 0 ||
1288 die "unable to copy start-stop-daemon\n";
1290 diversion_add ($targetdir, "/sbin/start-stop-daemon", "/sbin/fake-start-stop-daemon");
1291 diversion_add ($targetdir, "/usr/sbin/update-grub", "/bin/true");
1292 diversion_add ($targetdir, "/usr/sbin/update-initramfs", "/bin/true");
1294 syscmd ("touch $targetdir/proxmox_install_mode");
1296 my $grub_install_devices_txt = '';
1297 foreach my $di (@$bootdevinfo) {
1298 $grub_install_devices_txt .= ', ' if $grub_install_devices_txt;
1299 $grub_install_devices_txt .= $di->{by_id} || $di->{devname};
1302 # Note: debian-installer/locale is used by console-setup
1304 debconfig_set ($targetdir, <<_EOD);
1305 locales locales/default_environment_locale select en_US.UTF-8
1306 locales locales/locales_to_be_generated select en_US.UTF-8 UTF-8
1307 samba-common samba-common/dhcp boolean false
1308 samba-common samba-common/workgroup string WORKGROUP
1309 postfix postfix/main_mailer_type select Local only
1310 keyboard-configuration keyboard-configuration/xkb-keymap select $keymap
1311 d-i debian-installer/locale select en_US.UTF-8
1312 grub-pc grub-pc/install_devices select $grub_install_devices_txt
1315 my $pkgdir = $opt_testmode ?
"packages" : "/proxmox/packages";
1317 while (<$pkgdir/*.deb
>) { $pkg_count++ };
1319 # btrfs/dpkg is extremely slow without --force-unsafe-io
1320 my $dpkg_opts = $use_btrfs ?
"--force-unsafe-io" : "";
1323 while (<$pkgdir/*.deb
>) {
1326 my ($deb) = $path =~ m/$pkgdir\/(.*\
.deb
)/;
1327 # if ($deb =~ m/^grub-efi-/ && $deb !~ m/^grub-${grub_plattform}/) {
1331 update_progress
($count/$pkg_count, 0.5, 0.75, "extracting $deb");
1332 print "extracting: $deb\n";
1333 syscmd
("cp $path $targetdir/tmp/$deb") == 0 ||
1334 die "installation of package $deb failed\n";
1335 syscmd
("chroot $targetdir dpkg $dpkg_opts --force-depends --no-triggers --unpack /tmp/$deb") == 0 ||
1336 die "installation of package $deb failed\n";
1337 update_progress
((++$count)/$pkg_count, 0.5, 0.75);
1340 display_html
("extract4-virus.htm");
1342 my $cmd = "chroot $targetdir dpkg $dpkg_opts --force-confold --configure -a";
1344 run_command
($cmd, sub {
1346 if ($line =~ m/Setting up\s+(\S+)/) {
1347 update_progress
((++$count)/$pkg_count, 0.75, 0.95,
1352 debconfig_set
($targetdir, <<_EOD);
1353 postfix postfix/main_mailer_type select No configuration
1356 unlink "$targetdir/etc/mailname";
1357 $postfix_main_cf =~ s/__FQDN__/${hostname}.${domain}/;
1358 write_config
($postfix_main_cf, "$targetdir/etc/postfix/main.cf");
1360 # make sure we have all postfix directories
1361 syscmd
("chroot $targetdir /usr/sbin/postfix check");
1362 # cleanup mail queue
1363 syscmd
("chroot $targetdir /usr/sbin/postsuper -d ALL");
1365 # enable NTP (timedatectl set-ntp true does not work without DBUS)
1366 syscmd
("chroot $targetdir /bin/systemctl enable systemd-timesyncd.service");
1368 unlink "$targetdir/proxmox_install_mode";
1371 unlink ("$targetdir/etc/localtime");
1372 symlink ("/usr/share/zoneinfo/$timezone", "$targetdir/etc/localtime");
1373 write_config
("$timezone\n", "$targetdir/etc/timezone");
1376 if (my $mirror = $cmap->{country
}->{$country}->{mirror
}) {
1377 my $fn = "$targetdir/etc/apt/sources.list";
1378 syscmd
("sed -i 's/ftp\\.debian\\.org/$mirror/' '$fn'");
1381 # create extended_states for apt (avoid cron job warning if that
1382 # file does not exist)
1383 write_config
('', "$targetdir/var/lib/apt/extended_states");
1385 # allow ssh root login
1386 syscmd
("sed -i 's/^PermitRootLogin.*/PermitRootLogin yes/' '$targetdir/etc/ssh/sshd_config'");
1388 # save installer settings
1389 my $ucc = uc ($country);
1390 debconfig_set
($targetdir, <<_EOD);
1391 pve-manager pve-manager/country string $ucc
1394 update_progress
(0.8, 0.95, 1, "make system bootable");
1397 syscmd
("sed -i -e 's/^GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"root=ZFS=$zfspoolname\\/ROOT\\/pve-1 boot=zfs\"/' $targetdir/etc/default/grub") == 0 ||
1398 die "unable to update /etc/default/grub\n";
1402 diversion_remove
($targetdir, "/usr/sbin/update-grub");
1403 diversion_remove
($targetdir, "/usr/sbin/update-initramfs");
1405 if (!$opt_testmode) {
1407 unlink ("$targetdir/etc/mtab");
1408 symlink ("/proc/mounts", "$targetdir/etc/mtab");
1409 syscmd
("mount -n --bind /dev $targetdir/dev");
1411 syscmd
("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0 ||
1412 die "unable to install initramfs\n";
1414 foreach my $di (@$bootdevinfo) {
1415 my $dev = $di->{devname
};
1416 syscmd
("chroot $targetdir /usr/sbin/grub-install --target i386-pc --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
1417 die "unable to install the i386-pc boot loader on '$dev'\n";
1420 syscmd
("mount -n $di->{esp} $targetdir/boot/efi") == 0 ||
1421 die "unable to mount $di->{esp}\n";
1422 syscmd
("chroot $targetdir /usr/sbin/grub-install --target x86_64-efi --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
1423 die "unable to install the EFI boot loader on '$dev'\n";
1424 # also install fallback boot file (OVMF does not boot without)
1425 mkdir("$targetdir/boot/efi/EFI/BOOT");
1426 syscmd
("cp $targetdir/boot/efi/EFI/proxmox/grubx64.efi $targetdir/boot/efi/EFI/BOOT/BOOTx64.EFI") == 0 ||
1427 die "unable to copy efi boot loader\n";
1429 syscmd
("umount $targetdir/boot/efi") == 0 ||
1430 die "unable to umount $targetdir/boot/efi\n";
1434 syscmd
("chroot $targetdir /usr/sbin/update-grub") == 0 ||
1435 die "unable to update boot loader config\n";
1437 syscmd
("umount $targetdir/dev");
1442 # hack: remove dead.letter from sshd installation
1443 syscmd
("rm -rf $targetdir/dead.letter");
1445 unlink "$targetdir/usr/sbin/policy-rc.d";
1447 diversion_remove
($targetdir, "/sbin/start-stop-daemon");
1450 my $octets = encode
("utf-8", $password);
1451 run_command
("chroot $targetdir /usr/sbin/chpasswd", undef,
1456 my $tmpdir = "$targetdir/tmp/pve";
1459 # write vnc keymap to datacenter.cfg
1460 my $vnckmap = $cmap->{kmap
}->{$keymap}->{kvm
} || 'en-us';
1461 write_config
("keyboard: $vnckmap\n",
1462 "$tmpdir/datacenter.cfg");
1465 write_config
("user:root\@pam:1:0:::${mailto}::\n",
1466 "$tmpdir/user.cfg");
1469 my $strorage_cfg_fn = "$tmpdir/storage.cfg";
1471 write_config
($storage_cfg_zfs, $strorage_cfg_fn);
1472 } elsif ($use_btrfs) {
1473 write_config
($storage_cfg_btrfs, $strorage_cfg_fn);
1475 write_config
($storage_cfg_lvmthin, $strorage_cfg_fn);
1478 run_command
("chroot $targetdir /usr/bin/create_pmxcfs_db /tmp/pve /var/lib/pve-cluster/config.db");
1480 syscmd
("rm -rf $tmpdir");
1485 update_progress
(1, 0, 1, "");
1489 if ($opt_testmode) {
1490 my $elapsed = Time
::HiRes
::tv_interval
($starttime);
1491 print "Elapsed extract time: $elapsed\n";
1493 syscmd
("chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> pve-final.pkglist");
1496 syscmd
("umount $targetdir/var/lib/vz");
1497 syscmd
("umount $targetdir/tmp");
1498 syscmd
("umount $targetdir/proc");
1499 syscmd
("umount $targetdir/sys");
1502 syscmd
("zfs umount -a") == 0 ||
1503 die "unable to unmount zfs\n";
1505 syscmd
("umount -d $targetdir");
1508 if (!$err && $use_zfs) {
1509 syscmd
("zfs set sync=standard $zfspoolname") == 0 ||
1510 die "unable to set zfs properties\n";
1512 syscmd
("zfs set mountpoint=/ $zfspoolname/ROOT/pve-1") == 0 ||
1513 die "zfs set mountpoint failed\n";
1515 syscmd
("zpool set bootfs=$zfspoolname/ROOT/pve-1 $zfspoolname") == 0 ||
1516 die "zfs set bootfs failed\n";
1523 my ($filename) = @_;
1525 my $path = "${proxmox_dir}/html/$filename";
1526 my $url = "file://$path";
1528 my $data = file_get_contents
($path);
1530 if ($filename eq 'license.htm') {
1531 my $licensefn = -f
"/EULA" ?
"/EULA" :
1532 $opt_testmode ?
"./copyright" :
1533 "/usr/share/doc/pve-installer/copyright";
1534 my $license = decode
('utf8', file_get_contents
($licensefn));
1535 $license =~ m/^\s+(.+\n)/;
1536 my $title = $licensefn eq '/EULA' ?
"END USER LICENSE AGREEMENT (EULA)": $1;
1537 $data =~ s/__LICENSE__/$license/;
1538 $data =~ s/__LICENSE_TITLE__/$title/;
1541 $htmlview->load_html_string($data, $url);
1545 my ($text, $fctn) = @_;
1548 $text = "_Next" if !$text;
1549 $next->set_label ($text);
1551 $next->grab_focus ();
1555 my ($doc, $url, $stream) = @_;
1557 $stream->set_cancel_func (sub {}); # hack: avoid warning
1559 my $path = "${proxmox_dir}/html/$url";
1562 open (HTMLTMP
, $path) ||
1563 die "unable to open file '$path' - $!\n";
1565 while (my $i = read (HTMLTMP
, $buf, 4096)) {
1566 $stream->write ($buf);
1567 Gtk3
::main_iteration
() while Gtk3
::events_pending
();
1572 #$stream->close(); # hack: dont close - avoid crash
1575 sub create_main_window
{
1577 $window = Gtk3
::Window-
>new ();
1578 $window->set_default_size (1024, 768);
1579 $window->set_has_resize_grip(0);
1580 $window->set_decorated (0) if !$opt_testmode;
1582 my $vbox = Gtk3
::VBox-
>new (0, 0);
1584 my $image = Gtk3
::Image-
>new_from_file ("${proxmox_dir}/proxlogo.png");
1585 $vbox->pack_start ($image, 0, 0, 0);
1587 my $hbox = Gtk3
::HBox-
>new (0, 0);
1588 $vbox->pack_start ($hbox, 1, 1, 0);
1590 # my $f1 = Gtk3::Frame->new ('test');
1591 # $f1->set_shadow_type ('none');
1592 # $hbox->pack_start ($f1, 1, 1, 0);
1594 my $sep1 = Gtk3
::HSeparator-
>new;
1595 $vbox->pack_start ($sep1, 0, 0, 0);
1597 $cmdbox = Gtk3
::HBox-
>new ();
1598 $vbox->pack_start ($cmdbox, 0, 0, 10);
1600 $next = Gtk3
::Button-
>new ('_Next');
1601 $next->signal_connect (clicked
=> sub { &$next_fctn (); });
1602 $cmdbox->pack_end ($next, 0, 0, 10);
1603 my $abort = Gtk3
::Button-
>new ('_Abort');
1604 $abort->set_can_focus (0);
1605 $cmdbox->pack_start ($abort, 0, 0, 10);
1606 $abort->signal_connect (clicked
=> sub { exit (-1); });
1608 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1609 $hbox->add ($vbox2);
1611 $htmlview = Gtk3
::WebKit
::WebView-
>new();
1612 my $scrolls = Gtk3
::ScrolledWindow-
>new();
1613 $scrolls->add($htmlview);
1615 my $hbox2 = Gtk3
::HBox-
>new (0, 0);
1616 $hbox2->pack_start ($scrolls, 1, 1, 0);
1618 $vbox2->pack_start ($hbox2, 1, 1, 0);
1620 my $vbox3 = Gtk3
::VBox-
>new (0, 0);
1621 $vbox2->pack_start ($vbox3, 0, 0, 0);
1623 my $sep2 = Gtk3
::HSeparator-
>new;
1624 $vbox3->pack_start ($sep2, 0, 0, 0);
1626 $inbox = Gtk3
::HBox-
>new (0, 0);
1627 $vbox3->pack_start ($inbox, 0, 0, 0);
1629 $window->add ($vbox);
1632 $window->realize ();
1636 $inbox->foreach(sub {
1638 $inbox->remove ($child);
1642 # fixme: newer GTK3 has special properties to handle numbers with Entry
1643 # only allow floating point numbers with Gtk3::Entry
1645 my ($entry, $event) = @_;
1648 my $val = $event->get_keyval;
1650 if ($val == ord '.' ||
1651 $val == Gtk3
::Gdk
::KEY_ISO_Left_Tab
||
1652 $val == Gtk3
::Gdk
::KEY_Shift_L
||
1653 $val == Gtk3
::Gdk
::KEY_Tab
||
1654 $val == Gtk3
::Gdk
::KEY_Left
||
1655 $val == Gtk3
::Gdk
::KEY_Right
||
1656 $val == Gtk3
::Gdk
::KEY_BackSpace
||
1657 $val == Gtk3
::Gdk
::KEY_Delete
||
1658 ($val >= ord '0' && $val <= ord '9') ||
1659 ($val >= Gtk3
::Gdk
::KEY_KP_0
&&
1660 $val <= Gtk3
::Gdk
::KEY_KP_9
)) {
1667 sub create_text_input
{
1668 my ($default, $text) = @_;
1670 my $hbox = Gtk3
::HBox-
>new (0, 0);
1672 my $label = Gtk3
::Label-
>new ($text);
1673 $label->set_size_request (150, -1);
1674 $label->set_alignment (1, 0.5);
1675 $hbox->pack_start ($label, 0, 0, 10);
1676 my $e1 = Gtk3
::Entry-
>new ();
1677 $e1->set_width_chars (30);
1678 $hbox->pack_start ($e1, 0, 0, 0);
1679 $e1->set_text ($default);
1681 return ($hbox, $e1);
1686 my $ifconfig = `ifconfig eth0`;
1688 my ($addr) = $ifconfig =~ m/inet addr:(\S*)/m;
1689 my ($mask) = $ifconfig =~ m/Mask:(\S*)/m;
1691 my $route = `route -n`;
1692 my ($gateway) = $route =~ m/^0\.0\.0\.0\s+(\d+\.\d+\.\d+\.\d+)\s+/m;
1694 my $resolvconf = `cat /etc/resolv.conf`;
1695 my ($dnsserver) = $resolvconf =~ m/^nameserver\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/m;
1696 my ($domain) = $resolvconf =~ m/^domain\s+(\S+)$/m;
1701 gateway
=> $gateway,
1702 dnsserver
=> $dnsserver,
1707 sub display_message
{
1710 my $dialog = Gtk3
::MessageDialog-
>new ($window, 'modal',
1711 'info', 'ok', $msg);
1719 my $dialog = Gtk3
::MessageDialog-
>new ($window, 'modal',
1720 'error', 'ok', $msg);
1725 sub create_ipconf_view
{
1728 display_html
("ipconf.htm");
1730 my $vbox = Gtk3
::VBox-
>new (0, 0);
1731 $inbox->pack_start ($vbox, 1, 0, 0);
1732 my $hbox = Gtk3
::HBox-
>new (0, 0);
1733 $vbox->pack_start ($hbox, 0, 0, 10);
1734 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1735 $hbox->add ($vbox2);
1737 my $addr = $ipconf->{addr
} || '192.168.100.2';
1738 my $mask = $ipconf->{mask
} || '255.255.255.0';
1740 my $hn = $ipconf->{domain
} ?
"pve.$ipconf->{domain}" : 'pve.domain.tld';
1742 my ($hostbox, $hostentry) =
1743 create_text_input
($hn, 'Hostname (FQDN):');
1744 $vbox2->pack_start ($hostbox, 0, 0, 2);
1747 ($ipbox, $ipconf_entry_addr) =
1748 create_text_input
($addr, 'IP Address:');
1749 $vbox2->pack_start ($ipbox, 0, 0, 2);
1752 ($maskbox, $ipconf_entry_mask) =
1753 create_text_input
($mask, 'Netmask:');
1754 $vbox2->pack_start ($maskbox, 0, 0, 2);
1756 $gateway = $ipconf->{gateway
} || '192.168.100.1';
1759 ($gwbox, $ipconf_entry_gw) =
1760 create_text_input
($gateway, 'Gateway:');
1762 $vbox2->pack_start ($gwbox, 0, 0, 2);
1764 $dnsserver = $ipconf->{dnsserver
} || $gateway;
1767 ($dnsbox, $ipconf_entry_dns) =
1768 create_text_input
($dnsserver, 'DNS Server:');
1770 $vbox2->pack_start ($dnsbox, 0, 0, 0);
1773 set_next
(undef, sub {
1777 my $text = $hostentry->get_text();
1782 my $namere = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
1784 # Debian does not support purely numeric hostnames
1785 if ($text && $text =~ /^[0-9]+(?:\.|$)/) {
1786 display_message
("Purely numeric hostnames are not allowed.");
1787 $hostentry->grab_focus();
1791 if ($text && $text =~ m/^(${namere}\.)*${namere}$/ && $text !~ m/.domain.tld$/ &&
1792 $text =~ m/^([^\.]+)\.(\S+)$/) {
1796 display_message
("Hostname does not look like a fully qualified domain name.");
1797 $hostentry->grab_focus();
1803 $text = $ipconf_entry_addr->get_text();
1806 if ($text =~ m!^($IPV4RE)$!) {
1809 } elsif ($text =~ m!^($IPV6RE)$!) {
1813 display_message
("IP address is not valid.");
1814 $ipconf_entry_addr->grab_focus();
1818 $text = $ipconf_entry_mask->get_text();
1821 if (($ipversion == 6) && ($text =~ m/^(\d+)$/) && ($1 >= 8) && ($1 <= 126)) {
1823 } elsif (($ipversion == 4) && defined($ipv4_mask_hash->{$text})) {
1826 display_message
("Netmask is not valid.");
1827 $ipconf_entry_mask->grab_focus();
1831 $text = $ipconf_entry_gw->get_text();
1834 if (($ipversion == 4) && ($text =~ m!^($IPV4RE)$!)) {
1836 } elsif (($ipversion == 6) && ($text =~ m!^($IPV6RE)$!)) {
1839 display_message
("Gateway is not valid.");
1840 $ipconf_entry_gw->grab_focus();
1844 $text = $ipconf_entry_dns->get_text();
1847 if (($ipversion == 4) && ($text =~ m!^($IPV4RE)$!)) {
1849 } elsif (($ipversion == 6) && ($text =~ m!^($IPV6RE)$!)) {
1852 display_message
("DNS server is not valid.");
1853 $ipconf_entry_dns->grab_focus();
1857 #print "TEST $ipaddress $netmask $gateway $dnsserver\n";
1859 create_extract_view
();
1862 $hostentry->grab_focus();
1865 sub get_device_desc
{
1866 my ($devname, $size, $model) = @_;
1868 if ($size && ($size > 0)) {
1869 $size = int($size/2048); # size in MB
1871 my $text = "$devname (";
1872 if ($size >= 1024) {
1873 $size = int($size/1024); # size in GB
1874 $text .= "${size}GB";
1876 $text .= "${size}MB";
1879 $text .= ", $model" if $model;
1888 my ($cb, $kmap) = @_;
1893 my $kmaphash = $cmap->{kmaphash
};
1894 foreach my $layout (sort keys %$kmaphash) {
1895 $def = $i if $kmaphash->{$layout} eq 'en-us';
1896 $ind = $i if $kmap && $kmaphash->{$layout} eq $kmap;
1900 $cb->set_active ($ind || $def || 0);
1904 sub update_zonelist
{
1905 my ($box, $cc) = @_;
1907 my $cczones = $cmap->{cczones
};
1908 my $zones = $cmap->{zones
};
1912 $sel = $lastzonecb->get_active_text();
1913 $box->remove ($lastzonecb);
1915 $sel = $timezone; # used once to select default
1918 my $cb = $lastzonecb = Gtk3
::ComboBoxText-
>new();
1919 $cb->set_size_request (200, -1);
1921 $cb->signal_connect ('changed' => sub {
1922 $timezone = $cb->get_active_text();
1926 if ($cc && defined ($cczones->{$cc})) {
1927 @za = keys %{$cczones->{$cc}};
1933 foreach my $zone (sort @za) {
1934 $ind = $i if $sel && $zone eq $sel;
1935 $cb->append_text ($zone);
1939 $cb->set_active ($ind || 0);
1942 $box->pack_start ($cb, 0, 0, 0);
1945 sub create_password_view
{
1949 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1950 $inbox->pack_start ($vbox2, 1, 0, 0);
1951 my $vbox = Gtk3
::VBox-
>new (0, 0);
1952 $vbox2->pack_start ($vbox, 0, 0, 10);
1954 my $hbox1 = Gtk3
::HBox-
>new (0, 0);
1955 my $label = Gtk3
::Label-
>new ("Password");
1956 $label->set_size_request (150, -1);
1957 $label->set_alignment (1, 0.5);
1958 $hbox1->pack_start ($label, 0, 0, 10);
1959 my $pwe1 = Gtk3
::Entry-
>new ();
1960 $pwe1->set_visibility (0);
1961 $pwe1->set_size_request (200, -1);
1962 $hbox1->pack_start ($pwe1, 0, 0, 0);
1964 my $hbox2 = Gtk3
::HBox-
>new (0, 0);
1965 $label = Gtk3
::Label-
>new ("Confirm");
1966 $label->set_size_request (150, -1);
1967 $label->set_alignment (1, 0.5);
1968 $hbox2->pack_start ($label, 0, 0, 10);
1969 my $pwe2 = Gtk3
::Entry-
>new ();
1970 $pwe2->set_visibility (0);
1971 $pwe2->set_size_request (200, -1);
1972 $hbox2->pack_start ($pwe2, 0, 0, 0);
1974 my $hbox3 = Gtk3
::HBox-
>new (0, 0);
1975 $label = Gtk3
::Label-
>new ("E-Mail");
1976 $label->set_size_request (150, -1);
1977 $label->set_alignment (1, 0.5);
1978 $hbox3->pack_start ($label, 0, 0, 10);
1979 my $eme = Gtk3
::Entry-
>new ();
1980 $eme->set_size_request (200, -1);
1981 $hbox3->pack_start ($eme, 0, 0, 0);
1984 $vbox->pack_start ($hbox1, 0, 0, 5);
1985 $vbox->pack_start ($hbox2, 0, 0, 5);
1986 $vbox->pack_start ($hbox3, 0, 0, 15);
1990 display_html
("passwd.htm");
1992 set_next
(undef, sub {
1994 my $t1 = $pwe1->get_text;
1995 my $t2 = $pwe2->get_text;
1997 if (length ($t1) < 5) {
1998 display_message
("Password is too short.");
1999 $pwe1->grab_focus();
2004 display_message
("Password does not match.");
2005 $pwe1->grab_focus();
2009 my $t3 = $eme->get_text;
2010 if ($t3 !~ m/^\S+\@\S+\.\S+$/) {
2011 display_message
("E-Mail does not look like a vaild address" .
2012 " (user\@domain.tld)");
2021 create_ipconf_view
();
2024 $pwe1->grab_focus();
2028 sub create_country_view
{
2032 my $countryhash = $cmap->{countryhash
};
2033 my $ctr = $cmap->{country
};
2035 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
2036 $inbox->pack_start ($vbox2, 1, 0, 0);
2037 my $vbox = Gtk3
::VBox-
>new (0, 0);
2038 $vbox2->pack_start ($vbox, 0, 0, 10);
2040 my $w = Gtk3
::Entry-
>new ();
2041 $w->set_size_request (200, -1);
2043 my $c = Gtk3
::EntryCompletion-
>new ();
2044 $c->set_text_column (0);
2045 $c->set_minimum_key_length(0);
2046 $c->set_popup_set_width (1);
2047 $c->set_inline_completion (1);
2049 my $hbox2 = Gtk3
::HBox-
>new (0, 0);
2050 my $label = Gtk3
::Label-
>new ("Time zone");
2051 $label->set_size_request (150, -1);
2052 $label->set_alignment (1, 0.5);
2053 $hbox2->pack_start ($label, 0, 0, 10);
2054 update_zonelist
($hbox2);
2056 my $hbox3 = Gtk3
::HBox-
>new (0, 0);
2057 $label = Gtk3
::Label-
>new ("Keyboard Layout");
2058 $label->set_size_request (150, -1);
2059 $label->set_alignment (1, 0.5);
2060 $hbox3->pack_start ($label, 0, 0, 10);
2062 my $kmapcb = Gtk3
::ComboBoxText-
>new();
2063 $kmapcb->set_size_request (200, -1);
2064 foreach my $layout (sort keys %{$cmap->{kmaphash
}}) {
2065 $kmapcb->append_text ($layout);
2068 update_layout
($kmapcb);
2069 $hbox3->pack_start ($kmapcb, 0, 0, 0);
2071 $kmapcb->signal_connect ('changed' => sub {
2072 my $sel = $kmapcb->get_active_text();
2073 if (my $kmap = $cmap->{kmaphash
}->{$sel}) {
2074 my $xkmap = $cmap->{kmap
}->{$kmap}->{x11
};
2075 my $xvar = $cmap->{kmap
}->{$kmap}->{x11var
};
2076 syscmd
("setxkbmap $xkmap $xvar") if !$opt_testmode;
2081 $w->signal_connect ('changed' => sub {
2082 my ($entry, $event) = @_;
2083 my $text = $entry->get_text;
2085 if (my $cc = $countryhash->{lc($text)}) {
2086 update_zonelist
($hbox2, $cc);
2087 my $kmap = $ctr->{$cc}->{kmap
} || 'en-us';
2088 update_layout
($kmapcb, $kmap);
2092 $w->signal_connect (key_press_event
=> sub {
2093 my ($entry, $event) = @_;
2094 my $text = $entry->get_text;
2096 my $val = $event->get_keyval;
2098 if ($val == Gtk3
::Gdk
::KEY_Tab
) {
2099 my $cc = $countryhash->{lc($text)};
2106 $compl = $ctr->{$cc}->{name
};
2108 foreach my $cc (keys %$ctr) {
2109 my $ct = $ctr->{$cc}->{name
};
2110 if ($ct =~ m/^\Q$text\E.*$/i) {
2119 $entry->set_text($compl);
2124 print chr(7); # beep ?
2129 my $buf = $w->get_buffer();
2130 $buf->insert_text(-1, '', -1); # popup selection
2138 my $ls = Gtk3
::ListStore-
>new('Glib::String');
2139 foreach my $cc (sort {$ctr->{$a}->{name
} cmp $ctr->{$b}->{name
} } keys %$ctr) {
2140 my $iter = $ls->append();
2141 $ls->set ($iter, 0, $ctr->{$cc}->{name
});
2143 $c->set_model ($ls);
2145 $w->set_completion ($c);
2147 my $hbox = Gtk3
::HBox-
>new (0, 0);
2149 $label = Gtk3
::Label-
>new ("Country");
2150 $label->set_alignment (1, 0.5);
2151 $label->set_size_request (150, -1);
2152 $hbox->pack_start ($label, 0, 0, 10);
2153 $hbox->pack_start ($w, 0, 0, 0);
2155 $vbox->pack_start ($hbox, 0, 0, 5);
2156 $vbox->pack_start ($hbox2, 0, 0, 5);
2157 $vbox->pack_start ($hbox3, 0, 0, 5);
2160 $w->set_text ($ctr->{$country}->{name
});
2165 display_html
("country.htm");
2166 set_next
(undef, sub {
2168 my $text = $w->get_text;
2170 if (my $cc = $countryhash->{lc($text)}) {
2172 create_password_view
();
2175 display_message
("Please select a country first.");
2183 my $target_hd_combo;
2184 my $target_hd_label;
2186 my $hdopion_first_setup = 1;
2188 sub create_hdoption_view
{
2190 my $dialog = Gtk3
::Dialog-
>new();
2192 $dialog->set_title("Harddisk options");
2194 $dialog->add_button("_OK", 1);
2196 my $contarea = $dialog->get_content_area();
2198 my $hbox2 = Gtk3
::Box-
>new('horizontal', 0);
2199 $contarea->pack_start($hbox2, 1, 1, 10);
2201 my $grid = Gtk3
::Grid-
>new();
2202 $grid->set_column_spacing(10);
2203 $grid->set_row_spacing(10);
2205 $hbox2->pack_start($grid, 1, 0, 10);
2211 my $label0 = Gtk3
::Label-
>new ("Filesystem");
2212 $label0->set_alignment (1, 0.5);
2213 $grid->attach($label0, 0, $row, 1, 1);
2215 my $fstypecb = Gtk3
::ComboBoxText-
>new();
2217 my $fstype = ['ext3', 'ext4', 'xfs',
2218 'zfs (RAID0)', 'zfs (RAID1)',
2219 'zfs (RAID10)', 'zfs (RAIDZ-1)',
2220 'zfs (RAIDZ-2)', 'zfs (RAIDZ-3)',
2221 'btrfs (RAID0)', 'btrfs (RAID1)', 'btrfs (RAID10)'];
2224 foreach my $tmp (@$fstype) {
2225 $fstypecb->append_text($tmp);
2226 $fstypecb->set_active ($tcount)
2227 if $config_options->{filesys
} eq $tmp;
2231 $grid->attach($fstypecb, 1, $row, 1, 1);
2239 for (my $i = 0; $i < 8; $i++) {
2240 $disk_label[$i] = Gtk3
::Label-
>new ("Hardisk $i");
2241 $disk_label[$i]->set_alignment (1, 0.5);
2242 $grid->attach($disk_label[$i], 0, $row, 1, 1);
2243 $disk_selector[$i] = Gtk3
::ComboBoxText-
>new();
2244 $disk_selector[$i]->append_text("-- do not use --");
2245 $disk_selector[$i]->set_active(0);
2246 foreach my $hd (@$hds) {
2247 my ($disk, $devname, $size, $model) = @$hd;
2248 $disk_selector[$i]->append_text(get_device_desc
($devname, $size, $model));
2249 $disk_selector[$i]->{pve_disk_id
} = $i;
2250 $disk_selector[$i]->signal_connect (changed
=> sub {
2252 my $diskid = $w->{pve_disk_id
};
2253 my $a = $w->get_active - 1;
2254 $config_options->{"disksel${diskid}"} = ($a >= 0) ?
$hds->[$a] : undef;
2258 if ($hdopion_first_setup) {
2259 $disk_selector[$i]->set_active ($i+1) if $hds->[$i];
2262 if (my $cur_hd = $config_options->{"disksel$i"}) {
2263 foreach my $hd (@$hds) {
2264 if (@$hd[1] eq @$cur_hd[1]) {
2265 $disk_selector[$i]->set_active($hdind+1);
2274 $grid->attach($disk_selector[$i], 1, $row, 1, 1);
2279 $hdopion_first_setup = 0;
2281 my $label_hdsize = Gtk3
::Label-
>new ("hdsize");
2282 $label_hdsize->set_alignment (1, 0.5);
2283 $grid->attach($label_hdsize, 0, $row, 1, 1);
2287 if ( -b
$target_hd) {
2288 $hdsize = int(hd_size
($target_hd) / (1024*1024.0)); # size in GB
2289 } elsif ($target_hd) {
2290 $hdsize = int((-s
$target_hd) / (1024*1024*1024.0));
2293 my $hdsize_size_adj = Gtk3
::Adjustment-
>new($config_options->{hdsize
} || $hdsize, 0, $hdsize+1, 1, 1, 1);
2294 my $spinbutton_hdsize = Gtk3
::SpinButton-
>new($hdsize_size_adj, 1, 1);
2295 $spinbutton_hdsize->set_tooltip_text("only use specified size (GB) of the harddisk (rest left unpartitioned)");
2296 $grid->attach($spinbutton_hdsize, 1, $row, 1, 1);
2299 my $label_swapsize = Gtk3
::Label-
>new ("swapsize");
2300 $label_swapsize->set_alignment (1, 0.5);
2301 $grid->attach($label_swapsize, 0, $row, 1, 1);
2303 my $entry_swapsize = Gtk3
::Entry-
>new();
2304 $entry_swapsize->set_tooltip_text("maximum SWAP size (GB)");
2305 $entry_swapsize->signal_connect (key_press_event
=> \
&check_float
);
2306 $entry_swapsize->set_text($config_options->{swapsize
}) if $config_options->{swapsize
};
2307 $grid->attach($entry_swapsize, 1, $row, 1, 1);
2310 my $label_maxroot = Gtk3
::Label-
>new ("maxroot");
2311 $label_maxroot->set_alignment (1, 0.5);
2312 $grid->attach($label_maxroot, 0, $row, 1, 1);
2314 my $entry_maxroot = Gtk3
::Entry-
>new();
2315 $entry_maxroot->set_tooltip_text("maximum size (GB) for LVM root volume");
2316 $entry_maxroot->signal_connect (key_press_event
=> \
&check_float
);
2317 $entry_maxroot->set_text($config_options->{maxroot
}) if $config_options->{maxroot
};
2318 $grid->attach($entry_maxroot, 1, $row, 1, 1);
2321 my $label_minfree = Gtk3
::Label-
>new ("minfree");
2322 $label_minfree->set_alignment (1, 0.5);
2323 $grid->attach($label_minfree, 0, $row, 1, 1);
2325 my $entry_minfree = Gtk3
::Entry-
>new();
2326 $entry_minfree->set_tooltip_text("minumum free LVM space (GB, required for LVM snapshots)");
2327 $entry_minfree->signal_connect (key_press_event
=> \
&check_float
);
2328 $entry_minfree->set_text($config_options->{minfree
}) if $config_options->{minfree
};
2329 $grid->attach($entry_minfree, 1, $row, 1, 1);
2332 my $label_maxvz = Gtk3
::Label-
>new ("maxvz");
2333 $label_maxvz->set_alignment (1, 0.5);
2334 $grid->attach($label_maxvz, 0, $row, 1, 1);
2336 my $entry_maxvz = Gtk3
::Entry-
>new();
2337 $entry_maxvz->set_tooltip_text("maximum size (GB) for LVM data volume");
2338 $entry_maxvz->signal_connect (key_press_event
=> \
&check_float
);
2339 $entry_maxvz->set_text($config_options->{maxvz
}) if $config_options->{maxvz
};
2340 $grid->attach($entry_maxvz, 1, $row, 1, 1);
2343 my $set_sensitive_flag = sub {
2344 my $enable_size_hints = $config_options->{filesys
} !~ m/zfs|btrfs/;
2346 if ($config_options->{filesys
} =~ m/zfs|btrfs/) {
2347 $target_hd_combo->set_visible(0);
2348 $target_hd_label->set_text("Target: $config_options->{filesys} ");
2349 foreach my $w (@disk_selector) { $w->set_visible(1); }
2350 foreach my $w (@disk_label) { $w->set_visible(1); }
2352 $target_hd_combo->set_visible(1);
2353 foreach my $w (@disk_selector) { $w->set_visible(0); }
2354 foreach my $w (@disk_label) { $w->set_visible(0); }
2355 $target_hd_label->set_text("Target Harddisk: ");
2358 $spinbutton_hdsize->set_visible($enable_size_hints);
2359 $label_hdsize->set_visible($enable_size_hints);
2360 $entry_swapsize->set_visible($enable_size_hints);
2361 $label_swapsize->set_visible($enable_size_hints);
2362 $entry_maxroot->set_visible($enable_size_hints);
2363 $label_maxroot->set_visible($enable_size_hints);
2364 $entry_minfree->set_visible($enable_size_hints);
2365 $label_minfree->set_visible($enable_size_hints);
2366 $entry_maxvz->set_visible($enable_size_hints);
2367 $label_maxvz->set_visible($enable_size_hints);
2370 &$set_sensitive_flag();
2372 $fstypecb->signal_connect (changed
=> sub {
2373 $config_options->{filesys
} = $fstypecb->get_active_text();
2374 &$set_sensitive_flag();
2381 my $get_float = sub {
2384 my $text = $entry->get_text();
2385 return undef if !defined($text);
2390 return undef if $text !~ m/^\d+(\.\d+)?$/;
2397 if (($tmp = &$get_float($spinbutton_hdsize)) && ($tmp != $hdsize)) {
2398 $config_options->{hdsize
} = $tmp;
2400 delete $config_options->{hdsize
};
2403 if (defined($tmp = &$get_float($entry_swapsize))) {
2404 $config_options->{swapsize
} = $tmp;
2406 delete $config_options->{swapsize
};
2409 if (defined($tmp = &$get_float($entry_maxroot))) {
2410 $config_options->{maxroot
} = $tmp;
2412 delete $config_options->{maxroot
};
2415 if (defined($tmp = &$get_float($entry_minfree))) {
2416 $config_options->{minfree
} = $tmp;
2418 delete $config_options->{minfree
};
2421 if (defined($tmp = &$get_float($entry_maxvz))) {
2422 $config_options->{maxvz
} = $tmp;
2424 delete $config_options->{maxvz
};
2430 my $get_raid_devlist = sub {
2432 my $dev_name_hash = {};
2435 for (my $i = 0; $i < 8; $i++) {
2436 if (my $hd = $config_options->{"disksel$i"}) {
2437 my ($disk, $devname, $size, $model) = @$hd;
2438 die "device '$devname' is used more than once\n"
2439 if $dev_name_hash->{$devname};
2440 $dev_name_hash->{$devname} = $hd;
2441 push @$devlist, $hd;
2448 sub get_zfs_raid_setup
{
2450 my $filesys = $config_options->{filesys
};
2452 my $devlist = &$get_raid_devlist();
2454 my $diskcount = scalar(@$devlist);
2455 die "$filesys need at least one device\n" if $diskcount < 1;
2457 my $bootdevlist = [];
2460 if ($filesys eq 'zfs (RAID0)') {
2461 push @$bootdevlist, @$devlist[0];
2462 foreach my $hd (@$devlist) {
2465 } elsif ($filesys eq 'zfs (RAID1)') {
2466 die "zfs (RAID1) need at least 2 device\n" if $diskcount < 2;
2468 my $hd = @$devlist[0];
2469 my $expected_size = @$hd[2]; # all disks needs same size
2470 foreach $hd (@$devlist) {
2471 die "mirrored disks must have same size\n" if @$hd[2] != $expected_size;
2473 push @$bootdevlist, $hd;
2475 } elsif ($filesys eq 'zfs (RAID10)') {
2476 my $half = int($diskcount/2);
2477 die "zfs (RAID10) need at least 4 device\n" if $diskcount < 4;
2478 die "zfs (RAID10) need at an even numver of devices\n" if $half*2 != $diskcount;
2480 push @$bootdevlist, @$devlist[0], @$devlist[1];
2482 for (my $i = 0; $i < $diskcount; $i+=2) {
2483 my $hd1 = @$devlist[$i];
2484 my $hd2 = @$devlist[$i+1];
2485 die "mirrored disks must have same size\n" if @$hd1[2] != @$hd2[2];
2486 $cmd .= ' mirror ' . @$hd1[1] . ' ' . @$hd2[1];
2489 } elsif ($filesys =~ m/^zfs \(RAIDZ-([123])\)$/) {
2491 my $mindisks = 2 + $level;
2492 die "zfs (RAIDZ-$level) need at least $mindisks devices\n" if scalar(@$devlist) < $mindisks;
2493 my $hd = @$devlist[0];
2494 my $expected_size = @$hd[2]; # all disks needs same size
2495 $cmd .= " raidz$level";
2496 foreach $hd (@$devlist) {
2497 die "mirrored disks must have same size\n" if @$hd[2] != $expected_size;
2499 push @$bootdevlist, $hd;
2502 die "unknown zfs mode '$filesys'\n";
2505 return ($devlist, $bootdevlist, $cmd);
2508 sub get_btrfs_raid_setup
{
2510 my $filesys = $config_options->{filesys
};
2512 my $devlist = &$get_raid_devlist();
2514 my $diskcount = scalar(@$devlist);
2515 die "$filesys need at least one device\n" if $diskcount < 1;
2519 if ($diskcount == 1) {
2522 if ($filesys eq 'btrfs (RAID0)') {
2524 } elsif ($filesys eq 'btrfs (RAID1)') {
2525 die "btrfs (RAID1) need at least 2 device\n" if $diskcount < 2;
2527 } elsif ($filesys eq 'btrfs (RAID10)') {
2528 die "btrfs (RAID10) need at least 4 device\n" if $diskcount < 4;
2531 die "unknown zfs mode '$filesys'\n";
2535 return ($devlist, $mode);
2538 sub create_hdsel_view
{
2542 my $vbox = Gtk3
::VBox-
>new (0, 0);
2543 $inbox->pack_start ($vbox, 1, 0, 0);
2544 my $hbox = Gtk3
::HBox-
>new (0, 0);
2545 $vbox->pack_start ($hbox, 0, 0, 10);
2547 my ($disk, $devname, $size, $model) = @{@$hds[0]};
2548 $target_hd = $devname;
2550 $target_hd_label = Gtk3
::Label-
>new ("Target Harddisk: ");
2551 $hbox->pack_start ($target_hd_label, 0, 0, 0);
2553 $target_hd_combo = Gtk3
::ComboBoxText-
>new();
2555 foreach my $hd (@$hds) {
2556 ($disk, $devname, $size, $model) = @$hd;
2557 $target_hd_combo->append_text (get_device_desc
($devname, $size, $model));
2560 $target_hd_combo->set_active (0);
2561 $target_hd_combo->signal_connect (changed
=> sub {
2562 $a = shift-
>get_active;
2563 my ($disk, $devname) = @{@$hds[$a]};
2564 $target_hd = $devname;
2567 $hbox->pack_start ($target_hd_combo, 0, 0, 10);
2569 my $options = Gtk3
::Button-
>new ('_Options');
2570 $options->signal_connect (clicked
=> \
&create_hdoption_view
);
2571 $hbox->pack_start ($options, 0, 0, 0);
2576 display_html
("page1.htm");
2578 set_next
(undef, sub {
2580 if ($config_options->{filesys
} =~ m/zfs/) {
2581 eval { get_zfs_raid_setup
(); };
2583 display_message
("Warning: $err\n" .
2584 "Please fix ZFS setup first.");
2586 create_country_view
();
2588 } elsif ($config_options->{filesys
} =~ m/btrfs/) {
2589 eval { get_btrfs_raid_setup
(); };
2591 display_message
("Warning: $err\n" .
2592 "Please fix BTRFS setup first.");
2594 create_country_view
();
2597 create_country_view
();
2602 sub create_extract_view
{
2606 display_html
("extract1-license.htm");
2607 $next->set_sensitive (0);
2609 my $vbox = Gtk3
::VBox-
>new (0, 0);
2610 $inbox->pack_start ($vbox, 1, 0, 0);
2611 my $hbox = Gtk3
::HBox-
>new (0, 0);
2612 $vbox->pack_start ($hbox, 0, 0, 10);
2614 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
2615 $hbox->pack_start ($vbox2, 0, 0, 0);
2617 $progress_status = Gtk3
::Label-
>new ('');
2618 $vbox2->pack_start ($progress_status, 1, 1, 0);
2620 $progress = Gtk3
::ProgressBar-
>new;
2621 $progress->set_show_text(1);
2622 $progress->set_size_request (600, -1);
2624 $vbox2->pack_start ($progress, 0, 0, 0);
2628 my $tdir = $opt_testmode ?
"target" : "/target";
2630 my $base = $opt_testmode ?
"/pve/$release/install/pve-base.tar" : "/proxmox/pve-base.tar";
2632 eval { extract_data
($base, $tdir); };
2635 $next->set_sensitive (1);
2637 set_next
("_Reboot", sub { exit (0); } );
2640 display_html
("fail.htm");
2641 display_error
($err);
2644 display_html
("success.htm");
2648 sub create_intro_view
{
2652 display_html
("license.htm");
2654 set_next
("I a_gree", \
&create_hdsel_view
);
2657 $ipconf = get_ip_config
();
2659 $country = detect_country
() if $ipconf->{addr
} || $opt_testmode;;
2661 # read country, kmap and timezone infos
2662 $cmap = read_cmap
();
2664 create_main_window
();
2666 if (!defined ($hds) || (scalar (@$hds) <= 0)) {
2667 print "no hardisks found\n";
2668 display_html
("nohds.htm");
2669 set_next
("Reboot", sub { exit (0); } );
2672 foreach my $hd (@$hds) {
2673 my ($disk, $devname) = @$hd;
2674 next if $devname =~ m
|^/dev/md\d
+$|;
2675 print "found Disk$disk N:$devname\n";
2678 create_intro_view
();