]>
git.proxmox.com Git - pve-installer.git/blob - proxinstall
3 $ENV{DEBIAN_FRONTEND
} = 'noninteractive';
18 use String
::ShellQuote
;
23 use ProxmoxInstallerSetup
;
25 my $setup = ProxmoxInstallerSetup
::setup
();
29 if (!$ENV{G_SLICE
} || $ENV{G_SLICE
} ne "always-malloc") {
30 die "do not use slice allocator (run with 'G_SLICE=always-malloc ./proxinstall ...')\n";
33 if (!GetOptions
('testmode=s' => \
$opt_testmode)) {
38 my $zfstestpool = "test_rpool";
39 my $zfspoolname = $opt_testmode ?
$zfstestpool : 'rpool';
40 my $zfsrootvolname = "$setup->{product}-1";
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
75 my $storage_cfg_local = <<__EOD__;
78 content iso,vztmpl,backup,rootdir,images
81 sub file_read_firstline
{
84 my $fh = IO
::File-
>new ($filename, "r");
92 my $logfd = IO
::File-
>new (">/tmp/install.log");
94 my $proxmox_libdir = $opt_testmode ?
95 Cwd
::cwd
() . "/testdir/var/lib/pve-installer" : "/var/lib/pve-installer";
96 my $proxmox_cddir = $opt_testmode ?
"../pve-cd-builder/tmp/data-gz/" : "/cdrom";
97 my $proxmox_pkgdir = "${proxmox_cddir}/proxmox/packages/";
99 my $grub_plattform = "pc"; # pc, efi-amd64 or efi-ia32
101 $grub_plattform = "efi-amd64" if -d
"/sys/firmware/efi";
103 my $IPV4OCTET = "(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9])?[0-9])";
104 my $IPV4RE = "(?:(?:$IPV4OCTET\\.){3}$IPV4OCTET)";
105 my $IPV6H16 = "(?:[0-9a-fA-F]{1,4})";
106 my $IPV6LS32 = "(?:(?:$IPV4RE|$IPV6H16:$IPV6H16))";
109 "(?:(?:" . "(?:$IPV6H16:){6})$IPV6LS32)|" .
110 "(?:(?:" . "::(?:$IPV6H16:){5})$IPV6LS32)|" .
111 "(?:(?:(?:" . "$IPV6H16)?::(?:$IPV6H16:){4})$IPV6LS32)|" .
112 "(?:(?:(?:(?:$IPV6H16:){0,1}$IPV6H16)?::(?:$IPV6H16:){3})$IPV6LS32)|" .
113 "(?:(?:(?:(?:$IPV6H16:){0,2}$IPV6H16)?::(?:$IPV6H16:){2})$IPV6LS32)|" .
114 "(?:(?:(?:(?:$IPV6H16:){0,3}$IPV6H16)?::(?:$IPV6H16:){1})$IPV6LS32)|" .
115 "(?:(?:(?:(?:$IPV6H16:){0,4}$IPV6H16)?::" . ")$IPV6LS32)|" .
116 "(?:(?:(?:(?:$IPV6H16:){0,5}$IPV6H16)?::" . ")$IPV6H16)|" .
117 "(?:(?:(?:(?:$IPV6H16:){0,6}$IPV6H16)?::" . ")))";
119 my $IPRE = "(?:$IPV4RE|$IPV6RE)";
122 my $ipv4_mask_hash = {
139 '255.255.128.0' => 17,
140 '255.255.192.0' => 18,
141 '255.255.224.0' => 19,
142 '255.255.240.0' => 20,
143 '255.255.248.0' => 21,
144 '255.255.252.0' => 22,
145 '255.255.254.0' => 23,
146 '255.255.255.0' => 24,
147 '255.255.255.128' => 25,
148 '255.255.255.192' => 26,
149 '255.255.255.224' => 27,
150 '255.255.255.240' => 28,
151 '255.255.255.248' => 29,
152 '255.255.255.252' => 30,
153 '255.255.255.254' => 31,
154 '255.255.255.255' => 32
157 my $ipv4_reverse_mask = [
193 my ($window, $cmdbox, $inbox, $htmlview);
194 my ($next, $next_fctn, $target_hd);
195 my ($progress, $progress_status);
196 my ($ipversion, $ipaddress, $ipconf_entry_addr);
197 my ($netmask, $ipconf_entry_mask);
198 my ($gateway, $ipconf_entry_gw);
199 my ($dnsserver, $ipconf_entry_dns);
200 my $hostname = 'proxmox';
201 my $domain = 'domain.tld';
202 my $cmdline = file_read_firstline
("/proc/cmdline");
205 my $timezone = 'Europe/Vienna';
208 my $keymap = 'en-us';
211 # parse command line args
213 my $config_options = {};
215 if ($cmdline =~ m/\s(ext3|ext4|xfs)(\s.*)?$/) {
216 $config_options->{filesys
} = $1;
218 $config_options->{filesys
} = 'ext4';
221 if ($cmdline =~ m/hdsize=(\d+(\.\d+)?)[\s\n]/i) {
222 $config_options->{hdsize
} = $1;
225 if ($cmdline =~ m/swapsize=(\d+(\.\d+)?)[\s\n]/i) {
226 $config_options->{swapsize
} = $1;
229 if ($cmdline =~ m/maxroot=(\d+(\.\d+)?)[\s\n]/i) {
230 $config_options->{maxroot
} = $1;
233 if ($cmdline =~ m/minfree=(\d+(\.\d+)?)[\s\n]/i) {
234 $config_options->{minfree
} = $1;
237 if ($setup->{product
} eq 'pve') {
238 if ($cmdline =~ m/maxvz=(\d+(\.\d+)?)[\s\n]/i) {
239 $config_options->{maxvz
} = $1;
243 my $postfix_main_cf = <<_EOD;
244 # See /usr/share/postfix/main.cf.dist for a commented, more complete version
248 smtpd_banner = \$myhostname ESMTP \$mail_name (Debian/GNU)
251 # appending .domain is the MUA's job.
252 append_dot_mydomain = no
254 # Uncomment the next line to generate "delayed mail" warnings
255 #delay_warning_time = 4h
257 alias_maps = hash:/etc/aliases
258 alias_database = hash:/etc/aliases
259 mydestination = \$myhostname, localhost.\$mydomain, localhost
261 mynetworks = 127.0.0.0/8
262 inet_interfaces = loopback-only
263 recipient_delimiter = +
270 return String
::ShellQuote
::shell_quote
($str);
276 die "no arguments" if !$cmd;
278 return $cmd if !ref($cmd);
281 foreach my $arg (@$cmd) { push @qa, shellquote
($arg); }
283 return join (' ', @qa);
289 return run_command
($cmd, undef, undef, 1);
293 my ($cmd, $func, $input, $noout) = @_;
299 # see 'man bash' for option pipefail
300 $cmd = [ '/bin/bash', '-c', "set -o pipefail && $cmd" ];
305 $cmdstr = cmd2string
($cmd);
309 if ($input && ($cmdstr !~ m/chpasswd/)) {
310 $cmdtxt = "# $cmdstr <<EOD\n$input";
312 $cmdtxt .= "\nEOD\n";
314 $cmdtxt = "# $cmdstr\n";
322 print $logfd $cmdtxt;
324 my $reader = IO
::File-
>new();
325 my $writer = IO
::File-
>new();
326 my $error = IO
::File-
>new();
332 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
338 if ($orig_pid != $$) {
345 print $writer $input if defined $input;
348 my $select = new IO
::Select
;
349 $select->add ($reader);
350 $select->add ($error);
352 my ($ostream, $logout) = ('', '', '');
354 while ($select->count) {
355 my @handles = $select->can_read (0.2);
357 Gtk3
::main_iteration
() while Gtk3
::events_pending
();
359 next if !scalar (@handles); # timeout
361 foreach my $h (@handles) {
363 my $count = sysread ($h, $buf, 4096);
364 if (!defined ($count)) {
368 die "command '$cmd' failed: $err";
370 $select->remove ($h) if !$count;
372 $ostream .= $buf if !($noout || $func);
374 while ($logout =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
376 &$func($line) if $func;
379 } elsif ($h eq $error) {
380 $ostream .= $buf if !($noout || $func);
388 &$func($logout) if $func;
390 my $rv = waitpid ($pid, 0);
392 return $? if $noout; # behave like standard system();
395 die "command '$cmdstr' failed to execute\n";
396 } elsif (my $sig = ($? & 127)) {
397 die "command '$cmdstr' failed - got signal $sig\n";
398 } elsif (my $exitcode = ($? >> 8)) {
399 die "command '$cmdstr' failed with exit code $exitcode";
407 print "trying to detect country...\n";
408 my $cpid = open2
(\
*TMP
, undef, "traceroute -N 1 -q 1 -n 8.8.8.8");
409 return undef if !$cpid;
413 my $previous_alarm = alarm (10);
415 local $SIG{ALRM
} = sub { die "timed out!\n" };
417 while (defined ($line = <TMP
>)) {
418 print $logfd "DC TRACEROUTE: $line";
419 if ($line =~ m/\s*\d+\s+(\d+\.\d+\.\d+\.\d+)\s/) {
420 my $geoip = `geoiplookup $1`;
421 print $logfd "DC GEOIP: $geoip";
422 if ($geoip =~ m/GeoIP Country Edition:\s*([A-Z]+),/) {
424 print $logfd "DC FOUND: $country\n";
433 alarm ($previous_alarm);
438 print "unable to detect country - $err\n";
440 print "detected country: " . uc($country) . "\n";
442 print "unable to detect country\n";
450 open (MEMINFO, "/proc/meminfo");
452 my $res = 512; # default to 512 if something goes wrong
453 while (my $line = <MEMINFO>) {
454 if ($line =~ m/^MemTotal:\s+(\d+)\s*kB/i) {
455 $res = int ($1 / 1024);
464 my $total_memory = get_memtotal();
467 my ($src, $dest) = @_;
469 my ($dev1,$ino1) = stat ($src);
470 my ($dev2,$ino2) = stat ($dest);
472 return 0 if !($dev1 && $dev2 && $ino1 && $ino2);
474 return $ino1 == $ino2 && $dev1 == $dev2;
477 sub find_stable_path {
478 my ($stabledir, $bdev) = @_;
480 foreach my $path (<$stabledir/*>) {
481 if (link_points_to ($path, $bdev)) {
482 return wantarray ? ($path, basename($path)) : $path;
487 sub find_dev_by_uuid {
490 my ($full_path, $name) = find_stable_path ("/dev/disk/by-uuid", $bdev);
500 push @$res, [-1, $opt_testmode, int((-s $opt_testmode)/512), "TESTDISK"];
506 foreach my $bd (</sys/block/*>) {
507 next if $bd =~ m|^/sys/block/ram\d+$|;
508 next if $bd =~ m|^/sys/block/loop\d+$|;
509 next if $bd =~ m|^/sys/block/md\d+$|;
510 next if $bd =~ m|^/sys/block/dm-.*$|;
511 next if $bd =~ m|^/sys/block/fd\d+$|;
512 next if $bd =~ m|^/sys/block/sr\d+$|;
514 my $dev = file_read_firstline("$bd/dev");
519 my $info = `udevadm info
--path
$bd --query all
`;
522 next if $info !~ m/^E: DEVTYPE=disk$/m;
524 next if $info =~ m/^E: ID_CDROM/m;
526 my ($name) = $info =~ m/^N: (\S+)$/m;
529 my $real_name = "/dev/$name";
531 my $size = file_read_firstline("$bd/size");
533 $size = undef if !($size && $size =~ m/^\d+$/);
535 my $model = file_read_firstline("$bd/device/model") || '';
538 if (length ($model) > 30) {
539 $model = substr ($model, 0, 30);
541 push @$res, [$count++, $real_name, $size, $model] if $size;
543 print STDERR "ERROR: unable to map device $dev ($bd)\n";
551 my $countryfn = "${proxmox_libdir}/country.dat";
552 open (TMP, "<$countryfn") || die "unable to open '$countryfn' - $!\n";
555 my $countryhash = {};
558 while (defined ($line = <TMP>)) {
559 if ($line =~ m|^map:([^\s:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]*):$|) {
567 $kmaphash->{$2} = $1;
568 } elsif ($line =~ m|^([a-z]{2}):([^:]+):([^:]*):([^:]*):$|) {
574 $countryhash->{lc($2)} = $1;
576 warn "unable to parse 'country.dat' line: $line";
583 my $zonefn = "/usr/share/zoneinfo/zone.tab";
584 open (TMP, "<$zonefn") || die "unable to open '$zonefn' - $!\n";
585 while (defined ($line = <TMP>)) {
586 next if $line =~ m/^\#/;
587 next if $line =~ m/^\s*$/;
588 if ($line =~ m|^([A-Z][A-Z])\s+\S+\s+(([^/]+)/\S+)\s|) {
590 $cczones->{$cc}->{$2} = 1;
591 $country->{$cc}->{zone} = $2 if !defined ($country->{$cc}->{zone});
602 countryhash => $countryhash,
604 kmaphash => $kmaphash,
608 # search for Harddisks
609 my $hds = hd_list ();
614 foreach my $hd (@$hds) {
615 my ($disk, $devname, $size, $model) = @$hd;
616 # size is always in 512B "sectors"! convert to KB
617 return int($size/2) if $devname eq $dev;
620 die "no such device '$dev'\n";
623 sub get_partition_dev {
624 my ($dev, $partnum) = @_;
626 if ($dev =~ m|^/dev/sd([a-h]?[a-z]\|i[a-v])$|) {
627 return "${dev}$partnum";
628 } elsif ($dev =~ m|^/dev/[hxev]d[a-z]$|) {
629 return "${dev}$partnum";
630 } elsif ($dev =~ m|^/dev/[^/]+/c\d+d\d+$|) {
631 return "${dev}p$partnum";
632 } elsif ($dev =~ m|^/dev/[^/]+/d\d+$|) {
633 return "${dev}p$partnum";
634 } elsif ($dev =~ m|^/dev/[^/]+/hd[a-z]$|) {
635 return "${dev}$partnum";
636 } elsif ($dev =~ m|^/dev/nvme\d+n\d+$|) {
637 return "${dev}p$partnum";
639 die "unable to get device for partition $partnum on device $dev\n";
644 sub file_get_contents {
645 my ($filename, $max) = @_;
647 my $fh = IO::File->new($filename, "r") ||
648 die "can't open '$filename' - $!\n";
650 local $/; # slurp mode
660 my ($text, $filename) = @_;
662 my $fd = IO::File->new (">$filename") ||
663 die "unable to open file '$filename' - $!\n";
668 sub update_progress {
669 my ($frac, $start, $end, $text) = @_;
671 my $part = $end - $start;
672 my $res = $start + $frac*$part;
674 $progress->set_fraction ($res);
675 $progress->set_text (sprintf ("%d%%", int ($res*100)));
676 $progress_status->set_text ($text) if defined ($text);
678 display_info() if $res < 0.9;
680 Gtk3::main_iteration() while Gtk3::events_pending();
685 mkfs => 'mkfs.ext3 -F',
687 mkfs_data_opt => '-m 0',
688 root_mountopt => 'errors=remount-ro',
691 mkfs => 'mkfs.ext4 -F',
693 mkfs_data_opt => '-m 0',
694 root_mountopt => 'errors=remount-ro',
697 mkfs => 'mkfs.xfs -f',
704 sub create_filesystem {
705 my ($dev, $name, $type, $start, $end, $fs, $fe) = @_;
707 my $range = $end - $start;
708 my $rs = $start + $range*$fs;
709 my $re = $start + $range*$fe;
712 my $fsdata = $fssetup->{$type} || die "internal error - unknown file system '$type'";
713 my $opts = $name eq 'root' ? $fsdata->{mkfs_root_opt} : $fsdata->{mkfs_data_opt};
715 update_progress (0, $rs, $re, "creating $name filesystem");
717 run_command ("$fsdata->{mkfs} $opts $dev", sub {
720 if ($line =~ m/Writing inode tables:\s+(\d+)\/(\d+)/) {
722 } elsif ($max && $line =~ m/(\d+)\/$max/) {
723 update_progress (($1/$max)*0.9, $rs, $re);
724 } elsif ($line =~ m/Creating journal.*done/) {
725 update_progress (0.95, $rs, $re);
726 } elsif ($line =~ m/Writing superblocks and filesystem.*done/) {
727 update_progress (1, $rs, $re);
733 my ($targetdir, $dcdata) = @_;
735 my $cfgfile = "/tmp/debconf.txt";
736 write_config ($dcdata, "$targetdir/$cfgfile");
737 syscmd ("chroot $targetdir debconf-set-selections $cfgfile");
738 unlink "$targetdir/$cfgfile";
742 my ($targetdir, $cmd, $new_cmd) = @_;
744 syscmd ("chroot $targetdir dpkg-divert --package proxmox " .
745 "--add --rename $cmd") == 0 ||
746 die "unable to exec dpkg-divert\n";
748 syscmd ("ln -sf ${new_cmd} $targetdir/$cmd") == 0 ||
749 die "unable to link diversion to ${new_cmd}\n";
752 sub diversion_remove {
753 my ($targetdir, $cmd) = @_;
755 syscmd ("mv $targetdir/${cmd}.distrib $targetdir/${cmd};") == 0 ||
756 die "unable to remove $cmd diversion\n";
758 syscmd ("chroot $targetdir dpkg-divert --remove $cmd") == 0 ||
759 die "unable to remove $cmd diversion\n";
763 my ($partitions, $mode) = @_;
765 die "unknown btrfs mode '$mode'"
766 if !($mode eq 'single' || $mode eq 'raid0' ||
767 $mode eq 'raid1' || $mode eq 'raid10');
769 my $cmd = ['mkfs.btrfs', '-f'];
771 push @$cmd, '-d', $mode, '-m', $mode;
773 push @$cmd, @$partitions;
778 sub zfs_create_rpool {
781 my $cmd = "zpool create -f -o cachefile=none";
783 $cmd .= " -o ashift=$config_options->{ashift}"
784 if defined($config_options->{ashift});
786 syscmd ("$cmd $zfspoolname $vdev") == 0 ||
787 die "unable to create zfs root pool\n";
789 syscmd ("zfs create $zfspoolname/ROOT") == 0 ||
790 die "unable to create zfs $zfspoolname/ROOT volume\n";
792 if ($setup->{product} eq 'pve') {
793 syscmd ("zfs create $zfspoolname/data") == 0 ||
794 die "unable to create zfs $zfspoolname/data volume\n";
797 syscmd ("zfs create $zfspoolname/ROOT/$zfsrootvolname") == 0 ||
798 die "unable to create zfs $zfspoolname/ROOT/$zfsrootvolname volume\n";
800 # disable atime during install
801 syscmd ("zfs set atime=off $zfspoolname") == 0 ||
802 die "unable to set zfs properties\n";
804 my $value = $config_options->{compress};
805 syscmd ("zfs set compression=$value $zfspoolname")
806 if defined($value) && $value ne 'off';
808 $value = $config_options->{checksum};
809 syscmd ("zfs set checksum=$value $zfspoolname")
810 if defined($value) && $value ne 'on';
812 $value = $config_options->{copies};
813 syscmd ("zfs set copies=$value $zfspoolname")
814 if defined($value) && $value != 1;
817 my $udevadm_trigger_block = sub {
820 sleep(1) if !$nowait; # give kernel time to reread part table
822 # trigger udev to create /dev/disk/by-uuid
823 syscmd ("udevadm trigger --subsystem-match block");
824 syscmd ("udevadm settle --timeout 10");
827 my $clean_disk = sub {
830 my $partitions = `lsblk
--output kname
--noheadings
--path
--list
$disk`;
831 foreach my $part (split "\n", $partitions) {
832 next if $part eq $disk;
833 next if $part !~ /^\Q$disk\E/;
834 eval { syscmd
("pvremove -ff -y $part"); };
835 eval { syscmd
("dd if=/dev/zero of=$part bs=1M count=16"); };
839 sub partition_bootable_disk
{
840 my ($target_dev, $maxhdsizegb, $ptype) = @_;
842 die "too dangerous" if $opt_testmode;
844 die "unknown partition type '$ptype'"
845 if !($ptype eq '8E00' || $ptype eq '8300' || $ptype eq 'BF01');
847 syscmd
("sgdisk -Z ${target_dev}");
848 my $hdsize = hd_size
($target_dev); # size in KB (1024 bytes)
850 my $restricted_hdsize_mb = 0; # 0 ==> end of partition
852 my $maxhdsize = $maxhdsizegb * 1024 * 1024;
853 if ($maxhdsize < $hdsize) {
854 $hdsize = $maxhdsize;
855 $restricted_hdsize_mb = int($hdsize/1024) . 'M';
859 my $hdgb = int($hdsize/(1024*1024));
860 die "hardisk '$target_dev' too small (${hdgb}GB)\n" if $hdgb < 8;
862 # 1 - BIOS boot partition (Grub Stage2): first free 1M
863 # 2 - EFI ESP: next free 512M
864 # 3 - OS/Data partition: rest, up to $maxhdsize in MB
866 my $grubbootdev = get_partition_dev
($target_dev, 1);
867 my $efibootdev = get_partition_dev
($target_dev, 2);
868 my $osdev = get_partition_dev
($target_dev, 3);
870 my $pcmd = ['sgdisk'];
873 push @$pcmd, "-n${pnum}:1M:+512M", "-t$pnum:EF00";
876 push @$pcmd, "-n${pnum}:513M:${restricted_hdsize_mb}", "-t$pnum:$ptype";
878 push @$pcmd, $target_dev;
880 my $os_size = $hdsize - 513*1024; # 512M efi + 1M bios_boot + 1M alignment
882 syscmd
($pcmd) == 0 ||
883 die "unable to partition harddisk '${target_dev}'\n";
886 $pcmd = ['sgdisk', '-a1', "-n$pnum:34:2047", "-t$pnum:EF02" , $target_dev];
888 syscmd
($pcmd) == 0 ||
889 die "unable to create bios_boot partition '${target_dev}'\n";
891 &$udevadm_trigger_block();
893 foreach my $part ($efibootdev, $osdev) {
894 syscmd
("dd if=/dev/zero of=$part bs=1M count=256") if -b
$part;
897 return ($os_size, $osdev, $efibootdev);
900 sub create_lvm_volumes
{
901 my ($lvmdev, $os_size, $swap_size) = @_;
903 my $vgname = $setup->{product
};
905 my $rootdev = "/dev/$vgname/root";
906 my $datadev = "/dev/$vgname/data";
909 # we use --metadatasize 250k, which results in "pe_start = 512"
910 # so pe_start is aligned on a 128k boundary (advantage for SSDs)
911 syscmd
("/sbin/pvcreate --metadatasize 250k -y -ff $lvmdev") == 0 ||
912 die "unable to initialize physical volume $lvmdev\n";
913 syscmd
("/sbin/vgcreate $vgname $lvmdev") == 0 ||
914 die "unable to create volume group '$vgname'\n";
916 my $hdgb = int($os_size/(1024*1024));
917 my $space = (($hdgb > 128) ?
16 : ($hdgb/8))*1024*1024;
922 if ($setup->{product
} eq 'pve') {
925 if ($config_options->{maxroot
}) {
926 $maxroot = $config_options->{maxroot
};
931 $rootsize = (($hdgb > ($maxroot*4)) ?
$maxroot : $hdgb/4)*1024*1024;
933 my $rest = $os_size - $swap_size - $rootsize; # in KB
936 if (defined($config_options->{minfree
})) {
937 $minfree = (($config_options->{minfree
}*1024*1024) >= $rest ) ?
$space :
938 $config_options->{minfree
}*1024*1024 ;
943 $rest = $rest - $minfree;
945 if (defined($config_options->{maxvz
})) {
946 $rest = (($config_options->{maxvz
}*1024*1024) <= $rest) ?
947 $config_options->{maxvz
}*1024*1024 : $rest;
953 my $minfree = defined($config_options->{minfree
}) ?
$config_options->{minfree
}*1024*1024 : $space;
954 $rootsize = $os_size - $minfree - $swap_size; # in KB
958 syscmd
("/sbin/lvcreate -L${swap_size}K -nswap $vgname") == 0 ||
959 die "unable to create swap volume\n";
961 $swapfile = "/dev/$vgname/swap";
964 syscmd
("/sbin/lvcreate -L${rootsize}K -nroot $vgname") == 0 ||
965 die "unable to create root volume\n";
967 if ($datasize > 4*1024*1024) {
968 my $metadatasize = $datasize/100; # default 1% of data
969 $metadatasize = 1024*1024 if $metadatasize < 1024*1024; # but at least 1G
970 $metadatasize = 16*1024*1024 if $metadatasize > 16*1024*1024; # but at most 16G
972 # otherwise the metadata is taken out of $minfree
973 $datasize -= 2*$metadatasize;
975 # 1 4MB PE to allow for rounding
978 syscmd
("/sbin/lvcreate -L${datasize}K -ndata $vgname") == 0 ||
979 die "unable to create data volume\n";
981 syscmd
("/sbin/lvconvert --yes --type thin-pool --poolmetadatasize ${metadatasize}K $vgname/data") == 0 ||
982 die "unable to create data thin-pool\n";
987 syscmd
("/sbin/vgchange -a y $vgname") == 0 ||
988 die "unable to activate volume group\n";
990 return ($rootdev, $swapfile, $datadev);
993 sub compute_swapsize
{
996 my $hdgb = int($hdsize/(1024*1024));
999 if (defined($config_options->{swapsize
})) {
1000 $swapsize = $config_options->{swapsize
}*1024*1024;
1002 my $ss = int ($total_memory / 1024);
1004 $ss = ($hdgb/8) if $ss > ($hdgb/8);
1006 $swapsize = $ss*1024*1024;
1014 my ($basefile, $targetdir) = @_;
1016 die "target '$targetdir' does not exist\n" if ! -d
$targetdir;
1018 my $starttime = [Time
::HiRes
::gettimeofday
];
1020 my $bootdevinfo = [];
1029 my $filesys = $config_options->{filesys
};
1031 if ($filesys =~ m/zfs/) {
1032 $target_hd = undef; # do not use this config
1034 $targetdir = "/$zfspoolname/ROOT/$zfsrootvolname";
1035 } elsif ($filesys =~ m/btrfs/) {
1036 $target_hd = undef; # do not use this config
1042 for ($i = 5; $i > 0; $i--) {
1043 syscmd
("modprobe zfs");
1044 last if -c
"/dev/zfs";
1048 die "unable to load zfs kernel module\n" if !$i;
1056 update_progress
(0, 0, $maxper, "create partitions");
1058 syscmd
("vgchange -an") if !$opt_testmode; # deactivate all detected VGs
1060 if ($opt_testmode) {
1062 $rootdev = abs_path
($opt_testmode);
1063 syscmd
("umount $rootdev");
1067 die "unsupported btrfs mode (for testing environment)\n"
1068 if $filesys ne 'btrfs (RAID0)';
1070 btrfs_create
([$rootdev], 'single');
1072 } elsif ($use_zfs) {
1074 die "unsupported zfs mode (for testing environment)\n"
1075 if $filesys ne 'zfs (RAID0)';
1077 syscmd
("zpool destroy $zfstestpool");
1079 zfs_create_rpool
($rootdev);
1086 } elsif ($use_btrfs) {
1088 my ($devlist, $btrfs_mode) = get_btrfs_raid_setup
();
1089 my $btrfs_partitions = [];
1091 foreach my $hd (@$devlist) {
1092 my $devname = @$hd[1];
1093 &$clean_disk($devname);
1094 my ($size, $osdev, $efidev) =
1095 partition_bootable_disk
($devname, undef, '8300');
1096 $rootdev = $osdev if !defined($rootdev); # simply point to first disk
1097 my $by_id = find_stable_path
("/dev/disk/by-id", $devname);
1098 push @$bootdevinfo, { esp
=> $efidev, devname
=> $devname,
1099 osdev
=> $osdev, by_id
=> $by_id };
1100 push @$btrfs_partitions, $osdev;
1104 &$udevadm_trigger_block();
1106 btrfs_create
($btrfs_partitions, $btrfs_mode);
1108 } elsif ($use_zfs) {
1110 my ($devlist, $bootdevlist, $vdev) = get_zfs_raid_setup
();
1113 foreach my $hd (@$devlist) {
1114 &$clean_disk(@$hd[1]);
1116 foreach my $hd (@$bootdevlist) {
1117 my $devname = @$hd[1];
1119 my ($size, $osdev) =
1120 partition_bootable_disk
($devname, $config_options->{hdsize
}, 'BF01');
1121 zfs_mirror_size_check
($disksize, $size) if $disksize;
1122 push @$bootdevinfo, { devname
=> $devname, osdev
=> $osdev};
1126 &$udevadm_trigger_block();
1128 foreach my $di (@$bootdevinfo) {
1129 my $devname = $di->{devname
};
1130 $di->{by_id
} = find_stable_path
("/dev/disk/by-id", $devname);
1132 # Note: using /dev/disk/by-id/ does not work for unknown reason, we get
1133 # cannot create 'rpool': no such pool or dataset
1134 #my $osdev = find_stable_path ("/dev/disk/by-id", $di->{osdev}) || $di->{osdev};
1136 my $osdev = $di->{osdev
};
1137 $vdev =~ s/ $devname/ $osdev/;
1140 zfs_create_rpool
($vdev);
1144 die "target '$target_hd' is not a valid block device\n" if ! -b
$target_hd;
1146 &$clean_disk($target_hd);
1148 my ($os_size, $osdev, $efidev);
1149 ($os_size, $osdev, $efidev) =
1150 partition_bootable_disk
($target_hd, $config_options->{hdsize
}, '8E00');
1152 &$udevadm_trigger_block();
1154 my $by_id = find_stable_path
("/dev/disk/by-id", $target_hd);
1155 push @$bootdevinfo, { esp
=> $efidev, devname
=> $target_hd,
1156 osdev
=> $osdev, by_id
=> $by_id };
1158 my $swap_size = compute_swapsize
($os_size);
1159 ($rootdev, $swapfile, $datadev) =
1160 create_lvm_volumes
($osdev, $os_size, $swap_size);
1162 # trigger udev to create /dev/disk/by-uuid
1163 &$udevadm_trigger_block(1);
1167 # to be fast during installation
1168 syscmd
("zfs set sync=disabled $zfspoolname") == 0 ||
1169 die "unable to set zfs properties\n";
1172 update_progress
(0.03, 0, $maxper, "create swap space");
1174 syscmd
("mkswap -f $swapfile") == 0 ||
1175 die "unable to create swap space\n";
1178 update_progress
(0.05, 0, $maxper, "creating filesystems");
1180 foreach my $di (@$bootdevinfo) {
1181 next if !$di->{esp
};
1182 syscmd
("mkfs.vfat -F32 $di->{esp}") == 0 ||
1183 die "unable to initialize EFI ESP on device $di->{esp}\n";
1188 } elsif ($use_btrfs) {
1191 create_filesystem
($rootdev, 'root', $filesys, 0.05, $maxper, 0, 1);
1194 update_progress
(1, 0.05, $maxper, "mounting target $rootdev");
1199 my $mount_opts = 'noatime';
1200 $mount_opts .= ',nobarrier'
1201 if $use_btrfs || $filesys =~ /^ext\d$/;
1203 syscmd
("mount -n $rootdev -o $mount_opts $targetdir") == 0 ||
1204 die "unable to mount $rootdev\n";
1207 mkdir "$targetdir/boot";
1208 mkdir "$targetdir/boot/efi";
1210 mkdir "$targetdir/var";
1211 mkdir "$targetdir/var/lib";
1213 if ($setup->{product
} eq 'pve') {
1214 mkdir "$targetdir/var/lib/vz";
1215 mkdir "$targetdir/var/lib/pve";
1218 syscmd
("btrfs subvolume create $targetdir/var/lib/pve/local-btrfs") == 0 ||
1219 die "unable to create btrfs subvolume\n";
1223 update_progress
(1, 0.05, $maxper, "extracting base system");
1225 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = stat ($basefile);
1226 $ino || die "unable to open file '$basefile' - $!\n";
1228 my $files = file_read_firstline
("${proxmox_cddir}/proxmox/$setup->{product}-base.cnt") ||
1229 die "unable to read base file count\n";
1234 run_command
("unsquashfs -f -dest $targetdir -i $basefile", sub {
1236 return if $line !~ m/^$targetdir/;
1238 my $nper = int (($count *100)/$files);
1239 if ($nper != $per) {
1241 my $frac = $per > 100 ?
1 : $per/100;
1242 update_progress
($frac, $maxper, 0.5);
1246 syscmd
("mount -n -t tmpfs tmpfs $targetdir/tmp") == 0 ||
1247 die "unable to mount tmpfs on $targetdir/tmp\n";
1248 syscmd
("mount -n -t proc proc $targetdir/proc") == 0 ||
1249 die "unable to mount proc on $targetdir/proc\n";
1250 syscmd
("mount -n -t sysfs sysfs $targetdir/sys") == 0 ||
1251 die "unable to mount sysfs on $targetdir/sys\n";
1253 update_progress
(1, $maxper, 0.5, "configuring base system");
1258 "127.0.0.1 localhost.localdomain localhost\n" .
1259 "$ipaddress $hostname.$domain $hostname\n\n" .
1260 "# The following lines are desirable for IPv6 capable hosts\n\n" .
1261 "::1 ip6-localhost ip6-loopback\n" .
1262 "fe00::0 ip6-localnet\n" .
1263 "ff00::0 ip6-mcastprefix\n" .
1264 "ff02::1 ip6-allnodes\n" .
1265 "ff02::2 ip6-allrouters\n" .
1266 "ff02::3 ip6-allhosts\n";
1268 write_config
($hosts, "$targetdir/etc/hosts");
1270 write_config
("$hostname\n", "$targetdir/etc/hostname");
1272 syscmd
("/bin/hostname $hostname") if !$opt_testmode;
1274 # configure interfaces
1276 my $ifaces = "auto lo\niface lo inet loopback\n\n";
1278 my $ntype = $ipversion == 4 ?
'inet' : 'inet6';
1280 my $ethdev = $ipconf->{ifaces
}->{$ipconf->{selected
}}->{name
};
1282 if ($setup->{bridged_network
}) {
1283 $ifaces .= "iface $ethdev $ntype manual\n";
1286 "\nauto vmbr0\niface vmbr0 $ntype static\n" .
1287 "\taddress $ipaddress\n" .
1288 "\tnetmask $netmask\n" .
1289 "\tgateway $gateway\n" .
1290 "\tbridge_ports $ethdev\n" .
1291 "\tbridge_stp off\n" .
1294 $ifaces .= "auto $ethdev\n" .
1295 "iface $ethdev $ntype static\n" .
1296 "\taddress $ipaddress\n" .
1297 "\tnetmask $netmask\n" .
1298 "\tgateway $gateway\n";
1301 foreach my $iface (sort keys %{$ipconf->{ifaces
}}) {
1302 my $name = $ipconf->{ifaces
}->{$iface}->{name
};
1303 next if $name eq $ethdev;
1305 $ifaces .= "\niface $name $ntype manual\n";
1308 write_config
($ifaces, "$targetdir/etc/network/interfaces");
1312 my $resolvconf = "search $domain\nnameserver $dnsserver\n";
1313 write_config
($resolvconf, "$targetdir/etc/resolv.conf");
1317 my $fstab = "# <file system> <mount point> <type> <options> <dump> <pass>\n";
1321 } elsif ($use_btrfs) {
1323 my $cmd = "blkid -u filesystem -t TYPE=btrfs -o export $rootdev";
1324 run_command
($cmd, sub {
1327 if ($line =~ m/^UUID=([A-Fa-f0-9\-]+)$/) {
1332 die "unable to detect FS UUID" if !defined($fsuuid);
1334 $fstab .= "UUID=$fsuuid / btrfs defaults 0 1\n";
1336 my $root_mountopt = $fssetup->{$filesys}->{root_mountopt
} || 'defaults';
1337 $fstab .= "$rootdev / $filesys ${root_mountopt} 0 1\n";
1341 # Note: this is required by current grub, but really dangerous, because
1342 # vfat does not have journaling, so it triggers manual fsck after each crash
1343 # so we only mount /boot/efi if really required (efi systems).
1344 if ($grub_plattform =~ m/^efi-/) {
1345 if (scalar(@$bootdevinfo)) {
1346 my $di = @$bootdevinfo[0]; # simply use first disk
1348 my $efi_boot_uuid = $di->{esp
};
1349 if (my $uuid = find_dev_by_uuid
($di->{esp
})) {
1350 $efi_boot_uuid = "UUID=$uuid";
1353 $fstab .= "${efi_boot_uuid} /boot/efi vfat defaults 0 1\n";
1359 $fstab .= "$swapfile none swap sw 0 0\n" if $swapfile;
1361 $fstab .= "proc /proc proc defaults 0 0\n";
1363 write_config
($fstab, "$targetdir/etc/fstab");
1364 write_config
("", "$targetdir/etc/mtab");
1366 syscmd
("cp ${proxmox_libdir}/policy-disable-rc.d " .
1367 "$targetdir/usr/sbin/policy-rc.d") == 0 ||
1368 die "unable to copy policy-rc.d\n";
1369 syscmd
("cp ${proxmox_libdir}/fake-start-stop-daemon " .
1370 "$targetdir/sbin/") == 0 ||
1371 die "unable to copy start-stop-daemon\n";
1373 diversion_add
($targetdir, "/sbin/start-stop-daemon", "/sbin/fake-start-stop-daemon");
1374 diversion_add
($targetdir, "/usr/sbin/update-grub", "/bin/true");
1375 diversion_add
($targetdir, "/usr/sbin/update-initramfs", "/bin/true");
1377 syscmd
("touch $targetdir/proxmox_install_mode");
1379 my $grub_install_devices_txt = '';
1380 foreach my $di (@$bootdevinfo) {
1381 $grub_install_devices_txt .= ', ' if $grub_install_devices_txt;
1382 $grub_install_devices_txt .= $di->{by_id
} || $di->{devname
};
1385 # Note: keyboard-configuration/xbkb-keymap is used by console-setup
1386 my $xkmap = $cmap->{kmap
}->{$keymap}->{x11
} // 'us';
1388 debconfig_set
($targetdir, <<_EOD);
1389 locales locales/default_environment_locale select en_US.UTF-8
1390 locales locales/locales_to_be_generated select en_US.UTF-8 UTF-8
1391 samba-common samba-common/dhcp boolean false
1392 samba-common samba-common/workgroup string WORKGROUP
1393 postfix postfix/main_mailer_type select No configuration
1394 keyboard-configuration keyboard-configuration/xkb-keymap select $xkmap
1395 d-i debian-installer/locale select en_US.UTF-8
1396 grub-pc grub-pc/install_devices select $grub_install_devices_txt
1400 while (<${proxmox_pkgdir
}/*.deb
>) { $pkg_count++ };
1402 # btrfs/dpkg is extremely slow without --force-unsafe-io
1403 my $dpkg_opts = $use_btrfs ?
"--force-unsafe-io" : "";
1406 while (<${proxmox_pkgdir
}/*.deb
>) {
1409 my ($deb) = $path =~ m/${proxmox_pkgdir}\/(.*\
.deb
)/;
1410 # if ($deb =~ m/^grub-efi-/ && $deb !~ m/^grub-${grub_plattform}/) {
1414 update_progress
($count/$pkg_count, 0.5, 0.75, "extracting $deb");
1415 print "extracting: $deb\n";
1416 syscmd
("cp $path $targetdir/tmp/$deb") == 0 ||
1417 die "installation of package $deb failed\n";
1418 syscmd
("chroot $targetdir dpkg $dpkg_opts --force-depends --no-triggers --unpack /tmp/$deb") == 0 ||
1419 die "installation of package $deb failed\n";
1420 update_progress
((++$count)/$pkg_count, 0.5, 0.75);
1423 # needed for postfix postinst in case no other NIC is active
1424 syscmd
("chroot $targetdir ifup lo");
1426 my $cmd = "chroot $targetdir dpkg $dpkg_opts --force-confold --configure -a";
1428 run_command
($cmd, sub {
1430 if ($line =~ m/Setting up\s+(\S+)/) {
1431 update_progress
((++$count)/$pkg_count, 0.75, 0.95,
1436 unlink "$targetdir/etc/mailname";
1437 $postfix_main_cf =~ s/__FQDN__/${hostname}.${domain}/;
1438 write_config
($postfix_main_cf, "$targetdir/etc/postfix/main.cf");
1440 # make sure we have all postfix directories
1441 syscmd
("chroot $targetdir /usr/sbin/postfix check");
1442 # cleanup mail queue
1443 syscmd
("chroot $targetdir /usr/sbin/postsuper -d ALL");
1445 # enable NTP (timedatectl set-ntp true does not work without DBUS)
1446 syscmd
("chroot $targetdir /bin/systemctl enable systemd-timesyncd.service");
1448 unlink "$targetdir/proxmox_install_mode";
1451 unlink ("$targetdir/etc/localtime");
1452 symlink ("/usr/share/zoneinfo/$timezone", "$targetdir/etc/localtime");
1453 write_config
("$timezone\n", "$targetdir/etc/timezone");
1456 if (my $mirror = $cmap->{country
}->{$country}->{mirror
}) {
1457 my $fn = "$targetdir/etc/apt/sources.list";
1458 syscmd
("sed -i 's/ftp\\.debian\\.org/$mirror/' '$fn'");
1461 # create extended_states for apt (avoid cron job warning if that
1462 # file does not exist)
1463 write_config
('', "$targetdir/var/lib/apt/extended_states");
1465 # allow ssh root login
1466 syscmd
(['sed', '-i', 's/^#\?PermitRootLogin.*/PermitRootLogin yes/', "$targetdir/etc/ssh/sshd_config"]);
1468 if ($setup->{product
} eq 'pmg') {
1469 # install initial clamav DB
1470 my $srcdir = "${proxmox_cddir}/proxmox/clamav";
1471 foreach my $fn ("main.cvd", "bytecode.cvd", "daily.cvd", "safebrowsing.cvd") {
1472 syscmd
("cp \"$srcdir/$fn\" \"$targetdir/var/lib/clamav\"") == 0 ||
1473 die "installation of clamav db file '$fn' failed\n";
1475 syscmd
("chroot $targetdir /bin/chown clamav:clamav -R /var/lib/clamav") == 0 ||
1476 die "unable to set owner for clamav database files\n";
1479 if ($setup->{product
} eq 'pve') {
1480 # save installer settings
1481 my $ucc = uc ($country);
1482 debconfig_set
($targetdir, "pve-manager pve-manager/country string $ucc\n");
1485 update_progress
(0.8, 0.95, 1, "make system bootable");
1488 syscmd
("sed -i -e 's/^GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"root=ZFS=$zfspoolname\\/ROOT\\/$zfsrootvolname boot=zfs\"/' $targetdir/etc/default/grub") == 0 ||
1489 die "unable to update /etc/default/grub\n";
1493 diversion_remove
($targetdir, "/usr/sbin/update-grub");
1494 diversion_remove
($targetdir, "/usr/sbin/update-initramfs");
1497 foreach my $fn (<$targetdir/lib/modules/*>) {
1498 if ($fn =~ m!/(\d+\.\d+\.\d+-\d+-pve)$!) {
1499 die "found multiple kernels\n" if defined($kapi);
1503 die "unable to detect kernel version\n" if !defined($kapi);
1505 if (!$opt_testmode) {
1507 unlink ("$targetdir/etc/mtab");
1508 symlink ("/proc/mounts", "$targetdir/etc/mtab");
1509 syscmd
("mount -n --bind /dev $targetdir/dev");
1511 syscmd
("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0 ||
1512 die "unable to install initramfs\n";
1514 foreach my $di (@$bootdevinfo) {
1515 my $dev = $di->{devname
};
1516 syscmd
("chroot $targetdir /usr/sbin/grub-install --target i386-pc --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
1517 die "unable to install the i386-pc boot loader on '$dev'\n";
1520 syscmd
("mount -n $di->{esp} -t vfat $targetdir/boot/efi") == 0 ||
1521 die "unable to mount $di->{esp}\n";
1522 my $rc = syscmd
("chroot $targetdir /usr/sbin/grub-install --target x86_64-efi --no-floppy --bootloader-id='proxmox' $dev");
1524 if (-d
'/sys/firmware/efi') {
1525 die "unable to install the EFI boot loader on '$dev'\n";
1527 warn "unable to install the EFI boot loader on '$dev', ignoring (not booted using UEFI)\n";
1530 # also install fallback boot file (OVMF does not boot without)
1531 mkdir("$targetdir/boot/efi/EFI/BOOT");
1532 syscmd
("cp $targetdir/boot/efi/EFI/proxmox/grubx64.efi $targetdir/boot/efi/EFI/BOOT/BOOTx64.EFI") == 0 ||
1533 die "unable to copy efi boot loader\n";
1535 syscmd
("umount $targetdir/boot/efi") == 0 ||
1536 die "unable to umount $targetdir/boot/efi\n";
1540 syscmd
("chroot $targetdir /usr/sbin/update-grub") == 0 ||
1541 die "unable to update boot loader config\n";
1543 syscmd
("umount $targetdir/dev");
1548 # hack: remove dead.letter from sshd installation
1549 syscmd
("rm -rf $targetdir/dead.letter");
1551 unlink "$targetdir/usr/sbin/policy-rc.d";
1553 diversion_remove
($targetdir, "/sbin/start-stop-daemon");
1556 my $octets = encode
("utf-8", $password);
1557 run_command
("chroot $targetdir /usr/sbin/chpasswd", undef,
1560 if ($setup->{product
} eq 'pmg') {
1562 write_config
("section: admin\n\temail ${mailto}\n",
1563 "$targetdir/etc/pmg/pmg.conf");
1565 } elsif ($setup->{product
} eq 'pve') {
1569 my $tmpdir = "$targetdir/tmp/pve";
1572 # write vnc keymap to datacenter.cfg
1573 my $vnckmap = $cmap->{kmap
}->{$keymap}->{kvm
} || 'en-us';
1574 write_config
("keyboard: $vnckmap\n",
1575 "$tmpdir/datacenter.cfg");
1578 write_config
("user:root\@pam:1:0:::${mailto}::\n",
1579 "$tmpdir/user.cfg");
1582 my $storage_cfg_fn = "$tmpdir/storage.cfg";
1584 write_config
($storage_cfg_zfs, $storage_cfg_fn);
1585 } elsif ($use_btrfs) {
1586 write_config
($storage_cfg_btrfs, $storage_cfg_fn);
1587 } elsif ($datadev) {
1588 write_config
($storage_cfg_lvmthin, $storage_cfg_fn);
1590 write_config
($storage_cfg_local, $storage_cfg_fn);
1593 run_command
("chroot $targetdir /usr/bin/create_pmxcfs_db /tmp/pve /var/lib/pve-cluster/config.db");
1595 syscmd
("rm -rf $tmpdir");
1601 update_progress
(1, 0, 1, "");
1605 if ($opt_testmode) {
1606 my $elapsed = Time
::HiRes
::tv_interval
($starttime);
1607 print "Elapsed extract time: $elapsed\n";
1609 syscmd
("chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> final.pkglist");
1612 syscmd
("umount $targetdir/tmp");
1613 syscmd
("umount $targetdir/proc");
1614 syscmd
("umount $targetdir/sys");
1617 syscmd
("zfs umount -a") == 0 ||
1618 die "unable to unmount zfs\n";
1620 syscmd
("umount -d $targetdir");
1623 if (!$err && $use_zfs) {
1624 syscmd
("zfs set sync=standard $zfspoolname") == 0 ||
1625 die "unable to set zfs properties\n";
1627 syscmd
("zfs set mountpoint=/ $zfspoolname/ROOT/$zfsrootvolname") == 0 ||
1628 die "zfs set mountpoint failed\n";
1630 syscmd
("zpool set bootfs=$zfspoolname/ROOT/$zfsrootvolname $zfspoolname") == 0 ||
1631 die "zfs set bootfs failed\n";
1632 syscmd
("zpool export $zfspoolname");
1638 my $last_display_change = 0;
1640 my $display_info_counter = 0;
1642 my $display_info_items = [
1643 "extract1-license.htm",
1644 "extract2-rulesystem.htm",
1645 "extract3-spam.htm",
1646 "extract4-virus.htm",
1651 my $min_display_time = 15;
1655 return if ($ctime - $last_display_change) < $min_display_time;
1657 my $page = $display_info_items->[$display_info_counter % scalar(@$display_info_items)];
1659 $display_info_counter++;
1661 display_html
($page);
1665 my ($filename) = @_;
1667 my $path = "${proxmox_libdir}/html/$filename";
1669 my $url = "file://$path";
1671 my $data = file_get_contents
($path);
1673 if ($filename eq 'license.htm') {
1674 my $license = decode
('utf8', file_get_contents
("${proxmox_cddir}/EULA"));
1675 my $title = "END USER LICENSE AGREEMENT (EULA)";
1676 $data =~ s/__LICENSE__/$license/;
1677 $data =~ s/__LICENSE_TITLE__/$title/;
1680 $htmlview->load_html_string($data, $url);
1682 $last_display_change = time();
1686 my ($text, $fctn) = @_;
1689 $text = "_Next" if !$text;
1690 $next->set_label ($text);
1692 $next->grab_focus ();
1695 sub create_main_window
{
1697 $window = Gtk3
::Window-
>new ();
1698 $window->set_default_size (1024, 768);
1699 $window->set_has_resize_grip(0);
1700 $window->set_decorated (0) if !$opt_testmode;
1702 my $vbox = Gtk3
::VBox-
>new (0, 0);
1704 my $logofn = "$setup->{product}-banner.png";
1705 my $image = Gtk3
::Image-
>new_from_file("${proxmox_libdir}/$logofn");
1706 $vbox->pack_start ($image, 0, 0, 0);
1708 my $hbox = Gtk3
::HBox-
>new (0, 0);
1709 $vbox->pack_start ($hbox, 1, 1, 0);
1711 # my $f1 = Gtk3::Frame->new ('test');
1712 # $f1->set_shadow_type ('none');
1713 # $hbox->pack_start ($f1, 1, 1, 0);
1715 my $sep1 = Gtk3
::HSeparator-
>new;
1716 $vbox->pack_start ($sep1, 0, 0, 0);
1718 $cmdbox = Gtk3
::HBox-
>new ();
1719 $vbox->pack_start ($cmdbox, 0, 0, 10);
1721 $next = Gtk3
::Button-
>new ('_Next');
1722 $next->signal_connect (clicked
=> sub { $last_display_change = 0; &$next_fctn (); });
1723 $cmdbox->pack_end ($next, 0, 0, 10);
1724 my $abort = Gtk3
::Button-
>new ('_Abort');
1725 $abort->set_can_focus (0);
1726 $cmdbox->pack_start ($abort, 0, 0, 10);
1727 $abort->signal_connect (clicked
=> sub { exit (-1); });
1729 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1730 $hbox->add ($vbox2);
1732 $htmlview = Gtk3
::WebKit
::WebView-
>new();
1733 my $scrolls = Gtk3
::ScrolledWindow-
>new();
1734 $scrolls->add($htmlview);
1736 my $hbox2 = Gtk3
::HBox-
>new (0, 0);
1737 $hbox2->pack_start ($scrolls, 1, 1, 0);
1739 $vbox2->pack_start ($hbox2, 1, 1, 0);
1741 my $vbox3 = Gtk3
::VBox-
>new (0, 0);
1742 $vbox2->pack_start ($vbox3, 0, 0, 0);
1744 my $sep2 = Gtk3
::HSeparator-
>new;
1745 $vbox3->pack_start ($sep2, 0, 0, 0);
1747 $inbox = Gtk3
::HBox-
>new (0, 0);
1748 $vbox3->pack_start ($inbox, 0, 0, 0);
1750 $window->add ($vbox);
1753 $window->realize ();
1757 $inbox->foreach(sub {
1759 $inbox->remove ($child);
1763 # fixme: newer GTK3 has special properties to handle numbers with Entry
1764 # only allow floating point numbers with Gtk3::Entry
1767 my ($entry, $event) = @_;
1769 return check_number
($entry, $event, 1);
1773 my ($entry, $event) = @_;
1775 return check_number
($entry, $event, 0);
1779 my ($entry, $event, $float) = @_;
1781 my $val = $event->get_keyval;
1783 if (($float && $val == ord '.') ||
1784 $val == Gtk3
::Gdk
::KEY_ISO_Left_Tab
||
1785 $val == Gtk3
::Gdk
::KEY_Shift_L
||
1786 $val == Gtk3
::Gdk
::KEY_Tab
||
1787 $val == Gtk3
::Gdk
::KEY_Left
||
1788 $val == Gtk3
::Gdk
::KEY_Right
||
1789 $val == Gtk3
::Gdk
::KEY_BackSpace
||
1790 $val == Gtk3
::Gdk
::KEY_Delete
||
1791 ($val >= ord '0' && $val <= ord '9') ||
1792 ($val >= Gtk3
::Gdk
::KEY_KP_0
&&
1793 $val <= Gtk3
::Gdk
::KEY_KP_9
)) {
1800 sub create_text_input
{
1801 my ($default, $text) = @_;
1803 my $hbox = Gtk3
::HBox-
>new (0, 0);
1805 my $label = Gtk3
::Label-
>new ($text);
1806 $label->set_size_request (150, -1);
1807 $label->set_alignment (1, 0.5);
1808 $hbox->pack_start ($label, 0, 0, 10);
1809 my $e1 = Gtk3
::Entry-
>new ();
1810 $e1->set_width_chars (30);
1811 $hbox->pack_start ($e1, 0, 0, 0);
1812 $e1->set_text ($default);
1814 return ($hbox, $e1);
1822 my $links = `ip -o l`;
1823 foreach my $l (split /\n/,$links) {
1824 my ($index, $name, $flags, $state, $mac) = $l =~ m/^(\d+):\s+(\S+):\s+<(\S+)>.*\s+state\s+(\S+)\s+.*\s+link\/ether\s
+(\S
+)\s
+/;
1825 next if !$name || $name eq 'lo';
1827 my $driver = readlink "/sys/class/net/$name/device/driver" || 'unknown';
1828 $driver =~ s!^.*/!!;
1830 $ifaces->{"$index"} = {
1838 my $addresses = `ip -o a s $name`;
1839 foreach my $a (split /\n/,$addresses) {
1840 my ($family, $ip, $prefix) = $a =~ m/^\Q$index\E:\s+\Q$name\E\s+(inet|inet6)\s+($IPRE)\/(\d+)\s+/;
1842 next if $a =~ /scope\s+link/; # ignore link local
1846 if ($family eq 'inet') {
1847 next if !$ip =~ /$IPV4RE/;
1848 next if $prefix < 8 || $prefix > 32;
1849 $mask = @$ipv4_reverse_mask[$prefix];
1851 next if !$ip =~ /$IPV6RE/;
1854 $default = $index if !$default;
1856 $ifaces->{"$index"}->{"$family"} = {
1864 my $route = `ip route
`;
1865 my ($gateway) = $route =~ m/^default\s+via\s+(\S+)\s+/m;
1867 my $resolvconf = `cat
/etc/resolv
.conf
`;
1868 my ($dnsserver) = $resolvconf =~ m/^nameserver\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/m;
1869 my ($domain) = $resolvconf =~ m/^domain\s+(\S+)$/m;
1872 default => $default,
1874 gateway => $gateway,
1875 dnsserver => $dnsserver,
1880 sub display_message {
1883 my $dialog = Gtk3::MessageDialog->new ($window, 'modal',
1884 'info', 'ok', $msg);
1892 my $dialog = Gtk3::MessageDialog->new ($window, 'modal',
1893 'error', 'ok', $msg);
1898 my $ipconf_first_view = 1;
1900 sub create_ipconf_view {
1903 display_html ("ipconf.htm");
1905 my $vbox = Gtk3::VBox->new (0, 0);
1906 $inbox->pack_start ($vbox, 1, 0, 0);
1907 my $hbox = Gtk3::HBox->new (0, 0);
1908 $vbox->pack_start ($hbox, 0, 0, 10);
1909 my $vbox2 = Gtk3::VBox->new (0, 0);
1910 $hbox->add ($vbox2);
1913 ($ipbox, $ipconf_entry_addr) =
1914 create_text_input ("192.168.100.2", 'IP Address:');
1917 ($maskbox, $ipconf_entry_mask) =
1918 create_text_input ("255.255.255.0", 'Netmask:');
1920 my $device_cb = Gtk3::ComboBoxText->new();
1921 $device_cb->set_active(0);
1922 $device_cb->set_visible(1);
1924 my $get_device_desc = sub {
1926 return "$iface->{name} - $iface->{mac} ($iface->{driver})";
1929 my $device_active_map = {};
1931 my $device_change_handler = sub {
1932 my $current = shift;
1933 $ipconf->{selected} = $device_active_map->{$current->get_active()};
1934 my $iface = $ipconf->{ifaces}->{$ipconf->{selected}};
1935 $ipconf_entry_addr->set_text($iface->{inet}->{addr} || $iface->{inet6}->{addr})
1936 if $iface->{inet}->{addr} || $iface->{inet6}->{addr};
1937 $ipconf_entry_mask->set_text($iface->{inet}->{mask} || $iface->{inet6}->{mask})
1938 if $iface->{inet}->{mask} || $iface->{inet6}->{mask};
1942 foreach my $index (sort keys %{$ipconf->{ifaces}}) {
1943 $device_cb->append_text(&$get_device_desc($ipconf->{ifaces}->{$index}));
1944 $device_active_map->{$i} = $index;
1945 if ($ipconf_first_view && $index == $ipconf->{default}) {
1946 $device_cb->set_active($i);
1947 &$device_change_handler($device_cb);
1948 $ipconf_first_view = 0;
1950 $device_cb->signal_connect ('changed' => $device_change_handler);
1954 $device_cb->set_active(0)
1955 if !($ipconf->{selected});
1957 my $devicebox = Gtk3::HBox->new (0, 0);
1958 my $label = Gtk3::Label->new ("Management Interface:");
1959 $label->set_size_request (150, -1);
1960 $label->set_alignment (1, 0.5);
1961 $devicebox->pack_start ($label, 0, 0, 10);
1962 $devicebox->pack_start ($device_cb, 0, 0, 0);
1964 $vbox2->pack_start ($devicebox, 0, 0, 2);
1966 my $hn = $ipconf->{domain} ?
1967 "$setup->{product}.$ipconf->{domain}" : "$setup->{product}.example.invalid";
1969 my ($hostbox, $hostentry) =
1970 create_text_input ($hn, 'Hostname (FQDN):');
1971 $vbox2->pack_start ($hostbox, 0, 0, 2);
1973 $vbox2->pack_start ($ipbox, 0, 0, 2);
1975 $vbox2->pack_start ($maskbox, 0, 0, 2);
1977 $gateway = $ipconf->{gateway} || '192.168.100.1';
1980 ($gwbox, $ipconf_entry_gw) =
1981 create_text_input ($gateway, 'Gateway:');
1983 $vbox2->pack_start ($gwbox, 0, 0, 2);
1985 $dnsserver = $ipconf->{dnsserver} || $gateway;
1988 ($dnsbox, $ipconf_entry_dns) =
1989 create_text_input ($dnsserver, 'DNS Server:');
1991 $vbox2->pack_start ($dnsbox, 0, 0, 0);
1994 set_next ('_Install', sub {
1998 my $text = $hostentry->get_text();
2003 my $namere = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
2005 # Debian does not support purely numeric hostnames
2006 if ($text && $text =~ /^[0-9]+(?:\.|$)/) {
2007 display_message("Purely numeric hostnames are not allowed.");
2008 $hostentry->grab_focus();
2012 if ($text && $text =~ m/^(${namere}\.)*${namere}$/ && $text !~ m/.example.invalid$/ &&
2013 $text =~ m/^([^\.]+)\.(\S+)$/) {
2017 display_message ("Hostname does not look like a fully qualified domain name.");
2018 $hostentry->grab_focus();
2024 $text = $ipconf_entry_addr->get_text();
2027 if ($text =~ m!^($IPV4RE)$!) {
2030 } elsif ($text =~ m!^($IPV6RE)$!) {
2034 display_message ("IP address is not valid.");
2035 $ipconf_entry_addr->grab_focus();
2039 $text = $ipconf_entry_mask->get_text();
2042 if (($ipversion == 6) && ($text =~ m/^(\d+)$/) && ($1 >= 8) && ($1 <= 126)) {
2044 } elsif (($ipversion == 4) && defined($ipv4_mask_hash->{$text})) {
2047 display_message ("Netmask is not valid.");
2048 $ipconf_entry_mask->grab_focus();
2052 $text = $ipconf_entry_gw->get_text();
2055 if (($ipversion == 4) && ($text =~ m!^($IPV4RE)$!)) {
2057 } elsif (($ipversion == 6) && ($text =~ m!^($IPV6RE)$!)) {
2060 display_message ("Gateway is not valid.");
2061 $ipconf_entry_gw->grab_focus();
2065 $text = $ipconf_entry_dns->get_text();
2068 if (($ipversion == 4) && ($text =~ m!^($IPV4RE)$!)) {
2070 } elsif (($ipversion == 6) && ($text =~ m!^($IPV6RE)$!)) {
2073 display_message ("DNS server is not valid.");
2074 $ipconf_entry_dns->grab_focus();
2078 #print "TEST $ipaddress $netmask $gateway $dnsserver\n";
2080 create_extract_view ();
2083 $hostentry->grab_focus();
2086 sub get_device_desc {
2087 my ($devname, $size, $model) = @_;
2089 if ($size && ($size > 0)) {
2090 $size = int($size/2048); # size in MB, from 512B "sectors"
2092 my $text = "$devname (";
2093 if ($size >= 1024) {
2094 $size = int($size/1024); # size in GB
2095 $text .= "${size}GB";
2097 $text .= "${size}MB";
2100 $text .= ", $model" if $model;
2109 my ($cb, $kmap) = @_;
2114 my $kmaphash = $cmap->{kmaphash};
2115 foreach my $layout (sort keys %$kmaphash) {
2116 $def = $i if $kmaphash->{$layout} eq 'en-us';
2117 $ind = $i if $kmap && $kmaphash->{$layout} eq $kmap;
2121 $cb->set_active ($ind || $def || 0);
2125 sub update_zonelist {
2126 my ($box, $cc) = @_;
2128 my $cczones = $cmap->{cczones};
2129 my $zones = $cmap->{zones};
2133 $sel = $lastzonecb->get_active_text();
2134 $box->remove ($lastzonecb);
2136 $sel = $timezone; # used once to select default
2139 my $cb = $lastzonecb = Gtk3::ComboBoxText->new();
2140 $cb->set_size_request (200, -1);
2142 $cb->signal_connect ('changed' => sub {
2143 $timezone = $cb->get_active_text();
2147 if ($cc && defined ($cczones->{$cc})) {
2148 @za = keys %{$cczones->{$cc}};
2154 foreach my $zone (sort @za) {
2155 $ind = $i if $sel && $zone eq $sel;
2156 $cb->append_text ($zone);
2160 $cb->set_active ($ind || 0);
2163 $box->pack_start ($cb, 0, 0, 0);
2166 sub create_password_view {
2170 my $vbox2 = Gtk3::VBox->new (0, 0);
2171 $inbox->pack_start ($vbox2, 1, 0, 0);
2172 my $vbox = Gtk3::VBox->new (0, 0);
2173 $vbox2->pack_start ($vbox, 0, 0, 10);
2175 my $hbox1 = Gtk3::HBox->new (0, 0);
2176 my $label = Gtk3::Label->new ("Password");
2177 $label->set_size_request (150, -1);
2178 $label->set_alignment (1, 0.5);
2179 $hbox1->pack_start ($label, 0, 0, 10);
2180 my $pwe1 = Gtk3::Entry->new ();
2181 $pwe1->set_visibility (0);
2182 $pwe1->set_size_request (200, -1);
2183 $hbox1->pack_start ($pwe1, 0, 0, 0);
2185 my $hbox2 = Gtk3::HBox->new (0, 0);
2186 $label = Gtk3::Label->new ("Confirm");
2187 $label->set_size_request (150, -1);
2188 $label->set_alignment (1, 0.5);
2189 $hbox2->pack_start ($label, 0, 0, 10);
2190 my $pwe2 = Gtk3::Entry->new ();
2191 $pwe2->set_visibility (0);
2192 $pwe2->set_size_request (200, -1);
2193 $hbox2->pack_start ($pwe2, 0, 0, 0);
2195 my $hbox3 = Gtk3::HBox->new (0, 0);
2196 $label = Gtk3::Label->new ("E-Mail");
2197 $label->set_size_request (150, -1);
2198 $label->set_alignment (1, 0.5);
2199 $hbox3->pack_start ($label, 0, 0, 10);
2200 my $eme = Gtk3::Entry->new ();
2201 $eme->set_size_request (200, -1);
2202 $eme->set_text('mail@example.invalid');
2203 $hbox3->pack_start ($eme, 0, 0, 0);
2206 $vbox->pack_start ($hbox1, 0, 0, 5);
2207 $vbox->pack_start ($hbox2, 0, 0, 5);
2208 $vbox->pack_start ($hbox3, 0, 0, 15);
2212 display_html ("passwd.htm");
2214 set_next (undef, sub {
2216 my $t1 = $pwe1->get_text;
2217 my $t2 = $pwe2->get_text;
2219 if (length ($t1) < 5) {
2220 display_message ("Password is too short.");
2221 $pwe1->grab_focus();
2226 display_message ("Password does not match.");
2227 $pwe1->grab_focus();
2231 my $t3 = $eme->get_text;
2232 if ($t3 !~ m/^\S+\@\S+\.\S+$/) {
2233 display_message ("E-Mail does not look like a valid address" .
2234 " (user\@domain.tld)");
2239 if ($t3 eq 'mail@example.invalid') {
2240 display_message ("Please enter a valid E-Mail address");
2248 create_ipconf_view();
2251 $pwe1->grab_focus();
2255 sub create_country_view {
2259 my $countryhash = $cmap->{countryhash};
2260 my $ctr = $cmap->{country};
2262 my $vbox2 = Gtk3::VBox->new (0, 0);
2263 $inbox->pack_start ($vbox2, 1, 0, 0);
2264 my $vbox = Gtk3::VBox->new (0, 0);
2265 $vbox2->pack_start ($vbox, 0, 0, 10);
2267 my $w = Gtk3::Entry->new ();
2268 $w->set_size_request (200, -1);
2270 my $c = Gtk3::EntryCompletion->new ();
2271 $c->set_text_column (0);
2272 $c->set_minimum_key_length(0);
2273 $c->set_popup_set_width (1);
2274 $c->set_inline_completion (1);
2276 my $hbox2 = Gtk3::HBox->new (0, 0);
2277 my $label = Gtk3::Label->new ("Time zone");
2278 $label->set_size_request (150, -1);
2279 $label->set_alignment (1, 0.5);
2280 $hbox2->pack_start ($label, 0, 0, 10);
2281 update_zonelist ($hbox2);
2283 my $hbox3 = Gtk3::HBox->new (0, 0);
2284 $label = Gtk3::Label->new ("Keyboard Layout");
2285 $label->set_size_request (150, -1);
2286 $label->set_alignment (1, 0.5);
2287 $hbox3->pack_start ($label, 0, 0, 10);
2289 my $kmapcb = Gtk3::ComboBoxText->new();
2290 $kmapcb->set_size_request (200, -1);
2291 foreach my $layout (sort keys %{$cmap->{kmaphash}}) {
2292 $kmapcb->append_text ($layout);
2295 update_layout ($kmapcb);
2296 $hbox3->pack_start ($kmapcb, 0, 0, 0);
2298 $kmapcb->signal_connect ('changed' => sub {
2299 my $sel = $kmapcb->get_active_text();
2300 if (my $kmap = $cmap->{kmaphash}->{$sel}) {
2301 my $xkmap = $cmap->{kmap}->{$kmap}->{x11};
2302 my $xvar = $cmap->{kmap}->{$kmap}->{x11var};
2303 syscmd ("setxkbmap $xkmap $xvar") if !$opt_testmode;
2308 $w->signal_connect ('changed' => sub {
2309 my ($entry, $event) = @_;
2310 my $text = $entry->get_text;
2312 if (my $cc = $countryhash->{lc($text)}) {
2313 update_zonelist ($hbox2, $cc);
2314 my $kmap = $ctr->{$cc}->{kmap} || 'en-us';
2315 update_layout ($kmapcb, $kmap);
2319 $w->signal_connect (key_press_event => sub {
2320 my ($entry, $event) = @_;
2321 my $text = $entry->get_text;
2323 my $val = $event->get_keyval;
2325 if ($val == Gtk3::Gdk::KEY_Tab) {
2326 my $cc = $countryhash->{lc($text)};
2333 $compl = $ctr->{$cc}->{name};
2335 foreach my $cc (keys %$ctr) {
2336 my $ct = $ctr->{$cc}->{name};
2337 if ($ct =~ m/^\Q$text\E.*$/i) {
2346 $entry->set_text($compl);
2351 print chr(7); # beep ?
2356 my $buf = $w->get_buffer();
2357 $buf->insert_text(-1, '', -1); # popup selection
2365 my $ls = Gtk3::ListStore->new('Glib::String');
2366 foreach my $cc (sort {$ctr->{$a}->{name} cmp $ctr->{$b}->{name} } keys %$ctr) {
2367 my $iter = $ls->append();
2368 $ls->set ($iter, 0, $ctr->{$cc}->{name});
2370 $c->set_model ($ls);
2372 $w->set_completion ($c);
2374 my $hbox = Gtk3::HBox->new (0, 0);
2376 $label = Gtk3::Label->new ("Country");
2377 $label->set_alignment (1, 0.5);
2378 $label->set_size_request (150, -1);
2379 $hbox->pack_start ($label, 0, 0, 10);
2380 $hbox->pack_start ($w, 0, 0, 0);
2382 $vbox->pack_start ($hbox, 0, 0, 5);
2383 $vbox->pack_start ($hbox2, 0, 0, 5);
2384 $vbox->pack_start ($hbox3, 0, 0, 5);
2386 if ($country && $ctr->{$country}) {
2387 $w->set_text ($ctr->{$country}->{name});
2392 display_html ("country.htm");
2393 set_next (undef, sub {
2395 my $text = $w->get_text;
2397 if (my $cc = $countryhash->{lc($text)}) {
2399 create_password_view();
2402 display_message ("Please select a country first.");
2410 my $target_hd_combo;
2411 my $target_hd_label;
2413 my $hdopion_first_setup = 1;
2415 my $create_basic_grid = sub {
2416 my $grid = Gtk3::Grid->new();
2417 $grid->set_visible(1);
2418 $grid->set_column_spacing(10);
2419 $grid->set_row_spacing(10);
2420 $grid->set_hexpand(1);
2422 $grid->set_margin_start(5);
2423 $grid->set_margin_end(5);
2424 $grid->set_margin_top(5);
2425 $grid->set_margin_bottom(5);
2430 my $create_label_widget_grid = sub {
2431 my ($labeled_widgets) = @_;
2433 my $grid = &$create_basic_grid();
2436 for (my $i = 0; $i < @$labeled_widgets; $i += 2) {
2437 my $widget = @$labeled_widgets[$i+1];
2438 my $label = Gtk3::Label->new(@$labeled_widgets[$i]);
2439 $label->set_visible(1);
2440 $label->set_alignment (1, 0.5);
2441 $grid->attach($label, 0, $row, 1, 1);
2442 $widget->set_visible(1);
2443 $grid->attach($widget, 1, $row, 1, 1);
2450 my $create_raid_disk_grid = sub {
2451 my $disk_labeled_widgets = [];
2452 for (my $i = 0; $i < @$hds; $i++) {
2453 my $disk_selector = Gtk3::ComboBoxText->new();
2454 $disk_selector->append_text("-- do not use --");
2455 $disk_selector->set_active(0);
2456 $disk_selector->set_visible(1);
2457 foreach my $hd (@$hds) {
2458 my ($disk, $devname, $size, $model) = @$hd;
2459 $disk_selector->append_text(get_device_desc ($devname, $size, $model));
2460 $disk_selector->{pve_disk_id} = $i;
2461 $disk_selector->signal_connect (changed => sub {
2463 my $diskid = $w->{pve_disk_id};
2464 my $a = $w->get_active - 1;
2465 $config_options->{"disksel${diskid}"} = ($a >= 0) ? $hds->[$a] : undef;
2469 if ($hdopion_first_setup) {
2470 $disk_selector->set_active ($i+1) if $hds->[$i];
2473 if (my $cur_hd = $config_options->{"disksel$i"}) {
2474 foreach my $hd (@$hds) {
2475 if (@$hd[1] eq @$cur_hd[1]) {
2476 $disk_selector->set_active($hdind+1);
2484 push @$disk_labeled_widgets, "Harddisk $i", $disk_selector;
2487 my $scrolled_window = Gtk3::ScrolledWindow->new();
2488 $scrolled_window->set_hexpand(1);
2489 $scrolled_window->set_propagate_natural_height(1) if @$hds > 4;
2490 $scrolled_window->add(&$create_label_widget_grid($disk_labeled_widgets));
2491 $scrolled_window->set_policy('never', 'automatic');
2493 return $scrolled_window;
2494 # &$create_label_widget_grid($disk_labeled_widgets)
2497 # shared between different ui parts (e.g., ZFS and "normal" single disk FS)
2498 my $hdsize_size_adj;
2499 my $hdsize_entry_buffer;
2501 my $get_hdsize_spinbtn = sub {
2504 $hdsize_entry_buffer //= Gtk3::EntryBuffer->new(undef, 1);
2506 if (defined($hdsize)) {
2507 $hdsize_size_adj = Gtk3::Adjustment->new($config_options->{hdsize} || $hdsize, 0, $hdsize+1, 1, 1, 1);
2509 die "called get_hdsize_spinbtn with \$hdsize_size_adj not defined but did not pass hdsize!\n"
2510 if !defined($hdsize_size_adj);
2513 my $spinbutton_hdsize = Gtk3::SpinButton->new($hdsize_size_adj, 1, 1);
2514 $spinbutton_hdsize->set_buffer($hdsize_entry_buffer);
2515 $spinbutton_hdsize->set_adjustment($hdsize_size_adj);
2516 $spinbutton_hdsize->set_tooltip_text("only use specified size (GB) of the harddisk (rest left unpartitioned)");
2517 return $spinbutton_hdsize;
2520 my $create_raid_advanced_grid = sub {
2521 my $labeled_widgets = [];
2522 my $spinbutton_ashift = Gtk3::SpinButton->new_with_range(9,13,1);
2523 $spinbutton_ashift->set_tooltip_text("zpool ashift property (pool sector size, default 2^12)");
2524 $spinbutton_ashift->signal_connect ("value-changed" => sub {
2526 $config_options->{ashift} = $w->get_value_as_int();
2528 $config_options->{ashift} = 12 if ! defined($config_options->{ashift});
2529 $spinbutton_ashift->set_value($config_options->{ashift});
2530 push @$labeled_widgets, "ashift";
2531 push @$labeled_widgets, $spinbutton_ashift;
2533 my $combo_compress = Gtk3::ComboBoxText->new();
2534 $combo_compress->set_tooltip_text("zfs compression algorithm for rpool dataset");
2535 # note: gzip / lze not allowed for bootfs vdevs
2536 my $comp_opts = ["on","off","lzjb","lz4"];
2537 foreach my $opt (@$comp_opts) {
2538 $combo_compress->append($opt, $opt);
2540 $config_options->{compress} = "on" if !defined($config_options->{compress});
2541 $combo_compress->set_active_id($config_options->{compress});
2542 $combo_compress->signal_connect (changed => sub {
2544 $config_options->{compress} = $w->get_active_text();
2546 push @$labeled_widgets, "compress";
2547 push @$labeled_widgets, $combo_compress;
2549 my $combo_checksum = Gtk3::ComboBoxText->new();
2550 $combo_checksum->set_tooltip_text("zfs checksum algorithm for rpool dataset");
2551 my $csum_opts = ["on", "off","fletcher2", "fletcher4", "sha256"];
2552 foreach my $opt (@$csum_opts) {
2553 $combo_checksum->append($opt, $opt);
2555 $config_options->{checksum} = "on" if !($config_options->{checksum});
2556 $combo_checksum->set_active_id($config_options->{checksum});
2557 $combo_checksum->signal_connect (changed => sub {
2559 $config_options->{checksum} = $w->get_active_text();
2561 push @$labeled_widgets, "checksum";
2562 push @$labeled_widgets, $combo_checksum;
2564 my $spinbutton_copies = Gtk3::SpinButton->new_with_range(1,3,1);
2565 $spinbutton_copies->set_tooltip_text("zfs copies property for rpool dataset (in addition to RAID redundancy!)");
2566 $spinbutton_copies->signal_connect ("value-changed" => sub {
2568 $config_options->{copies} = $w->get_value_as_int();
2570 $config_options->{copies} = 1 if !defined($config_options->{copies});
2571 $spinbutton_copies->set_value($config_options->{copies});
2572 push @$labeled_widgets, "copies", $spinbutton_copies;
2574 push @$labeled_widgets, "hdsize", $get_hdsize_spinbtn->();
2575 return &$create_label_widget_grid($labeled_widgets);;
2578 sub create_hdoption_view {
2580 my $dialog = Gtk3::Dialog->new();
2582 $dialog->set_title("Harddisk options");
2584 $dialog->add_button("_OK", 1);
2586 my $contarea = $dialog->get_content_area();
2588 my $hbox2 = Gtk3::Box->new('horizontal', 0);
2589 $contarea->pack_start($hbox2, 1, 1, 10);
2591 my $grid = Gtk3::Grid->new();
2592 $grid->set_column_spacing(10);
2593 $grid->set_row_spacing(10);
2595 $hbox2->pack_start($grid, 1, 0, 10);
2601 my $label0 = Gtk3::Label->new ("Filesystem");
2602 $label0->set_alignment (1, 0.5);
2603 $grid->attach($label0, 0, $row, 1, 1);
2605 my $fstypecb = Gtk3::ComboBoxText->new();
2607 my $fstype = ['ext3', 'ext4', 'xfs',
2608 'zfs (RAID0)', 'zfs (RAID1)',
2609 'zfs (RAID10)', 'zfs (RAIDZ-1)',
2610 'zfs (RAIDZ-2)', 'zfs (RAIDZ-3)'];
2612 push @$fstype, 'btrfs (RAID0)', 'btrfs (RAID1)', 'btrfs (RAID10)'
2613 if $setup->{enable_btrfs};
2616 foreach my $tmp (@$fstype) {
2617 $fstypecb->append_text($tmp);
2618 $fstypecb->set_active ($tcount)
2619 if $config_options->{filesys} eq $tmp;
2623 $grid->attach($fstypecb, 1, $row, 1, 1);
2629 my $sep = Gtk3::HSeparator->new();
2630 $sep->set_visible(1);
2631 $grid->attach($sep, 0, $row, 2, 1);
2634 my $hdsize_labeled_widgets = [];
2638 if ( -b $target_hd) {
2639 $hdsize = int(hd_size ($target_hd) / (1024*1024.0)); # size in GB
2640 } elsif ($target_hd) {
2641 $hdsize = int((-s $target_hd) / (1024*1024*1024.0));
2644 my $spinbutton_hdsize = $get_hdsize_spinbtn->($hdsize);
2645 push @$hdsize_labeled_widgets, "hdsize", $spinbutton_hdsize;
2647 my $entry_swapsize = Gtk3::Entry->new();
2648 $entry_swapsize->set_tooltip_text("maximum SWAP size (GB)");
2649 $entry_swapsize->signal_connect (key_press_event => \&check_float);
2650 $entry_swapsize->set_text($config_options->{swapsize}) if defined($config_options->{swapsize});
2651 push @$hdsize_labeled_widgets, "swapsize", $entry_swapsize;
2653 my $entry_maxroot = Gtk3::Entry->new();
2654 if ($setup->{product} eq 'pve') {
2655 $entry_maxroot->set_tooltip_text("maximum size (GB) for LVM root volume");
2656 $entry_maxroot->signal_connect (key_press_event => \&check_float);
2657 $entry_maxroot->set_text($config_options->{maxroot}) if $config_options->{maxroot};
2658 push @$hdsize_labeled_widgets, "maxroot", $entry_maxroot;
2661 my $entry_minfree = Gtk3::Entry->new();
2662 $entry_minfree->set_tooltip_text("minimum free LVM space (GB, required for LVM snapshots)");
2663 $entry_minfree->signal_connect (key_press_event => \&check_float);
2664 $entry_minfree->set_text($config_options->{minfree}) if defined($config_options->{minfree});
2665 push @$hdsize_labeled_widgets, "minfree", $entry_minfree;
2668 if ($setup->{product} eq 'pve') {
2669 $entry_maxvz = Gtk3::Entry->new();
2670 $entry_maxvz->set_tooltip_text("maximum size (GB) for LVM data volume");
2671 $entry_maxvz->signal_connect (key_press_event => \&check_float);
2672 $entry_maxvz->set_text($config_options->{maxvz}) if defined($config_options->{maxvz});
2673 push @$hdsize_labeled_widgets, "maxvz", $entry_maxvz;
2676 my $options_stack = Gtk3::Stack->new();
2677 $options_stack->set_visible(1);
2678 $options_stack->set_hexpand(1);
2679 $options_stack->set_vexpand(1);
2680 $options_stack->add_titled(&$create_raid_disk_grid(), "raiddisk", "Disk Setup");
2681 $options_stack->add_titled(&$create_label_widget_grid($hdsize_labeled_widgets), "hdsize", "Size Options");
2682 $options_stack->add_titled(&$create_raid_advanced_grid("zfs"), "raidzfsadvanced", "Advanced Options");
2683 $options_stack->set_visible_child_name("raiddisk");
2684 my $options_stack_switcher = Gtk3::StackSwitcher->new();
2685 $options_stack_switcher->set_halign('center');
2686 $options_stack_switcher->set_stack($options_stack);
2687 $grid->attach($options_stack_switcher, 0, $row, 2, 1);
2689 $grid->attach($options_stack, 0, $row, 2, 1);
2692 $hdopion_first_setup = 0;
2694 my $switch_view = sub {
2695 my $raid = $config_options->{filesys} =~ m/zfs|btrfs/;
2696 my $enable_zfs_opts = $config_options->{filesys} =~ m/zfs/;
2698 $target_hd_combo->set_visible(!$raid);
2699 $options_stack->get_child_by_name("hdsize")->set_visible(!$raid);
2700 $options_stack->get_child_by_name("raiddisk")->set_visible($raid);
2701 $options_stack_switcher->set_visible($enable_zfs_opts);
2702 $options_stack->get_child_by_name("raidzfsadvanced")->set_visible($enable_zfs_opts);
2704 $target_hd_label->set_text("Target: $config_options->{filesys} ");
2705 $options_stack->set_visible_child_name("raiddisk");
2707 $target_hd_label->set_text("Target Harddisk: ");
2709 my (undef, $pref_width) = $dialog->get_preferred_width();
2710 my (undef, $pref_height) = $dialog->get_preferred_height();
2711 $pref_height = 750 if $pref_height > 750;
2712 $dialog->resize($pref_width, $pref_height);
2717 $fstypecb->signal_connect (changed => sub {
2718 $config_options->{filesys} = $fstypecb->get_active_text();
2726 my $get_float = sub {
2729 my $text = $entry->get_text();
2730 return undef if !defined($text);
2735 return undef if $text !~ m/^\d+(\.\d+)?$/;
2742 if (($tmp = &$get_float($spinbutton_hdsize)) && ($tmp != $hdsize)) {
2743 $config_options->{hdsize} = $tmp;
2745 delete $config_options->{hdsize};
2748 if (defined($tmp = &$get_float($entry_swapsize))) {
2749 $config_options->{swapsize} = $tmp;
2751 delete $config_options->{swapsize};
2754 if (defined($tmp = &$get_float($entry_maxroot))) {
2755 $config_options->{maxroot} = $tmp;
2757 delete $config_options->{maxroot};
2760 if (defined($tmp = &$get_float($entry_minfree))) {
2761 $config_options->{minfree} = $tmp;
2763 delete $config_options->{minfree};
2766 if ($entry_maxvz && defined($tmp = &$get_float($entry_maxvz))) {
2767 $config_options->{maxvz} = $tmp;
2769 delete $config_options->{maxvz};
2775 my $get_raid_devlist = sub {
2777 my $dev_name_hash = {};
2780 for (my $i = 0; $i < @$hds; $i++) {
2781 if (my $hd = $config_options->{"disksel$i"}) {
2782 my ($disk, $devname, $size, $model) = @$hd;
2783 die "device '$devname' is used more than once\n"
2784 if $dev_name_hash->{$devname};
2785 $dev_name_hash->{$devname} = $hd;
2786 push @$devlist, $hd;
2793 sub zfs_mirror_size_check {
2794 my ($expected, $actual) = @_;
2796 die "mirrored disks must have same size\n"
2797 if abs($expected - $actual) > $expected / 10;
2800 sub get_zfs_raid_setup {
2802 my $filesys = $config_options->{filesys};
2804 my $devlist = &$get_raid_devlist();
2806 my $diskcount = scalar(@$devlist);
2807 die "$filesys needs at least one device\n" if $diskcount < 1;
2809 my $bootdevlist = [];
2812 if ($filesys eq 'zfs (RAID0)') {
2813 push @$bootdevlist, @$devlist[0];
2814 foreach my $hd (@$devlist) {
2817 } elsif ($filesys eq 'zfs (RAID1)') {
2818 die "zfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
2820 my $hd = @$devlist[0];
2821 my $expected_size = @$hd[2]; # all disks need approximately same size
2822 foreach $hd (@$devlist) {
2823 zfs_mirror_size_check($expected_size, @$hd[2]);
2825 push @$bootdevlist, $hd;
2827 } elsif ($filesys eq 'zfs (RAID10)') {
2828 die "zfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
2829 die "zfs (RAID10) needs an even number of devices\n" if $diskcount & 1;
2831 push @$bootdevlist, @$devlist[0], @$devlist[1];
2833 for (my $i = 0; $i < $diskcount; $i+=2) {
2834 my $hd1 = @$devlist[$i];
2835 my $hd2 = @$devlist[$i+1];
2836 zfs_mirror_size_check(@$hd1[2], @$hd2[2]); # pairs need approximately same size
2837 $cmd .= ' mirror ' . @$hd1[1] . ' ' . @$hd2[1];
2840 } elsif ($filesys =~ m/^zfs \(RAIDZ-([123])\)$/) {
2842 my $mindisks = 2 + $level;
2843 die "zfs (RAIDZ-$level) needs at least $mindisks devices\n" if scalar(@$devlist) < $mindisks;
2844 my $hd = @$devlist[0];
2845 my $expected_size = @$hd[2]; # all disks need approximately same size
2846 $cmd .= " raidz$level";
2847 foreach $hd (@$devlist) {
2848 zfs_mirror_size_check($expected_size, @$hd[2]);
2850 push @$bootdevlist, $hd;
2853 die "unknown zfs mode '$filesys'\n";
2856 return ($devlist, $bootdevlist, $cmd);
2859 sub get_btrfs_raid_setup {
2861 my $filesys = $config_options->{filesys};
2863 my $devlist = &$get_raid_devlist();
2865 my $diskcount = scalar(@$devlist);
2866 die "$filesys needs at least one device\n" if $diskcount < 1;
2870 if ($diskcount == 1) {
2873 if ($filesys eq 'btrfs (RAID0)') {
2875 } elsif ($filesys eq 'btrfs (RAID1)') {
2876 die "btrfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
2878 } elsif ($filesys eq 'btrfs (RAID10)') {
2879 die "btrfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
2882 die "unknown btrfs mode '$filesys'\n";
2886 return ($devlist, $mode);
2889 sub create_hdsel_view {
2893 my $vbox = Gtk3::VBox->new (0, 0);
2894 $inbox->pack_start ($vbox, 1, 0, 0);
2895 my $hbox = Gtk3::HBox->new (0, 0);
2896 $vbox->pack_start ($hbox, 0, 0, 10);
2898 my ($disk, $devname, $size, $model) = @{@$hds[0]};
2899 $target_hd = $devname;
2901 $target_hd_label = Gtk3::Label->new ("Target Harddisk: ");
2902 $hbox->pack_start ($target_hd_label, 0, 0, 0);
2904 $target_hd_combo = Gtk3::ComboBoxText->new();
2906 foreach my $hd (@$hds) {
2907 ($disk, $devname, $size, $model) = @$hd;
2908 $target_hd_combo->append_text (get_device_desc ($devname, $size, $model));
2911 $target_hd_combo->set_active (0);
2912 $target_hd_combo->signal_connect (changed => sub {
2913 $a = shift->get_active;
2914 my ($disk, $devname) = @{@$hds[$a]};
2915 $target_hd = $devname;
2918 $hbox->pack_start ($target_hd_combo, 0, 0, 10);
2920 my $options = Gtk3::Button->new ('_Options');
2921 $options->signal_connect (clicked => \&create_hdoption_view);
2922 $hbox->pack_start ($options, 0, 0, 0);
2927 display_html ("page1.htm");
2929 set_next (undef, sub {
2931 if ($config_options->{filesys} =~ m/zfs/) {
2932 eval { get_zfs_raid_setup(); };
2934 display_message ("Warning: $err\n" .
2935 "Please fix ZFS setup first.");
2937 create_country_view();
2939 } elsif ($config_options->{filesys} =~ m/btrfs/) {
2940 eval { get_btrfs_raid_setup(); };
2942 display_message ("Warning: $err\n" .
2943 "Please fix BTRFS setup first.");
2945 create_country_view();
2948 create_country_view();
2953 sub create_extract_view {
2959 $next->set_sensitive (0);
2961 my $vbox = Gtk3::VBox->new (0, 0);
2962 $inbox->pack_start ($vbox, 1, 0, 0);
2963 my $hbox = Gtk3::HBox->new (0, 0);
2964 $vbox->pack_start ($hbox, 0, 0, 10);
2966 my $vbox2 = Gtk3::VBox->new (0, 0);
2967 $hbox->pack_start ($vbox2, 0, 0, 0);
2969 $progress_status = Gtk3::Label->new ('');
2970 $vbox2->pack_start ($progress_status, 1, 1, 0);
2972 $progress = Gtk3::ProgressBar->new;
2973 $progress->set_show_text(1);
2974 $progress->set_size_request (600, -1);
2976 $vbox2->pack_start ($progress, 0, 0, 0);
2980 my $tdir = $opt_testmode ? "target" : "/target";
2982 my $base = "${proxmox_cddir}/$setup->{product}-base.squashfs";
2984 eval { extract_data ($base, $tdir); };
2987 $next->set_sensitive (1);
2989 set_next ("_Reboot", sub { exit (0); } );
2992 display_html ("fail.htm");
2993 display_error ($err);
2996 display_html ("success.htm");
3000 sub create_intro_view {
3004 if ($setup->{product} eq 'pve') {
3006 my $cpuinfo = file_get_contents('/proc/cpuinfo');
3007 if ($cpuinfo && !($cpuinfo =~ /^flags\s*:.*(vmx|svm)/m)) {
3008 display_error("No support for KVM virtualisation detected.\n\n" .
3009 "Check BIOS settings for Intel VT / AMD-V / SVM.")
3014 display_html ("license.htm");
3016 set_next ("I a_gree", \&create_hdsel_view);
3019 $ipconf = get_ip_config ();
3021 $country = detect_country() if $ipconf->{default} || $opt_testmode;
3023 # read country, kmap and timezone infos
3024 $cmap = read_cmap ();
3026 if (!defined($cmap->{country}->{$country})) {
3027 print $logfd "ignoring detected country '$country', invalid or unknown\n";
3031 create_main_window ();
3033 my $initial_error = 0;
3035 if (!defined ($hds) || (scalar (@$hds) <= 0)) {
3036 print "no hardisks found\n";
3038 display_html ("nohds.htm");
3039 set_next ("Reboot", sub { exit (0); } );
3041 foreach my $hd (@$hds) {
3042 my ($disk, $devname) = @$hd;
3043 next if $devname =~ m|^/dev/md\d+$|;
3044 print "found Disk$disk N:$devname\n";
3048 if (!$initial_error && (scalar keys %{ $ipconf->{ifaces} } == 0)) {
3049 print "no network interfaces found\n";
3051 display_html ("nonics.htm");
3052 set_next ("Reboot", sub { exit (0); } );
3055 create_intro_view () if !$initial_error;