3 $ENV{DEBIAN_FRONTEND
} = 'noninteractive';
18 use String
::ShellQuote
;
23 use ProxmoxInstallerSetup
;
25 my $setup = ProxmoxInstallerSetup
::setup
();
27 my $release = $setup->{release
};
29 my $kapi = `uname -r`;
32 my $enable_btrfs = $setup->{enable_btrfs
};
36 if (!$ENV{G_SLICE
} || $ENV{G_SLICE
} ne "always-malloc") {
37 die "do not use slice allocator (run with 'G_SLICE=always-malloc ./proxinstall ...')\n";
40 if (!GetOptions
('testmode=s' => \
$opt_testmode)) {
45 my $zfstestpool = "test_rpool";
46 my $zfspoolname = $opt_testmode ?
$zfstestpool : 'rpool';
48 my $storage_cfg_zfs = <<__EOD__;
51 content iso,vztmpl,backup
54 pool $zfspoolname/data
56 content images,rootdir
59 my $storage_cfg_btrfs = <<__EOD__;
62 content iso,vztmpl,backup
66 path /var/lib/pve/local-btrfs
67 content iso,vztmpl,backup,images,rootdir
70 my $storage_cfg_lvmthin = <<__EOD__;
73 content iso,vztmpl,backup
78 content rootdir,images
82 sub file_read_firstline
{
85 my $fh = IO
::File-
>new ($filename, "r");
93 my $logfd = IO
::File-
>new (">/tmp/install.log");
95 my $proxmox_libdir = $opt_testmode ? Cwd
::cwd
() : "/var/lib/pve-installer";
97 my $grub_plattform = "pc"; # pc, efi-amd64 or efi-ia32
99 $grub_plattform = "efi-amd64" if -d
"/sys/firmware/efi";
101 my $IPV4OCTET = "(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9])?[0-9])";
102 my $IPV4RE = "(?:(?:$IPV4OCTET\\.){3}$IPV4OCTET)";
103 my $IPV6H16 = "(?:[0-9a-fA-F]{1,4})";
104 my $IPV6LS32 = "(?:(?:$IPV4RE|$IPV6H16:$IPV6H16))";
107 "(?:(?:" . "(?:$IPV6H16:){6})$IPV6LS32)|" .
108 "(?:(?:" . "::(?:$IPV6H16:){5})$IPV6LS32)|" .
109 "(?:(?:(?:" . "$IPV6H16)?::(?:$IPV6H16:){4})$IPV6LS32)|" .
110 "(?:(?:(?:(?:$IPV6H16:){0,1}$IPV6H16)?::(?:$IPV6H16:){3})$IPV6LS32)|" .
111 "(?:(?:(?:(?:$IPV6H16:){0,2}$IPV6H16)?::(?:$IPV6H16:){2})$IPV6LS32)|" .
112 "(?:(?:(?:(?:$IPV6H16:){0,3}$IPV6H16)?::(?:$IPV6H16:){1})$IPV6LS32)|" .
113 "(?:(?:(?:(?:$IPV6H16:){0,4}$IPV6H16)?::" . ")$IPV6LS32)|" .
114 "(?:(?:(?:(?:$IPV6H16:){0,5}$IPV6H16)?::" . ")$IPV6H16)|" .
115 "(?:(?:(?:(?:$IPV6H16:){0,6}$IPV6H16)?::" . ")))";
117 my $IPRE = "(?:$IPV4RE|$IPV6RE)";
120 my $ipv4_mask_hash = {
137 '255.255.128.0' => 17,
138 '255.255.192.0' => 18,
139 '255.255.224.0' => 19,
140 '255.255.240.0' => 20,
141 '255.255.248.0' => 21,
142 '255.255.252.0' => 22,
143 '255.255.254.0' => 23,
144 '255.255.255.0' => 24,
145 '255.255.255.128' => 25,
146 '255.255.255.192' => 26,
147 '255.255.255.224' => 27,
148 '255.255.255.240' => 28,
149 '255.255.255.248' => 29,
150 '255.255.255.252' => 30
153 my $ipv4_reverse_mask = [
189 my ($window, $cmdbox, $inbox, $htmlview);
190 my ($next, $next_fctn, $target_hd);
191 my ($progress, $progress_status);
192 my ($ipversion, $ipaddress, $ipconf_entry_addr);
193 my ($netmask, $ipconf_entry_mask);
194 my ($gateway, $ipconf_entry_gw);
195 my ($dnsserver, $ipconf_entry_dns);
196 my $hostname = 'proxmox';
197 my $domain = 'domain.tld';
198 my $cmdline = file_read_firstline
("/proc/cmdline");
201 my $timezone = 'Europe/Vienna';
204 my $keymap = 'en-us';
207 # parse command line args
209 my $config_options = {};
211 if ($cmdline =~ m/\s(ext3|ext4|xfs)(\s.*)?$/) {
212 $config_options->{filesys
} = $1;
214 $config_options->{filesys
} = 'ext4';
217 if ($cmdline =~ m/hdsize=(\d+(\.\d+)?)[\s\n]/i) {
218 $config_options->{hdsize
} = $1;
221 if ($cmdline =~ m/swapsize=(\d+(\.\d+)?)[\s\n]/i) {
222 $config_options->{swapsize
} = $1;
225 if ($cmdline =~ m/maxroot=(\d+(\.\d+)?)[\s\n]/i) {
226 $config_options->{maxroot
} = $1;
229 if ($cmdline =~ m/minfree=(\d+(\.\d+)?)[\s\n]/i) {
230 $config_options->{minfree
} = $1;
233 if ($cmdline =~ m/maxvz=(\d+(\.\d+)?)[\s\n]/i) {
234 $config_options->{maxvz
} = $1;
237 my $postfix_main_cf = <<_EOD;
238 # See /usr/share/postfix/main.cf.dist for a commented, more complete version
242 smtpd_banner = \$myhostname ESMTP \$mail_name (Debian/GNU)
245 # appending .domain is the MUA's job.
246 append_dot_mydomain = no
248 # Uncomment the next line to generate "delayed mail" warnings
249 #delay_warning_time = 4h
251 alias_maps = hash:/etc/aliases
252 alias_database = hash:/etc/aliases
253 mydestination = \$myhostname, localhost.\$mydomain, localhost
255 mynetworks = 127.0.0.0/8
256 inet_interfaces = loopback-only
257 recipient_delimiter = +
264 return String
::ShellQuote
::shell_quote
($str);
270 die "no arguments" if !$cmd;
272 return $cmd if !ref($cmd);
275 foreach my $arg (@$cmd) { push @qa, shellquote
($arg); }
277 return join (' ', @qa);
283 return run_command
($cmd, undef, undef, 1);
287 my ($cmd, $func, $input, $noout) = @_;
293 # see 'man bash' for option pipefail
294 $cmd = [ '/bin/bash', '-c', "set -o pipefail && $cmd" ];
299 $cmdstr = cmd2string
($cmd);
303 if ($input && ($cmdstr !~ m/chpasswd/)) {
304 $cmdtxt = "# $cmdstr <<EOD\n$input";
306 $cmdtxt .= "\nEOD\n";
308 $cmdtxt = "# $cmdstr\n";
316 print $logfd $cmdtxt;
318 my $reader = IO
::File-
>new();
319 my $writer = IO
::File-
>new();
320 my $error = IO
::File-
>new();
326 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
332 if ($orig_pid != $$) {
339 print $writer $input if defined $input;
342 my $select = new IO
::Select
;
343 $select->add ($reader);
344 $select->add ($error);
346 my ($ostream, $logout) = ('', '', '');
348 while ($select->count) {
349 my @handles = $select->can_read (0.2);
351 Gtk3
::main_iteration
() while Gtk3
::events_pending
();
353 next if !scalar (@handles); # timeout
355 foreach my $h (@handles) {
357 my $count = sysread ($h, $buf, 4096);
358 if (!defined ($count)) {
362 die "command '$cmd' failed: $err";
364 $select->remove ($h) if !$count;
366 $ostream .= $buf if !($noout || $func);
368 while ($logout =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
370 &$func($line) if $func;
373 } elsif ($h eq $error) {
374 $ostream .= $buf if !($noout || $func);
382 &$func($logout) if $func;
384 my $rv = waitpid ($pid, 0);
386 return $? if $noout; # behave like standard system();
389 die "command '$cmdstr' failed to execute\n";
390 } elsif (my $sig = ($? & 127)) {
391 die "command '$cmdstr' failed - got signal $sig\n";
392 } elsif (my $exitcode = ($? >> 8)) {
393 die "command '$cmdstr' failed with exit code $exitcode";
401 print "trying to detect country...\n";
402 my $cpid = open2
(\
*TMP
, undef, "traceroute -N 1 -q 1 -n 8.8.8.8");
403 return undef if !$cpid;
407 my $previous_alarm = alarm (10);
409 local $SIG{ALRM
} = sub { die "timed out!\n" };
411 while (defined ($line = <TMP
>)) {
412 print $logfd "DC TRACEROUTE: $line";
413 if ($line =~ m/\s*\d+\s+(\d+\.\d+\.\d+\.\d+)\s/) {
414 my $geoip = `geoiplookup $1`;
415 print $logfd "DC GEOIP: $geoip";
416 if ($geoip =~ m/GeoIP Country Edition:\s*([A-Z]+),/) {
418 print $logfd "DC FOUND: $country\n";
427 alarm ($previous_alarm);
432 print "unable to detect country - $err\n";
434 print "detected country: " . uc($country) . "\n";
436 print "unable to detect country\n";
444 open (MEMINFO, "/proc/meminfo");
446 my $res = 512; # default to 512 if something goes wrong
447 while (my $line = <MEMINFO>) {
448 if ($line =~ m/^MemTotal:\s+(\d+)\s*kB/i) {
449 $res = int ($1 / 1024);
458 my $total_memory = get_memtotal();
461 my ($src, $dest) = @_;
463 my ($dev1,$ino1) = stat ($src);
464 my ($dev2,$ino2) = stat ($dest);
466 return 0 if !($dev1 && $dev2 && $ino1 && $ino2);
468 return $ino1 == $ino2 && $dev1 == $dev2;
471 sub find_stable_path {
472 my ($stabledir, $bdev) = @_;
474 foreach my $path (<$stabledir/*>) {
475 if (link_points_to ($path, $bdev)) {
476 return wantarray ? ($path, basename($path)) : $path;
481 sub find_dev_by_uuid {
484 my ($full_path, $name) = find_stable_path ("/dev/disk/by-uuid", $bdev);
494 push @$res, [-1, $opt_testmode, int((-s $opt_testmode)/512), "TESTDISK"];
500 foreach my $bd (</sys/block/*>) {
501 next if $bd =~ m|^/sys/block/ram\d+$|;
502 next if $bd =~ m|^/sys/block/loop\d+$|;
503 next if $bd =~ m|^/sys/block/md\d+$|;
504 next if $bd =~ m|^/sys/block/dm-.*$|;
505 next if $bd =~ m|^/sys/block/fd\d+$|;
506 next if $bd =~ m|^/sys/block/sr\d+$|;
508 my $dev = file_read_firstline("$bd/dev");
513 my $info = `udevadm info
--path
$bd --query all
`;
516 next if $info !~ m/^E: DEVTYPE=disk$/m;
518 next if $info =~ m/^E: ID_CDROM/m;
520 my ($name) = $info =~ m/^N: (\S+)$/m;
523 my $real_name = "/dev/$name";
525 my $size = file_read_firstline("$bd/size");
527 $size = undef if !($size && $size =~ m/^\d+$/);
529 my $model = file_read_firstline("$bd/device/model") || '';
532 if (length ($model) > 30) {
533 $model = substr ($model, 0, 30);
535 push @$res, [$count++, $real_name, $size, $model] if $size;
537 print STDERR "ERROR: unable to map device $dev ($bd)\n";
545 my $countryfn = "${proxmox_libdir}/country.dat";
546 open (TMP, "<$countryfn") || die "unable to open '$countryfn' - $!\n";
549 my $countryhash = {};
552 while (defined ($line = <TMP>)) {
553 if ($line =~ m|^map:([^\s:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]*):$|) {
561 $kmaphash->{$2} = $1;
562 } elsif ($line =~ m|^([a-z]{2}):([^:]+):([^:]*):([^:]*):$|) {
568 $countryhash->{lc($2)} = $1;
570 warn "unable to parse 'country.dat' line: $line";
577 my $zonefn = "/usr/share/zoneinfo/zone.tab";
578 open (TMP, "<$zonefn") || die "unable to open '$zonefn' - $!\n";
579 while (defined ($line = <TMP>)) {
580 next if $line =~ m/^\#/;
581 next if $line =~ m/^\s*$/;
582 if ($line =~ m|^([A-Z][A-Z])\s+\S+\s+(([^/]+)/\S+)\s|) {
584 $cczones->{$cc}->{$2} = 1;
585 $country->{$cc}->{zone} = $2 if !defined ($country->{$cc}->{zone});
596 countryhash => $countryhash,
598 kmaphash => $kmaphash,
602 # search for Harddisks
603 my $hds = hd_list ();
608 foreach my $hd (@$hds) {
609 my ($disk, $devname, $size, $model) = @$hd;
610 # size is always in 512B "sectors"! convert to KB
611 return int($size/2) if $devname eq $dev;
614 die "no such device '$dev'\n";
617 sub get_partition_dev {
618 my ($dev, $partnum) = @_;
620 if ($dev =~ m|^/dev/[hxsev]d[a-z]$|) {
621 return "${dev}$partnum";
622 } elsif ($dev =~ m|^/dev/[^/]+/c\d+d\d+$|) {
623 return "${dev}p$partnum";
624 } elsif ($dev =~ m|^/dev/[^/]+/d\d+$|) {
625 return "${dev}p$partnum";
626 } elsif ($dev =~ m|^/dev/[^/]+/hd[a-z]$|) {
627 return "${dev}$partnum";
628 } elsif ($dev =~ m|^/dev/nvme\d+n\d+$|) {
629 return "${dev}p$partnum";
631 die "unable to get device for partition $partnum on device $dev\n";
636 sub file_get_contents {
637 my ($filename, $max) = @_;
639 my $fh = IO::File->new($filename, "r") ||
640 die "can't open '$filename' - $!\n";
642 local $/; # slurp mode
652 my ($text, $filename) = @_;
654 my $fd = IO::File->new (">$filename") ||
655 die "unable to open file '$filename' - $!\n";
660 sub update_progress {
661 my ($frac, $start, $end, $text) = @_;
663 my $part = $end - $start;
664 my $res = $start + $frac*$part;
666 $progress->set_fraction ($res);
667 $progress->set_text (sprintf ("%d%%", int ($res*100)));
668 $progress_status->set_text ($text) if defined ($text);
670 Gtk3::main_iteration() while Gtk3::events_pending();
675 mkfs => 'mkfs.ext3 -F',
677 mkfs_data_opt => '-m 0',
678 root_mountopt => 'errors=remount-ro',
681 mkfs => 'mkfs.ext4 -F',
683 mkfs_data_opt => '-m 0',
684 root_mountopt => 'errors=remount-ro',
687 mkfs => 'mkfs.xfs -f',
694 sub create_filesystem {
695 my ($dev, $name, $type, $start, $end, $fs, $fe) = @_;
697 my $range = $end - $start;
698 my $rs = $start + $range*$fs;
699 my $re = $start + $range*$fe;
702 my $fsdata = $fssetup->{$type} || die "internal error - unknown file system '$type'";
703 my $opts = $name eq 'root' ? $fsdata->{mkfs_root_opt} : $fsdata->{mkfs_data_opt};
705 update_progress (0, $rs, $re, "creating $name filesystem");
707 run_command ("$fsdata->{mkfs} $opts $dev", sub {
710 if ($line =~ m/Writing inode tables:\s+(\d+)\/(\d+)/) {
712 } elsif ($max && $line =~ m/(\d+)\/$max/) {
713 update_progress (($1/$max)*0.9, $rs, $re);
714 } elsif ($line =~ m/Creating journal.*done/) {
715 update_progress (0.95, $rs, $re);
716 } elsif ($line =~ m/Writing superblocks and filesystem.*done/) {
717 update_progress (1, $rs, $re);
723 my ($targetdir, $dcdata) = @_;
725 my $cfgfile = "/tmp/debconf.txt";
726 write_config ($dcdata, "$targetdir/$cfgfile");
727 syscmd ("chroot $targetdir debconf-set-selections $cfgfile");
728 unlink "$targetdir/$cfgfile";
732 my ($targetdir, $cmd, $new_cmd) = @_;
734 syscmd ("chroot $targetdir dpkg-divert --package proxmox " .
735 "--add --rename $cmd") == 0 ||
736 die "unable to exec dpkg-divert\n";
738 syscmd ("ln -sf ${new_cmd} $targetdir/$cmd") == 0 ||
739 die "unable to link diversion to ${new_cmd}\n";
742 sub diversion_remove {
743 my ($targetdir, $cmd) = @_;
745 syscmd ("mv $targetdir/${cmd}.distrib $targetdir/${cmd};") == 0 ||
746 die "unable to remove $cmd diversion\n";
748 syscmd ("chroot $targetdir dpkg-divert --remove $cmd") == 0 ||
749 die "unable to remove $cmd diversion\n";
753 my ($partitions, $mode) = @_;
755 die "unknown btrfs mode '$mode'"
756 if !($mode eq 'single' || $mode eq 'raid0' ||
757 $mode eq 'raid1' || $mode eq 'raid10');
759 my $cmd = ['mkfs.btrfs', '-f'];
761 push @$cmd, '-d', $mode, '-m', $mode;
763 push @$cmd, @$partitions;
768 sub zfs_create_rpool {
771 my $cmd = "zpool create -f -o cachefile=none";
773 $cmd .= " -o ashift=$config_options->{ashift}"
774 if defined($config_options->{ashift});
776 syscmd ("$cmd $zfspoolname $vdev") == 0 ||
777 die "unable to create zfs root pool\n";
779 syscmd ("zfs create $zfspoolname/ROOT") == 0 ||
780 die "unable to create zfs $zfspoolname/ROOT volume\n";
782 syscmd ("zfs create $zfspoolname/data") == 0 ||
783 die "unable to create zfs $zfspoolname/data volume\n";
785 syscmd ("zfs create $zfspoolname/ROOT/pve-1") == 0 ||
786 die "unable to create zfs $zfspoolname/ROOT/pve-1 volume\n";
788 # disable atime during install
789 syscmd ("zfs set atime=off $zfspoolname") == 0 ||
790 die "unable to set zfs properties\n";
792 my $value = $config_options->{compress};
793 syscmd ("zfs set compression=$value $zfspoolname")
794 if defined($value) && $value ne 'off';
796 $value = $config_options->{checksum};
797 syscmd ("zfs set checksum=$value $zfspoolname")
798 if defined($value) && $value ne 'on';
800 $value = $config_options->{copies};
801 syscmd ("zfs set copies=$value $zfspoolname")
802 if defined($value) && $value != 1;
805 sub zfs_create_swap {
808 my $cmd = "zfs create -V ${swapsize}K -b 4K";
810 $cmd .= " -o com.sun:auto-snapshot=false";
812 # copies for swap does not make sense
813 $cmd .= " -o copies=1";
815 # reduces memory pressure
816 $cmd .= " -o sync=always";
818 # cheapest compression to drop zero pages
819 $cmd .= " -o compression=zle";
822 $cmd .= " -o logbias=throughput";
823 # only cache metadata in RAM (caching swap content does not make sense)
824 $cmd .= " -o primarycache=metadata";
825 # don't cache anything in L2ARC
826 $cmd .= " -o secondarycache=none";
828 $cmd .= " $zfspoolname/swap";
829 syscmd ($cmd) == 0 ||
830 die "unable to create zfs swap device\n";
832 return "/dev/zvol/$zfspoolname/swap";
835 my $udevadm_trigger_block = sub {
838 sleep(1) if !$nowait; # give kernel time to reread part table
840 # trigger udev to create /dev/disk/by-uuid
841 syscmd ("udevadm trigger --subsystem-match block");
842 syscmd ("udevadm settle --timeout 10");
845 my $clean_disk = sub {
848 my $partitions = `lsblk
--output kname
--noheadings
--path
--list
$disk`;
849 foreach my $part (split "\n", $partitions) {
850 next if $part eq $disk;
851 next if $part !~ /^\Q$disk\E/;
852 eval { syscmd
("pvremove -ff -y $part"); };
853 eval { syscmd
("dd if=/dev/zero of=$part bs=1M count=16"); };
857 sub partition_bootable_disk
{
858 my ($target_dev, $maxhdsize, $ptype) = @_;
860 die "too dangerous" if $opt_testmode;
862 die "unknown partition type '$ptype'"
863 if !($ptype eq '8E00' || $ptype eq '8300');
865 syscmd
("sgdisk -Z ${target_dev}");
866 my $hdsize = hd_size
($target_dev); # size in KB (1024 bytes)
868 my $restricted_hdsize_mb = 0; # 0 ==> end of partition
869 if ($maxhdsize && ($maxhdsize < $hdsize)) {
870 $hdsize = $maxhdsize;
871 $restricted_hdsize_mb = int($hdsize/1024) . 'M';
874 my $hdgb = int($hdsize/(1024*1024));
875 die "hardisk '$target_dev' too small (${hdsize}GB)\n" if $hdgb < 8;
877 # 1 - BIOS boot partition (Grub Stage2): first free 1M
878 # 2 - EFI ESP: next free 256M
879 # 3 - OS/Data partition: rest, up to $maxhdsize in MB
881 my $grubbootdev = get_partition_dev
($target_dev, 1);
882 my $efibootdev = get_partition_dev
($target_dev, 2);
883 my $osdev = get_partition_dev
($target_dev, 3);
885 my $pcmd = ['sgdisk'];
888 push @$pcmd, "-n${pnum}:1M:+1M", "-t$pnum:EF02";
891 push @$pcmd, "-n${pnum}:2M:+256M", "-t$pnum:EF00";
894 push @$pcmd, "-n${pnum}:258M:${restricted_hdsize_mb}", "-t$pnum:$ptype";
896 push @$pcmd, $target_dev;
898 my $os_size = $hdsize - 258*1024; # 256M + 1M + 1M alignment
900 syscmd
($pcmd) == 0 ||
901 die "unable to partition harddisk '${target_dev}'\n";
903 &$udevadm_trigger_block();
905 foreach my $part ($efibootdev, $osdev) {
906 syscmd
("dd if=/dev/zero of=$part bs=1M count=256") if -b
$part;
909 return ($os_size, $osdev, $efibootdev);
912 # ZFS has this use_whole_disk concept, so we try to partition the same
913 # way as zfs does by default. There is room at start of disk to insert
914 # a grub boot partition. But adding a EFI ESP is not possible.
916 # Note: zfs people think this is just a waste of space an not
917 # required. Instead, you should put the ESP on another disk (log,
920 sub partition_bootable_zfs_disk
{
921 my ($target_dev) = @_;
923 die "too dangerous" if $opt_testmode;
925 syscmd
("sgdisk -Z ${target_dev}");
926 my $hdsize = hd_size
($target_dev); # size in blocks (1024 bytes)
928 my $hdgb = int($hdsize/(1024*1024));
929 die "hardisk '$target_dev' too small (${hdsize}GB)\n" if $hdgb < 8;
931 # 1 - GRUB boot partition: 1M
932 # 2 - OS/Data partition
933 # 9 - ZFS reserved partition
935 my $grubbootdev = get_partition_dev
($target_dev, 1);
936 my $osdev = get_partition_dev
($target_dev, 2);
938 my $pcmd = ['sgdisk', '-a1'];
941 push @$pcmd, "-n$pnum:34:2047", "-t$pnum:EF02";
944 push @$pcmd, "-n$pnum:-8M:0", "-t$pnum:BF07";
947 push @$pcmd, "-n$pnum:2048:0", "-t$pnum:BF01", '-c', "$pnum:zfs";
949 push @$pcmd, $target_dev;
951 my $os_size = $hdsize - 1024 - 1024*8;
953 syscmd
($pcmd) == 0 ||
954 die "unable to partition harddisk '${target_dev}'\n";
956 &$udevadm_trigger_block();
958 syscmd
("dd if=/dev/zero of=$osdev bs=1M count=16") if -b
$osdev;
960 return ($os_size, $osdev);
963 sub create_lvm_volumes
{
964 my ($lvmdev, $os_size, $swap_size) = @_;
966 my $rootdev = '/dev/pve/root';
967 my $datadev = '/dev/pve/data';
968 my $swapfile = '/dev/pve/swap';
970 # we use --metadatasize 250k, which results in "pe_start = 512"
971 # so pe_start is aligned on a 128k boundary (advantage for SSDs)
972 syscmd
("/sbin/pvcreate --metadatasize 250k -y -ff $lvmdev") == 0 ||
973 die "unable to initialize physical volume $lvmdev\n";
974 syscmd
("/sbin/vgcreate pve $lvmdev") == 0 ||
975 die "unable to create volume group 'pve'\n";
977 my $hdgb = int($os_size/(1024*1024));
978 my $space = (($hdgb > 128) ?
16 : ($hdgb/8))*1024*1024;
981 if ($config_options->{maxroot
}) {
982 $maxroot = $config_options->{maxroot
};
987 my $rootsize = (($hdgb > ($maxroot*4)) ?
$maxroot : $hdgb/4)*1024*1024;
989 my $rest = $os_size - $swap_size - $rootsize; # in KB
992 if ($config_options->{minfree
}) {
993 $minfree = (($config_options->{minfree
}*1024*1024) >= $rest ) ?
$space :
994 $config_options->{minfree
}*1024*1024 ;
999 $rest = $rest - $minfree;
1001 if ($config_options->{maxvz
}) {
1002 $rest = (($config_options->{maxvz
}*1024*1024) <= $rest) ?
1003 $config_options->{maxvz
}*1024*1024 : $rest;
1006 syscmd
("/sbin/lvcreate -L${swap_size}K -nswap pve") == 0 ||
1007 die "unable to create swap volume\n";
1009 syscmd
("/sbin/lvcreate -L${rootsize}K -nroot pve") == 0 ||
1010 die "unable to create root volume\n";
1012 syscmd
("/sbin/lvcreate -L${rest}K -ndata pve") == 0 ||
1013 die "unable to create data volume\n";
1015 syscmd
("/sbin/lvconvert --yes --type thin-pool pve/data") == 0 ||
1016 die "unable to create data thin-pool\n";
1018 syscmd
("/sbin/vgchange -a y pve") == 0 ||
1019 die "unable to activate volume group\n";
1021 return ($rootdev, $datadev, $swapfile);
1024 sub compute_swapsize
{
1027 my $hdgb = int($hdsize/(1024*1024));
1030 if ($config_options->{swapsize
}) {
1031 $swapsize = $config_options->{swapsize
}*1024*1024;
1033 my $ss = int ($total_memory / 1024);
1035 $ss = ($hdgb/8) if $ss > ($hdgb/8);
1037 $swapsize = $ss*1024*1024;
1045 my ($basefile, $targetdir) = @_;
1047 die "target '$targetdir' does not exist\n" if ! -d
$targetdir;
1049 my $starttime = [Time
::HiRes
::gettimeofday
];
1051 my $bootdevinfo = [];
1060 my $filesys = $config_options->{filesys
};
1062 if ($filesys =~ m/zfs/) {
1063 $target_hd = undef; # do not use this config
1065 $targetdir = "/$zfspoolname/ROOT/pve-1";
1066 } elsif ($filesys =~ m/btrfs/) {
1067 $target_hd = undef; # do not use this config
1073 for ($i = 5; $i > 0; $i--) {
1074 syscmd
("modprobe zfs");
1075 last if -c
"/dev/zfs";
1079 die "unable to load zfs kernel module\n" if !$i;
1087 update_progress
(0, 0, $maxper, "create partitions");
1089 syscmd
("vgchange -an") if !$opt_testmode; # deactivate all detected VGs
1091 if ($opt_testmode) {
1093 $rootdev = abs_path
($opt_testmode);
1094 syscmd
("umount $rootdev");
1098 die "unsupported btrfs mode (for testing environment)\n"
1099 if $filesys ne 'btrfs (RAID0)';
1101 btrfs_create
([$rootdev], 'single');
1103 } elsif ($use_zfs) {
1105 die "unsupported zfs mode (for testing environment)\n"
1106 if $filesys ne 'zfs (RAID0)';
1108 syscmd
("zpool destroy $zfstestpool");
1110 zfs_create_rpool
($rootdev);
1117 } elsif ($use_btrfs) {
1119 my ($devlist, $btrfs_mode) = get_btrfs_raid_setup
();
1120 my $btrfs_partitions = [];
1122 foreach my $hd (@$devlist) {
1123 my $devname = @$hd[1];
1124 &$clean_disk($devname);
1125 my ($size, $osdev, $efidev) =
1126 partition_bootable_disk
($devname, undef, '8300');
1127 $rootdev = $osdev if !defined($rootdev); # simply point to first disk
1128 my $by_id = find_stable_path
("/dev/disk/by-id", $devname);
1129 push @$bootdevinfo, { esp
=> $efidev, devname
=> $devname,
1130 osdev
=> $osdev, by_id
=> $by_id };
1131 push @$btrfs_partitions, $osdev;
1135 &$udevadm_trigger_block();
1137 btrfs_create
($btrfs_partitions, $btrfs_mode);
1139 } elsif ($use_zfs) {
1141 my ($devlist, $bootdevlist, $vdev) = get_zfs_raid_setup
();
1144 foreach my $hd (@$devlist) {
1145 &$clean_disk(@$hd[1]);
1147 foreach my $hd (@$bootdevlist) {
1148 my $devname = @$hd[1];
1149 my ($size, $osdev) =
1150 partition_bootable_zfs_disk
($devname);
1151 zfs_mirror_size_check
($disksize, $size) if $disksize;
1152 push @$bootdevinfo, { devname
=> $devname, osdev
=> $osdev};
1156 &$udevadm_trigger_block();
1158 foreach my $di (@$bootdevinfo) {
1159 my $devname = $di->{devname
};
1160 $di->{by_id
} = find_stable_path
("/dev/disk/by-id", $devname);
1162 # Note: using /dev/disk/by-id/ does not work for unknown reason, we get
1163 # cannot create 'rpool': no such pool or dataset
1164 #my $osdev = find_stable_path ("/dev/disk/by-id", $di->{osdev}) || $di->{osdev};
1166 my $osdev = $di->{osdev
};
1167 $vdev =~ s/ $devname/ $osdev/;
1170 zfs_create_rpool
($vdev);
1172 my $swap_size = compute_swapsize
($disksize);
1173 $swapfile = zfs_create_swap
($swap_size);
1177 die "target '$target_hd' is not a valid block device\n" if ! -b
$target_hd;
1180 if ($config_options->{hdsize
}) {
1181 # max hdsize passed on cmdline (GB)
1182 $maxhdsize = $config_options->{hdsize
}*1024*1024;
1185 &$clean_disk($target_hd);
1187 my ($os_size, $osdev, $efidev);
1188 ($os_size, $osdev, $efidev) =
1189 partition_bootable_disk
($target_hd, $maxhdsize, '8E00');
1191 &$udevadm_trigger_block();
1193 my $by_id = find_stable_path
("/dev/disk/by-id", $target_hd);
1194 push @$bootdevinfo, { esp
=> $efidev, devname
=> $target_hd,
1195 osdev
=> $osdev, by_id
=> $by_id };
1197 my $swap_size = compute_swapsize
($os_size);
1198 ($rootdev, $datadev, $swapfile) =
1199 create_lvm_volumes
($osdev, $os_size, $swap_size);
1201 # trigger udev to create /dev/disk/by-uuid
1202 &$udevadm_trigger_block(1);
1206 # to be fast during installation
1207 syscmd
("zfs set sync=disabled $zfspoolname") == 0 ||
1208 die "unable to set zfs properties\n";
1211 update_progress
(0.03, 0, $maxper, "create swap space");
1213 syscmd
("mkswap -f $swapfile") == 0 ||
1214 die "unable to create swap space\n";
1217 update_progress
(0.05, 0, $maxper, "creating filesystems");
1219 foreach my $di (@$bootdevinfo) {
1220 next if !$di->{esp
};
1221 syscmd
("mkfs.vfat -F32 $di->{esp}") == 0 ||
1222 die "unable to initialize EFI ESP on device $di->{esp}\n";
1227 } elsif ($use_btrfs) {
1230 create_filesystem
($rootdev, 'root', $filesys, 0.05, $maxper, 0, 1);
1233 update_progress
(1, 0.05, $maxper, "mounting target $rootdev");
1238 my $mount_opts = 'noatime';
1239 $mount_opts .= ',nobarrier'
1240 if $use_btrfs || $filesys =~ /^ext\d$/;
1242 syscmd
("mount -n $rootdev -o $mount_opts $targetdir") == 0 ||
1243 die "unable to mount $rootdev\n";
1246 mkdir "$targetdir/boot";
1247 mkdir "$targetdir/boot/efi";
1249 mkdir "$targetdir/var";
1250 mkdir "$targetdir/var/lib";
1251 mkdir "$targetdir/var/lib/vz";
1252 mkdir "$targetdir/var/lib/pve";
1255 syscmd
("btrfs subvolume create $targetdir/var/lib/pve/local-btrfs") == 0 ||
1256 die "unable to create btrfs subvolume\n";
1259 display_html
("extract2-rulesystem.htm");
1260 update_progress
(1, 0.05, $maxper, "extracting base system");
1262 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = stat ($basefile);
1263 $ino || die "unable to open file '$basefile' - $!\n";
1266 if ($opt_testmode) {
1267 $files = file_read_firstline
("../pve-cd-builder/base.cnt");
1269 $files = file_read_firstline
("/cdrom/proxmox/$setup->{product}-base.cnt");
1275 run_command
("unsquashfs -f -dest $targetdir -i $basefile", sub {
1277 return if $line !~ m/^$targetdir/;
1279 my $nper = int (($count *100)/$files);
1280 if ($nper != $per) {
1282 my $frac = $per > 100 ?
1 : $per/100;
1283 update_progress
($frac, $maxper, 0.5);
1287 syscmd
("mount -n -t tmpfs tmpfs $targetdir/tmp") == 0 ||
1288 die "unable to mount tmpfs on $targetdir/tmp\n";
1289 syscmd
("mount -n -t proc proc $targetdir/proc") == 0 ||
1290 die "unable to mount proc on $targetdir/proc\n";
1291 syscmd
("mount -n -t sysfs sysfs $targetdir/sys") == 0 ||
1292 die "unable to mount sysfs on $targetdir/sys\n";
1294 display_html
("extract3-spam.htm");
1295 update_progress
(1, $maxper, 0.5, "configuring base system");
1300 "127.0.0.1 localhost.localdomain localhost\n" .
1301 "$ipaddress $hostname.$domain $hostname pvelocalhost\n\n" .
1302 "# The following lines are desirable for IPv6 capable hosts\n\n" .
1303 "::1 ip6-localhost ip6-loopback\n" .
1304 "fe00::0 ip6-localnet\n" .
1305 "ff00::0 ip6-mcastprefix\n" .
1306 "ff02::1 ip6-allnodes\n" .
1307 "ff02::2 ip6-allrouters\n" .
1308 "ff02::3 ip6-allhosts\n";
1310 write_config
($hosts, "$targetdir/etc/hosts");
1312 write_config
("$hostname\n", "$targetdir/etc/hostname");
1314 syscmd
("/bin/hostname $hostname") if !$opt_testmode;
1316 # configure interfaces
1318 my $ifaces = "auto lo\niface lo inet loopback\n\n";
1320 my $ntype = $ipversion == 4 ?
'inet' : 'inet6';
1322 my $bridge_port = $ipconf->{ifaces
}->{$ipconf->{selected
}}->{name
};
1324 $ifaces .= "iface $bridge_port $ntype manual\n";
1327 "\nauto vmbr0\niface vmbr0 $ntype static\n" .
1328 "\taddress $ipaddress\n" .
1329 "\tnetmask $netmask\n" .
1330 "\tgateway $gateway\n" .
1331 "\tbridge_ports $bridge_port\n" .
1332 "\tbridge_stp off\n" .
1335 foreach my $iface (sort keys %{$ipconf->{ifaces
}}) {
1336 my $name = $ipconf->{ifaces
}->{$iface}->{name
};
1337 next if $name eq $bridge_port;
1339 $ifaces .= "\niface $name $ntype manual\n";
1342 write_config
($ifaces, "$targetdir/etc/network/interfaces");
1346 my $resolvconf = "search $domain\nnameserver $dnsserver\n";
1347 write_config
($resolvconf, "$targetdir/etc/resolv.conf");
1351 my $fstab = "# <file system> <mount point> <type> <options> <dump> <pass>\n";
1355 } elsif ($use_btrfs) {
1357 my $cmd = "blkid -u filesystem -t TYPE=btrfs -o export $rootdev";
1358 run_command
($cmd, sub {
1361 if ($line =~ m/^UUID=([A-Fa-f0-9\-]+)$/) {
1366 die "unable to detect FS UUID" if !defined($fsuuid);
1368 $fstab .= "UUID=$fsuuid / btrfs defaults 0 1\n";
1370 my $root_mountopt = $fssetup->{$filesys}->{root_mountopt
} || 'defaults';
1371 $fstab .= "$rootdev / $filesys ${root_mountopt} 0 1\n";
1375 # Note: this is required by current grub, but really dangerous, because
1376 # vfat does not have journaling, so it triggers manual fsck after each crash
1377 # so we only mount /boot/efi if really required (efi systems).
1378 if ($grub_plattform =~ m/^efi-/) {
1379 if (scalar(@$bootdevinfo)) {
1380 my $di = @$bootdevinfo[0]; # simply use first disk
1382 my $efi_boot_uuid = $di->{esp
};
1383 if (my $uuid = find_dev_by_uuid
($di->{esp
})) {
1384 $efi_boot_uuid = "UUID=$uuid";
1387 $fstab .= "${efi_boot_uuid} /boot/efi vfat defaults 0 1\n";
1393 $fstab .= "$swapfile none swap sw 0 0\n" if $swapfile;
1395 $fstab .= "proc /proc proc defaults 0 0\n";
1397 write_config
($fstab, "$targetdir/etc/fstab");
1398 write_config
("", "$targetdir/etc/mtab");
1400 syscmd
("cp ${proxmox_libdir}/policy-disable-rc.d " .
1401 "$targetdir/usr/sbin/policy-rc.d") == 0 ||
1402 die "unable to copy policy-rc.d\n";
1403 syscmd
("cp ${proxmox_libdir}/fake-start-stop-daemon " .
1404 "$targetdir/sbin/") == 0 ||
1405 die "unable to copy start-stop-daemon\n";
1407 diversion_add
($targetdir, "/sbin/start-stop-daemon", "/sbin/fake-start-stop-daemon");
1408 diversion_add
($targetdir, "/usr/sbin/update-grub", "/bin/true");
1409 diversion_add
($targetdir, "/usr/sbin/update-initramfs", "/bin/true");
1411 syscmd
("touch $targetdir/proxmox_install_mode");
1413 my $grub_install_devices_txt = '';
1414 foreach my $di (@$bootdevinfo) {
1415 $grub_install_devices_txt .= ', ' if $grub_install_devices_txt;
1416 $grub_install_devices_txt .= $di->{by_id
} || $di->{devname
};
1419 # Note: keyboard-configuration/xbkb-keymap is used by console-setup
1420 my $xkmap = $cmap->{kmap
}->{$keymap}->{x11
} // 'us';
1422 debconfig_set
($targetdir, <<_EOD);
1423 locales locales/default_environment_locale select en_US.UTF-8
1424 locales locales/locales_to_be_generated select en_US.UTF-8 UTF-8
1425 samba-common samba-common/dhcp boolean false
1426 samba-common samba-common/workgroup string WORKGROUP
1427 postfix postfix/main_mailer_type select Local only
1428 keyboard-configuration keyboard-configuration/xkb-keymap select $xkmap
1429 d-i debian-installer/locale select en_US.UTF-8
1430 grub-pc grub-pc/install_devices select $grub_install_devices_txt
1433 my $pkgdir = $opt_testmode ?
"../pve-cd-builder/tmp/data-gz/proxmox/packages/" : "/cdrom/proxmox/packages";
1435 while (<$pkgdir/*.deb
>) { $pkg_count++ };
1437 # btrfs/dpkg is extremely slow without --force-unsafe-io
1438 my $dpkg_opts = $use_btrfs ?
"--force-unsafe-io" : "";
1441 while (<$pkgdir/*.deb
>) {
1444 my ($deb) = $path =~ m/$pkgdir\/(.*\
.deb
)/;
1445 # if ($deb =~ m/^grub-efi-/ && $deb !~ m/^grub-${grub_plattform}/) {
1449 update_progress
($count/$pkg_count, 0.5, 0.75, "extracting $deb");
1450 print "extracting: $deb\n";
1451 syscmd
("cp $path $targetdir/tmp/$deb") == 0 ||
1452 die "installation of package $deb failed\n";
1453 syscmd
("chroot $targetdir dpkg $dpkg_opts --force-depends --no-triggers --unpack /tmp/$deb") == 0 ||
1454 die "installation of package $deb failed\n";
1455 update_progress
((++$count)/$pkg_count, 0.5, 0.75);
1458 display_html
("extract4-virus.htm");
1460 # needed for postfix postinst in case no other NIC is active
1461 syscmd
("chroot $targetdir ifup lo");
1463 my $cmd = "chroot $targetdir dpkg $dpkg_opts --force-confold --configure -a";
1465 run_command
($cmd, sub {
1467 if ($line =~ m/Setting up\s+(\S+)/) {
1468 update_progress
((++$count)/$pkg_count, 0.75, 0.95,
1473 debconfig_set
($targetdir, <<_EOD);
1474 postfix postfix/main_mailer_type select No configuration
1477 unlink "$targetdir/etc/mailname";
1478 $postfix_main_cf =~ s/__FQDN__/${hostname}.${domain}/;
1479 write_config
($postfix_main_cf, "$targetdir/etc/postfix/main.cf");
1481 # make sure we have all postfix directories
1482 syscmd
("chroot $targetdir /usr/sbin/postfix check");
1483 # cleanup mail queue
1484 syscmd
("chroot $targetdir /usr/sbin/postsuper -d ALL");
1486 # enable NTP (timedatectl set-ntp true does not work without DBUS)
1487 syscmd
("chroot $targetdir /bin/systemctl enable systemd-timesyncd.service");
1489 unlink "$targetdir/proxmox_install_mode";
1492 unlink ("$targetdir/etc/localtime");
1493 symlink ("/usr/share/zoneinfo/$timezone", "$targetdir/etc/localtime");
1494 write_config
("$timezone\n", "$targetdir/etc/timezone");
1497 if (my $mirror = $cmap->{country
}->{$country}->{mirror
}) {
1498 my $fn = "$targetdir/etc/apt/sources.list";
1499 syscmd
("sed -i 's/ftp\\.debian\\.org/$mirror/' '$fn'");
1502 # create extended_states for apt (avoid cron job warning if that
1503 # file does not exist)
1504 write_config
('', "$targetdir/var/lib/apt/extended_states");
1506 # allow ssh root login
1507 syscmd
("sed -i 's/^PermitRootLogin.*/PermitRootLogin yes/' '$targetdir/etc/ssh/sshd_config'");
1509 # save installer settings
1510 my $ucc = uc ($country);
1511 debconfig_set
($targetdir, <<_EOD);
1512 pve-manager pve-manager/country string $ucc
1515 update_progress
(0.8, 0.95, 1, "make system bootable");
1518 syscmd
("sed -i -e 's/^GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"root=ZFS=$zfspoolname\\/ROOT\\/pve-1 boot=zfs\"/' $targetdir/etc/default/grub") == 0 ||
1519 die "unable to update /etc/default/grub\n";
1523 diversion_remove
($targetdir, "/usr/sbin/update-grub");
1524 diversion_remove
($targetdir, "/usr/sbin/update-initramfs");
1526 if (!$opt_testmode) {
1528 unlink ("$targetdir/etc/mtab");
1529 symlink ("/proc/mounts", "$targetdir/etc/mtab");
1530 syscmd
("mount -n --bind /dev $targetdir/dev");
1532 syscmd
("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0 ||
1533 die "unable to install initramfs\n";
1535 foreach my $di (@$bootdevinfo) {
1536 my $dev = $di->{devname
};
1537 syscmd
("chroot $targetdir /usr/sbin/grub-install --target i386-pc --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
1538 die "unable to install the i386-pc boot loader on '$dev'\n";
1541 syscmd
("mount -n $di->{esp} -t vfat $targetdir/boot/efi") == 0 ||
1542 die "unable to mount $di->{esp}\n";
1543 my $rc = syscmd
("chroot $targetdir /usr/sbin/grub-install --target x86_64-efi --no-floppy --bootloader-id='proxmox' $dev");
1545 if (-d
'/sys/firmware/efi') {
1546 die "unable to install the EFI boot loader on '$dev'\n";
1548 warn "unable to install the EFI boot loader on '$dev', ignoring (not booted using UEFI)\n";
1551 # also install fallback boot file (OVMF does not boot without)
1552 mkdir("$targetdir/boot/efi/EFI/BOOT");
1553 syscmd
("cp $targetdir/boot/efi/EFI/proxmox/grubx64.efi $targetdir/boot/efi/EFI/BOOT/BOOTx64.EFI") == 0 ||
1554 die "unable to copy efi boot loader\n";
1556 syscmd
("umount $targetdir/boot/efi") == 0 ||
1557 die "unable to umount $targetdir/boot/efi\n";
1561 syscmd
("chroot $targetdir /usr/sbin/update-grub") == 0 ||
1562 die "unable to update boot loader config\n";
1564 syscmd
("umount $targetdir/dev");
1569 # hack: remove dead.letter from sshd installation
1570 syscmd
("rm -rf $targetdir/dead.letter");
1572 unlink "$targetdir/usr/sbin/policy-rc.d";
1574 diversion_remove
($targetdir, "/sbin/start-stop-daemon");
1577 my $octets = encode
("utf-8", $password);
1578 run_command
("chroot $targetdir /usr/sbin/chpasswd", undef,
1583 my $tmpdir = "$targetdir/tmp/pve";
1586 # write vnc keymap to datacenter.cfg
1587 my $vnckmap = $cmap->{kmap
}->{$keymap}->{kvm
} || 'en-us';
1588 write_config
("keyboard: $vnckmap\n",
1589 "$tmpdir/datacenter.cfg");
1592 write_config
("user:root\@pam:1:0:::${mailto}::\n",
1593 "$tmpdir/user.cfg");
1596 my $strorage_cfg_fn = "$tmpdir/storage.cfg";
1598 write_config
($storage_cfg_zfs, $strorage_cfg_fn);
1599 } elsif ($use_btrfs) {
1600 write_config
($storage_cfg_btrfs, $strorage_cfg_fn);
1602 write_config
($storage_cfg_lvmthin, $strorage_cfg_fn);
1605 run_command
("chroot $targetdir /usr/bin/create_pmxcfs_db /tmp/pve /var/lib/pve-cluster/config.db");
1607 syscmd
("rm -rf $tmpdir");
1612 update_progress
(1, 0, 1, "");
1616 if ($opt_testmode) {
1617 my $elapsed = Time
::HiRes
::tv_interval
($starttime);
1618 print "Elapsed extract time: $elapsed\n";
1620 syscmd
("chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> pve-final.pkglist");
1623 syscmd
("umount $targetdir/var/lib/vz");
1624 syscmd
("umount $targetdir/tmp");
1625 syscmd
("umount $targetdir/proc");
1626 syscmd
("umount $targetdir/sys");
1629 syscmd
("zfs umount -a") == 0 ||
1630 die "unable to unmount zfs\n";
1632 syscmd
("umount -d $targetdir");
1635 if (!$err && $use_zfs) {
1636 syscmd
("zfs set sync=standard $zfspoolname") == 0 ||
1637 die "unable to set zfs properties\n";
1639 syscmd
("zfs set mountpoint=/ $zfspoolname/ROOT/pve-1") == 0 ||
1640 die "zfs set mountpoint failed\n";
1642 syscmd
("zpool set bootfs=$zfspoolname/ROOT/pve-1 $zfspoolname") == 0 ||
1643 die "zfs set bootfs failed\n";
1644 syscmd
("zpool export $zfspoolname");
1651 my ($filename) = @_;
1653 my $path = "${proxmox_libdir}/html/$filename";
1654 my $url = "file://$path";
1656 my $data = file_get_contents
($path);
1658 if ($filename eq 'license.htm') {
1659 my $licensefn = -f
"/EULA" ?
"/EULA" :
1660 $opt_testmode ?
"./copyright" :
1661 "/usr/share/doc/pve-installer/copyright";
1662 my $license = decode
('utf8', file_get_contents
($licensefn));
1663 $license =~ m/^\s+(.+\n)/;
1664 my $title = $licensefn eq '/EULA' ?
"END USER LICENSE AGREEMENT (EULA)": $1;
1665 $data =~ s/__LICENSE__/$license/;
1666 $data =~ s/__LICENSE_TITLE__/$title/;
1669 $htmlview->load_html_string($data, $url);
1673 my ($text, $fctn) = @_;
1676 $text = "_Next" if !$text;
1677 $next->set_label ($text);
1679 $next->grab_focus ();
1683 my ($doc, $url, $stream) = @_;
1685 $stream->set_cancel_func (sub {}); # hack: avoid warning
1687 my $path = "${proxmox_libdir}/html/$url";
1690 open (HTMLTMP
, $path) ||
1691 die "unable to open file '$path' - $!\n";
1693 while (my $i = read (HTMLTMP
, $buf, 4096)) {
1694 $stream->write ($buf);
1695 Gtk3
::main_iteration
() while Gtk3
::events_pending
();
1700 #$stream->close(); # hack: dont close - avoid crash
1703 sub create_main_window
{
1705 $window = Gtk3
::Window-
>new ();
1706 $window->set_default_size (1024, 768);
1707 $window->set_has_resize_grip(0);
1708 $window->set_decorated (0) if !$opt_testmode;
1710 my $vbox = Gtk3
::VBox-
>new (0, 0);
1712 my $image = Gtk3
::Image-
>new_from_file ("${proxmox_libdir}/proxlogo.png");
1713 $vbox->pack_start ($image, 0, 0, 0);
1715 my $hbox = Gtk3
::HBox-
>new (0, 0);
1716 $vbox->pack_start ($hbox, 1, 1, 0);
1718 # my $f1 = Gtk3::Frame->new ('test');
1719 # $f1->set_shadow_type ('none');
1720 # $hbox->pack_start ($f1, 1, 1, 0);
1722 my $sep1 = Gtk3
::HSeparator-
>new;
1723 $vbox->pack_start ($sep1, 0, 0, 0);
1725 $cmdbox = Gtk3
::HBox-
>new ();
1726 $vbox->pack_start ($cmdbox, 0, 0, 10);
1728 $next = Gtk3
::Button-
>new ('_Next');
1729 $next->signal_connect (clicked
=> sub { &$next_fctn (); });
1730 $cmdbox->pack_end ($next, 0, 0, 10);
1731 my $abort = Gtk3
::Button-
>new ('_Abort');
1732 $abort->set_can_focus (0);
1733 $cmdbox->pack_start ($abort, 0, 0, 10);
1734 $abort->signal_connect (clicked
=> sub { exit (-1); });
1736 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1737 $hbox->add ($vbox2);
1739 $htmlview = Gtk3
::WebKit
::WebView-
>new();
1740 my $scrolls = Gtk3
::ScrolledWindow-
>new();
1741 $scrolls->add($htmlview);
1743 my $hbox2 = Gtk3
::HBox-
>new (0, 0);
1744 $hbox2->pack_start ($scrolls, 1, 1, 0);
1746 $vbox2->pack_start ($hbox2, 1, 1, 0);
1748 my $vbox3 = Gtk3
::VBox-
>new (0, 0);
1749 $vbox2->pack_start ($vbox3, 0, 0, 0);
1751 my $sep2 = Gtk3
::HSeparator-
>new;
1752 $vbox3->pack_start ($sep2, 0, 0, 0);
1754 $inbox = Gtk3
::HBox-
>new (0, 0);
1755 $vbox3->pack_start ($inbox, 0, 0, 0);
1757 $window->add ($vbox);
1760 $window->realize ();
1764 $inbox->foreach(sub {
1766 $inbox->remove ($child);
1770 # fixme: newer GTK3 has special properties to handle numbers with Entry
1771 # only allow floating point numbers with Gtk3::Entry
1774 my ($entry, $event) = @_;
1776 return check_number
($entry, $event, 1);
1780 my ($entry, $event) = @_;
1782 return check_number
($entry, $event, 0);
1786 my ($entry, $event, $float) = @_;
1788 my $val = $event->get_keyval;
1790 if (($float && $val == ord '.') ||
1791 $val == Gtk3
::Gdk
::KEY_ISO_Left_Tab
||
1792 $val == Gtk3
::Gdk
::KEY_Shift_L
||
1793 $val == Gtk3
::Gdk
::KEY_Tab
||
1794 $val == Gtk3
::Gdk
::KEY_Left
||
1795 $val == Gtk3
::Gdk
::KEY_Right
||
1796 $val == Gtk3
::Gdk
::KEY_BackSpace
||
1797 $val == Gtk3
::Gdk
::KEY_Delete
||
1798 ($val >= ord '0' && $val <= ord '9') ||
1799 ($val >= Gtk3
::Gdk
::KEY_KP_0
&&
1800 $val <= Gtk3
::Gdk
::KEY_KP_9
)) {
1807 sub create_text_input
{
1808 my ($default, $text) = @_;
1810 my $hbox = Gtk3
::HBox-
>new (0, 0);
1812 my $label = Gtk3
::Label-
>new ($text);
1813 $label->set_size_request (150, -1);
1814 $label->set_alignment (1, 0.5);
1815 $hbox->pack_start ($label, 0, 0, 10);
1816 my $e1 = Gtk3
::Entry-
>new ();
1817 $e1->set_width_chars (30);
1818 $hbox->pack_start ($e1, 0, 0, 0);
1819 $e1->set_text ($default);
1821 return ($hbox, $e1);
1829 my $links = `ip -o l`;
1830 foreach my $l (split /\n/,$links) {
1831 my ($index, $name, $flags, $state, $mac) = $l =~ m/^(\d+):\s+(\S+):\s+<(\S+)>.*\s+state\s+(\S+)\s+.*\s+link\/ether\s
+(\S
+)\s
+/;
1832 next if !$name || $name eq 'lo';
1834 my $driver = readlink "/sys/class/net/$name/device/driver" || 'unknown';
1835 $driver =~ s!^.*/!!;
1837 $ifaces->{"$index"} = {
1845 my $addresses = `ip -o a s $name`;
1846 foreach my $a (split /\n/,$addresses) {
1847 my ($family, $ip, $prefix) = $a =~ m/^\Q$index\E:\s+\Q$name\E\s+(inet|inet6)\s+($IPRE)\/(\d+)\s+/;
1849 next if $a =~ /scope\s+link/; # ignore link local
1853 if ($family eq 'inet') {
1854 next if !$ip =~ /$IPV4RE/;
1855 next if $prefix < 8 || $prefix > 32;
1856 $mask = @$ipv4_reverse_mask[$prefix];
1858 next if !$ip =~ /$IPV6RE/;
1861 $default = $index if !$default;
1863 $ifaces->{"$index"}->{"$family"} = {
1871 my $route = `ip route
`;
1872 my ($gateway) = $route =~ m/^default\s+via\s+(\S+)\s+/m;
1874 my $resolvconf = `cat
/etc/resolv
.conf
`;
1875 my ($dnsserver) = $resolvconf =~ m/^nameserver\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/m;
1876 my ($domain) = $resolvconf =~ m/^domain\s+(\S+)$/m;
1879 default => $default,
1881 gateway => $gateway,
1882 dnsserver => $dnsserver,
1887 sub display_message {
1890 my $dialog = Gtk3::MessageDialog->new ($window, 'modal',
1891 'info', 'ok', $msg);
1899 my $dialog = Gtk3::MessageDialog->new ($window, 'modal',
1900 'error', 'ok', $msg);
1905 my $ipconf_first_view = 1;
1907 sub create_ipconf_view {
1910 display_html ("ipconf.htm");
1912 my $vbox = Gtk3::VBox->new (0, 0);
1913 $inbox->pack_start ($vbox, 1, 0, 0);
1914 my $hbox = Gtk3::HBox->new (0, 0);
1915 $vbox->pack_start ($hbox, 0, 0, 10);
1916 my $vbox2 = Gtk3::VBox->new (0, 0);
1917 $hbox->add ($vbox2);
1920 ($ipbox, $ipconf_entry_addr) =
1921 create_text_input ("192.168.100.2", 'IP Address:');
1924 ($maskbox, $ipconf_entry_mask) =
1925 create_text_input ("255.255.255.0", 'Netmask:');
1927 my $device_cb = Gtk3::ComboBoxText->new();
1928 $device_cb->set_active(0);
1929 $device_cb->set_visible(1);
1931 my $get_device_desc = sub {
1933 return "$iface->{name} - $iface->{mac} ($iface->{driver})";
1936 my $device_active_map = {};
1938 my $device_change_handler = sub {
1939 my $current = shift;
1940 $ipconf->{selected} = $device_active_map->{$current->get_active()};
1941 my $iface = $ipconf->{ifaces}->{$ipconf->{selected}};
1942 $ipconf_entry_addr->set_text($iface->{inet}->{addr} || $iface->{inet6}->{addr})
1943 if $iface->{inet}->{addr} || $iface->{inet6}->{addr};
1944 $ipconf_entry_mask->set_text($iface->{inet}->{mask} || $iface->{inet6}->{mask})
1945 if $iface->{inet}->{mask} || $iface->{inet6}->{mask};
1949 foreach my $index (sort keys %{$ipconf->{ifaces}}) {
1950 $device_cb->append_text(&$get_device_desc($ipconf->{ifaces}->{$index}));
1951 $device_active_map->{$i} = $index;
1952 if ($ipconf_first_view && $index == $ipconf->{default}) {
1953 $device_cb->set_active($i);
1954 &$device_change_handler($device_cb);
1955 $ipconf_first_view = 0;
1957 $device_cb->signal_connect ('changed' => $device_change_handler);
1961 $device_cb->set_active(0)
1962 if !($ipconf->{selected});
1964 my $devicebox = Gtk3::HBox->new (0, 0);
1965 my $label = Gtk3::Label->new ("Management Interface:");
1966 $label->set_size_request (150, -1);
1967 $label->set_alignment (1, 0.5);
1968 $devicebox->pack_start ($label, 0, 0, 10);
1969 $devicebox->pack_start ($device_cb, 0, 0, 0);
1971 $vbox2->pack_start ($devicebox, 0, 0, 2);
1973 my $hn = $ipconf->{domain} ? "pve.$ipconf->{domain}" : 'pve.example.invalid';
1975 my ($hostbox, $hostentry) =
1976 create_text_input ($hn, 'Hostname (FQDN):');
1977 $vbox2->pack_start ($hostbox, 0, 0, 2);
1979 $vbox2->pack_start ($ipbox, 0, 0, 2);
1981 $vbox2->pack_start ($maskbox, 0, 0, 2);
1983 $gateway = $ipconf->{gateway} || '192.168.100.1';
1986 ($gwbox, $ipconf_entry_gw) =
1987 create_text_input ($gateway, 'Gateway:');
1989 $vbox2->pack_start ($gwbox, 0, 0, 2);
1991 $dnsserver = $ipconf->{dnsserver} || $gateway;
1994 ($dnsbox, $ipconf_entry_dns) =
1995 create_text_input ($dnsserver, 'DNS Server:');
1997 $vbox2->pack_start ($dnsbox, 0, 0, 0);
2000 set_next (undef, sub {
2004 my $text = $hostentry->get_text();
2009 my $namere = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
2011 # Debian does not support purely numeric hostnames
2012 if ($text && $text =~ /^[0-9]+(?:\.|$)/) {
2013 display_message("Purely numeric hostnames are not allowed.");
2014 $hostentry->grab_focus();
2018 if ($text && $text =~ m/^(${namere}\.)*${namere}$/ && $text !~ m/.example.invalid$/ &&
2019 $text =~ m/^([^\.]+)\.(\S+)$/) {
2023 display_message ("Hostname does not look like a fully qualified domain name.");
2024 $hostentry->grab_focus();
2030 $text = $ipconf_entry_addr->get_text();
2033 if ($text =~ m!^($IPV4RE)$!) {
2036 } elsif ($text =~ m!^($IPV6RE)$!) {
2040 display_message ("IP address is not valid.");
2041 $ipconf_entry_addr->grab_focus();
2045 $text = $ipconf_entry_mask->get_text();
2048 if (($ipversion == 6) && ($text =~ m/^(\d+)$/) && ($1 >= 8) && ($1 <= 126)) {
2050 } elsif (($ipversion == 4) && defined($ipv4_mask_hash->{$text})) {
2053 display_message ("Netmask is not valid.");
2054 $ipconf_entry_mask->grab_focus();
2058 $text = $ipconf_entry_gw->get_text();
2061 if (($ipversion == 4) && ($text =~ m!^($IPV4RE)$!)) {
2063 } elsif (($ipversion == 6) && ($text =~ m!^($IPV6RE)$!)) {
2066 display_message ("Gateway is not valid.");
2067 $ipconf_entry_gw->grab_focus();
2071 $text = $ipconf_entry_dns->get_text();
2074 if (($ipversion == 4) && ($text =~ m!^($IPV4RE)$!)) {
2076 } elsif (($ipversion == 6) && ($text =~ m!^($IPV6RE)$!)) {
2079 display_message ("DNS server is not valid.");
2080 $ipconf_entry_dns->grab_focus();
2084 #print "TEST $ipaddress $netmask $gateway $dnsserver\n";
2086 create_extract_view ();
2089 $hostentry->grab_focus();
2092 sub get_device_desc {
2093 my ($devname, $size, $model) = @_;
2095 if ($size && ($size > 0)) {
2096 $size = int($size/2048); # size in MB, from 512B "sectors"
2098 my $text = "$devname (";
2099 if ($size >= 1024) {
2100 $size = int($size/1024); # size in GB
2101 $text .= "${size}GB";
2103 $text .= "${size}MB";
2106 $text .= ", $model" if $model;
2115 my ($cb, $kmap) = @_;
2120 my $kmaphash = $cmap->{kmaphash};
2121 foreach my $layout (sort keys %$kmaphash) {
2122 $def = $i if $kmaphash->{$layout} eq 'en-us';
2123 $ind = $i if $kmap && $kmaphash->{$layout} eq $kmap;
2127 $cb->set_active ($ind || $def || 0);
2131 sub update_zonelist {
2132 my ($box, $cc) = @_;
2134 my $cczones = $cmap->{cczones};
2135 my $zones = $cmap->{zones};
2139 $sel = $lastzonecb->get_active_text();
2140 $box->remove ($lastzonecb);
2142 $sel = $timezone; # used once to select default
2145 my $cb = $lastzonecb = Gtk3::ComboBoxText->new();
2146 $cb->set_size_request (200, -1);
2148 $cb->signal_connect ('changed' => sub {
2149 $timezone = $cb->get_active_text();
2153 if ($cc && defined ($cczones->{$cc})) {
2154 @za = keys %{$cczones->{$cc}};
2160 foreach my $zone (sort @za) {
2161 $ind = $i if $sel && $zone eq $sel;
2162 $cb->append_text ($zone);
2166 $cb->set_active ($ind || 0);
2169 $box->pack_start ($cb, 0, 0, 0);
2172 sub create_password_view {
2176 my $vbox2 = Gtk3::VBox->new (0, 0);
2177 $inbox->pack_start ($vbox2, 1, 0, 0);
2178 my $vbox = Gtk3::VBox->new (0, 0);
2179 $vbox2->pack_start ($vbox, 0, 0, 10);
2181 my $hbox1 = Gtk3::HBox->new (0, 0);
2182 my $label = Gtk3::Label->new ("Password");
2183 $label->set_size_request (150, -1);
2184 $label->set_alignment (1, 0.5);
2185 $hbox1->pack_start ($label, 0, 0, 10);
2186 my $pwe1 = Gtk3::Entry->new ();
2187 $pwe1->set_visibility (0);
2188 $pwe1->set_size_request (200, -1);
2189 $hbox1->pack_start ($pwe1, 0, 0, 0);
2191 my $hbox2 = Gtk3::HBox->new (0, 0);
2192 $label = Gtk3::Label->new ("Confirm");
2193 $label->set_size_request (150, -1);
2194 $label->set_alignment (1, 0.5);
2195 $hbox2->pack_start ($label, 0, 0, 10);
2196 my $pwe2 = Gtk3::Entry->new ();
2197 $pwe2->set_visibility (0);
2198 $pwe2->set_size_request (200, -1);
2199 $hbox2->pack_start ($pwe2, 0, 0, 0);
2201 my $hbox3 = Gtk3::HBox->new (0, 0);
2202 $label = Gtk3::Label->new ("E-Mail");
2203 $label->set_size_request (150, -1);
2204 $label->set_alignment (1, 0.5);
2205 $hbox3->pack_start ($label, 0, 0, 10);
2206 my $eme = Gtk3::Entry->new ();
2207 $eme->set_size_request (200, -1);
2208 $eme->set_text('mail@example.invalid');
2209 $hbox3->pack_start ($eme, 0, 0, 0);
2212 $vbox->pack_start ($hbox1, 0, 0, 5);
2213 $vbox->pack_start ($hbox2, 0, 0, 5);
2214 $vbox->pack_start ($hbox3, 0, 0, 15);
2218 display_html ("passwd.htm");
2220 set_next (undef, sub {
2222 my $t1 = $pwe1->get_text;
2223 my $t2 = $pwe2->get_text;
2225 if (length ($t1) < 5) {
2226 display_message ("Password is too short.");
2227 $pwe1->grab_focus();
2232 display_message ("Password does not match.");
2233 $pwe1->grab_focus();
2237 my $t3 = $eme->get_text;
2238 if ($t3 !~ m/^\S+\@\S+\.\S+$/) {
2239 display_message ("E-Mail does not look like a valid address" .
2240 " (user\@domain.tld)");
2245 if ($t3 eq 'mail@example.invalid') {
2246 display_message ("Please enter a valid E-Mail address");
2254 create_ipconf_view();
2257 $pwe1->grab_focus();
2261 sub create_country_view {
2265 my $countryhash = $cmap->{countryhash};
2266 my $ctr = $cmap->{country};
2268 my $vbox2 = Gtk3::VBox->new (0, 0);
2269 $inbox->pack_start ($vbox2, 1, 0, 0);
2270 my $vbox = Gtk3::VBox->new (0, 0);
2271 $vbox2->pack_start ($vbox, 0, 0, 10);
2273 my $w = Gtk3::Entry->new ();
2274 $w->set_size_request (200, -1);
2276 my $c = Gtk3::EntryCompletion->new ();
2277 $c->set_text_column (0);
2278 $c->set_minimum_key_length(0);
2279 $c->set_popup_set_width (1);
2280 $c->set_inline_completion (1);
2282 my $hbox2 = Gtk3::HBox->new (0, 0);
2283 my $label = Gtk3::Label->new ("Time zone");
2284 $label->set_size_request (150, -1);
2285 $label->set_alignment (1, 0.5);
2286 $hbox2->pack_start ($label, 0, 0, 10);
2287 update_zonelist ($hbox2);
2289 my $hbox3 = Gtk3::HBox->new (0, 0);
2290 $label = Gtk3::Label->new ("Keyboard Layout");
2291 $label->set_size_request (150, -1);
2292 $label->set_alignment (1, 0.5);
2293 $hbox3->pack_start ($label, 0, 0, 10);
2295 my $kmapcb = Gtk3::ComboBoxText->new();
2296 $kmapcb->set_size_request (200, -1);
2297 foreach my $layout (sort keys %{$cmap->{kmaphash}}) {
2298 $kmapcb->append_text ($layout);
2301 update_layout ($kmapcb);
2302 $hbox3->pack_start ($kmapcb, 0, 0, 0);
2304 $kmapcb->signal_connect ('changed' => sub {
2305 my $sel = $kmapcb->get_active_text();
2306 if (my $kmap = $cmap->{kmaphash}->{$sel}) {
2307 my $xkmap = $cmap->{kmap}->{$kmap}->{x11};
2308 my $xvar = $cmap->{kmap}->{$kmap}->{x11var};
2309 syscmd ("setxkbmap $xkmap $xvar") if !$opt_testmode;
2314 $w->signal_connect ('changed' => sub {
2315 my ($entry, $event) = @_;
2316 my $text = $entry->get_text;
2318 if (my $cc = $countryhash->{lc($text)}) {
2319 update_zonelist ($hbox2, $cc);
2320 my $kmap = $ctr->{$cc}->{kmap} || 'en-us';
2321 update_layout ($kmapcb, $kmap);
2325 $w->signal_connect (key_press_event => sub {
2326 my ($entry, $event) = @_;
2327 my $text = $entry->get_text;
2329 my $val = $event->get_keyval;
2331 if ($val == Gtk3::Gdk::KEY_Tab) {
2332 my $cc = $countryhash->{lc($text)};
2339 $compl = $ctr->{$cc}->{name};
2341 foreach my $cc (keys %$ctr) {
2342 my $ct = $ctr->{$cc}->{name};
2343 if ($ct =~ m/^\Q$text\E.*$/i) {
2352 $entry->set_text($compl);
2357 print chr(7); # beep ?
2362 my $buf = $w->get_buffer();
2363 $buf->insert_text(-1, '', -1); # popup selection
2371 my $ls = Gtk3::ListStore->new('Glib::String');
2372 foreach my $cc (sort {$ctr->{$a}->{name} cmp $ctr->{$b}->{name} } keys %$ctr) {
2373 my $iter = $ls->append();
2374 $ls->set ($iter, 0, $ctr->{$cc}->{name});
2376 $c->set_model ($ls);
2378 $w->set_completion ($c);
2380 my $hbox = Gtk3::HBox->new (0, 0);
2382 $label = Gtk3::Label->new ("Country");
2383 $label->set_alignment (1, 0.5);
2384 $label->set_size_request (150, -1);
2385 $hbox->pack_start ($label, 0, 0, 10);
2386 $hbox->pack_start ($w, 0, 0, 0);
2388 $vbox->pack_start ($hbox, 0, 0, 5);
2389 $vbox->pack_start ($hbox2, 0, 0, 5);
2390 $vbox->pack_start ($hbox3, 0, 0, 5);
2392 if ($country && $ctr->{$country}) {
2393 $w->set_text ($ctr->{$country}->{name});
2398 display_html ("country.htm");
2399 set_next (undef, sub {
2401 my $text = $w->get_text;
2403 if (my $cc = $countryhash->{lc($text)}) {
2405 create_password_view();
2408 display_message ("Please select a country first.");
2416 my $target_hd_combo;
2417 my $target_hd_label;
2419 my $hdopion_first_setup = 1;
2421 my $create_basic_grid = sub {
2422 my $grid = Gtk3::Grid->new();
2423 $grid->set_visible(1);
2424 $grid->set_column_spacing(10);
2425 $grid->set_row_spacing(10);
2426 $grid->set_hexpand(1);
2428 $grid->set_margin_start(5);
2429 $grid->set_margin_end(5);
2430 $grid->set_margin_top(5);
2431 $grid->set_margin_bottom(5);
2436 my $create_label_widget_grid = sub {
2437 my ($labeled_widgets) = @_;
2439 my $grid = &$create_basic_grid();
2442 for (my $i = 0; $i < @$labeled_widgets; $i += 2) {
2443 my $widget = @$labeled_widgets[$i+1];
2444 my $label = Gtk3::Label->new(@$labeled_widgets[$i]);
2445 $label->set_visible(1);
2446 $label->set_alignment (1, 0.5);
2447 $grid->attach($label, 0, $row, 1, 1);
2448 $widget->set_visible(1);
2449 $grid->attach($widget, 1, $row, 1, 1);
2456 my $create_raid_disk_grid = sub {
2457 my $disk_labeled_widgets = [];
2458 for (my $i = 0; $i < @$hds; $i++) {
2459 my $disk_selector = Gtk3::ComboBoxText->new();
2460 $disk_selector->append_text("-- do not use --");
2461 $disk_selector->set_active(0);
2462 $disk_selector->set_visible(1);
2463 foreach my $hd (@$hds) {
2464 my ($disk, $devname, $size, $model) = @$hd;
2465 $disk_selector->append_text(get_device_desc ($devname, $size, $model));
2466 $disk_selector->{pve_disk_id} = $i;
2467 $disk_selector->signal_connect (changed => sub {
2469 my $diskid = $w->{pve_disk_id};
2470 my $a = $w->get_active - 1;
2471 $config_options->{"disksel${diskid}"} = ($a >= 0) ? $hds->[$a] : undef;
2475 if ($hdopion_first_setup) {
2476 $disk_selector->set_active ($i+1) if $hds->[$i];
2479 if (my $cur_hd = $config_options->{"disksel$i"}) {
2480 foreach my $hd (@$hds) {
2481 if (@$hd[1] eq @$cur_hd[1]) {
2482 $disk_selector->set_active($hdind+1);
2490 push @$disk_labeled_widgets, "Harddisk $i", $disk_selector;
2493 my $scrolled_window = Gtk3::ScrolledWindow->new();
2494 $scrolled_window->set_hexpand(1);
2495 $scrolled_window->set_propagate_natural_height(1) if @$hds > 4;
2496 $scrolled_window->add(&$create_label_widget_grid($disk_labeled_widgets));
2497 $scrolled_window->set_policy('never', 'automatic');
2499 return $scrolled_window;
2500 # &$create_label_widget_grid($disk_labeled_widgets)
2503 my $create_raid_advanced_grid = sub {
2504 my $labeled_widgets = [];
2505 my $spinbutton_ashift = Gtk3::SpinButton->new_with_range(9,13,1);
2506 $spinbutton_ashift->set_tooltip_text("zpool ashift property (pool sector size, default 2^12)");
2507 $spinbutton_ashift->signal_connect ("value-changed" => sub {
2509 $config_options->{ashift} = $w->get_value_as_int();
2511 $config_options->{ashift} = 12 if ! defined($config_options->{ashift});
2512 $spinbutton_ashift->set_value($config_options->{ashift});
2513 push @$labeled_widgets, "ashift";
2514 push @$labeled_widgets, $spinbutton_ashift;
2516 my $combo_compress = Gtk3::ComboBoxText->new();
2517 $combo_compress->set_tooltip_text("zfs compression algorithm for rpool dataset");
2518 # note: gzip / lze not allowed for bootfs vdevs
2519 my $comp_opts = ["on","off","lzjb","lz4"];
2520 foreach my $opt (@$comp_opts) {
2521 $combo_compress->append($opt, $opt);
2523 $config_options->{compress} = "on" if !defined($config_options->{compress});
2524 $combo_compress->set_active_id($config_options->{compress});
2525 $combo_compress->signal_connect (changed => sub {
2527 $config_options->{compress} = $w->get_active_text();
2529 push @$labeled_widgets, "compress";
2530 push @$labeled_widgets, $combo_compress;
2532 my $combo_checksum = Gtk3::ComboBoxText->new();
2533 $combo_checksum->set_tooltip_text("zfs checksum algorithm for rpool dataset");
2534 my $csum_opts = ["on", "off","fletcher2", "fletcher4", "sha256"];
2535 foreach my $opt (@$csum_opts) {
2536 $combo_checksum->append($opt, $opt);
2538 $config_options->{checksum} = "on" if !($config_options->{checksum});
2539 $combo_checksum->set_active_id($config_options->{checksum});
2540 $combo_checksum->signal_connect (changed => sub {
2542 $config_options->{checksum} = $w->get_active_text();
2544 push @$labeled_widgets, "checksum";
2545 push @$labeled_widgets, $combo_checksum;
2547 my $spinbutton_copies = Gtk3::SpinButton->new_with_range(1,3,1);
2548 $spinbutton_copies->set_tooltip_text("zfs copies property for rpool dataset (in addition to RAID redundancy!)");
2549 $spinbutton_copies->signal_connect ("value-changed" => sub {
2551 $config_options->{copies} = $w->get_value_as_int();
2553 $config_options->{copies} = 1 if !defined($config_options->{copies});
2554 $spinbutton_copies->set_value($config_options->{copies});
2555 push @$labeled_widgets, "copies", $spinbutton_copies;
2557 return &$create_label_widget_grid($labeled_widgets);;
2560 sub create_hdoption_view {
2562 my $dialog = Gtk3::Dialog->new();
2564 $dialog->set_title("Harddisk options");
2566 $dialog->add_button("_OK", 1);
2568 my $contarea = $dialog->get_content_area();
2570 my $hbox2 = Gtk3::Box->new('horizontal', 0);
2571 $contarea->pack_start($hbox2, 1, 1, 10);
2573 my $grid = Gtk3::Grid->new();
2574 $grid->set_column_spacing(10);
2575 $grid->set_row_spacing(10);
2577 $hbox2->pack_start($grid, 1, 0, 10);
2583 my $label0 = Gtk3::Label->new ("Filesystem");
2584 $label0->set_alignment (1, 0.5);
2585 $grid->attach($label0, 0, $row, 1, 1);
2587 my $fstypecb = Gtk3::ComboBoxText->new();
2589 my $fstype = ['ext3', 'ext4', 'xfs',
2590 'zfs (RAID0)', 'zfs (RAID1)',
2591 'zfs (RAID10)', 'zfs (RAIDZ-1)',
2592 'zfs (RAIDZ-2)', 'zfs (RAIDZ-3)'];
2594 push @$fstype, 'btrfs (RAID0)', 'btrfs (RAID1)', 'btrfs (RAID10)'
2598 foreach my $tmp (@$fstype) {
2599 $fstypecb->append_text($tmp);
2600 $fstypecb->set_active ($tcount)
2601 if $config_options->{filesys} eq $tmp;
2605 $grid->attach($fstypecb, 1, $row, 1, 1);
2611 my $sep = Gtk3::HSeparator->new();
2612 $sep->set_visible(1);
2613 $grid->attach($sep, 0, $row, 2, 1);
2616 my $hdsize_labeled_widgets = [];
2620 if ( -b $target_hd) {
2621 $hdsize = int(hd_size ($target_hd) / (1024*1024.0)); # size in GB
2622 } elsif ($target_hd) {
2623 $hdsize = int((-s $target_hd) / (1024*1024*1024.0));
2626 my $hdsize_size_adj = Gtk3::Adjustment->new($config_options->{hdsize} || $hdsize, 0, $hdsize+1, 1, 1, 1);
2627 my $spinbutton_hdsize = Gtk3::SpinButton->new($hdsize_size_adj, 1, 1);
2628 $spinbutton_hdsize->set_tooltip_text("only use specified size (GB) of the harddisk (rest left unpartitioned)");
2629 push @$hdsize_labeled_widgets, "hdsize", $spinbutton_hdsize;
2631 my $entry_swapsize = Gtk3::Entry->new();
2632 $entry_swapsize->set_tooltip_text("maximum SWAP size (GB)");
2633 $entry_swapsize->signal_connect (key_press_event => \&check_float);
2634 $entry_swapsize->set_text($config_options->{swapsize}) if $config_options->{swapsize};
2635 push @$hdsize_labeled_widgets, "swapsize", $entry_swapsize;
2637 my $entry_maxroot = Gtk3::Entry->new();
2638 $entry_maxroot->set_tooltip_text("maximum size (GB) for LVM root volume");
2639 $entry_maxroot->signal_connect (key_press_event => \&check_float);
2640 $entry_maxroot->set_text($config_options->{maxroot}) if $config_options->{maxroot};
2641 push @$hdsize_labeled_widgets, "maxroot", $entry_maxroot;
2643 my $entry_minfree = Gtk3::Entry->new();
2644 $entry_minfree->set_tooltip_text("minimum free LVM space (GB, required for LVM snapshots)");
2645 $entry_minfree->signal_connect (key_press_event => \&check_float);
2646 $entry_minfree->set_text($config_options->{minfree}) if $config_options->{minfree};
2647 push @$hdsize_labeled_widgets, "minfree", $entry_minfree;
2649 my $entry_maxvz = Gtk3::Entry->new();
2650 $entry_maxvz->set_tooltip_text("maximum size (GB) for LVM data volume");
2651 $entry_maxvz->signal_connect (key_press_event => \&check_float);
2652 $entry_maxvz->set_text($config_options->{maxvz}) if $config_options->{maxvz};
2653 push @$hdsize_labeled_widgets, "maxvz", $entry_maxvz;
2655 my $options_stack = Gtk3::Stack->new();
2656 $options_stack->set_visible(1);
2657 $options_stack->set_hexpand(1);
2658 $options_stack->set_vexpand(1);
2659 $options_stack->add_titled(&$create_raid_disk_grid(), "raiddisk", "Disk Setup");
2660 $options_stack->add_titled(&$create_label_widget_grid($hdsize_labeled_widgets), "hdsize", "Size Options");
2661 $options_stack->add_titled(&$create_raid_advanced_grid("zfs"), "raidzfsadvanced", "Advanced Options");
2662 $options_stack->set_visible_child_name("raiddisk");
2663 my $options_stack_switcher = Gtk3::StackSwitcher->new();
2664 $options_stack_switcher->set_halign('center');
2665 $options_stack_switcher->set_stack($options_stack);
2666 $grid->attach($options_stack_switcher, 0, $row, 2, 1);
2668 $grid->attach($options_stack, 0, $row, 2, 1);
2671 $hdopion_first_setup = 0;
2673 my $switch_view = sub {
2674 my $raid = $config_options->{filesys} =~ m/zfs|btrfs/;
2675 my $enable_zfs_opts = $config_options->{filesys} =~ m/zfs/;
2677 $target_hd_combo->set_visible(!$raid);
2678 $options_stack->get_child_by_name("hdsize")->set_visible(!$raid);
2679 $options_stack->get_child_by_name("raiddisk")->set_visible($raid);
2680 $options_stack_switcher->set_visible($enable_zfs_opts);
2681 $options_stack->get_child_by_name("raidzfsadvanced")->set_visible($enable_zfs_opts);
2683 $target_hd_label->set_text("Target: $config_options->{filesys} ");
2684 $options_stack->set_visible_child_name("raiddisk");
2686 $target_hd_label->set_text("Target Harddisk: ");
2688 my (undef, $pref_width) = $dialog->get_preferred_width();
2689 my (undef, $pref_height) = $dialog->get_preferred_height();
2690 $pref_height = 750 if $pref_height > 750;
2691 $dialog->resize($pref_width, $pref_height);
2696 $fstypecb->signal_connect (changed => sub {
2697 $config_options->{filesys} = $fstypecb->get_active_text();
2705 my $get_float = sub {
2708 my $text = $entry->get_text();
2709 return undef if !defined($text);
2714 return undef if $text !~ m/^\d+(\.\d+)?$/;
2721 if (($tmp = &$get_float($spinbutton_hdsize)) && ($tmp != $hdsize)) {
2722 $config_options->{hdsize} = $tmp;
2724 delete $config_options->{hdsize};
2727 if (defined($tmp = &$get_float($entry_swapsize))) {
2728 $config_options->{swapsize} = $tmp;
2730 delete $config_options->{swapsize};
2733 if (defined($tmp = &$get_float($entry_maxroot))) {
2734 $config_options->{maxroot} = $tmp;
2736 delete $config_options->{maxroot};
2739 if (defined($tmp = &$get_float($entry_minfree))) {
2740 $config_options->{minfree} = $tmp;
2742 delete $config_options->{minfree};
2745 if (defined($tmp = &$get_float($entry_maxvz))) {
2746 $config_options->{maxvz} = $tmp;
2748 delete $config_options->{maxvz};
2754 my $get_raid_devlist = sub {
2756 my $dev_name_hash = {};
2759 for (my $i = 0; $i < @$hds; $i++) {
2760 if (my $hd = $config_options->{"disksel$i"}) {
2761 my ($disk, $devname, $size, $model) = @$hd;
2762 die "device '$devname' is used more than once\n"
2763 if $dev_name_hash->{$devname};
2764 $dev_name_hash->{$devname} = $hd;
2765 push @$devlist, $hd;
2772 sub zfs_mirror_size_check {
2773 my ($expected, $actual) = @_;
2775 die "mirrored disks must have same size\n"
2776 if abs($expected - $actual) > $expected / 10;
2779 sub get_zfs_raid_setup {
2781 my $filesys = $config_options->{filesys};
2783 my $devlist = &$get_raid_devlist();
2785 my $diskcount = scalar(@$devlist);
2786 die "$filesys needs at least one device\n" if $diskcount < 1;
2788 my $bootdevlist = [];
2791 if ($filesys eq 'zfs (RAID0)') {
2792 push @$bootdevlist, @$devlist[0];
2793 foreach my $hd (@$devlist) {
2796 } elsif ($filesys eq 'zfs (RAID1)') {
2797 die "zfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
2799 my $hd = @$devlist[0];
2800 my $expected_size = @$hd[2]; # all disks need approximately same size
2801 foreach $hd (@$devlist) {
2802 zfs_mirror_size_check($expected_size, @$hd[2]);
2804 push @$bootdevlist, $hd;
2806 } elsif ($filesys eq 'zfs (RAID10)') {
2807 die "zfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
2808 die "zfs (RAID10) needs an even number of devices\n" if $diskcount & 1;
2810 push @$bootdevlist, @$devlist[0], @$devlist[1];
2812 for (my $i = 0; $i < $diskcount; $i+=2) {
2813 my $hd1 = @$devlist[$i];
2814 my $hd2 = @$devlist[$i+1];
2815 zfs_mirror_size_check(@$hd1[2], @$hd2[2]); # pairs need approximately same size
2816 $cmd .= ' mirror ' . @$hd1[1] . ' ' . @$hd2[1];
2819 } elsif ($filesys =~ m/^zfs \(RAIDZ-([123])\)$/) {
2821 my $mindisks = 2 + $level;
2822 die "zfs (RAIDZ-$level) needs at least $mindisks devices\n" if scalar(@$devlist) < $mindisks;
2823 my $hd = @$devlist[0];
2824 my $expected_size = @$hd[2]; # all disks need approximately same size
2825 $cmd .= " raidz$level";
2826 foreach $hd (@$devlist) {
2827 zfs_mirror_size_check($expected_size, @$hd[2]);
2829 push @$bootdevlist, $hd;
2832 die "unknown zfs mode '$filesys'\n";
2835 return ($devlist, $bootdevlist, $cmd);
2838 sub get_btrfs_raid_setup {
2840 my $filesys = $config_options->{filesys};
2842 my $devlist = &$get_raid_devlist();
2844 my $diskcount = scalar(@$devlist);
2845 die "$filesys needs at least one device\n" if $diskcount < 1;
2849 if ($diskcount == 1) {
2852 if ($filesys eq 'btrfs (RAID0)') {
2854 } elsif ($filesys eq 'btrfs (RAID1)') {
2855 die "btrfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
2857 } elsif ($filesys eq 'btrfs (RAID10)') {
2858 die "btrfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
2861 die "unknown btrfs mode '$filesys'\n";
2865 return ($devlist, $mode);
2868 sub create_hdsel_view {
2872 my $vbox = Gtk3::VBox->new (0, 0);
2873 $inbox->pack_start ($vbox, 1, 0, 0);
2874 my $hbox = Gtk3::HBox->new (0, 0);
2875 $vbox->pack_start ($hbox, 0, 0, 10);
2877 my ($disk, $devname, $size, $model) = @{@$hds[0]};
2878 $target_hd = $devname;
2880 $target_hd_label = Gtk3::Label->new ("Target Harddisk: ");
2881 $hbox->pack_start ($target_hd_label, 0, 0, 0);
2883 $target_hd_combo = Gtk3::ComboBoxText->new();
2885 foreach my $hd (@$hds) {
2886 ($disk, $devname, $size, $model) = @$hd;
2887 $target_hd_combo->append_text (get_device_desc ($devname, $size, $model));
2890 $target_hd_combo->set_active (0);
2891 $target_hd_combo->signal_connect (changed => sub {
2892 $a = shift->get_active;
2893 my ($disk, $devname) = @{@$hds[$a]};
2894 $target_hd = $devname;
2897 $hbox->pack_start ($target_hd_combo, 0, 0, 10);
2899 my $options = Gtk3::Button->new ('_Options');
2900 $options->signal_connect (clicked => \&create_hdoption_view);
2901 $hbox->pack_start ($options, 0, 0, 0);
2906 display_html ("page1.htm");
2908 set_next (undef, sub {
2910 if ($config_options->{filesys} =~ m/zfs/) {
2911 eval { get_zfs_raid_setup(); };
2913 display_message ("Warning: $err\n" .
2914 "Please fix ZFS setup first.");
2916 create_country_view();
2918 } elsif ($config_options->{filesys} =~ m/btrfs/) {
2919 eval { get_btrfs_raid_setup(); };
2921 display_message ("Warning: $err\n" .
2922 "Please fix BTRFS setup first.");
2924 create_country_view();
2927 create_country_view();
2932 sub create_extract_view {
2936 display_html ("extract1-license.htm");
2937 $next->set_sensitive (0);
2939 my $vbox = Gtk3::VBox->new (0, 0);
2940 $inbox->pack_start ($vbox, 1, 0, 0);
2941 my $hbox = Gtk3::HBox->new (0, 0);
2942 $vbox->pack_start ($hbox, 0, 0, 10);
2944 my $vbox2 = Gtk3::VBox->new (0, 0);
2945 $hbox->pack_start ($vbox2, 0, 0, 0);
2947 $progress_status = Gtk3::Label->new ('');
2948 $vbox2->pack_start ($progress_status, 1, 1, 0);
2950 $progress = Gtk3::ProgressBar->new;
2951 $progress->set_show_text(1);
2952 $progress->set_size_request (600, -1);
2954 $vbox2->pack_start ($progress, 0, 0, 0);
2958 my $tdir = $opt_testmode ? "target" : "/target";
2960 my $base = $opt_testmode ? "../pve-cd-builder/base.squashfs" : "/cdrom/$setup->{product}-base.squashfs";
2962 eval { extract_data ($base, $tdir); };
2965 $next->set_sensitive (1);
2967 set_next ("_Reboot", sub { exit (0); } );
2970 display_html ("fail.htm");
2971 display_error ($err);
2974 display_html ("success.htm");
2978 sub create_intro_view {
2983 my $cpuinfo = file_get_contents('/proc/cpuinfo');
2984 if ($cpuinfo && !($cpuinfo =~ /^flags\s*:.*(vmx|svm)/m)) {
2985 display_error("No support for KVM virtualisation detected.\n\n" .
2986 "Check BIOS settings for Intel VT / AMD-V / SVM.")
2990 display_html ("license.htm");
2992 set_next ("I a_gree", \&create_hdsel_view);
2995 $ipconf = get_ip_config ();
2997 $country = detect_country() if $ipconf->{default} || $opt_testmode;
2999 # read country, kmap and timezone infos
3000 $cmap = read_cmap ();
3002 if (!defined($cmap->{country}->{$country})) {
3003 print $logfd "ignoring detected country '$country', invalid or unknown\n";
3007 create_main_window ();
3009 my $initial_error = 0;
3011 if (!defined ($hds) || (scalar (@$hds) <= 0)) {
3012 print "no hardisks found\n";
3014 display_html ("nohds.htm");
3015 set_next ("Reboot", sub { exit (0); } );
3017 foreach my $hd (@$hds) {
3018 my ($disk, $devname) = @$hd;
3019 next if $devname =~ m|^/dev/md\d+$|;
3020 print "found Disk$disk N:$devname\n";
3024 if (!$initial_error && (scalar keys %{ $ipconf->{ifaces} } == 0)) {
3025 print "no network interfaces found\n";
3027 display_html ("nonics.htm");
3028 set_next ("Reboot", sub { exit (0); } );
3031 create_intro_view () if !$initial_error;