]>
git.proxmox.com Git - pve-installer.git/blob - proxinstall
3 $ENV{DEBIAN_FRONTEND
} = 'noninteractive';
16 use String
::ShellQuote
;
23 my $kapi = `uname -r`;
30 if (!$ENV{G_SLICE
} || $ENV{G_SLICE
} ne "always-malloc") {
31 die "do not use slice allocator (run with 'G_SLICE=always-malloc ./proxinstall ...')\n";
34 if (!GetOptions
('testmode=s' => \
$opt_testmode)) {
39 my $zfstestpool = "test_rpool";
40 my $zfspoolname = $opt_testmode ?
$zfstestpool : 'rpool';
42 my $storage_cfg_zfs = <<__EOD__;
45 content iso,vztmpl,backup
48 pool $zfspoolname/data
50 content images,rootdir
53 my $storage_cfg_btrfs = <<__EOD__;
56 content iso,vztmpl,backup
60 path /var/lib/pve/local-btrfs
61 content iso,vztmpl,backup,images,rootdir
64 my $storage_cfg_lvmthin = <<__EOD__;
67 content iso,vztmpl,backup
72 content rootdir,images
76 sub file_read_firstline
{
79 my $fh = IO
::File-
>new ($filename, "r");
87 my $logfd = IO
::File-
>new (">/tmp/install.log");
89 my $proxmox_dir = $opt_testmode ? Cwd
::cwd
() : "/var/lib/pve-installer";
91 my $grub_plattform = "pc"; # pc, efi-amd64 or efi-ia32
93 $grub_plattform = "efi-amd64" if -d
"/sys/firmware/efi";
95 my $IPV4OCTET = "(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9])?[0-9])";
96 my $IPV4RE = "(?:(?:$IPV4OCTET\\.){3}$IPV4OCTET)";
97 my $IPV6H16 = "(?:[0-9a-fA-F]{1,4})";
98 my $IPV6LS32 = "(?:(?:$IPV4RE|$IPV6H16:$IPV6H16))";
101 "(?:(?:" . "(?:$IPV6H16:){6})$IPV6LS32)|" .
102 "(?:(?:" . "::(?:$IPV6H16:){5})$IPV6LS32)|" .
103 "(?:(?:(?:" . "$IPV6H16)?::(?:$IPV6H16:){4})$IPV6LS32)|" .
104 "(?:(?:(?:(?:$IPV6H16:){0,1}$IPV6H16)?::(?:$IPV6H16:){3})$IPV6LS32)|" .
105 "(?:(?:(?:(?:$IPV6H16:){0,2}$IPV6H16)?::(?:$IPV6H16:){2})$IPV6LS32)|" .
106 "(?:(?:(?:(?:$IPV6H16:){0,3}$IPV6H16)?::(?:$IPV6H16:){1})$IPV6LS32)|" .
107 "(?:(?:(?:(?:$IPV6H16:){0,4}$IPV6H16)?::" . ")$IPV6LS32)|" .
108 "(?:(?:(?:(?:$IPV6H16:){0,5}$IPV6H16)?::" . ")$IPV6H16)|" .
109 "(?:(?:(?:(?:$IPV6H16:){0,6}$IPV6H16)?::" . ")))";
111 my $IPRE = "(?:$IPV4RE|$IPV6RE)";
114 my $ipv4_mask_hash = {
131 '255.255.128.0' => 17,
132 '255.255.192.0' => 18,
133 '255.255.224.0' => 19,
134 '255.255.240.0' => 20,
135 '255.255.248.0' => 21,
136 '255.255.252.0' => 22,
137 '255.255.254.0' => 23,
138 '255.255.255.0' => 24,
139 '255.255.255.128' => 25,
140 '255.255.255.192' => 26,
141 '255.255.255.224' => 27,
142 '255.255.255.240' => 28,
143 '255.255.255.248' => 29,
144 '255.255.255.252' => 30
147 my ($window, $cmdbox, $inbox, $htmlview);
148 my ($next, $next_fctn, $target_hd);
149 my ($progress, $progress_status);
150 my ($ipversion, $ipaddress, $ipconf_entry_addr);
151 my ($netmask, $ipconf_entry_mask);
152 my ($gateway, $ipconf_entry_gw);
153 my ($dnsserver, $ipconf_entry_dns);
154 my $hostname = 'proxmox';
155 my $domain = 'domain.tld';
156 my $cmdline = file_read_firstline
("/proc/cmdline");
159 my $timezone = 'Europe/Vienna';
162 my $keymap = 'en-us';
165 # parse command line args
167 my $config_options = {};
169 if ($cmdline =~ m/\s(ext3|ext4|xfs)(\s.*)?$/) {
170 $config_options->{filesys
} = $1;
172 $config_options->{filesys
} = 'ext4';
175 if ($cmdline =~ m/hdsize=(\d+(\.\d+)?)[\s\n]/i) {
176 $config_options->{hdsize
} = $1;
179 if ($cmdline =~ m/swapsize=(\d+(\.\d+)?)[\s\n]/i) {
180 $config_options->{swapsize
} = $1;
183 if ($cmdline =~ m/maxroot=(\d+(\.\d+)?)[\s\n]/i) {
184 $config_options->{maxroot
} = $1;
187 if ($cmdline =~ m/minfree=(\d+(\.\d+)?)[\s\n]/i) {
188 $config_options->{minfree
} = $1;
191 if ($cmdline =~ m/maxvz=(\d+(\.\d+)?)[\s\n]/i) {
192 $config_options->{maxvz
} = $1;
195 my $postfix_main_cf = <<_EOD;
196 # See /usr/share/postfix/main.cf.dist for a commented, more complete version
200 smtpd_banner = \$myhostname ESMTP \$mail_name (Debian/GNU)
203 # appending .domain is the MUA's job.
204 append_dot_mydomain = no
206 # Uncomment the next line to generate "delayed mail" warnings
207 #delay_warning_time = 4h
209 alias_maps = hash:/etc/aliases
210 alias_database = hash:/etc/aliases
211 mydestination = \$myhostname, localhost.\$mydomain, localhost
213 mynetworks = 127.0.0.0/8
214 inet_interfaces = loopback-only
215 recipient_delimiter = +
222 return String
::ShellQuote
::shell_quote
($str);
228 die "no arguments" if !$cmd;
230 return $cmd if !ref($cmd);
233 foreach my $arg (@$cmd) { push @qa, shellquote
($arg); }
235 return join (' ', @qa);
241 return run_command
($cmd, undef, undef, 1);
245 my ($cmd, $func, $input, $noout) = @_;
251 # see 'man bash' for option pipefail
252 $cmd = [ '/bin/bash', '-c', "set -o pipefail && $cmd" ];
257 $cmdstr = cmd2string
($cmd);
261 if ($input && ($cmdstr !~ m/chpasswd/)) {
262 $cmdtxt = "# $cmdstr <<EOD\n$input";
264 $cmdtxt .= "\nEOD\n";
266 $cmdtxt = "# $cmdstr\n";
274 print $logfd $cmdtxt;
276 my $reader = IO
::File-
>new();
277 my $writer = IO
::File-
>new();
278 my $error = IO
::File-
>new();
284 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
290 if ($orig_pid != $$) {
297 print $writer $input if defined $input;
300 my $select = new IO
::Select
;
301 $select->add ($reader);
302 $select->add ($error);
304 my ($ostream, $logout) = ('', '', '');
306 while ($select->count) {
307 my @handles = $select->can_read (0.2);
309 Gtk3
::main_iteration
() while Gtk3
::events_pending
();
311 next if !scalar (@handles); # timeout
313 foreach my $h (@handles) {
315 my $count = sysread ($h, $buf, 4096);
316 if (!defined ($count)) {
320 die "command '$cmd' failed: $err";
322 $select->remove ($h) if !$count;
324 $ostream .= $buf if !($noout || $func);
326 while ($logout =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
328 &$func($line) if $func;
331 } elsif ($h eq $error) {
332 $ostream .= $buf if !($noout || $func);
340 &$func($logout) if $func;
342 my $rv = waitpid ($pid, 0);
344 return $? if $noout; # behave like standard system();
349 die "command '$cmdstr' failed with exit code $ec";
357 print "trying to detect country...\n";
358 my $cpid = open2
(\
*TMP
, undef, "traceroute -N 1 -q 1 -n 8.8.8.8");
359 return undef if !$cpid;
363 my $previous_alarm = alarm (10);
365 local $SIG{ALRM
} = sub { die "timed out!\n" };
367 while (defined ($line = <TMP
>)) {
368 print $logfd "DC TRACEROUTE: $line";
369 if ($line =~ m/\s*\d+\s+(\d+\.\d+\.\d+\.\d+)\s/) {
370 my $geoip = `geoiplookup $1`;
371 print $logfd "DC GEOIP: $geoip";
372 if ($geoip =~ m/GeoIP Country Edition:\s*([A-Z]+),/) {
374 print $logfd "DC FOUND: $country\n";
383 alarm ($previous_alarm);
388 print "unable to detect country - $err\n";
390 print "detected country: " . uc($country) . "\n";
392 print "unable to detect country\n";
400 open (MEMINFO, "/proc/meminfo");
402 my $res = 512; # default to 512 if something goes wrong
403 while (my $line = <MEMINFO>) {
404 if ($line =~ m/^MemTotal:\s+(\d+)\s*kB/i) {
405 $res = int ($1 / 1024);
414 my $total_memory = get_memtotal();
417 my ($src, $dest) = @_;
419 my ($dev1,$ino1) = stat ($src);
420 my ($dev2,$ino2) = stat ($dest);
422 return 0 if !($dev1 && $dev2 && $ino1 && $ino2);
424 return $ino1 == $ino2 && $dev1 == $dev2;
427 sub find_stable_path {
428 my ($stabledir, $bdev) = @_;
430 foreach my $path (<$stabledir/*>) {
431 if (link_points_to ($path, $bdev)) {
432 return wantarray ? ($path, basename($path)) : $path;
437 sub find_dev_by_uuid {
440 my ($full_path, $name) = find_stable_path ("/dev/disk/by-uuid", $bdev);
450 push @$res, [-1, $opt_testmode, int((-s $opt_testmode)/512), "TESTDISK"];
456 foreach my $bd (</sys/block/*>) {
457 next if $bd =~ m|^/sys/block/ram\d+$|;
458 next if $bd =~ m|^/sys/block/loop\d+$|;
459 next if $bd =~ m|^/sys/block/md\d+$|;
460 next if $bd =~ m|^/sys/block/dm-.*$|;
461 next if $bd =~ m|^/sys/block/fd\d+$|;
462 next if $bd =~ m|^/sys/block/sr\d+$|;
464 my $dev = file_read_firstline("$bd/dev");
469 my $info = `udevadm info
--path
$bd --query all
`;
472 next if $info !~ m/^E: DEVTYPE=disk$/m;
474 next if $info =~ m/^E: ID_CDROM/m;
476 my ($name) = $info =~ m/^N: (\S+)$/m;
479 my $real_name = "/dev/$name";
481 my $size = file_read_firstline("$bd/size");
483 $size = undef if !($size && $size =~ m/^\d+$/);
485 my $model = file_read_firstline("$bd/device/model") || '';
488 if (length ($model) > 30) {
489 $model = substr ($model, 0, 30);
491 push @$res, [$count++, $real_name, $size, $model] if $size;
493 print STDERR "ERROR: unable to map device $dev ($bd)\n";
501 my $countryfn = $opt_testmode ? "/usr/share/pve-manager/country.dat" :
502 "/cdrom/proxmox/country.dat";
503 open (TMP, "<$countryfn") || die "unable to open '$countryfn' - $!\n";
506 my $countryhash = {};
509 while (defined ($line = <TMP>)) {
510 if ($line =~ m|^map:([^\s:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]*):$|) {
518 $kmaphash->{$2} = $1;
519 } elsif ($line =~ m|^([a-z]{2}):([^:]+):([^:]*):([^:]*):$|) {
525 $countryhash->{lc($2)} = $1;
527 warn "unable to parse 'country.dat' line: $line";
534 my $zonefn = "/usr/share/zoneinfo/zone.tab";
535 open (TMP, "<$zonefn") || die "unable to open '$zonefn' - $!\n";
536 while (defined ($line = <TMP>)) {
537 next if $line =~ m/^\#/;
538 next if $line =~ m/^\s*$/;
539 if ($line =~ m|^([A-Z][A-Z])\s+\S+\s+(([^/]+)/\S+)\s|) {
541 $cczones->{$cc}->{$2} = 1;
542 $country->{$cc}->{zone} = $2 if !defined ($country->{$cc}->{zone});
553 countryhash => $countryhash,
555 kmaphash => $kmaphash,
559 # search for Harddisks
560 my $hds = hd_list ();
565 foreach my $hd (@$hds) {
566 my ($disk, $devname, $size, $model) = @$hd;
567 return int($size/2) if $devname eq $dev;
570 die "no such device '$dev'\n";
573 sub get_partition_dev {
574 my ($dev, $partnum) = @_;
576 if ($dev =~ m|^/dev/[hxsev]d[a-z]$|) {
577 return "${dev}$partnum";
578 } elsif ($dev =~ m|^/dev/[^/]+/c\d+d\d+$|) {
579 return "${dev}p$partnum";
580 } elsif ($dev =~ m|^/dev/[^/]+/d\d+$|) {
581 return "${dev}p$partnum";
582 } elsif ($dev =~ m|^/dev/[^/]+/hd[a-z]$|) {
583 return "${dev}$partnum";
584 } elsif ($dev =~ m|^/dev/nvme\d+n\d+$|) {
585 return "${dev}p$partnum";
587 die "unable to get device for partition $partnum on device $dev\n";
592 sub file_get_contents {
593 my ($filename, $max) = @_;
595 my $fh = IO::File->new($filename, "r") ||
596 die "can't open '$filename' - $!\n";
598 local $/; # slurp mode
608 my ($text, $filename) = @_;
610 my $fd = IO::File->new (">$filename") ||
611 die "unable to open file '$filename' - $!\n";
616 sub update_progress {
617 my ($frac, $start, $end, $text) = @_;
619 my $part = $end - $start;
620 my $res = $start + $frac*$part;
622 $progress->set_fraction ($res);
623 $progress->set_text (sprintf ("%d%%", int ($res*100)));
624 $progress_status->set_text ($text) if defined ($text);
626 Gtk3::main_iteration() while Gtk3::events_pending();
631 mkfs => 'mkfs.ext3 -F',
633 mkfs_data_opt => '-m 0',
634 root_mountopt => 'errors=remount-ro',
637 mkfs => 'mkfs.ext4 -F',
639 mkfs_data_opt => '-m 0',
640 root_mountopt => 'errors=remount-ro',
643 mkfs => 'mkfs.xfs -f',
650 sub create_filesystem {
651 my ($dev, $name, $type, $start, $end, $fs, $fe) = @_;
653 my $range = $end - $start;
654 my $rs = $start + $range*$fs;
655 my $re = $start + $range*$fe;
658 my $fsdata = $fssetup->{$type} || die "internal error - unknown file system '$type'";
659 my $opts = $name eq 'root' ? $fsdata->{mkfs_root_opt} : $fsdata->{mkfs_data_opt};
661 update_progress (0, $rs, $re, "creating $name filesystem");
663 run_command ("$fsdata->{mkfs} $opts $dev", sub {
666 if ($line =~ m/Writing inode tables:\s+(\d+)\/(\d+)/) {
668 } elsif ($max && $line =~ m/(\d+)\/$max/) {
669 update_progress (($1/$max)*0.9, $rs, $re);
670 } elsif ($line =~ m/Creating journal.*done/) {
671 update_progress (0.95, $rs, $re);
672 } elsif ($line =~ m/Writing superblocks and filesystem.*done/) {
673 update_progress (1, $rs, $re);
679 my ($targetdir, $dcdata) = @_;
681 my $cfgfile = "/tmp/debconf.txt";
682 write_config ($dcdata, "$targetdir/$cfgfile");
683 syscmd ("chroot $targetdir debconf-set-selections $cfgfile");
684 unlink "$targetdir/$cfgfile";
688 my ($targetdir, $cmd, $new_cmd) = @_;
690 syscmd ("chroot $targetdir dpkg-divert --package proxmox " .
691 "--add --rename $cmd") == 0 ||
692 die "unable to exec dpkg-divert\n";
694 syscmd ("ln -sf ${new_cmd} $targetdir/$cmd") == 0 ||
695 die "unable to link diversion to ${new_cmd}\n";
698 sub diversion_remove {
699 my ($targetdir, $cmd) = @_;
701 syscmd ("mv $targetdir/${cmd}.distrib $targetdir/${cmd};") == 0 ||
702 die "unable to remove $cmd diversion\n";
704 syscmd ("chroot $targetdir dpkg-divert --remove $cmd") == 0 ||
705 die "unable to remove $cmd diversion\n";
709 my ($partitions, $mode) = @_;
711 die "unknown btrfs mode '$mode'"
712 if !($mode eq 'single' || $mode eq 'raid0' ||
713 $mode eq 'raid1' || $mode eq 'raid10');
715 my $cmd = ['mkfs.btrfs', '-f'];
717 push @$cmd, '-d', $mode, '-m', $mode;
719 push @$cmd, @$partitions;
724 sub zfs_create_rpool {
727 syscmd ("zpool create -f -o ashift=12 -o cachefile=none $zfspoolname $vdev") == 0 ||
728 die "unable to create zfs root pool\n";
730 syscmd ("zfs create $zfspoolname/ROOT") == 0 ||
731 die "unable to create zfs $zfspoolname/ROOT volume\n";
733 syscmd ("zfs create $zfspoolname/data") == 0 ||
734 die "unable to create zfs $zfspoolname/data volume\n";
736 syscmd ("zfs create $zfspoolname/ROOT/pve-1") == 0 ||
737 die "unable to create zfs $zfspoolname/ROOT/pve-1 volume\n";
739 # disable atime during insatll
740 syscmd ("zfs set atime=off $zfspoolname") == 0 ||
741 die "unable to set zfs properties\n";
742 syscmd ("zfs set compression=lz4 $zfspoolname") == 0 ||
743 die "unable to set zfs properties\n";
746 sub zfs_create_swap {
749 syscmd ("zfs create -V ${swapsize}K -b 4K $zfspoolname/swap") == 0 ||
750 die "unable to create zfs swap device\n";
752 syscmd ("zfs set com.sun:auto-snapshot=false $zfspoolname/swap") == 0 ||
753 die "unable to set zfs properties\n";
755 # reduces memory pressure
756 syscmd ("zfs set sync=always $zfspoolname/swap") == 0 ||
757 die "unable to set zfs properties\n";
759 return "/dev/zvol/$zfspoolname/swap";
762 sub partition_bootable_disk {
763 my ($target_dev, $maxhdsize, $ptype) = @_;
765 die "too dangerous" if $opt_testmode;
767 die "unknown partition type '$ptype'"
768 if !($ptype eq '8E00' || $ptype eq '8300');
770 syscmd("sgdisk -Z ${target_dev}");
771 my $hdsize = hd_size($target_dev); # size in blocks (1024 bytes)
773 my $restricted_hdsize_mb = 0; # 0 ==> end of partition
774 if ($maxhdsize && ($maxhdsize < $hdsize)) {
775 $hdsize = $maxhdsize;
776 $restricted_hdsize_mb = int($hdsize/1024) . 'M';
779 my $hdgb = int($hdsize/(1024*1024));
780 die "hardisk '$target_dev' too small (${hdsize}GB)\n" if $hdgb < 8;
782 # 1 - GRUB boot partition: 1M
784 # 3 - OS/Data partition
786 my $grubbootdev = get_partition_dev($target_dev, 1);
787 my $efibootdev = get_partition_dev($target_dev, 2);
788 my $osdev = get_partition_dev ($target_dev, 3);
790 my $pcmd = ['sgdisk', '-a1'];
793 push @$pcmd, "-n$pnum:34:2047", "-t$pnum:EF02";
796 # Note: from sector 2048 to 128M
797 my $endsec = 128*1024*2 - 1;
798 push @$pcmd, "-n$pnum:2048:$endsec", "-t$pnum:EF00";
801 # Note: from 128M to end
802 push @$pcmd, "-n$pnum:128M:${restricted_hdsize_mb}", "-t$pnum:$ptype";
804 push @$pcmd, $target_dev;
806 my $os_size = $hdsize - 128*1024;
808 syscmd($pcmd) == 0 ||
809 die "unable to partition harddisk '${target_dev}'\n";
811 return ($os_size, $osdev, $efibootdev);
814 # ZFS has this use_whole_disk concept, so we try to partition the same
815 # way as zfs does by default. There is room at start of disk to insert
816 # a grub boot partition. But adding a EFI ESP is not possible.
818 # Note: zfs people think this is just a waste of space an not
819 # required. Instead, you should put the ESP on another disk (log,
822 sub partition_bootable_zfs_disk {
823 my ($target_dev) = @_;
825 die "too dangerous" if $opt_testmode;
827 syscmd("sgdisk -Z ${target_dev}");
828 my $hdsize = hd_size($target_dev); # size in blocks (1024 bytes)
830 my $hdgb = int($hdsize/(1024*1024));
831 die "hardisk '$target_dev' too small (${hdsize}GB)\n" if $hdgb < 8;
833 # 1 - GRUB boot partition: 1M
834 # 2 - OS/Data partition
835 # 9 - ZFS reserved partition
837 my $grubbootdev = get_partition_dev($target_dev, 1);
838 my $osdev = get_partition_dev ($target_dev, 2);
840 my $pcmd = ['sgdisk', '-a1'];
843 push @$pcmd, "-n$pnum:34:2047", "-t$pnum:EF02";
846 push @$pcmd, "-n$pnum:-8M:0", "-t$pnum:BF07";
849 push @$pcmd, "-n$pnum:2048:0", "-t$pnum:BF01", '-c', "$pnum:zfs";
851 push @$pcmd, $target_dev;
853 my $os_size = $hdsize - 1024 - 1024*8;
855 syscmd($pcmd) == 0 ||
856 die "unable to partition harddisk '${target_dev}'\n";
858 return ($os_size, $osdev);
861 sub create_lvm_volumes {
862 my ($lvmdev, $os_size, $swap_size) = @_;
864 my $rootdev = '/dev/pve/root';
865 my $datadev = '/dev/pve/data';
866 my $swapfile = '/dev/pve/swap';
868 # we use --metadatasize 250k, which reseults in "pe_start = 512"
869 # so pe_start is aligned on a 128k boundary (advantage for SSDs)
870 syscmd ("/sbin/pvcreate --metadatasize 250k -y -ff $lvmdev") == 0 ||
871 die "unable to initialize physical volume $lvmdev\n";
872 syscmd ("/sbin/vgcreate pve $lvmdev") == 0 ||
873 die "unable to create volume group 'pve'\n";
875 my $hdgb = int($os_size/(1024*1024));
876 my $space = (($hdgb > 128) ? 16 : ($hdgb/8))*1024*1024;
879 if ($config_options->{maxroot}) {
880 $maxroot = $config_options->{maxroot};
885 my $rootsize = (($hdgb > ($maxroot*4)) ? $maxroot : $hdgb/4)*1024*1024;
887 my $rest = $os_size - $swap_size - $rootsize; # in KB
890 if ($config_options->{minfree}) {
891 $minfree = (($config_options->{minfree}*1024*1024) >= $rest ) ? $space :
892 $config_options->{minfree}*1024*1024 ;
897 $rest = $rest - $minfree;
899 if ($config_options->{maxvz}) {
900 $rest = (($config_options->{maxvz}*1024*1024) <= $rest) ?
901 $config_options->{maxvz}*1024*1024 : $rest;
904 syscmd ("/sbin/lvcreate -L${swap_size}K -nswap pve") == 0 ||
905 die "unable to create swap volume\n";
907 syscmd ("/sbin/lvcreate -L${rootsize}K -nroot pve") == 0 ||
908 die "unable to create root volume\n";
910 syscmd ("/sbin/lvcreate -L${rest}K -ndata pve") == 0 ||
911 die "unable to create data volume\n";
913 syscmd ("/sbin/lvconvert --yes --type thin-pool pve/data") == 0 ||
914 die "unable to create data thin-pool\n";
916 syscmd ("/sbin/vgchange -a y pve") == 0 ||
917 die "unable to activate volume group\n";
919 return ($rootdev, $datadev, $swapfile);
922 sub compute_swapsize {
925 my $hdgb = int($hdsize/(1024*1024));
928 if ($config_options->{swapsize}) {
929 $swapsize = $config_options->{swapsize}*1024*1024;
931 my $ss = int ($total_memory / 1024);
933 $ss = ($hdgb/8) if $ss > ($hdgb/8);
935 $swapsize = $ss*1024*1024;
939 my $udevadm_trigger_block = sub {
942 sleep(1) if !$nowait; # give kernel time to reread part table
944 # trigger udev to create /dev/disk/by-uuid
945 syscmd ("udevadm trigger --subsystem-match block");
946 syscmd ("udevadm settle --timeout 10");
950 my ($basefile, $targetdir) = @_;
952 die "target '$targetdir' does not exist\n" if ! -d $targetdir;
954 my $starttime = [Time::HiRes::gettimeofday];
956 my $bootdevinfo = [];
965 my $filesys = $config_options->{filesys};
967 if ($filesys =~ m/zfs/) {
968 $target_hd = undef; # do not use this config
970 $targetdir = "/$zfspoolname/ROOT/pve-1";
971 } elsif ($filesys =~ m/btrfs/) {
972 $target_hd = undef; # do not use this config
978 for ($i = 5; $i > 0; $i--) {
979 syscmd("modprobe zfs");
980 last if -c "/dev/zfs";
984 die "unable to load zfs kernel module\n" if !$i;
992 update_progress (0, 0, $maxper, "create partitions");
996 $rootdev = abs_path($opt_testmode);
997 syscmd("umount $rootdev");
1001 die "unsupported btrfs mode (for testing environment)\n"
1002 if $filesys ne 'btrfs (RAID0)';
1004 btrfs_create([$rootdev], 'single');
1006 } elsif ($use_zfs) {
1008 die "unsupported zfs mode (for testing environment)\n"
1009 if $filesys ne 'zfs (RAID0)';
1011 syscmd ("zpool destroy $zfstestpool");
1013 zfs_create_rpool($rootdev);
1020 } elsif ($use_btrfs) {
1022 my ($devlist, $btrfs_mode) = get_btrfs_raid_setup();
1023 my $btrfs_partitions = [];
1025 foreach my $hd (@$devlist) {
1026 my $devname = @$hd[1];
1027 my ($size, $osdev, $efidev) =
1028 partition_bootable_disk($devname, undef, '8300');
1029 $rootdev = $osdev if !defined($rootdev); # simply point to first disk
1030 my $by_id = find_stable_path("/dev/disk/by-id", $devname);
1031 push @$bootdevinfo, { esp => $efidev, devname => $devname,
1032 osdev => $osdev, by_id => $by_id };
1033 push @$btrfs_partitions, $osdev;
1037 &$udevadm_trigger_block();
1039 btrfs_create($btrfs_partitions, $btrfs_mode);
1041 } elsif ($use_zfs) {
1043 my ($devlist, $bootdevlist, $vdev) = get_zfs_raid_setup();
1046 foreach my $hd (@$bootdevlist) {
1047 my $devname = @$hd[1];
1048 my ($size, $osdev) =
1049 partition_bootable_zfs_disk($devname);
1050 zfs_mirror_size_check($disksize, $size) if $disksize;
1051 push @$bootdevinfo, { devname => $devname, osdev => $osdev};
1055 &$udevadm_trigger_block();
1057 foreach my $di (@$bootdevinfo) {
1058 my $devname = $di->{devname};
1059 $di->{by_id} = find_stable_path ("/dev/disk/by-id", $devname);
1061 # Note: using /dev/disk/by-id/ does not work for unknown reason, we get
1062 # cannot create 'rpool': no such pool or dataset
1063 #my $osdev = find_stable_path ("/dev/disk/by-id", $di->{osdev}) || $di->{osdev};
1065 my $osdev = $di->{osdev};
1066 $vdev =~ s/ $devname/ $osdev/;
1069 zfs_create_rpool($vdev);
1071 my $swap_size = compute_swapsize($disksize);
1072 $swapfile = zfs_create_swap($swap_size);
1076 die "target '$target_hd' is not a valid block device\n" if ! -b $target_hd;
1079 if ($config_options->{hdsize}) {
1080 # max hdsize passed on cmdline (GB)
1081 $maxhdsize = $config_options->{hdsize}*1024*1024;
1084 my ($os_size, $osdev, $efidev);
1085 ($os_size, $osdev, $efidev) =
1086 partition_bootable_disk($target_hd, $maxhdsize, '8E00');
1088 &$udevadm_trigger_block();
1090 my $by_id = find_stable_path ("/dev/disk/by-id", $target_hd);
1091 push @$bootdevinfo, { esp => $efidev, devname => $target_hd,
1092 osdev => $osdev, by_id => $by_id };
1094 my $swap_size = compute_swapsize($os_size);
1095 ($rootdev, $datadev, $swapfile) =
1096 create_lvm_volumes($osdev, $os_size, $swap_size);
1098 # trigger udev to create /dev/disk/by-uuid
1099 &$udevadm_trigger_block(1);
1103 # to be fast during installation
1104 syscmd ("zfs set sync=disabled $zfspoolname") == 0 ||
1105 die "unable to set zfs properties\n";
1108 update_progress (0.03, 0, $maxper, "create swap space");
1110 syscmd ("mkswap -f $swapfile") == 0 ||
1111 die "unable to create swap space\n";
1114 update_progress (0.05, 0, $maxper, "creating filesystems");
1116 foreach my $di (@$bootdevinfo) {
1117 next if !$di->{esp};
1118 syscmd ("mkfs.vfat -F32 $di->{esp}") == 0 ||
1119 die "unable to initialize EFI ESP on device $di->{esp}\n";
1124 } elsif ($use_btrfs) {
1127 create_filesystem ($rootdev, 'root', $filesys, 0.05, $maxper, 0, 1);
1130 update_progress (1, 0.05, $maxper, "mounting target $rootdev");
1134 } elsif ($use_btrfs) {
1135 syscmd("mount -n $rootdev -o noatime,nobarrier $targetdir") == 0 ||
1136 die "unable to mount $rootdev\n";
1138 syscmd ("mount -n $rootdev -o noatime,barrier=0 $targetdir") == 0 ||
1139 die "unable to mount $rootdev\n";
1142 mkdir "$targetdir/boot";
1143 mkdir "$targetdir/boot/efi";
1145 mkdir "$targetdir/var";
1146 mkdir "$targetdir/var/lib";
1147 mkdir "$targetdir/var/lib/vz";
1148 mkdir "$targetdir/var/lib/pve";
1151 syscmd("btrfs subvolume create $targetdir/var/lib/pve/local-btrfs") == 0 ||
1152 die "unable to create btrfs subvolume\n";
1155 display_html ("extract2-rulesystem.htm");
1156 update_progress (1, 0.05, $maxper, "extracting base system");
1158 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = stat ($basefile);
1159 $ino || die "unable to open file '$basefile' - $!\n";
1162 if ($opt_testmode) {
1163 $files = file_read_firstline("/pve/$release/install/pve-base.cnt");
1165 $files = file_read_firstline("/cdrom/proxmox/pve-base.cnt");
1171 run_command ("unsquashfs -f -dest $targetdir -i $basefile", sub {
1173 return if $line !~ m/^$targetdir/;
1175 my $nper = int (($count *100)/$files);
1176 if ($nper != $per) {
1178 my $frac = $per > 100 ? 1 : $per/100;
1179 update_progress ($frac, $maxper, 0.5);
1183 syscmd ("mount -n -t tmpfs tmpfs $targetdir/tmp") == 0 ||
1184 die "unable to mount tmpfs on $targetdir/tmp\n";
1185 syscmd ("mount -n -t proc proc $targetdir/proc") == 0 ||
1186 die "unable to mount proc on $targetdir/proc\n";
1187 syscmd ("mount -n -t sysfs sysfs $targetdir/sys") == 0 ||
1188 die "unable to mount sysfs on $targetdir/sys\n";
1190 display_html ("extract3-spam.htm");
1191 update_progress (1, $maxper, 0.5, "configuring base system");
1196 "127.0.0.1 localhost.localdomain localhost\n" .
1197 "$ipaddress $hostname.$domain $hostname pvelocalhost\n\n" .
1198 "# The following lines are desirable for IPv6 capable hosts\n\n" .
1199 "::1 ip6-localhost ip6-loopback\n" .
1200 "fe00::0 ip6-localnet\n" .
1201 "ff00::0 ip6-mcastprefix\n" .
1202 "ff02::1 ip6-allnodes\n" .
1203 "ff02::2 ip6-allrouters\n" .
1204 "ff02::3 ip6-allhosts\n";
1206 write_config ($hosts, "$targetdir/etc/hosts");
1208 write_config ("$hostname\n", "$targetdir/etc/hostname");
1210 syscmd ("/bin/hostname $hostname") if !$opt_testmode;
1212 # configure interfaces
1214 my $ifaces = "auto lo\niface lo inet loopback\n\n";
1216 my $ntype = $ipversion == 4 ? 'inet' : 'inet6';
1219 "auto vmbr0\niface vmbr0 $ntype static\n" .
1220 "\taddress $ipaddress\n" .
1221 "\tnetmask $netmask\n" .
1222 "\tgateway $gateway\n" .
1223 "\tbridge_ports eth0\n" .
1224 "\tbridge_stp off\n" .
1227 write_config ($ifaces, "$targetdir/etc/network/interfaces");
1231 my $resolfconf = "search $domain\nnameserver $dnsserver\n";
1232 write_config ($resolfconf, "$targetdir/etc/resolv.conf");
1236 my $fstab = "# <file system> <mount point> <type> <options> <dump> <pass>\n";
1240 } elsif ($use_btrfs) {
1242 my $cmd = "blkid -u filesystem -t TYPE=btrfs -o export $rootdev";
1243 run_command($cmd, sub {
1246 if ($line =~ m/^UUID=([A-Fa-f0-9\-]+)$/) {
1251 die "unable to detect FS UUID" if !defined($fsuuid);
1253 $fstab .= "UUID=$fsuuid / btrfs defaults 0 1\n";
1255 my $root_mountopt = $fssetup->{$filesys}->{root_mountopt} || 'defaults';
1256 $fstab .= "$rootdev / $filesys ${root_mountopt} 0 1\n";
1260 # Note: this is required by current grub, but really dangerous, because
1261 # vfat does not have journaling, so it triggers manual fsck after each crash
1262 # so we only mount /boot/efi if really required (efi systems).
1263 if ($grub_plattform =~ m/^efi-/) {
1264 if (scalar(@$bootdevinfo)) {
1265 my $di = @$bootdevinfo[0]; # simply use first disk
1267 my $efi_boot_uuid = $di->{esp};
1268 if (my $uuid = find_dev_by_uuid ($di->{esp})) {
1269 $efi_boot_uuid = "UUID=$uuid";
1272 $fstab .= "${efi_boot_uuid} /boot/efi vfat defaults 0 1\n";
1278 $fstab .= "$swapfile none swap sw 0 0\n" if $swapfile;
1280 $fstab .= "proc /proc proc defaults 0 0\n";
1282 write_config ($fstab, "$targetdir/etc/fstab");
1283 write_config ("", "$targetdir/etc/mtab");
1285 syscmd ("cp ${proxmox_dir}/policy-disable-rc.d " .
1286 "$targetdir/usr/sbin/policy-rc.d") == 0 ||
1287 die "unable to copy policy-rc.d\n";
1288 syscmd ("cp ${proxmox_dir}/fake-start-stop-daemon " .
1289 "$targetdir/sbin/") == 0 ||
1290 die "unable to copy start-stop-daemon\n";
1292 diversion_add ($targetdir, "/sbin/start-stop-daemon", "/sbin/fake-start-stop-daemon");
1293 diversion_add ($targetdir, "/usr/sbin/update-grub", "/bin/true");
1294 diversion_add ($targetdir, "/usr/sbin/update-initramfs", "/bin/true");
1296 syscmd ("touch $targetdir/proxmox_install_mode");
1298 my $grub_install_devices_txt = '';
1299 foreach my $di (@$bootdevinfo) {
1300 $grub_install_devices_txt .= ', ' if $grub_install_devices_txt;
1301 $grub_install_devices_txt .= $di->{by_id} || $di->{devname};
1304 # Note: debian-installer/locale is used by console-setup
1306 debconfig_set ($targetdir, <<_EOD);
1307 locales locales/default_environment_locale select en_US.UTF-8
1308 locales locales/locales_to_be_generated select en_US.UTF-8 UTF-8
1309 samba-common samba-common/dhcp boolean false
1310 samba-common samba-common/workgroup string WORKGROUP
1311 postfix postfix/main_mailer_type select Local only
1312 keyboard-configuration keyboard-configuration/xkb-keymap select $keymap
1313 d-i debian-installer/locale select en_US.UTF-8
1314 grub-pc grub-pc/install_devices select $grub_install_devices_txt
1317 my $pkgdir = $opt_testmode ?
"packages" : "/cdrom/proxmox/packages";
1319 while (<$pkgdir/*.deb
>) { $pkg_count++ };
1321 # btrfs/dpkg is extremely slow without --force-unsafe-io
1322 my $dpkg_opts = $use_btrfs ?
"--force-unsafe-io" : "";
1325 while (<$pkgdir/*.deb
>) {
1328 my ($deb) = $path =~ m/$pkgdir\/(.*\
.deb
)/;
1329 # if ($deb =~ m/^grub-efi-/ && $deb !~ m/^grub-${grub_plattform}/) {
1333 update_progress
($count/$pkg_count, 0.5, 0.75, "extracting $deb");
1334 print "extracting: $deb\n";
1335 syscmd
("cp $path $targetdir/tmp/$deb") == 0 ||
1336 die "installation of package $deb failed\n";
1337 syscmd
("chroot $targetdir dpkg $dpkg_opts --force-depends --no-triggers --unpack /tmp/$deb") == 0 ||
1338 die "installation of package $deb failed\n";
1339 update_progress
((++$count)/$pkg_count, 0.5, 0.75);
1342 display_html
("extract4-virus.htm");
1344 my $cmd = "chroot $targetdir dpkg $dpkg_opts --force-confold --configure -a";
1346 run_command
($cmd, sub {
1348 if ($line =~ m/Setting up\s+(\S+)/) {
1349 update_progress
((++$count)/$pkg_count, 0.75, 0.95,
1354 debconfig_set
($targetdir, <<_EOD);
1355 postfix postfix/main_mailer_type select No configuration
1358 unlink "$targetdir/etc/mailname";
1359 $postfix_main_cf =~ s/__FQDN__/${hostname}.${domain}/;
1360 write_config
($postfix_main_cf, "$targetdir/etc/postfix/main.cf");
1362 # make sure we have all postfix directories
1363 syscmd
("chroot $targetdir /usr/sbin/postfix check");
1364 # cleanup mail queue
1365 syscmd
("chroot $targetdir /usr/sbin/postsuper -d ALL");
1367 # enable NTP (timedatectl set-ntp true does not work without DBUS)
1368 syscmd
("chroot $targetdir /bin/systemctl enable systemd-timesyncd.service");
1370 unlink "$targetdir/proxmox_install_mode";
1373 unlink ("$targetdir/etc/localtime");
1374 symlink ("/usr/share/zoneinfo/$timezone", "$targetdir/etc/localtime");
1375 write_config
("$timezone\n", "$targetdir/etc/timezone");
1378 if (my $mirror = $cmap->{country
}->{$country}->{mirror
}) {
1379 my $fn = "$targetdir/etc/apt/sources.list";
1380 syscmd
("sed -i 's/ftp\\.debian\\.org/$mirror/' '$fn'");
1383 # create extended_states for apt (avoid cron job warning if that
1384 # file does not exist)
1385 write_config
('', "$targetdir/var/lib/apt/extended_states");
1387 # allow ssh root login
1388 syscmd
("sed -i 's/^PermitRootLogin.*/PermitRootLogin yes/' '$targetdir/etc/ssh/sshd_config'");
1390 # save installer settings
1391 my $ucc = uc ($country);
1392 debconfig_set
($targetdir, <<_EOD);
1393 pve-manager pve-manager/country string $ucc
1396 update_progress
(0.8, 0.95, 1, "make system bootable");
1399 syscmd
("sed -i -e 's/^GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"root=ZFS=$zfspoolname\\/ROOT\\/pve-1 boot=zfs\"/' $targetdir/etc/default/grub") == 0 ||
1400 die "unable to update /etc/default/grub\n";
1404 diversion_remove
($targetdir, "/usr/sbin/update-grub");
1405 diversion_remove
($targetdir, "/usr/sbin/update-initramfs");
1407 if (!$opt_testmode) {
1409 unlink ("$targetdir/etc/mtab");
1410 symlink ("/proc/mounts", "$targetdir/etc/mtab");
1411 syscmd
("mount -n --bind /dev $targetdir/dev");
1413 syscmd
("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0 ||
1414 die "unable to install initramfs\n";
1416 foreach my $di (@$bootdevinfo) {
1417 my $dev = $di->{devname
};
1418 syscmd
("chroot $targetdir /usr/sbin/grub-install --target i386-pc --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
1419 die "unable to install the i386-pc boot loader on '$dev'\n";
1422 syscmd
("mount -n $di->{esp} $targetdir/boot/efi") == 0 ||
1423 die "unable to mount $di->{esp}\n";
1424 syscmd
("chroot $targetdir /usr/sbin/grub-install --target x86_64-efi --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
1425 die "unable to install the EFI boot loader on '$dev'\n";
1426 # also install fallback boot file (OVMF does not boot without)
1427 mkdir("$targetdir/boot/efi/EFI/BOOT");
1428 syscmd
("cp $targetdir/boot/efi/EFI/proxmox/grubx64.efi $targetdir/boot/efi/EFI/BOOT/BOOTx64.EFI") == 0 ||
1429 die "unable to copy efi boot loader\n";
1431 syscmd
("umount $targetdir/boot/efi") == 0 ||
1432 die "unable to umount $targetdir/boot/efi\n";
1436 syscmd
("chroot $targetdir /usr/sbin/update-grub") == 0 ||
1437 die "unable to update boot loader config\n";
1439 syscmd
("umount $targetdir/dev");
1444 # hack: remove dead.letter from sshd installation
1445 syscmd
("rm -rf $targetdir/dead.letter");
1447 unlink "$targetdir/usr/sbin/policy-rc.d";
1449 diversion_remove
($targetdir, "/sbin/start-stop-daemon");
1452 my $octets = encode
("utf-8", $password);
1453 run_command
("chroot $targetdir /usr/sbin/chpasswd", undef,
1458 my $tmpdir = "$targetdir/tmp/pve";
1461 # write vnc keymap to datacenter.cfg
1462 my $vnckmap = $cmap->{kmap
}->{$keymap}->{kvm
} || 'en-us';
1463 write_config
("keyboard: $vnckmap\n",
1464 "$tmpdir/datacenter.cfg");
1467 write_config
("user:root\@pam:1:0:::${mailto}::\n",
1468 "$tmpdir/user.cfg");
1471 my $strorage_cfg_fn = "$tmpdir/storage.cfg";
1473 write_config
($storage_cfg_zfs, $strorage_cfg_fn);
1474 } elsif ($use_btrfs) {
1475 write_config
($storage_cfg_btrfs, $strorage_cfg_fn);
1477 write_config
($storage_cfg_lvmthin, $strorage_cfg_fn);
1480 run_command
("chroot $targetdir /usr/bin/create_pmxcfs_db /tmp/pve /var/lib/pve-cluster/config.db");
1482 syscmd
("rm -rf $tmpdir");
1487 update_progress
(1, 0, 1, "");
1491 if ($opt_testmode) {
1492 my $elapsed = Time
::HiRes
::tv_interval
($starttime);
1493 print "Elapsed extract time: $elapsed\n";
1495 syscmd
("chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> pve-final.pkglist");
1498 syscmd
("umount $targetdir/var/lib/vz");
1499 syscmd
("umount $targetdir/tmp");
1500 syscmd
("umount $targetdir/proc");
1501 syscmd
("umount $targetdir/sys");
1504 syscmd
("zfs umount -a") == 0 ||
1505 die "unable to unmount zfs\n";
1507 syscmd
("umount -d $targetdir");
1510 if (!$err && $use_zfs) {
1511 syscmd
("zfs set sync=standard $zfspoolname") == 0 ||
1512 die "unable to set zfs properties\n";
1514 syscmd
("zfs set mountpoint=/ $zfspoolname/ROOT/pve-1") == 0 ||
1515 die "zfs set mountpoint failed\n";
1517 syscmd
("zpool set bootfs=$zfspoolname/ROOT/pve-1 $zfspoolname") == 0 ||
1518 die "zfs set bootfs failed\n";
1525 my ($filename) = @_;
1527 my $path = "${proxmox_dir}/html/$filename";
1528 my $url = "file://$path";
1530 my $data = file_get_contents
($path);
1532 if ($filename eq 'license.htm') {
1533 my $licensefn = -f
"/EULA" ?
"/EULA" :
1534 $opt_testmode ?
"./copyright" :
1535 "/usr/share/doc/pve-installer/copyright";
1536 my $license = decode
('utf8', file_get_contents
($licensefn));
1537 $license =~ m/^\s+(.+\n)/;
1538 my $title = $licensefn eq '/EULA' ?
"END USER LICENSE AGREEMENT (EULA)": $1;
1539 $data =~ s/__LICENSE__/$license/;
1540 $data =~ s/__LICENSE_TITLE__/$title/;
1543 $htmlview->load_html_string($data, $url);
1547 my ($text, $fctn) = @_;
1550 $text = "_Next" if !$text;
1551 $next->set_label ($text);
1553 $next->grab_focus ();
1557 my ($doc, $url, $stream) = @_;
1559 $stream->set_cancel_func (sub {}); # hack: avoid warning
1561 my $path = "${proxmox_dir}/html/$url";
1564 open (HTMLTMP
, $path) ||
1565 die "unable to open file '$path' - $!\n";
1567 while (my $i = read (HTMLTMP
, $buf, 4096)) {
1568 $stream->write ($buf);
1569 Gtk3
::main_iteration
() while Gtk3
::events_pending
();
1574 #$stream->close(); # hack: dont close - avoid crash
1577 sub create_main_window
{
1579 $window = Gtk3
::Window-
>new ();
1580 $window->set_default_size (1024, 768);
1581 $window->set_has_resize_grip(0);
1582 $window->set_decorated (0) if !$opt_testmode;
1584 my $vbox = Gtk3
::VBox-
>new (0, 0);
1586 my $image = Gtk3
::Image-
>new_from_file ("${proxmox_dir}/proxlogo.png");
1587 $vbox->pack_start ($image, 0, 0, 0);
1589 my $hbox = Gtk3
::HBox-
>new (0, 0);
1590 $vbox->pack_start ($hbox, 1, 1, 0);
1592 # my $f1 = Gtk3::Frame->new ('test');
1593 # $f1->set_shadow_type ('none');
1594 # $hbox->pack_start ($f1, 1, 1, 0);
1596 my $sep1 = Gtk3
::HSeparator-
>new;
1597 $vbox->pack_start ($sep1, 0, 0, 0);
1599 $cmdbox = Gtk3
::HBox-
>new ();
1600 $vbox->pack_start ($cmdbox, 0, 0, 10);
1602 $next = Gtk3
::Button-
>new ('_Next');
1603 $next->signal_connect (clicked
=> sub { &$next_fctn (); });
1604 $cmdbox->pack_end ($next, 0, 0, 10);
1605 my $abort = Gtk3
::Button-
>new ('_Abort');
1606 $abort->set_can_focus (0);
1607 $cmdbox->pack_start ($abort, 0, 0, 10);
1608 $abort->signal_connect (clicked
=> sub { exit (-1); });
1610 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1611 $hbox->add ($vbox2);
1613 $htmlview = Gtk3
::WebKit
::WebView-
>new();
1614 my $scrolls = Gtk3
::ScrolledWindow-
>new();
1615 $scrolls->add($htmlview);
1617 my $hbox2 = Gtk3
::HBox-
>new (0, 0);
1618 $hbox2->pack_start ($scrolls, 1, 1, 0);
1620 $vbox2->pack_start ($hbox2, 1, 1, 0);
1622 my $vbox3 = Gtk3
::VBox-
>new (0, 0);
1623 $vbox2->pack_start ($vbox3, 0, 0, 0);
1625 my $sep2 = Gtk3
::HSeparator-
>new;
1626 $vbox3->pack_start ($sep2, 0, 0, 0);
1628 $inbox = Gtk3
::HBox-
>new (0, 0);
1629 $vbox3->pack_start ($inbox, 0, 0, 0);
1631 $window->add ($vbox);
1634 $window->realize ();
1638 $inbox->foreach(sub {
1640 $inbox->remove ($child);
1644 # fixme: newer GTK3 has special properties to handle numbers with Entry
1645 # only allow floating point numbers with Gtk3::Entry
1647 my ($entry, $event) = @_;
1650 my $val = $event->get_keyval;
1652 if ($val == ord '.' ||
1653 $val == Gtk3
::Gdk
::KEY_ISO_Left_Tab
||
1654 $val == Gtk3
::Gdk
::KEY_Shift_L
||
1655 $val == Gtk3
::Gdk
::KEY_Tab
||
1656 $val == Gtk3
::Gdk
::KEY_Left
||
1657 $val == Gtk3
::Gdk
::KEY_Right
||
1658 $val == Gtk3
::Gdk
::KEY_BackSpace
||
1659 $val == Gtk3
::Gdk
::KEY_Delete
||
1660 ($val >= ord '0' && $val <= ord '9') ||
1661 ($val >= Gtk3
::Gdk
::KEY_KP_0
&&
1662 $val <= Gtk3
::Gdk
::KEY_KP_9
)) {
1669 sub create_text_input
{
1670 my ($default, $text) = @_;
1672 my $hbox = Gtk3
::HBox-
>new (0, 0);
1674 my $label = Gtk3
::Label-
>new ($text);
1675 $label->set_size_request (150, -1);
1676 $label->set_alignment (1, 0.5);
1677 $hbox->pack_start ($label, 0, 0, 10);
1678 my $e1 = Gtk3
::Entry-
>new ();
1679 $e1->set_width_chars (30);
1680 $hbox->pack_start ($e1, 0, 0, 0);
1681 $e1->set_text ($default);
1683 return ($hbox, $e1);
1688 my $ifconfig = `ifconfig eth0`;
1690 my ($addr) = $ifconfig =~ m/inet addr:(\S*)/m;
1691 my ($mask) = $ifconfig =~ m/Mask:(\S*)/m;
1693 my $route = `route -n`;
1694 my ($gateway) = $route =~ m/^0\.0\.0\.0\s+(\d+\.\d+\.\d+\.\d+)\s+/m;
1696 my $resolvconf = `cat /etc/resolv.conf`;
1697 my ($dnsserver) = $resolvconf =~ m/^nameserver\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/m;
1698 my ($domain) = $resolvconf =~ m/^domain\s+(\S+)$/m;
1703 gateway
=> $gateway,
1704 dnsserver
=> $dnsserver,
1709 sub display_message
{
1712 my $dialog = Gtk3
::MessageDialog-
>new ($window, 'modal',
1713 'info', 'ok', $msg);
1721 my $dialog = Gtk3
::MessageDialog-
>new ($window, 'modal',
1722 'error', 'ok', $msg);
1727 sub create_ipconf_view
{
1730 display_html
("ipconf.htm");
1732 my $vbox = Gtk3
::VBox-
>new (0, 0);
1733 $inbox->pack_start ($vbox, 1, 0, 0);
1734 my $hbox = Gtk3
::HBox-
>new (0, 0);
1735 $vbox->pack_start ($hbox, 0, 0, 10);
1736 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1737 $hbox->add ($vbox2);
1739 my $addr = $ipconf->{addr
} || '192.168.100.2';
1740 my $mask = $ipconf->{mask
} || '255.255.255.0';
1742 my $hn = $ipconf->{domain
} ?
"pve.$ipconf->{domain}" : 'pve.domain.tld';
1744 my ($hostbox, $hostentry) =
1745 create_text_input
($hn, 'Hostname (FQDN):');
1746 $vbox2->pack_start ($hostbox, 0, 0, 2);
1749 ($ipbox, $ipconf_entry_addr) =
1750 create_text_input
($addr, 'IP Address:');
1751 $vbox2->pack_start ($ipbox, 0, 0, 2);
1754 ($maskbox, $ipconf_entry_mask) =
1755 create_text_input
($mask, 'Netmask:');
1756 $vbox2->pack_start ($maskbox, 0, 0, 2);
1758 $gateway = $ipconf->{gateway
} || '192.168.100.1';
1761 ($gwbox, $ipconf_entry_gw) =
1762 create_text_input
($gateway, 'Gateway:');
1764 $vbox2->pack_start ($gwbox, 0, 0, 2);
1766 $dnsserver = $ipconf->{dnsserver
} || $gateway;
1769 ($dnsbox, $ipconf_entry_dns) =
1770 create_text_input
($dnsserver, 'DNS Server:');
1772 $vbox2->pack_start ($dnsbox, 0, 0, 0);
1775 set_next
(undef, sub {
1779 my $text = $hostentry->get_text();
1784 my $namere = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
1786 # Debian does not support purely numeric hostnames
1787 if ($text && $text =~ /^[0-9]+(?:\.|$)/) {
1788 display_message
("Purely numeric hostnames are not allowed.");
1789 $hostentry->grab_focus();
1793 if ($text && $text =~ m/^(${namere}\.)*${namere}$/ && $text !~ m/.domain.tld$/ &&
1794 $text =~ m/^([^\.]+)\.(\S+)$/) {
1798 display_message
("Hostname does not look like a fully qualified domain name.");
1799 $hostentry->grab_focus();
1805 $text = $ipconf_entry_addr->get_text();
1808 if ($text =~ m!^($IPV4RE)$!) {
1811 } elsif ($text =~ m!^($IPV6RE)$!) {
1815 display_message
("IP address is not valid.");
1816 $ipconf_entry_addr->grab_focus();
1820 $text = $ipconf_entry_mask->get_text();
1823 if (($ipversion == 6) && ($text =~ m/^(\d+)$/) && ($1 >= 8) && ($1 <= 126)) {
1825 } elsif (($ipversion == 4) && defined($ipv4_mask_hash->{$text})) {
1828 display_message
("Netmask is not valid.");
1829 $ipconf_entry_mask->grab_focus();
1833 $text = $ipconf_entry_gw->get_text();
1836 if (($ipversion == 4) && ($text =~ m!^($IPV4RE)$!)) {
1838 } elsif (($ipversion == 6) && ($text =~ m!^($IPV6RE)$!)) {
1841 display_message
("Gateway is not valid.");
1842 $ipconf_entry_gw->grab_focus();
1846 $text = $ipconf_entry_dns->get_text();
1849 if (($ipversion == 4) && ($text =~ m!^($IPV4RE)$!)) {
1851 } elsif (($ipversion == 6) && ($text =~ m!^($IPV6RE)$!)) {
1854 display_message
("DNS server is not valid.");
1855 $ipconf_entry_dns->grab_focus();
1859 #print "TEST $ipaddress $netmask $gateway $dnsserver\n";
1861 create_extract_view
();
1864 $hostentry->grab_focus();
1867 sub get_device_desc
{
1868 my ($devname, $size, $model) = @_;
1870 if ($size && ($size > 0)) {
1871 $size = int($size/2048); # size in MB
1873 my $text = "$devname (";
1874 if ($size >= 1024) {
1875 $size = int($size/1024); # size in GB
1876 $text .= "${size}GB";
1878 $text .= "${size}MB";
1881 $text .= ", $model" if $model;
1890 my ($cb, $kmap) = @_;
1895 my $kmaphash = $cmap->{kmaphash
};
1896 foreach my $layout (sort keys %$kmaphash) {
1897 $def = $i if $kmaphash->{$layout} eq 'en-us';
1898 $ind = $i if $kmap && $kmaphash->{$layout} eq $kmap;
1902 $cb->set_active ($ind || $def || 0);
1906 sub update_zonelist
{
1907 my ($box, $cc) = @_;
1909 my $cczones = $cmap->{cczones
};
1910 my $zones = $cmap->{zones
};
1914 $sel = $lastzonecb->get_active_text();
1915 $box->remove ($lastzonecb);
1917 $sel = $timezone; # used once to select default
1920 my $cb = $lastzonecb = Gtk3
::ComboBoxText-
>new();
1921 $cb->set_size_request (200, -1);
1923 $cb->signal_connect ('changed' => sub {
1924 $timezone = $cb->get_active_text();
1928 if ($cc && defined ($cczones->{$cc})) {
1929 @za = keys %{$cczones->{$cc}};
1935 foreach my $zone (sort @za) {
1936 $ind = $i if $sel && $zone eq $sel;
1937 $cb->append_text ($zone);
1941 $cb->set_active ($ind || 0);
1944 $box->pack_start ($cb, 0, 0, 0);
1947 sub create_password_view
{
1951 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1952 $inbox->pack_start ($vbox2, 1, 0, 0);
1953 my $vbox = Gtk3
::VBox-
>new (0, 0);
1954 $vbox2->pack_start ($vbox, 0, 0, 10);
1956 my $hbox1 = Gtk3
::HBox-
>new (0, 0);
1957 my $label = Gtk3
::Label-
>new ("Password");
1958 $label->set_size_request (150, -1);
1959 $label->set_alignment (1, 0.5);
1960 $hbox1->pack_start ($label, 0, 0, 10);
1961 my $pwe1 = Gtk3
::Entry-
>new ();
1962 $pwe1->set_visibility (0);
1963 $pwe1->set_size_request (200, -1);
1964 $hbox1->pack_start ($pwe1, 0, 0, 0);
1966 my $hbox2 = Gtk3
::HBox-
>new (0, 0);
1967 $label = Gtk3
::Label-
>new ("Confirm");
1968 $label->set_size_request (150, -1);
1969 $label->set_alignment (1, 0.5);
1970 $hbox2->pack_start ($label, 0, 0, 10);
1971 my $pwe2 = Gtk3
::Entry-
>new ();
1972 $pwe2->set_visibility (0);
1973 $pwe2->set_size_request (200, -1);
1974 $hbox2->pack_start ($pwe2, 0, 0, 0);
1976 my $hbox3 = Gtk3
::HBox-
>new (0, 0);
1977 $label = Gtk3
::Label-
>new ("E-Mail");
1978 $label->set_size_request (150, -1);
1979 $label->set_alignment (1, 0.5);
1980 $hbox3->pack_start ($label, 0, 0, 10);
1981 my $eme = Gtk3
::Entry-
>new ();
1982 $eme->set_size_request (200, -1);
1983 $hbox3->pack_start ($eme, 0, 0, 0);
1986 $vbox->pack_start ($hbox1, 0, 0, 5);
1987 $vbox->pack_start ($hbox2, 0, 0, 5);
1988 $vbox->pack_start ($hbox3, 0, 0, 15);
1992 display_html
("passwd.htm");
1994 set_next
(undef, sub {
1996 my $t1 = $pwe1->get_text;
1997 my $t2 = $pwe2->get_text;
1999 if (length ($t1) < 5) {
2000 display_message
("Password is too short.");
2001 $pwe1->grab_focus();
2006 display_message
("Password does not match.");
2007 $pwe1->grab_focus();
2011 my $t3 = $eme->get_text;
2012 if ($t3 !~ m/^\S+\@\S+\.\S+$/) {
2013 display_message
("E-Mail does not look like a vaild address" .
2014 " (user\@domain.tld)");
2023 create_ipconf_view
();
2026 $pwe1->grab_focus();
2030 sub create_country_view
{
2034 my $countryhash = $cmap->{countryhash
};
2035 my $ctr = $cmap->{country
};
2037 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
2038 $inbox->pack_start ($vbox2, 1, 0, 0);
2039 my $vbox = Gtk3
::VBox-
>new (0, 0);
2040 $vbox2->pack_start ($vbox, 0, 0, 10);
2042 my $w = Gtk3
::Entry-
>new ();
2043 $w->set_size_request (200, -1);
2045 my $c = Gtk3
::EntryCompletion-
>new ();
2046 $c->set_text_column (0);
2047 $c->set_minimum_key_length(0);
2048 $c->set_popup_set_width (1);
2049 $c->set_inline_completion (1);
2051 my $hbox2 = Gtk3
::HBox-
>new (0, 0);
2052 my $label = Gtk3
::Label-
>new ("Time zone");
2053 $label->set_size_request (150, -1);
2054 $label->set_alignment (1, 0.5);
2055 $hbox2->pack_start ($label, 0, 0, 10);
2056 update_zonelist
($hbox2);
2058 my $hbox3 = Gtk3
::HBox-
>new (0, 0);
2059 $label = Gtk3
::Label-
>new ("Keyboard Layout");
2060 $label->set_size_request (150, -1);
2061 $label->set_alignment (1, 0.5);
2062 $hbox3->pack_start ($label, 0, 0, 10);
2064 my $kmapcb = Gtk3
::ComboBoxText-
>new();
2065 $kmapcb->set_size_request (200, -1);
2066 foreach my $layout (sort keys %{$cmap->{kmaphash
}}) {
2067 $kmapcb->append_text ($layout);
2070 update_layout
($kmapcb);
2071 $hbox3->pack_start ($kmapcb, 0, 0, 0);
2073 $kmapcb->signal_connect ('changed' => sub {
2074 my $sel = $kmapcb->get_active_text();
2075 if (my $kmap = $cmap->{kmaphash
}->{$sel}) {
2076 my $xkmap = $cmap->{kmap
}->{$kmap}->{x11
};
2077 my $xvar = $cmap->{kmap
}->{$kmap}->{x11var
};
2078 syscmd
("setxkbmap $xkmap $xvar") if !$opt_testmode;
2083 $w->signal_connect ('changed' => sub {
2084 my ($entry, $event) = @_;
2085 my $text = $entry->get_text;
2087 if (my $cc = $countryhash->{lc($text)}) {
2088 update_zonelist
($hbox2, $cc);
2089 my $kmap = $ctr->{$cc}->{kmap
} || 'en-us';
2090 update_layout
($kmapcb, $kmap);
2094 $w->signal_connect (key_press_event
=> sub {
2095 my ($entry, $event) = @_;
2096 my $text = $entry->get_text;
2098 my $val = $event->get_keyval;
2100 if ($val == Gtk3
::Gdk
::KEY_Tab
) {
2101 my $cc = $countryhash->{lc($text)};
2108 $compl = $ctr->{$cc}->{name
};
2110 foreach my $cc (keys %$ctr) {
2111 my $ct = $ctr->{$cc}->{name
};
2112 if ($ct =~ m/^\Q$text\E.*$/i) {
2121 $entry->set_text($compl);
2126 print chr(7); # beep ?
2131 my $buf = $w->get_buffer();
2132 $buf->insert_text(-1, '', -1); # popup selection
2140 my $ls = Gtk3
::ListStore-
>new('Glib::String');
2141 foreach my $cc (sort {$ctr->{$a}->{name
} cmp $ctr->{$b}->{name
} } keys %$ctr) {
2142 my $iter = $ls->append();
2143 $ls->set ($iter, 0, $ctr->{$cc}->{name
});
2145 $c->set_model ($ls);
2147 $w->set_completion ($c);
2149 my $hbox = Gtk3
::HBox-
>new (0, 0);
2151 $label = Gtk3
::Label-
>new ("Country");
2152 $label->set_alignment (1, 0.5);
2153 $label->set_size_request (150, -1);
2154 $hbox->pack_start ($label, 0, 0, 10);
2155 $hbox->pack_start ($w, 0, 0, 0);
2157 $vbox->pack_start ($hbox, 0, 0, 5);
2158 $vbox->pack_start ($hbox2, 0, 0, 5);
2159 $vbox->pack_start ($hbox3, 0, 0, 5);
2162 $w->set_text ($ctr->{$country}->{name
});
2167 display_html
("country.htm");
2168 set_next
(undef, sub {
2170 my $text = $w->get_text;
2172 if (my $cc = $countryhash->{lc($text)}) {
2174 create_password_view
();
2177 display_message
("Please select a country first.");
2185 my $target_hd_combo;
2186 my $target_hd_label;
2188 my $hdopion_first_setup = 1;
2190 sub create_hdoption_view
{
2192 my $dialog = Gtk3
::Dialog-
>new();
2194 $dialog->set_title("Harddisk options");
2196 $dialog->add_button("_OK", 1);
2198 my $contarea = $dialog->get_content_area();
2200 my $hbox2 = Gtk3
::Box-
>new('horizontal', 0);
2201 $contarea->pack_start($hbox2, 1, 1, 10);
2203 my $grid = Gtk3
::Grid-
>new();
2204 $grid->set_column_spacing(10);
2205 $grid->set_row_spacing(10);
2207 $hbox2->pack_start($grid, 1, 0, 10);
2213 my $label0 = Gtk3
::Label-
>new ("Filesystem");
2214 $label0->set_alignment (1, 0.5);
2215 $grid->attach($label0, 0, $row, 1, 1);
2217 my $fstypecb = Gtk3
::ComboBoxText-
>new();
2219 my $fstype = ['ext3', 'ext4', 'xfs',
2220 'zfs (RAID0)', 'zfs (RAID1)',
2221 'zfs (RAID10)', 'zfs (RAIDZ-1)',
2222 'zfs (RAIDZ-2)', 'zfs (RAIDZ-3)'];
2224 push @$fstype, 'btrfs (RAID0)', 'btrfs (RAID1)', 'btrfs (RAID10)'
2228 foreach my $tmp (@$fstype) {
2229 $fstypecb->append_text($tmp);
2230 $fstypecb->set_active ($tcount)
2231 if $config_options->{filesys
} eq $tmp;
2235 $grid->attach($fstypecb, 1, $row, 1, 1);
2243 for (my $i = 0; $i < 8; $i++) {
2244 $disk_label[$i] = Gtk3
::Label-
>new ("Hardisk $i");
2245 $disk_label[$i]->set_alignment (1, 0.5);
2246 $grid->attach($disk_label[$i], 0, $row, 1, 1);
2247 $disk_selector[$i] = Gtk3
::ComboBoxText-
>new();
2248 $disk_selector[$i]->append_text("-- do not use --");
2249 $disk_selector[$i]->set_active(0);
2250 foreach my $hd (@$hds) {
2251 my ($disk, $devname, $size, $model) = @$hd;
2252 $disk_selector[$i]->append_text(get_device_desc
($devname, $size, $model));
2253 $disk_selector[$i]->{pve_disk_id
} = $i;
2254 $disk_selector[$i]->signal_connect (changed
=> sub {
2256 my $diskid = $w->{pve_disk_id
};
2257 my $a = $w->get_active - 1;
2258 $config_options->{"disksel${diskid}"} = ($a >= 0) ?
$hds->[$a] : undef;
2262 if ($hdopion_first_setup) {
2263 $disk_selector[$i]->set_active ($i+1) if $hds->[$i];
2266 if (my $cur_hd = $config_options->{"disksel$i"}) {
2267 foreach my $hd (@$hds) {
2268 if (@$hd[1] eq @$cur_hd[1]) {
2269 $disk_selector[$i]->set_active($hdind+1);
2278 $grid->attach($disk_selector[$i], 1, $row, 1, 1);
2283 $hdopion_first_setup = 0;
2285 my $label_hdsize = Gtk3
::Label-
>new ("hdsize");
2286 $label_hdsize->set_alignment (1, 0.5);
2287 $grid->attach($label_hdsize, 0, $row, 1, 1);
2291 if ( -b
$target_hd) {
2292 $hdsize = int(hd_size
($target_hd) / (1024*1024.0)); # size in GB
2293 } elsif ($target_hd) {
2294 $hdsize = int((-s
$target_hd) / (1024*1024*1024.0));
2297 my $hdsize_size_adj = Gtk3
::Adjustment-
>new($config_options->{hdsize
} || $hdsize, 0, $hdsize+1, 1, 1, 1);
2298 my $spinbutton_hdsize = Gtk3
::SpinButton-
>new($hdsize_size_adj, 1, 1);
2299 $spinbutton_hdsize->set_tooltip_text("only use specified size (GB) of the harddisk (rest left unpartitioned)");
2300 $grid->attach($spinbutton_hdsize, 1, $row, 1, 1);
2303 my $label_swapsize = Gtk3
::Label-
>new ("swapsize");
2304 $label_swapsize->set_alignment (1, 0.5);
2305 $grid->attach($label_swapsize, 0, $row, 1, 1);
2307 my $entry_swapsize = Gtk3
::Entry-
>new();
2308 $entry_swapsize->set_tooltip_text("maximum SWAP size (GB)");
2309 $entry_swapsize->signal_connect (key_press_event
=> \
&check_float
);
2310 $entry_swapsize->set_text($config_options->{swapsize
}) if $config_options->{swapsize
};
2311 $grid->attach($entry_swapsize, 1, $row, 1, 1);
2314 my $label_maxroot = Gtk3
::Label-
>new ("maxroot");
2315 $label_maxroot->set_alignment (1, 0.5);
2316 $grid->attach($label_maxroot, 0, $row, 1, 1);
2318 my $entry_maxroot = Gtk3
::Entry-
>new();
2319 $entry_maxroot->set_tooltip_text("maximum size (GB) for LVM root volume");
2320 $entry_maxroot->signal_connect (key_press_event
=> \
&check_float
);
2321 $entry_maxroot->set_text($config_options->{maxroot
}) if $config_options->{maxroot
};
2322 $grid->attach($entry_maxroot, 1, $row, 1, 1);
2325 my $label_minfree = Gtk3
::Label-
>new ("minfree");
2326 $label_minfree->set_alignment (1, 0.5);
2327 $grid->attach($label_minfree, 0, $row, 1, 1);
2329 my $entry_minfree = Gtk3
::Entry-
>new();
2330 $entry_minfree->set_tooltip_text("minumum free LVM space (GB, required for LVM snapshots)");
2331 $entry_minfree->signal_connect (key_press_event
=> \
&check_float
);
2332 $entry_minfree->set_text($config_options->{minfree
}) if $config_options->{minfree
};
2333 $grid->attach($entry_minfree, 1, $row, 1, 1);
2336 my $label_maxvz = Gtk3
::Label-
>new ("maxvz");
2337 $label_maxvz->set_alignment (1, 0.5);
2338 $grid->attach($label_maxvz, 0, $row, 1, 1);
2340 my $entry_maxvz = Gtk3
::Entry-
>new();
2341 $entry_maxvz->set_tooltip_text("maximum size (GB) for LVM data volume");
2342 $entry_maxvz->signal_connect (key_press_event
=> \
&check_float
);
2343 $entry_maxvz->set_text($config_options->{maxvz
}) if $config_options->{maxvz
};
2344 $grid->attach($entry_maxvz, 1, $row, 1, 1);
2347 my $set_sensitive_flag = sub {
2348 my $enable_size_hints = $config_options->{filesys
} !~ m/zfs|btrfs/;
2350 if ($config_options->{filesys
} =~ m/zfs|btrfs/) {
2351 $target_hd_combo->set_visible(0);
2352 $target_hd_label->set_text("Target: $config_options->{filesys} ");
2353 foreach my $w (@disk_selector) { $w->set_visible(1); }
2354 foreach my $w (@disk_label) { $w->set_visible(1); }
2356 $target_hd_combo->set_visible(1);
2357 foreach my $w (@disk_selector) { $w->set_visible(0); }
2358 foreach my $w (@disk_label) { $w->set_visible(0); }
2359 $target_hd_label->set_text("Target Harddisk: ");
2362 $spinbutton_hdsize->set_visible($enable_size_hints);
2363 $label_hdsize->set_visible($enable_size_hints);
2364 $entry_swapsize->set_visible($enable_size_hints);
2365 $label_swapsize->set_visible($enable_size_hints);
2366 $entry_maxroot->set_visible($enable_size_hints);
2367 $label_maxroot->set_visible($enable_size_hints);
2368 $entry_minfree->set_visible($enable_size_hints);
2369 $label_minfree->set_visible($enable_size_hints);
2370 $entry_maxvz->set_visible($enable_size_hints);
2371 $label_maxvz->set_visible($enable_size_hints);
2374 &$set_sensitive_flag();
2376 $fstypecb->signal_connect (changed
=> sub {
2377 $config_options->{filesys
} = $fstypecb->get_active_text();
2378 &$set_sensitive_flag();
2385 my $get_float = sub {
2388 my $text = $entry->get_text();
2389 return undef if !defined($text);
2394 return undef if $text !~ m/^\d+(\.\d+)?$/;
2401 if (($tmp = &$get_float($spinbutton_hdsize)) && ($tmp != $hdsize)) {
2402 $config_options->{hdsize
} = $tmp;
2404 delete $config_options->{hdsize
};
2407 if (defined($tmp = &$get_float($entry_swapsize))) {
2408 $config_options->{swapsize
} = $tmp;
2410 delete $config_options->{swapsize
};
2413 if (defined($tmp = &$get_float($entry_maxroot))) {
2414 $config_options->{maxroot
} = $tmp;
2416 delete $config_options->{maxroot
};
2419 if (defined($tmp = &$get_float($entry_minfree))) {
2420 $config_options->{minfree
} = $tmp;
2422 delete $config_options->{minfree
};
2425 if (defined($tmp = &$get_float($entry_maxvz))) {
2426 $config_options->{maxvz
} = $tmp;
2428 delete $config_options->{maxvz
};
2434 my $get_raid_devlist = sub {
2436 my $dev_name_hash = {};
2439 for (my $i = 0; $i < 8; $i++) {
2440 if (my $hd = $config_options->{"disksel$i"}) {
2441 my ($disk, $devname, $size, $model) = @$hd;
2442 die "device '$devname' is used more than once\n"
2443 if $dev_name_hash->{$devname};
2444 $dev_name_hash->{$devname} = $hd;
2445 push @$devlist, $hd;
2452 sub zfs_mirror_size_check
{
2453 my ($expected, $actual) = @_;
2455 die "mirrored disks must have same size\n"
2456 if abs($expected - $actual) > $expected / 10;
2459 sub get_zfs_raid_setup
{
2461 my $filesys = $config_options->{filesys
};
2463 my $devlist = &$get_raid_devlist();
2465 my $diskcount = scalar(@$devlist);
2466 die "$filesys need at least one device\n" if $diskcount < 1;
2468 my $bootdevlist = [];
2471 if ($filesys eq 'zfs (RAID0)') {
2472 push @$bootdevlist, @$devlist[0];
2473 foreach my $hd (@$devlist) {
2476 } elsif ($filesys eq 'zfs (RAID1)') {
2477 die "zfs (RAID1) need at least 2 device\n" if $diskcount < 2;
2479 my $hd = @$devlist[0];
2480 my $expected_size = @$hd[2]; # all disks need approximately same size
2481 foreach $hd (@$devlist) {
2482 zfs_mirror_size_check
($expected_size, @$hd[2]);
2484 push @$bootdevlist, $hd;
2486 } elsif ($filesys eq 'zfs (RAID10)') {
2487 my $half = int($diskcount/2);
2488 die "zfs (RAID10) need at least 4 device\n" if $diskcount < 4;
2489 die "zfs (RAID10) need at an even numver of devices\n" if $half*2 != $diskcount;
2491 push @$bootdevlist, @$devlist[0], @$devlist[1];
2493 for (my $i = 0; $i < $diskcount; $i+=2) {
2494 my $hd1 = @$devlist[$i];
2495 my $hd2 = @$devlist[$i+1];
2496 zfs_mirror_size_check
(@$hd1[2], @$hd2[2]); # pairs need approximately same size
2497 $cmd .= ' mirror ' . @$hd1[1] . ' ' . @$hd2[1];
2500 } elsif ($filesys =~ m/^zfs \(RAIDZ-([123])\)$/) {
2502 my $mindisks = 2 + $level;
2503 die "zfs (RAIDZ-$level) need at least $mindisks devices\n" if scalar(@$devlist) < $mindisks;
2504 my $hd = @$devlist[0];
2505 my $expected_size = @$hd[2]; # all disks need approximately same size
2506 $cmd .= " raidz$level";
2507 foreach $hd (@$devlist) {
2508 zfs_mirror_size_check
($expected_size, @$hd[2]);
2510 push @$bootdevlist, $hd;
2513 die "unknown zfs mode '$filesys'\n";
2516 return ($devlist, $bootdevlist, $cmd);
2519 sub get_btrfs_raid_setup
{
2521 my $filesys = $config_options->{filesys
};
2523 my $devlist = &$get_raid_devlist();
2525 my $diskcount = scalar(@$devlist);
2526 die "$filesys need at least one device\n" if $diskcount < 1;
2530 if ($diskcount == 1) {
2533 if ($filesys eq 'btrfs (RAID0)') {
2535 } elsif ($filesys eq 'btrfs (RAID1)') {
2536 die "btrfs (RAID1) need at least 2 device\n" if $diskcount < 2;
2538 } elsif ($filesys eq 'btrfs (RAID10)') {
2539 die "btrfs (RAID10) need at least 4 device\n" if $diskcount < 4;
2542 die "unknown btrfs mode '$filesys'\n";
2546 return ($devlist, $mode);
2549 sub create_hdsel_view
{
2553 my $vbox = Gtk3
::VBox-
>new (0, 0);
2554 $inbox->pack_start ($vbox, 1, 0, 0);
2555 my $hbox = Gtk3
::HBox-
>new (0, 0);
2556 $vbox->pack_start ($hbox, 0, 0, 10);
2558 my ($disk, $devname, $size, $model) = @{@$hds[0]};
2559 $target_hd = $devname;
2561 $target_hd_label = Gtk3
::Label-
>new ("Target Harddisk: ");
2562 $hbox->pack_start ($target_hd_label, 0, 0, 0);
2564 $target_hd_combo = Gtk3
::ComboBoxText-
>new();
2566 foreach my $hd (@$hds) {
2567 ($disk, $devname, $size, $model) = @$hd;
2568 $target_hd_combo->append_text (get_device_desc
($devname, $size, $model));
2571 $target_hd_combo->set_active (0);
2572 $target_hd_combo->signal_connect (changed
=> sub {
2573 $a = shift-
>get_active;
2574 my ($disk, $devname) = @{@$hds[$a]};
2575 $target_hd = $devname;
2578 $hbox->pack_start ($target_hd_combo, 0, 0, 10);
2580 my $options = Gtk3
::Button-
>new ('_Options');
2581 $options->signal_connect (clicked
=> \
&create_hdoption_view
);
2582 $hbox->pack_start ($options, 0, 0, 0);
2587 display_html
("page1.htm");
2589 set_next
(undef, sub {
2591 if ($config_options->{filesys
} =~ m/zfs/) {
2592 eval { get_zfs_raid_setup
(); };
2594 display_message
("Warning: $err\n" .
2595 "Please fix ZFS setup first.");
2597 create_country_view
();
2599 } elsif ($config_options->{filesys
} =~ m/btrfs/) {
2600 eval { get_btrfs_raid_setup
(); };
2602 display_message
("Warning: $err\n" .
2603 "Please fix BTRFS setup first.");
2605 create_country_view
();
2608 create_country_view
();
2613 sub create_extract_view
{
2617 display_html
("extract1-license.htm");
2618 $next->set_sensitive (0);
2620 my $vbox = Gtk3
::VBox-
>new (0, 0);
2621 $inbox->pack_start ($vbox, 1, 0, 0);
2622 my $hbox = Gtk3
::HBox-
>new (0, 0);
2623 $vbox->pack_start ($hbox, 0, 0, 10);
2625 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
2626 $hbox->pack_start ($vbox2, 0, 0, 0);
2628 $progress_status = Gtk3
::Label-
>new ('');
2629 $vbox2->pack_start ($progress_status, 1, 1, 0);
2631 $progress = Gtk3
::ProgressBar-
>new;
2632 $progress->set_show_text(1);
2633 $progress->set_size_request (600, -1);
2635 $vbox2->pack_start ($progress, 0, 0, 0);
2639 my $tdir = $opt_testmode ?
"target" : "/target";
2641 my $base = $opt_testmode ?
"/pve/$release/install/pve-base.squashfs" : "/cdrom/pve-base.squashfs";
2643 eval { extract_data
($base, $tdir); };
2646 $next->set_sensitive (1);
2648 set_next
("_Reboot", sub { exit (0); } );
2651 display_html
("fail.htm");
2652 display_error
($err);
2655 display_html
("success.htm");
2659 sub create_intro_view
{
2663 display_html
("license.htm");
2665 set_next
("I a_gree", \
&create_hdsel_view
);
2668 $ipconf = get_ip_config
();
2670 $country = detect_country
() if $ipconf->{addr
} || $opt_testmode;;
2672 # read country, kmap and timezone infos
2673 $cmap = read_cmap
();
2675 create_main_window
();
2677 if (!defined ($hds) || (scalar (@$hds) <= 0)) {
2678 print "no hardisks found\n";
2679 display_html
("nohds.htm");
2680 set_next
("Reboot", sub { exit (0); } );
2683 foreach my $hd (@$hds) {
2684 my ($disk, $devname) = @$hd;
2685 next if $devname =~ m
|^/dev/md\d
+$|;
2686 print "found Disk$disk N:$devname\n";
2689 create_intro_view
();