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
76 sub file_read_firstline
{
79 my $fh = IO
::File-
>new ($filename, "r");
87 my $logfd = IO
::File-
>new (">/tmp/install.log");
89 my $proxmox_libdir = $opt_testmode ?
90 Cwd
::cwd
() . "/testdir/var/lib/pve-installer" : "/var/lib/pve-installer";
91 my $proxmox_cddir = $opt_testmode ?
"../pve-cd-builder/tmp/data-gz/" : "/cdrom";
92 my $proxmox_pkgdir = "${proxmox_cddir}/proxmox/packages/";
94 my $grub_plattform = "pc"; # pc, efi-amd64 or efi-ia32
96 $grub_plattform = "efi-amd64" if -d
"/sys/firmware/efi";
98 my $IPV4OCTET = "(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9])?[0-9])";
99 my $IPV4RE = "(?:(?:$IPV4OCTET\\.){3}$IPV4OCTET)";
100 my $IPV6H16 = "(?:[0-9a-fA-F]{1,4})";
101 my $IPV6LS32 = "(?:(?:$IPV4RE|$IPV6H16:$IPV6H16))";
104 "(?:(?:" . "(?:$IPV6H16:){6})$IPV6LS32)|" .
105 "(?:(?:" . "::(?:$IPV6H16:){5})$IPV6LS32)|" .
106 "(?:(?:(?:" . "$IPV6H16)?::(?:$IPV6H16:){4})$IPV6LS32)|" .
107 "(?:(?:(?:(?:$IPV6H16:){0,1}$IPV6H16)?::(?:$IPV6H16:){3})$IPV6LS32)|" .
108 "(?:(?:(?:(?:$IPV6H16:){0,2}$IPV6H16)?::(?:$IPV6H16:){2})$IPV6LS32)|" .
109 "(?:(?:(?:(?:$IPV6H16:){0,3}$IPV6H16)?::(?:$IPV6H16:){1})$IPV6LS32)|" .
110 "(?:(?:(?:(?:$IPV6H16:){0,4}$IPV6H16)?::" . ")$IPV6LS32)|" .
111 "(?:(?:(?:(?:$IPV6H16:){0,5}$IPV6H16)?::" . ")$IPV6H16)|" .
112 "(?:(?:(?:(?:$IPV6H16:){0,6}$IPV6H16)?::" . ")))";
114 my $IPRE = "(?:$IPV4RE|$IPV6RE)";
117 my $ipv4_mask_hash = {
134 '255.255.128.0' => 17,
135 '255.255.192.0' => 18,
136 '255.255.224.0' => 19,
137 '255.255.240.0' => 20,
138 '255.255.248.0' => 21,
139 '255.255.252.0' => 22,
140 '255.255.254.0' => 23,
141 '255.255.255.0' => 24,
142 '255.255.255.128' => 25,
143 '255.255.255.192' => 26,
144 '255.255.255.224' => 27,
145 '255.255.255.240' => 28,
146 '255.255.255.248' => 29,
147 '255.255.255.252' => 30
150 my $ipv4_reverse_mask = [
186 my ($window, $cmdbox, $inbox, $htmlview);
187 my ($next, $next_fctn, $target_hd);
188 my ($progress, $progress_status);
189 my ($ipversion, $ipaddress, $ipconf_entry_addr);
190 my ($netmask, $ipconf_entry_mask);
191 my ($gateway, $ipconf_entry_gw);
192 my ($dnsserver, $ipconf_entry_dns);
193 my $hostname = 'proxmox';
194 my $domain = 'domain.tld';
195 my $cmdline = file_read_firstline
("/proc/cmdline");
198 my $timezone = 'Europe/Vienna';
201 my $keymap = 'en-us';
204 # parse command line args
206 my $config_options = {};
208 if ($cmdline =~ m/\s(ext3|ext4|xfs)(\s.*)?$/) {
209 $config_options->{filesys
} = $1;
211 $config_options->{filesys
} = 'ext4';
214 if ($cmdline =~ m/hdsize=(\d+(\.\d+)?)[\s\n]/i) {
215 $config_options->{hdsize
} = $1;
218 if ($cmdline =~ m/swapsize=(\d+(\.\d+)?)[\s\n]/i) {
219 $config_options->{swapsize
} = $1;
222 if ($cmdline =~ m/maxroot=(\d+(\.\d+)?)[\s\n]/i) {
223 $config_options->{maxroot
} = $1;
226 if ($cmdline =~ m/minfree=(\d+(\.\d+)?)[\s\n]/i) {
227 $config_options->{minfree
} = $1;
230 if ($cmdline =~ m/maxvz=(\d+(\.\d+)?)[\s\n]/i) {
231 $config_options->{maxvz
} = $1;
234 my $postfix_main_cf = <<_EOD;
235 # See /usr/share/postfix/main.cf.dist for a commented, more complete version
239 smtpd_banner = \$myhostname ESMTP \$mail_name (Debian/GNU)
242 # appending .domain is the MUA's job.
243 append_dot_mydomain = no
245 # Uncomment the next line to generate "delayed mail" warnings
246 #delay_warning_time = 4h
248 alias_maps = hash:/etc/aliases
249 alias_database = hash:/etc/aliases
250 mydestination = \$myhostname, localhost.\$mydomain, localhost
252 mynetworks = 127.0.0.0/8
253 inet_interfaces = loopback-only
254 recipient_delimiter = +
261 return String
::ShellQuote
::shell_quote
($str);
267 die "no arguments" if !$cmd;
269 return $cmd if !ref($cmd);
272 foreach my $arg (@$cmd) { push @qa, shellquote
($arg); }
274 return join (' ', @qa);
280 return run_command
($cmd, undef, undef, 1);
284 my ($cmd, $func, $input, $noout) = @_;
290 # see 'man bash' for option pipefail
291 $cmd = [ '/bin/bash', '-c', "set -o pipefail && $cmd" ];
296 $cmdstr = cmd2string
($cmd);
300 if ($input && ($cmdstr !~ m/chpasswd/)) {
301 $cmdtxt = "# $cmdstr <<EOD\n$input";
303 $cmdtxt .= "\nEOD\n";
305 $cmdtxt = "# $cmdstr\n";
313 print $logfd $cmdtxt;
315 my $reader = IO
::File-
>new();
316 my $writer = IO
::File-
>new();
317 my $error = IO
::File-
>new();
323 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
329 if ($orig_pid != $$) {
336 print $writer $input if defined $input;
339 my $select = new IO
::Select
;
340 $select->add ($reader);
341 $select->add ($error);
343 my ($ostream, $logout) = ('', '', '');
345 while ($select->count) {
346 my @handles = $select->can_read (0.2);
348 Gtk3
::main_iteration
() while Gtk3
::events_pending
();
350 next if !scalar (@handles); # timeout
352 foreach my $h (@handles) {
354 my $count = sysread ($h, $buf, 4096);
355 if (!defined ($count)) {
359 die "command '$cmd' failed: $err";
361 $select->remove ($h) if !$count;
363 $ostream .= $buf if !($noout || $func);
365 while ($logout =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
367 &$func($line) if $func;
370 } elsif ($h eq $error) {
371 $ostream .= $buf if !($noout || $func);
379 &$func($logout) if $func;
381 my $rv = waitpid ($pid, 0);
383 return $? if $noout; # behave like standard system();
386 die "command '$cmdstr' failed to execute\n";
387 } elsif (my $sig = ($? & 127)) {
388 die "command '$cmdstr' failed - got signal $sig\n";
389 } elsif (my $exitcode = ($? >> 8)) {
390 die "command '$cmdstr' failed with exit code $exitcode";
398 print "trying to detect country...\n";
399 my $cpid = open2
(\
*TMP
, undef, "traceroute -N 1 -q 1 -n 8.8.8.8");
400 return undef if !$cpid;
404 my $previous_alarm = alarm (10);
406 local $SIG{ALRM
} = sub { die "timed out!\n" };
408 while (defined ($line = <TMP
>)) {
409 print $logfd "DC TRACEROUTE: $line";
410 if ($line =~ m/\s*\d+\s+(\d+\.\d+\.\d+\.\d+)\s/) {
411 my $geoip = `geoiplookup $1`;
412 print $logfd "DC GEOIP: $geoip";
413 if ($geoip =~ m/GeoIP Country Edition:\s*([A-Z]+),/) {
415 print $logfd "DC FOUND: $country\n";
424 alarm ($previous_alarm);
429 print "unable to detect country - $err\n";
431 print "detected country: " . uc($country) . "\n";
433 print "unable to detect country\n";
441 open (MEMINFO, "/proc/meminfo");
443 my $res = 512; # default to 512 if something goes wrong
444 while (my $line = <MEMINFO>) {
445 if ($line =~ m/^MemTotal:\s+(\d+)\s*kB/i) {
446 $res = int ($1 / 1024);
455 my $total_memory = get_memtotal();
458 my ($src, $dest) = @_;
460 my ($dev1,$ino1) = stat ($src);
461 my ($dev2,$ino2) = stat ($dest);
463 return 0 if !($dev1 && $dev2 && $ino1 && $ino2);
465 return $ino1 == $ino2 && $dev1 == $dev2;
468 sub find_stable_path {
469 my ($stabledir, $bdev) = @_;
471 foreach my $path (<$stabledir/*>) {
472 if (link_points_to ($path, $bdev)) {
473 return wantarray ? ($path, basename($path)) : $path;
478 sub find_dev_by_uuid {
481 my ($full_path, $name) = find_stable_path ("/dev/disk/by-uuid", $bdev);
491 push @$res, [-1, $opt_testmode, int((-s $opt_testmode)/512), "TESTDISK"];
497 foreach my $bd (</sys/block/*>) {
498 next if $bd =~ m|^/sys/block/ram\d+$|;
499 next if $bd =~ m|^/sys/block/loop\d+$|;
500 next if $bd =~ m|^/sys/block/md\d+$|;
501 next if $bd =~ m|^/sys/block/dm-.*$|;
502 next if $bd =~ m|^/sys/block/fd\d+$|;
503 next if $bd =~ m|^/sys/block/sr\d+$|;
505 my $dev = file_read_firstline("$bd/dev");
510 my $info = `udevadm info
--path
$bd --query all
`;
513 next if $info !~ m/^E: DEVTYPE=disk$/m;
515 next if $info =~ m/^E: ID_CDROM/m;
517 my ($name) = $info =~ m/^N: (\S+)$/m;
520 my $real_name = "/dev/$name";
522 my $size = file_read_firstline("$bd/size");
524 $size = undef if !($size && $size =~ m/^\d+$/);
526 my $model = file_read_firstline("$bd/device/model") || '';
529 if (length ($model) > 30) {
530 $model = substr ($model, 0, 30);
532 push @$res, [$count++, $real_name, $size, $model] if $size;
534 print STDERR "ERROR: unable to map device $dev ($bd)\n";
542 my $countryfn = "${proxmox_libdir}/country.dat";
543 open (TMP, "<$countryfn") || die "unable to open '$countryfn' - $!\n";
546 my $countryhash = {};
549 while (defined ($line = <TMP>)) {
550 if ($line =~ m|^map:([^\s:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]*):$|) {
558 $kmaphash->{$2} = $1;
559 } elsif ($line =~ m|^([a-z]{2}):([^:]+):([^:]*):([^:]*):$|) {
565 $countryhash->{lc($2)} = $1;
567 warn "unable to parse 'country.dat' line: $line";
574 my $zonefn = "/usr/share/zoneinfo/zone.tab";
575 open (TMP, "<$zonefn") || die "unable to open '$zonefn' - $!\n";
576 while (defined ($line = <TMP>)) {
577 next if $line =~ m/^\#/;
578 next if $line =~ m/^\s*$/;
579 if ($line =~ m|^([A-Z][A-Z])\s+\S+\s+(([^/]+)/\S+)\s|) {
581 $cczones->{$cc}->{$2} = 1;
582 $country->{$cc}->{zone} = $2 if !defined ($country->{$cc}->{zone});
593 countryhash => $countryhash,
595 kmaphash => $kmaphash,
599 # search for Harddisks
600 my $hds = hd_list ();
605 foreach my $hd (@$hds) {
606 my ($disk, $devname, $size, $model) = @$hd;
607 # size is always in 512B "sectors"! convert to KB
608 return int($size/2) if $devname eq $dev;
611 die "no such device '$dev'\n";
614 sub get_partition_dev {
615 my ($dev, $partnum) = @_;
617 if ($dev =~ m|^/dev/[hxsev]d[a-z]$|) {
618 return "${dev}$partnum";
619 } elsif ($dev =~ m|^/dev/[^/]+/c\d+d\d+$|) {
620 return "${dev}p$partnum";
621 } elsif ($dev =~ m|^/dev/[^/]+/d\d+$|) {
622 return "${dev}p$partnum";
623 } elsif ($dev =~ m|^/dev/[^/]+/hd[a-z]$|) {
624 return "${dev}$partnum";
625 } elsif ($dev =~ m|^/dev/nvme\d+n\d+$|) {
626 return "${dev}p$partnum";
628 die "unable to get device for partition $partnum on device $dev\n";
633 sub file_get_contents {
634 my ($filename, $max) = @_;
636 my $fh = IO::File->new($filename, "r") ||
637 die "can't open '$filename' - $!\n";
639 local $/; # slurp mode
649 my ($text, $filename) = @_;
651 my $fd = IO::File->new (">$filename") ||
652 die "unable to open file '$filename' - $!\n";
657 sub update_progress {
658 my ($frac, $start, $end, $text) = @_;
660 my $part = $end - $start;
661 my $res = $start + $frac*$part;
663 $progress->set_fraction ($res);
664 $progress->set_text (sprintf ("%d%%", int ($res*100)));
665 $progress_status->set_text ($text) if defined ($text);
667 Gtk3::main_iteration() while Gtk3::events_pending();
672 mkfs => 'mkfs.ext3 -F',
674 mkfs_data_opt => '-m 0',
675 root_mountopt => 'errors=remount-ro',
678 mkfs => 'mkfs.ext4 -F',
680 mkfs_data_opt => '-m 0',
681 root_mountopt => 'errors=remount-ro',
684 mkfs => 'mkfs.xfs -f',
691 sub create_filesystem {
692 my ($dev, $name, $type, $start, $end, $fs, $fe) = @_;
694 my $range = $end - $start;
695 my $rs = $start + $range*$fs;
696 my $re = $start + $range*$fe;
699 my $fsdata = $fssetup->{$type} || die "internal error - unknown file system '$type'";
700 my $opts = $name eq 'root' ? $fsdata->{mkfs_root_opt} : $fsdata->{mkfs_data_opt};
702 update_progress (0, $rs, $re, "creating $name filesystem");
704 run_command ("$fsdata->{mkfs} $opts $dev", sub {
707 if ($line =~ m/Writing inode tables:\s+(\d+)\/(\d+)/) {
709 } elsif ($max && $line =~ m/(\d+)\/$max/) {
710 update_progress (($1/$max)*0.9, $rs, $re);
711 } elsif ($line =~ m/Creating journal.*done/) {
712 update_progress (0.95, $rs, $re);
713 } elsif ($line =~ m/Writing superblocks and filesystem.*done/) {
714 update_progress (1, $rs, $re);
720 my ($targetdir, $dcdata) = @_;
722 my $cfgfile = "/tmp/debconf.txt";
723 write_config ($dcdata, "$targetdir/$cfgfile");
724 syscmd ("chroot $targetdir debconf-set-selections $cfgfile");
725 unlink "$targetdir/$cfgfile";
729 my ($targetdir, $cmd, $new_cmd) = @_;
731 syscmd ("chroot $targetdir dpkg-divert --package proxmox " .
732 "--add --rename $cmd") == 0 ||
733 die "unable to exec dpkg-divert\n";
735 syscmd ("ln -sf ${new_cmd} $targetdir/$cmd") == 0 ||
736 die "unable to link diversion to ${new_cmd}\n";
739 sub diversion_remove {
740 my ($targetdir, $cmd) = @_;
742 syscmd ("mv $targetdir/${cmd}.distrib $targetdir/${cmd};") == 0 ||
743 die "unable to remove $cmd diversion\n";
745 syscmd ("chroot $targetdir dpkg-divert --remove $cmd") == 0 ||
746 die "unable to remove $cmd diversion\n";
750 my ($partitions, $mode) = @_;
752 die "unknown btrfs mode '$mode'"
753 if !($mode eq 'single' || $mode eq 'raid0' ||
754 $mode eq 'raid1' || $mode eq 'raid10');
756 my $cmd = ['mkfs.btrfs', '-f'];
758 push @$cmd, '-d', $mode, '-m', $mode;
760 push @$cmd, @$partitions;
765 sub zfs_create_rpool {
768 my $cmd = "zpool create -f -o cachefile=none";
770 $cmd .= " -o ashift=$config_options->{ashift}"
771 if defined($config_options->{ashift});
773 syscmd ("$cmd $zfspoolname $vdev") == 0 ||
774 die "unable to create zfs root pool\n";
776 syscmd ("zfs create $zfspoolname/ROOT") == 0 ||
777 die "unable to create zfs $zfspoolname/ROOT volume\n";
779 syscmd ("zfs create $zfspoolname/data") == 0 ||
780 die "unable to create zfs $zfspoolname/data volume\n";
782 syscmd ("zfs create $zfspoolname/ROOT/$zfsrootvolname") == 0 ||
783 die "unable to create zfs $zfspoolname/ROOT/$zfsrootvolname volume\n";
785 # disable atime during install
786 syscmd ("zfs set atime=off $zfspoolname") == 0 ||
787 die "unable to set zfs properties\n";
789 my $value = $config_options->{compress};
790 syscmd ("zfs set compression=$value $zfspoolname")
791 if defined($value) && $value ne 'off';
793 $value = $config_options->{checksum};
794 syscmd ("zfs set checksum=$value $zfspoolname")
795 if defined($value) && $value ne 'on';
797 $value = $config_options->{copies};
798 syscmd ("zfs set copies=$value $zfspoolname")
799 if defined($value) && $value != 1;
802 sub zfs_create_swap {
805 my $cmd = "zfs create -V ${swapsize}K -b 4K";
807 $cmd .= " -o com.sun:auto-snapshot=false";
809 # copies for swap does not make sense
810 $cmd .= " -o copies=1";
812 # reduces memory pressure
813 $cmd .= " -o sync=always";
815 # cheapest compression to drop zero pages
816 $cmd .= " -o compression=zle";
819 $cmd .= " -o logbias=throughput";
820 # only cache metadata in RAM (caching swap content does not make sense)
821 $cmd .= " -o primarycache=metadata";
822 # don't cache anything in L2ARC
823 $cmd .= " -o secondarycache=none";
825 $cmd .= " $zfspoolname/swap";
826 syscmd ($cmd) == 0 ||
827 die "unable to create zfs swap device\n";
829 return "/dev/zvol/$zfspoolname/swap";
832 my $udevadm_trigger_block = sub {
835 sleep(1) if !$nowait; # give kernel time to reread part table
837 # trigger udev to create /dev/disk/by-uuid
838 syscmd ("udevadm trigger --subsystem-match block");
839 syscmd ("udevadm settle --timeout 10");
842 my $clean_disk = sub {
845 my $partitions = `lsblk
--output kname
--noheadings
--path
--list
$disk`;
846 foreach my $part (split "\n", $partitions) {
847 next if $part eq $disk;
848 next if $part !~ /^\Q$disk\E/;
849 eval { syscmd
("pvremove -ff -y $part"); };
850 eval { syscmd
("dd if=/dev/zero of=$part bs=1M count=16"); };
854 sub partition_bootable_disk
{
855 my ($target_dev, $maxhdsize, $ptype) = @_;
857 die "too dangerous" if $opt_testmode;
859 die "unknown partition type '$ptype'"
860 if !($ptype eq '8E00' || $ptype eq '8300');
862 syscmd
("sgdisk -Z ${target_dev}");
863 my $hdsize = hd_size
($target_dev); # size in KB (1024 bytes)
865 my $restricted_hdsize_mb = 0; # 0 ==> end of partition
866 if ($maxhdsize && ($maxhdsize < $hdsize)) {
867 $hdsize = $maxhdsize;
868 $restricted_hdsize_mb = int($hdsize/1024) . 'M';
871 my $hdgb = int($hdsize/(1024*1024));
872 die "hardisk '$target_dev' too small (${hdsize}GB)\n" if $hdgb < 8;
874 # 1 - BIOS boot partition (Grub Stage2): first free 1M
875 # 2 - EFI ESP: next free 256M
876 # 3 - OS/Data partition: rest, up to $maxhdsize in MB
878 my $grubbootdev = get_partition_dev
($target_dev, 1);
879 my $efibootdev = get_partition_dev
($target_dev, 2);
880 my $osdev = get_partition_dev
($target_dev, 3);
882 my $pcmd = ['sgdisk'];
885 push @$pcmd, "-n${pnum}:1M:+1M", "-t$pnum:EF02";
888 push @$pcmd, "-n${pnum}:2M:+256M", "-t$pnum:EF00";
891 push @$pcmd, "-n${pnum}:258M:${restricted_hdsize_mb}", "-t$pnum:$ptype";
893 push @$pcmd, $target_dev;
895 my $os_size = $hdsize - 258*1024; # 256M + 1M + 1M alignment
897 syscmd
($pcmd) == 0 ||
898 die "unable to partition harddisk '${target_dev}'\n";
900 &$udevadm_trigger_block();
902 foreach my $part ($efibootdev, $osdev) {
903 syscmd
("dd if=/dev/zero of=$part bs=1M count=256") if -b
$part;
906 return ($os_size, $osdev, $efibootdev);
909 # ZFS has this use_whole_disk concept, so we try to partition the same
910 # way as zfs does by default. There is room at start of disk to insert
911 # a grub boot partition. But adding a EFI ESP is not possible.
913 # Note: zfs people think this is just a waste of space an not
914 # required. Instead, you should put the ESP on another disk (log,
917 sub partition_bootable_zfs_disk
{
918 my ($target_dev) = @_;
920 die "too dangerous" if $opt_testmode;
922 syscmd
("sgdisk -Z ${target_dev}");
923 my $hdsize = hd_size
($target_dev); # size in blocks (1024 bytes)
925 my $hdgb = int($hdsize/(1024*1024));
926 die "hardisk '$target_dev' too small (${hdsize}GB)\n" if $hdgb < 8;
928 # 1 - GRUB boot partition: 1M
929 # 2 - OS/Data partition
930 # 9 - ZFS reserved partition
932 my $grubbootdev = get_partition_dev
($target_dev, 1);
933 my $osdev = get_partition_dev
($target_dev, 2);
935 my $pcmd = ['sgdisk', '-a1'];
938 push @$pcmd, "-n$pnum:34:2047", "-t$pnum:EF02";
941 push @$pcmd, "-n$pnum:-8M:0", "-t$pnum:BF07";
944 push @$pcmd, "-n$pnum:2048:0", "-t$pnum:BF01", '-c', "$pnum:zfs";
946 push @$pcmd, $target_dev;
948 my $os_size = $hdsize - 1024 - 1024*8;
950 syscmd
($pcmd) == 0 ||
951 die "unable to partition harddisk '${target_dev}'\n";
953 &$udevadm_trigger_block();
955 syscmd
("dd if=/dev/zero of=$osdev bs=1M count=16") if -b
$osdev;
957 return ($os_size, $osdev);
960 sub create_lvm_volumes
{
961 my ($lvmdev, $os_size, $swap_size) = @_;
963 my $vgname = $setup->{product
};
965 my $rootdev = "/dev/$vgname/root";
966 my $datadev = "/dev/$vgname/data";
967 my $swapfile = "/dev/$vgname/swap";
969 # we use --metadatasize 250k, which results in "pe_start = 512"
970 # so pe_start is aligned on a 128k boundary (advantage for SSDs)
971 syscmd
("/sbin/pvcreate --metadatasize 250k -y -ff $lvmdev") == 0 ||
972 die "unable to initialize physical volume $lvmdev\n";
973 syscmd
("/sbin/vgcreate $vgname $lvmdev") == 0 ||
974 die "unable to create volume group '$vgname'\n";
976 my $hdgb = int($os_size/(1024*1024));
977 my $space = (($hdgb > 128) ?
16 : ($hdgb/8))*1024*1024;
980 if ($config_options->{maxroot
}) {
981 $maxroot = $config_options->{maxroot
};
986 my $rootsize = (($hdgb > ($maxroot*4)) ?
$maxroot : $hdgb/4)*1024*1024;
988 my $rest = $os_size - $swap_size - $rootsize; # in KB
991 if ($config_options->{minfree
}) {
992 $minfree = (($config_options->{minfree
}*1024*1024) >= $rest ) ?
$space :
993 $config_options->{minfree
}*1024*1024 ;
998 $rest = $rest - $minfree;
1000 if ($config_options->{maxvz
}) {
1001 $rest = (($config_options->{maxvz
}*1024*1024) <= $rest) ?
1002 $config_options->{maxvz
}*1024*1024 : $rest;
1005 syscmd
("/sbin/lvcreate -L${swap_size}K -nswap $vgname") == 0 ||
1006 die "unable to create swap volume\n";
1008 syscmd
("/sbin/lvcreate -L${rootsize}K -nroot $vgname") == 0 ||
1009 die "unable to create root volume\n";
1011 syscmd
("/sbin/lvcreate -L${rest}K -ndata $vgname") == 0 ||
1012 die "unable to create data volume\n";
1014 syscmd
("/sbin/lvconvert --yes --type thin-pool $vgname/data") == 0 ||
1015 die "unable to create data thin-pool\n";
1017 syscmd
("/sbin/vgchange -a y $vgname") == 0 ||
1018 die "unable to activate volume group\n";
1020 return ($rootdev, $datadev, $swapfile);
1023 sub compute_swapsize
{
1026 my $hdgb = int($hdsize/(1024*1024));
1029 if ($config_options->{swapsize
}) {
1030 $swapsize = $config_options->{swapsize
}*1024*1024;
1032 my $ss = int ($total_memory / 1024);
1034 $ss = ($hdgb/8) if $ss > ($hdgb/8);
1036 $swapsize = $ss*1024*1024;
1044 my ($basefile, $targetdir) = @_;
1046 die "target '$targetdir' does not exist\n" if ! -d
$targetdir;
1048 my $starttime = [Time
::HiRes
::gettimeofday
];
1050 my $bootdevinfo = [];
1059 my $filesys = $config_options->{filesys
};
1061 if ($filesys =~ m/zfs/) {
1062 $target_hd = undef; # do not use this config
1064 $targetdir = "/$zfspoolname/ROOT/$zfsrootvolname";
1065 } elsif ($filesys =~ m/btrfs/) {
1066 $target_hd = undef; # do not use this config
1072 for ($i = 5; $i > 0; $i--) {
1073 syscmd
("modprobe zfs");
1074 last if -c
"/dev/zfs";
1078 die "unable to load zfs kernel module\n" if !$i;
1086 update_progress
(0, 0, $maxper, "create partitions");
1088 syscmd
("vgchange -an") if !$opt_testmode; # deactivate all detected VGs
1090 if ($opt_testmode) {
1092 $rootdev = abs_path
($opt_testmode);
1093 syscmd
("umount $rootdev");
1097 die "unsupported btrfs mode (for testing environment)\n"
1098 if $filesys ne 'btrfs (RAID0)';
1100 btrfs_create
([$rootdev], 'single');
1102 } elsif ($use_zfs) {
1104 die "unsupported zfs mode (for testing environment)\n"
1105 if $filesys ne 'zfs (RAID0)';
1107 syscmd
("zpool destroy $zfstestpool");
1109 zfs_create_rpool
($rootdev);
1116 } elsif ($use_btrfs) {
1118 my ($devlist, $btrfs_mode) = get_btrfs_raid_setup
();
1119 my $btrfs_partitions = [];
1121 foreach my $hd (@$devlist) {
1122 my $devname = @$hd[1];
1123 &$clean_disk($devname);
1124 my ($size, $osdev, $efidev) =
1125 partition_bootable_disk
($devname, undef, '8300');
1126 $rootdev = $osdev if !defined($rootdev); # simply point to first disk
1127 my $by_id = find_stable_path
("/dev/disk/by-id", $devname);
1128 push @$bootdevinfo, { esp
=> $efidev, devname
=> $devname,
1129 osdev
=> $osdev, by_id
=> $by_id };
1130 push @$btrfs_partitions, $osdev;
1134 &$udevadm_trigger_block();
1136 btrfs_create
($btrfs_partitions, $btrfs_mode);
1138 } elsif ($use_zfs) {
1140 my ($devlist, $bootdevlist, $vdev) = get_zfs_raid_setup
();
1143 foreach my $hd (@$devlist) {
1144 &$clean_disk(@$hd[1]);
1146 foreach my $hd (@$bootdevlist) {
1147 my $devname = @$hd[1];
1148 my ($size, $osdev) =
1149 partition_bootable_zfs_disk
($devname);
1150 zfs_mirror_size_check
($disksize, $size) if $disksize;
1151 push @$bootdevinfo, { devname
=> $devname, osdev
=> $osdev};
1155 &$udevadm_trigger_block();
1157 foreach my $di (@$bootdevinfo) {
1158 my $devname = $di->{devname
};
1159 $di->{by_id
} = find_stable_path
("/dev/disk/by-id", $devname);
1161 # Note: using /dev/disk/by-id/ does not work for unknown reason, we get
1162 # cannot create 'rpool': no such pool or dataset
1163 #my $osdev = find_stable_path ("/dev/disk/by-id", $di->{osdev}) || $di->{osdev};
1165 my $osdev = $di->{osdev
};
1166 $vdev =~ s/ $devname/ $osdev/;
1169 zfs_create_rpool
($vdev);
1171 my $swap_size = compute_swapsize
($disksize);
1172 $swapfile = zfs_create_swap
($swap_size);
1176 die "target '$target_hd' is not a valid block device\n" if ! -b
$target_hd;
1179 if ($config_options->{hdsize
}) {
1180 # max hdsize passed on cmdline (GB)
1181 $maxhdsize = $config_options->{hdsize
}*1024*1024;
1184 &$clean_disk($target_hd);
1186 my ($os_size, $osdev, $efidev);
1187 ($os_size, $osdev, $efidev) =
1188 partition_bootable_disk
($target_hd, $maxhdsize, '8E00');
1190 &$udevadm_trigger_block();
1192 my $by_id = find_stable_path
("/dev/disk/by-id", $target_hd);
1193 push @$bootdevinfo, { esp
=> $efidev, devname
=> $target_hd,
1194 osdev
=> $osdev, by_id
=> $by_id };
1196 my $swap_size = compute_swapsize
($os_size);
1197 ($rootdev, $datadev, $swapfile) =
1198 create_lvm_volumes
($osdev, $os_size, $swap_size);
1200 # trigger udev to create /dev/disk/by-uuid
1201 &$udevadm_trigger_block(1);
1205 # to be fast during installation
1206 syscmd
("zfs set sync=disabled $zfspoolname") == 0 ||
1207 die "unable to set zfs properties\n";
1210 update_progress
(0.03, 0, $maxper, "create swap space");
1212 syscmd
("mkswap -f $swapfile") == 0 ||
1213 die "unable to create swap space\n";
1216 update_progress
(0.05, 0, $maxper, "creating filesystems");
1218 foreach my $di (@$bootdevinfo) {
1219 next if !$di->{esp
};
1220 syscmd
("mkfs.vfat -F32 $di->{esp}") == 0 ||
1221 die "unable to initialize EFI ESP on device $di->{esp}\n";
1226 } elsif ($use_btrfs) {
1229 create_filesystem
($rootdev, 'root', $filesys, 0.05, $maxper, 0, 1);
1232 update_progress
(1, 0.05, $maxper, "mounting target $rootdev");
1237 my $mount_opts = 'noatime';
1238 $mount_opts .= ',nobarrier'
1239 if $use_btrfs || $filesys =~ /^ext\d$/;
1241 syscmd
("mount -n $rootdev -o $mount_opts $targetdir") == 0 ||
1242 die "unable to mount $rootdev\n";
1245 mkdir "$targetdir/boot";
1246 mkdir "$targetdir/boot/efi";
1248 mkdir "$targetdir/var";
1249 mkdir "$targetdir/var/lib";
1251 if ($setup->{product
} eq 'pve') {
1252 mkdir "$targetdir/var/lib/vz";
1253 mkdir "$targetdir/var/lib/pve";
1256 syscmd
("btrfs subvolume create $targetdir/var/lib/pve/local-btrfs") == 0 ||
1257 die "unable to create btrfs subvolume\n";
1261 display_html
("extract2-rulesystem.htm");
1262 update_progress
(1, 0.05, $maxper, "extracting base system");
1264 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = stat ($basefile);
1265 $ino || die "unable to open file '$basefile' - $!\n";
1267 my $files = file_read_firstline
("${proxmox_cddir}/proxmox/$setup->{product}-base.cnt") ||
1268 die "unable to read base file count\n";
1273 run_command
("unsquashfs -f -dest $targetdir -i $basefile", sub {
1275 return if $line !~ m/^$targetdir/;
1277 my $nper = int (($count *100)/$files);
1278 if ($nper != $per) {
1280 my $frac = $per > 100 ?
1 : $per/100;
1281 update_progress
($frac, $maxper, 0.5);
1285 syscmd
("mount -n -t tmpfs tmpfs $targetdir/tmp") == 0 ||
1286 die "unable to mount tmpfs on $targetdir/tmp\n";
1287 syscmd
("mount -n -t proc proc $targetdir/proc") == 0 ||
1288 die "unable to mount proc on $targetdir/proc\n";
1289 syscmd
("mount -n -t sysfs sysfs $targetdir/sys") == 0 ||
1290 die "unable to mount sysfs on $targetdir/sys\n";
1292 display_html
("extract3-spam.htm");
1293 update_progress
(1, $maxper, 0.5, "configuring base system");
1298 "127.0.0.1 localhost.localdomain localhost\n" .
1299 "$ipaddress $hostname.$domain $hostname pvelocalhost\n\n" .
1300 "# The following lines are desirable for IPv6 capable hosts\n\n" .
1301 "::1 ip6-localhost ip6-loopback\n" .
1302 "fe00::0 ip6-localnet\n" .
1303 "ff00::0 ip6-mcastprefix\n" .
1304 "ff02::1 ip6-allnodes\n" .
1305 "ff02::2 ip6-allrouters\n" .
1306 "ff02::3 ip6-allhosts\n";
1308 write_config
($hosts, "$targetdir/etc/hosts");
1310 write_config
("$hostname\n", "$targetdir/etc/hostname");
1312 syscmd
("/bin/hostname $hostname") if !$opt_testmode;
1314 # configure interfaces
1316 my $ifaces = "auto lo\niface lo inet loopback\n\n";
1318 my $ntype = $ipversion == 4 ?
'inet' : 'inet6';
1320 my $ethdev = $ipconf->{ifaces
}->{$ipconf->{selected
}}->{name
};
1322 if ($setup->{bridged_network
}) {
1323 $ifaces .= "iface $ethdev $ntype manual\n";
1326 "\nauto vmbr0\niface vmbr0 $ntype static\n" .
1327 "\taddress $ipaddress\n" .
1328 "\tnetmask $netmask\n" .
1329 "\tgateway $gateway\n" .
1330 "\tbridge_ports $ethdev\n" .
1331 "\tbridge_stp off\n" .
1334 $ifaces .= "auto $ethdev\n" .
1335 "iface $ethdev $ntype static\n" .
1336 "\taddress $ipaddress\n" .
1337 "\tnetmask $netmask\n" .
1338 "\tgateway $gateway\n";
1341 foreach my $iface (sort keys %{$ipconf->{ifaces
}}) {
1342 my $name = $ipconf->{ifaces
}->{$iface}->{name
};
1343 next if $name eq $ethdev;
1345 $ifaces .= "\niface $name $ntype manual\n";
1348 write_config
($ifaces, "$targetdir/etc/network/interfaces");
1352 my $resolvconf = "search $domain\nnameserver $dnsserver\n";
1353 write_config
($resolvconf, "$targetdir/etc/resolv.conf");
1357 my $fstab = "# <file system> <mount point> <type> <options> <dump> <pass>\n";
1361 } elsif ($use_btrfs) {
1363 my $cmd = "blkid -u filesystem -t TYPE=btrfs -o export $rootdev";
1364 run_command
($cmd, sub {
1367 if ($line =~ m/^UUID=([A-Fa-f0-9\-]+)$/) {
1372 die "unable to detect FS UUID" if !defined($fsuuid);
1374 $fstab .= "UUID=$fsuuid / btrfs defaults 0 1\n";
1376 my $root_mountopt = $fssetup->{$filesys}->{root_mountopt
} || 'defaults';
1377 $fstab .= "$rootdev / $filesys ${root_mountopt} 0 1\n";
1381 # Note: this is required by current grub, but really dangerous, because
1382 # vfat does not have journaling, so it triggers manual fsck after each crash
1383 # so we only mount /boot/efi if really required (efi systems).
1384 if ($grub_plattform =~ m/^efi-/) {
1385 if (scalar(@$bootdevinfo)) {
1386 my $di = @$bootdevinfo[0]; # simply use first disk
1388 my $efi_boot_uuid = $di->{esp
};
1389 if (my $uuid = find_dev_by_uuid
($di->{esp
})) {
1390 $efi_boot_uuid = "UUID=$uuid";
1393 $fstab .= "${efi_boot_uuid} /boot/efi vfat defaults 0 1\n";
1399 $fstab .= "$swapfile none swap sw 0 0\n" if $swapfile;
1401 $fstab .= "proc /proc proc defaults 0 0\n";
1403 write_config
($fstab, "$targetdir/etc/fstab");
1404 write_config
("", "$targetdir/etc/mtab");
1406 syscmd
("cp ${proxmox_libdir}/policy-disable-rc.d " .
1407 "$targetdir/usr/sbin/policy-rc.d") == 0 ||
1408 die "unable to copy policy-rc.d\n";
1409 syscmd
("cp ${proxmox_libdir}/fake-start-stop-daemon " .
1410 "$targetdir/sbin/") == 0 ||
1411 die "unable to copy start-stop-daemon\n";
1413 diversion_add
($targetdir, "/sbin/start-stop-daemon", "/sbin/fake-start-stop-daemon");
1414 diversion_add
($targetdir, "/usr/sbin/update-grub", "/bin/true");
1415 diversion_add
($targetdir, "/usr/sbin/update-initramfs", "/bin/true");
1417 syscmd
("touch $targetdir/proxmox_install_mode");
1419 my $grub_install_devices_txt = '';
1420 foreach my $di (@$bootdevinfo) {
1421 $grub_install_devices_txt .= ', ' if $grub_install_devices_txt;
1422 $grub_install_devices_txt .= $di->{by_id
} || $di->{devname
};
1425 # Note: keyboard-configuration/xbkb-keymap is used by console-setup
1426 my $xkmap = $cmap->{kmap
}->{$keymap}->{x11
} // 'us';
1428 debconfig_set
($targetdir, <<_EOD);
1429 locales locales/default_environment_locale select en_US.UTF-8
1430 locales locales/locales_to_be_generated select en_US.UTF-8 UTF-8
1431 samba-common samba-common/dhcp boolean false
1432 samba-common samba-common/workgroup string WORKGROUP
1433 postfix postfix/main_mailer_type select No configuration
1434 keyboard-configuration keyboard-configuration/xkb-keymap select $xkmap
1435 d-i debian-installer/locale select en_US.UTF-8
1436 grub-pc grub-pc/install_devices select $grub_install_devices_txt
1440 while (<${proxmox_pkgdir
}/*.deb
>) { $pkg_count++ };
1442 # btrfs/dpkg is extremely slow without --force-unsafe-io
1443 my $dpkg_opts = $use_btrfs ?
"--force-unsafe-io" : "";
1446 while (<${proxmox_pkgdir
}/*.deb
>) {
1449 my ($deb) = $path =~ m/${proxmox_pkgdir}\/(.*\
.deb
)/;
1450 # if ($deb =~ m/^grub-efi-/ && $deb !~ m/^grub-${grub_plattform}/) {
1454 update_progress
($count/$pkg_count, 0.5, 0.75, "extracting $deb");
1455 print "extracting: $deb\n";
1456 syscmd
("cp $path $targetdir/tmp/$deb") == 0 ||
1457 die "installation of package $deb failed\n";
1458 syscmd
("chroot $targetdir dpkg $dpkg_opts --force-depends --no-triggers --unpack /tmp/$deb") == 0 ||
1459 die "installation of package $deb failed\n";
1460 update_progress
((++$count)/$pkg_count, 0.5, 0.75);
1463 display_html
("extract4-virus.htm");
1465 # needed for postfix postinst in case no other NIC is active
1466 syscmd
("chroot $targetdir ifup lo");
1468 my $cmd = "chroot $targetdir dpkg $dpkg_opts --force-confold --configure -a";
1470 run_command
($cmd, sub {
1472 if ($line =~ m/Setting up\s+(\S+)/) {
1473 update_progress
((++$count)/$pkg_count, 0.75, 0.95,
1478 unlink "$targetdir/etc/mailname";
1479 $postfix_main_cf =~ s/__FQDN__/${hostname}.${domain}/;
1480 write_config
($postfix_main_cf, "$targetdir/etc/postfix/main.cf");
1482 # make sure we have all postfix directories
1483 syscmd
("chroot $targetdir /usr/sbin/postfix check");
1484 # cleanup mail queue
1485 syscmd
("chroot $targetdir /usr/sbin/postsuper -d ALL");
1487 # enable NTP (timedatectl set-ntp true does not work without DBUS)
1488 syscmd
("chroot $targetdir /bin/systemctl enable systemd-timesyncd.service");
1490 unlink "$targetdir/proxmox_install_mode";
1493 unlink ("$targetdir/etc/localtime");
1494 symlink ("/usr/share/zoneinfo/$timezone", "$targetdir/etc/localtime");
1495 write_config
("$timezone\n", "$targetdir/etc/timezone");
1498 if (my $mirror = $cmap->{country
}->{$country}->{mirror
}) {
1499 my $fn = "$targetdir/etc/apt/sources.list";
1500 syscmd
("sed -i 's/ftp\\.debian\\.org/$mirror/' '$fn'");
1503 # create extended_states for apt (avoid cron job warning if that
1504 # file does not exist)
1505 write_config
('', "$targetdir/var/lib/apt/extended_states");
1507 # allow ssh root login
1508 syscmd
("sed -i 's/^PermitRootLogin.*/PermitRootLogin yes/' '$targetdir/etc/ssh/sshd_config'");
1510 if ($setup->{product
} eq 'pmg') {
1511 # install initial clamav DB
1512 my $srcdir = "${proxmox_cddir}/proxmox/clamav";
1513 foreach my $fn ("main.cvd", "bytecode.cvd", "daily.cvd", "safebrowsing.cvd") {
1514 syscmd
("cp \"$srcdir/$fn\" \"$targetdir/var/lib/clamav\"") == 0 ||
1515 die "installation of clamav db file '$fn' failed\n";
1517 syscmd
("chroot $targetdir /bin/chown clamav:clamav -R /var/lib/clamav") == 0 ||
1518 die "unable to set owner for clamav database files\n";
1521 if ($setup->{product
} eq 'pve') {
1522 # save installer settings
1523 my $ucc = uc ($country);
1524 debconfig_set
($targetdir, "pve-manager pve-manager/country string $ucc\n");
1527 update_progress
(0.8, 0.95, 1, "make system bootable");
1530 syscmd
("sed -i -e 's/^GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"root=ZFS=$zfspoolname\\/ROOT\\/$zfsrootvolname boot=zfs\"/' $targetdir/etc/default/grub") == 0 ||
1531 die "unable to update /etc/default/grub\n";
1535 diversion_remove
($targetdir, "/usr/sbin/update-grub");
1536 diversion_remove
($targetdir, "/usr/sbin/update-initramfs");
1539 foreach my $fn (<$targetdir/lib/modules/*>) {
1540 if ($fn =~ m!/(\d+\.\d+\.\d+-\d+-pve)$!) {
1541 die "found multiple kernels\n" if defined($kapi);
1545 die "unable to detect kernel version\n" if !defined($kapi);
1547 if (!$opt_testmode) {
1549 unlink ("$targetdir/etc/mtab");
1550 symlink ("/proc/mounts", "$targetdir/etc/mtab");
1551 syscmd
("mount -n --bind /dev $targetdir/dev");
1553 syscmd
("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0 ||
1554 die "unable to install initramfs\n";
1556 foreach my $di (@$bootdevinfo) {
1557 my $dev = $di->{devname
};
1558 syscmd
("chroot $targetdir /usr/sbin/grub-install --target i386-pc --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
1559 die "unable to install the i386-pc boot loader on '$dev'\n";
1562 syscmd
("mount -n $di->{esp} -t vfat $targetdir/boot/efi") == 0 ||
1563 die "unable to mount $di->{esp}\n";
1564 my $rc = syscmd
("chroot $targetdir /usr/sbin/grub-install --target x86_64-efi --no-floppy --bootloader-id='proxmox' $dev");
1566 if (-d
'/sys/firmware/efi') {
1567 die "unable to install the EFI boot loader on '$dev'\n";
1569 warn "unable to install the EFI boot loader on '$dev', ignoring (not booted using UEFI)\n";
1572 # also install fallback boot file (OVMF does not boot without)
1573 mkdir("$targetdir/boot/efi/EFI/BOOT");
1574 syscmd
("cp $targetdir/boot/efi/EFI/proxmox/grubx64.efi $targetdir/boot/efi/EFI/BOOT/BOOTx64.EFI") == 0 ||
1575 die "unable to copy efi boot loader\n";
1577 syscmd
("umount $targetdir/boot/efi") == 0 ||
1578 die "unable to umount $targetdir/boot/efi\n";
1582 syscmd
("chroot $targetdir /usr/sbin/update-grub") == 0 ||
1583 die "unable to update boot loader config\n";
1585 syscmd
("umount $targetdir/dev");
1590 # hack: remove dead.letter from sshd installation
1591 syscmd
("rm -rf $targetdir/dead.letter");
1593 unlink "$targetdir/usr/sbin/policy-rc.d";
1595 diversion_remove
($targetdir, "/sbin/start-stop-daemon");
1598 my $octets = encode
("utf-8", $password);
1599 run_command
("chroot $targetdir /usr/sbin/chpasswd", undef,
1602 if ($setup->{product
} eq 'pmg') {
1604 write_config
("#Unix Superuser\nroot:1:0::root:${mailto}:::\n",
1605 "$targetdir/etc/pmg/user.conf");
1607 } elsif ($setup->{product
} eq 'pve') {
1611 my $tmpdir = "$targetdir/tmp/pve";
1614 # write vnc keymap to datacenter.cfg
1615 my $vnckmap = $cmap->{kmap
}->{$keymap}->{kvm
} || 'en-us';
1616 write_config
("keyboard: $vnckmap\n",
1617 "$tmpdir/datacenter.cfg");
1620 write_config
("user:root\@pam:1:0:::${mailto}::\n",
1621 "$tmpdir/user.cfg");
1624 my $strorage_cfg_fn = "$tmpdir/storage.cfg";
1626 write_config
($storage_cfg_zfs, $strorage_cfg_fn);
1627 } elsif ($use_btrfs) {
1628 write_config
($storage_cfg_btrfs, $strorage_cfg_fn);
1630 write_config
($storage_cfg_lvmthin, $strorage_cfg_fn);
1633 run_command
("chroot $targetdir /usr/bin/create_pmxcfs_db /tmp/pve /var/lib/pve-cluster/config.db");
1635 syscmd
("rm -rf $tmpdir");
1641 update_progress
(1, 0, 1, "");
1645 if ($opt_testmode) {
1646 my $elapsed = Time
::HiRes
::tv_interval
($starttime);
1647 print "Elapsed extract time: $elapsed\n";
1649 syscmd
("chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> final.pkglist");
1652 syscmd
("umount $targetdir/tmp");
1653 syscmd
("umount $targetdir/proc");
1654 syscmd
("umount $targetdir/sys");
1657 syscmd
("zfs umount -a") == 0 ||
1658 die "unable to unmount zfs\n";
1660 syscmd
("umount -d $targetdir");
1663 if (!$err && $use_zfs) {
1664 syscmd
("zfs set sync=standard $zfspoolname") == 0 ||
1665 die "unable to set zfs properties\n";
1667 syscmd
("zfs set mountpoint=/ $zfspoolname/ROOT/$zfsrootvolname") == 0 ||
1668 die "zfs set mountpoint failed\n";
1670 syscmd
("zpool set bootfs=$zfspoolname/ROOT/$zfsrootvolname $zfspoolname") == 0 ||
1671 die "zfs set bootfs failed\n";
1672 syscmd
("zpool export $zfspoolname");
1679 my ($filename) = @_;
1681 my $path = "${proxmox_libdir}/html/$filename";
1683 my $url = "file://$path";
1685 my $data = file_get_contents
($path);
1687 if ($filename eq 'license.htm') {
1688 my $license = decode
('utf8', file_get_contents
("${proxmox_cddir}/EULA"));
1689 my $title = "END USER LICENSE AGREEMENT (EULA)";
1690 $data =~ s/__LICENSE__/$license/;
1691 $data =~ s/__LICENSE_TITLE__/$title/;
1694 $htmlview->load_html_string($data, $url);
1698 my ($text, $fctn) = @_;
1701 $text = "_Next" if !$text;
1702 $next->set_label ($text);
1704 $next->grab_focus ();
1707 sub create_main_window
{
1709 $window = Gtk3
::Window-
>new ();
1710 $window->set_default_size (1024, 768);
1711 $window->set_has_resize_grip(0);
1712 $window->set_decorated (0) if !$opt_testmode;
1714 my $vbox = Gtk3
::VBox-
>new (0, 0);
1716 my $image = Gtk3
::Image-
>new_from_file ("${proxmox_libdir}/proxlogo.png");
1717 $vbox->pack_start ($image, 0, 0, 0);
1719 my $hbox = Gtk3
::HBox-
>new (0, 0);
1720 $vbox->pack_start ($hbox, 1, 1, 0);
1722 # my $f1 = Gtk3::Frame->new ('test');
1723 # $f1->set_shadow_type ('none');
1724 # $hbox->pack_start ($f1, 1, 1, 0);
1726 my $sep1 = Gtk3
::HSeparator-
>new;
1727 $vbox->pack_start ($sep1, 0, 0, 0);
1729 $cmdbox = Gtk3
::HBox-
>new ();
1730 $vbox->pack_start ($cmdbox, 0, 0, 10);
1732 $next = Gtk3
::Button-
>new ('_Next');
1733 $next->signal_connect (clicked
=> sub { &$next_fctn (); });
1734 $cmdbox->pack_end ($next, 0, 0, 10);
1735 my $abort = Gtk3
::Button-
>new ('_Abort');
1736 $abort->set_can_focus (0);
1737 $cmdbox->pack_start ($abort, 0, 0, 10);
1738 $abort->signal_connect (clicked
=> sub { exit (-1); });
1740 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1741 $hbox->add ($vbox2);
1743 $htmlview = Gtk3
::WebKit
::WebView-
>new();
1744 my $scrolls = Gtk3
::ScrolledWindow-
>new();
1745 $scrolls->add($htmlview);
1747 my $hbox2 = Gtk3
::HBox-
>new (0, 0);
1748 $hbox2->pack_start ($scrolls, 1, 1, 0);
1750 $vbox2->pack_start ($hbox2, 1, 1, 0);
1752 my $vbox3 = Gtk3
::VBox-
>new (0, 0);
1753 $vbox2->pack_start ($vbox3, 0, 0, 0);
1755 my $sep2 = Gtk3
::HSeparator-
>new;
1756 $vbox3->pack_start ($sep2, 0, 0, 0);
1758 $inbox = Gtk3
::HBox-
>new (0, 0);
1759 $vbox3->pack_start ($inbox, 0, 0, 0);
1761 $window->add ($vbox);
1764 $window->realize ();
1768 $inbox->foreach(sub {
1770 $inbox->remove ($child);
1774 # fixme: newer GTK3 has special properties to handle numbers with Entry
1775 # only allow floating point numbers with Gtk3::Entry
1778 my ($entry, $event) = @_;
1780 return check_number
($entry, $event, 1);
1784 my ($entry, $event) = @_;
1786 return check_number
($entry, $event, 0);
1790 my ($entry, $event, $float) = @_;
1792 my $val = $event->get_keyval;
1794 if (($float && $val == ord '.') ||
1795 $val == Gtk3
::Gdk
::KEY_ISO_Left_Tab
||
1796 $val == Gtk3
::Gdk
::KEY_Shift_L
||
1797 $val == Gtk3
::Gdk
::KEY_Tab
||
1798 $val == Gtk3
::Gdk
::KEY_Left
||
1799 $val == Gtk3
::Gdk
::KEY_Right
||
1800 $val == Gtk3
::Gdk
::KEY_BackSpace
||
1801 $val == Gtk3
::Gdk
::KEY_Delete
||
1802 ($val >= ord '0' && $val <= ord '9') ||
1803 ($val >= Gtk3
::Gdk
::KEY_KP_0
&&
1804 $val <= Gtk3
::Gdk
::KEY_KP_9
)) {
1811 sub create_text_input
{
1812 my ($default, $text) = @_;
1814 my $hbox = Gtk3
::HBox-
>new (0, 0);
1816 my $label = Gtk3
::Label-
>new ($text);
1817 $label->set_size_request (150, -1);
1818 $label->set_alignment (1, 0.5);
1819 $hbox->pack_start ($label, 0, 0, 10);
1820 my $e1 = Gtk3
::Entry-
>new ();
1821 $e1->set_width_chars (30);
1822 $hbox->pack_start ($e1, 0, 0, 0);
1823 $e1->set_text ($default);
1825 return ($hbox, $e1);
1833 my $links = `ip -o l`;
1834 foreach my $l (split /\n/,$links) {
1835 my ($index, $name, $flags, $state, $mac) = $l =~ m/^(\d+):\s+(\S+):\s+<(\S+)>.*\s+state\s+(\S+)\s+.*\s+link\/ether\s
+(\S
+)\s
+/;
1836 next if !$name || $name eq 'lo';
1838 my $driver = readlink "/sys/class/net/$name/device/driver" || 'unknown';
1839 $driver =~ s!^.*/!!;
1841 $ifaces->{"$index"} = {
1849 my $addresses = `ip -o a s $name`;
1850 foreach my $a (split /\n/,$addresses) {
1851 my ($family, $ip, $prefix) = $a =~ m/^\Q$index\E:\s+\Q$name\E\s+(inet|inet6)\s+($IPRE)\/(\d+)\s+/;
1853 next if $a =~ /scope\s+link/; # ignore link local
1857 if ($family eq 'inet') {
1858 next if !$ip =~ /$IPV4RE/;
1859 next if $prefix < 8 || $prefix > 32;
1860 $mask = @$ipv4_reverse_mask[$prefix];
1862 next if !$ip =~ /$IPV6RE/;
1865 $default = $index if !$default;
1867 $ifaces->{"$index"}->{"$family"} = {
1875 my $route = `ip route
`;
1876 my ($gateway) = $route =~ m/^default\s+via\s+(\S+)\s+/m;
1878 my $resolvconf = `cat
/etc/resolv
.conf
`;
1879 my ($dnsserver) = $resolvconf =~ m/^nameserver\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/m;
1880 my ($domain) = $resolvconf =~ m/^domain\s+(\S+)$/m;
1883 default => $default,
1885 gateway => $gateway,
1886 dnsserver => $dnsserver,
1891 sub display_message {
1894 my $dialog = Gtk3::MessageDialog->new ($window, 'modal',
1895 'info', 'ok', $msg);
1903 my $dialog = Gtk3::MessageDialog->new ($window, 'modal',
1904 'error', 'ok', $msg);
1909 my $ipconf_first_view = 1;
1911 sub create_ipconf_view {
1914 display_html ("ipconf.htm");
1916 my $vbox = Gtk3::VBox->new (0, 0);
1917 $inbox->pack_start ($vbox, 1, 0, 0);
1918 my $hbox = Gtk3::HBox->new (0, 0);
1919 $vbox->pack_start ($hbox, 0, 0, 10);
1920 my $vbox2 = Gtk3::VBox->new (0, 0);
1921 $hbox->add ($vbox2);
1924 ($ipbox, $ipconf_entry_addr) =
1925 create_text_input ("192.168.100.2", 'IP Address:');
1928 ($maskbox, $ipconf_entry_mask) =
1929 create_text_input ("255.255.255.0", 'Netmask:');
1931 my $device_cb = Gtk3::ComboBoxText->new();
1932 $device_cb->set_active(0);
1933 $device_cb->set_visible(1);
1935 my $get_device_desc = sub {
1937 return "$iface->{name} - $iface->{mac} ($iface->{driver})";
1940 my $device_active_map = {};
1942 my $device_change_handler = sub {
1943 my $current = shift;
1944 $ipconf->{selected} = $device_active_map->{$current->get_active()};
1945 my $iface = $ipconf->{ifaces}->{$ipconf->{selected}};
1946 $ipconf_entry_addr->set_text($iface->{inet}->{addr} || $iface->{inet6}->{addr})
1947 if $iface->{inet}->{addr} || $iface->{inet6}->{addr};
1948 $ipconf_entry_mask->set_text($iface->{inet}->{mask} || $iface->{inet6}->{mask})
1949 if $iface->{inet}->{mask} || $iface->{inet6}->{mask};
1953 foreach my $index (sort keys %{$ipconf->{ifaces}}) {
1954 $device_cb->append_text(&$get_device_desc($ipconf->{ifaces}->{$index}));
1955 $device_active_map->{$i} = $index;
1956 if ($ipconf_first_view && $index == $ipconf->{default}) {
1957 $device_cb->set_active($i);
1958 &$device_change_handler($device_cb);
1959 $ipconf_first_view = 0;
1961 $device_cb->signal_connect ('changed' => $device_change_handler);
1965 $device_cb->set_active(0)
1966 if !($ipconf->{selected});
1968 my $devicebox = Gtk3::HBox->new (0, 0);
1969 my $label = Gtk3::Label->new ("Management Interface:");
1970 $label->set_size_request (150, -1);
1971 $label->set_alignment (1, 0.5);
1972 $devicebox->pack_start ($label, 0, 0, 10);
1973 $devicebox->pack_start ($device_cb, 0, 0, 0);
1975 $vbox2->pack_start ($devicebox, 0, 0, 2);
1977 my $hn = $ipconf->{domain} ?
1978 "$setup->{product}.$ipconf->{domain}" : "$setup->{product}.example.invalid";
1980 my ($hostbox, $hostentry) =
1981 create_text_input ($hn, 'Hostname (FQDN):');
1982 $vbox2->pack_start ($hostbox, 0, 0, 2);
1984 $vbox2->pack_start ($ipbox, 0, 0, 2);
1986 $vbox2->pack_start ($maskbox, 0, 0, 2);
1988 $gateway = $ipconf->{gateway} || '192.168.100.1';
1991 ($gwbox, $ipconf_entry_gw) =
1992 create_text_input ($gateway, 'Gateway:');
1994 $vbox2->pack_start ($gwbox, 0, 0, 2);
1996 $dnsserver = $ipconf->{dnsserver} || $gateway;
1999 ($dnsbox, $ipconf_entry_dns) =
2000 create_text_input ($dnsserver, 'DNS Server:');
2002 $vbox2->pack_start ($dnsbox, 0, 0, 0);
2005 set_next (undef, sub {
2009 my $text = $hostentry->get_text();
2014 my $namere = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
2016 # Debian does not support purely numeric hostnames
2017 if ($text && $text =~ /^[0-9]+(?:\.|$)/) {
2018 display_message("Purely numeric hostnames are not allowed.");
2019 $hostentry->grab_focus();
2023 if ($text && $text =~ m/^(${namere}\.)*${namere}$/ && $text !~ m/.example.invalid$/ &&
2024 $text =~ m/^([^\.]+)\.(\S+)$/) {
2028 display_message ("Hostname does not look like a fully qualified domain name.");
2029 $hostentry->grab_focus();
2035 $text = $ipconf_entry_addr->get_text();
2038 if ($text =~ m!^($IPV4RE)$!) {
2041 } elsif ($text =~ m!^($IPV6RE)$!) {
2045 display_message ("IP address is not valid.");
2046 $ipconf_entry_addr->grab_focus();
2050 $text = $ipconf_entry_mask->get_text();
2053 if (($ipversion == 6) && ($text =~ m/^(\d+)$/) && ($1 >= 8) && ($1 <= 126)) {
2055 } elsif (($ipversion == 4) && defined($ipv4_mask_hash->{$text})) {
2058 display_message ("Netmask is not valid.");
2059 $ipconf_entry_mask->grab_focus();
2063 $text = $ipconf_entry_gw->get_text();
2066 if (($ipversion == 4) && ($text =~ m!^($IPV4RE)$!)) {
2068 } elsif (($ipversion == 6) && ($text =~ m!^($IPV6RE)$!)) {
2071 display_message ("Gateway is not valid.");
2072 $ipconf_entry_gw->grab_focus();
2076 $text = $ipconf_entry_dns->get_text();
2079 if (($ipversion == 4) && ($text =~ m!^($IPV4RE)$!)) {
2081 } elsif (($ipversion == 6) && ($text =~ m!^($IPV6RE)$!)) {
2084 display_message ("DNS server is not valid.");
2085 $ipconf_entry_dns->grab_focus();
2089 #print "TEST $ipaddress $netmask $gateway $dnsserver\n";
2091 create_extract_view ();
2094 $hostentry->grab_focus();
2097 sub get_device_desc {
2098 my ($devname, $size, $model) = @_;
2100 if ($size && ($size > 0)) {
2101 $size = int($size/2048); # size in MB, from 512B "sectors"
2103 my $text = "$devname (";
2104 if ($size >= 1024) {
2105 $size = int($size/1024); # size in GB
2106 $text .= "${size}GB";
2108 $text .= "${size}MB";
2111 $text .= ", $model" if $model;
2120 my ($cb, $kmap) = @_;
2125 my $kmaphash = $cmap->{kmaphash};
2126 foreach my $layout (sort keys %$kmaphash) {
2127 $def = $i if $kmaphash->{$layout} eq 'en-us';
2128 $ind = $i if $kmap && $kmaphash->{$layout} eq $kmap;
2132 $cb->set_active ($ind || $def || 0);
2136 sub update_zonelist {
2137 my ($box, $cc) = @_;
2139 my $cczones = $cmap->{cczones};
2140 my $zones = $cmap->{zones};
2144 $sel = $lastzonecb->get_active_text();
2145 $box->remove ($lastzonecb);
2147 $sel = $timezone; # used once to select default
2150 my $cb = $lastzonecb = Gtk3::ComboBoxText->new();
2151 $cb->set_size_request (200, -1);
2153 $cb->signal_connect ('changed' => sub {
2154 $timezone = $cb->get_active_text();
2158 if ($cc && defined ($cczones->{$cc})) {
2159 @za = keys %{$cczones->{$cc}};
2165 foreach my $zone (sort @za) {
2166 $ind = $i if $sel && $zone eq $sel;
2167 $cb->append_text ($zone);
2171 $cb->set_active ($ind || 0);
2174 $box->pack_start ($cb, 0, 0, 0);
2177 sub create_password_view {
2181 my $vbox2 = Gtk3::VBox->new (0, 0);
2182 $inbox->pack_start ($vbox2, 1, 0, 0);
2183 my $vbox = Gtk3::VBox->new (0, 0);
2184 $vbox2->pack_start ($vbox, 0, 0, 10);
2186 my $hbox1 = Gtk3::HBox->new (0, 0);
2187 my $label = Gtk3::Label->new ("Password");
2188 $label->set_size_request (150, -1);
2189 $label->set_alignment (1, 0.5);
2190 $hbox1->pack_start ($label, 0, 0, 10);
2191 my $pwe1 = Gtk3::Entry->new ();
2192 $pwe1->set_visibility (0);
2193 $pwe1->set_size_request (200, -1);
2194 $hbox1->pack_start ($pwe1, 0, 0, 0);
2196 my $hbox2 = Gtk3::HBox->new (0, 0);
2197 $label = Gtk3::Label->new ("Confirm");
2198 $label->set_size_request (150, -1);
2199 $label->set_alignment (1, 0.5);
2200 $hbox2->pack_start ($label, 0, 0, 10);
2201 my $pwe2 = Gtk3::Entry->new ();
2202 $pwe2->set_visibility (0);
2203 $pwe2->set_size_request (200, -1);
2204 $hbox2->pack_start ($pwe2, 0, 0, 0);
2206 my $hbox3 = Gtk3::HBox->new (0, 0);
2207 $label = Gtk3::Label->new ("E-Mail");
2208 $label->set_size_request (150, -1);
2209 $label->set_alignment (1, 0.5);
2210 $hbox3->pack_start ($label, 0, 0, 10);
2211 my $eme = Gtk3::Entry->new ();
2212 $eme->set_size_request (200, -1);
2213 $eme->set_text('mail@example.invalid');
2214 $hbox3->pack_start ($eme, 0, 0, 0);
2217 $vbox->pack_start ($hbox1, 0, 0, 5);
2218 $vbox->pack_start ($hbox2, 0, 0, 5);
2219 $vbox->pack_start ($hbox3, 0, 0, 15);
2223 display_html ("passwd.htm");
2225 set_next (undef, sub {
2227 my $t1 = $pwe1->get_text;
2228 my $t2 = $pwe2->get_text;
2230 if (length ($t1) < 5) {
2231 display_message ("Password is too short.");
2232 $pwe1->grab_focus();
2237 display_message ("Password does not match.");
2238 $pwe1->grab_focus();
2242 my $t3 = $eme->get_text;
2243 if ($t3 !~ m/^\S+\@\S+\.\S+$/) {
2244 display_message ("E-Mail does not look like a valid address" .
2245 " (user\@domain.tld)");
2250 if ($t3 eq 'mail@example.invalid') {
2251 display_message ("Please enter a valid E-Mail address");
2259 create_ipconf_view();
2262 $pwe1->grab_focus();
2266 sub create_country_view {
2270 my $countryhash = $cmap->{countryhash};
2271 my $ctr = $cmap->{country};
2273 my $vbox2 = Gtk3::VBox->new (0, 0);
2274 $inbox->pack_start ($vbox2, 1, 0, 0);
2275 my $vbox = Gtk3::VBox->new (0, 0);
2276 $vbox2->pack_start ($vbox, 0, 0, 10);
2278 my $w = Gtk3::Entry->new ();
2279 $w->set_size_request (200, -1);
2281 my $c = Gtk3::EntryCompletion->new ();
2282 $c->set_text_column (0);
2283 $c->set_minimum_key_length(0);
2284 $c->set_popup_set_width (1);
2285 $c->set_inline_completion (1);
2287 my $hbox2 = Gtk3::HBox->new (0, 0);
2288 my $label = Gtk3::Label->new ("Time zone");
2289 $label->set_size_request (150, -1);
2290 $label->set_alignment (1, 0.5);
2291 $hbox2->pack_start ($label, 0, 0, 10);
2292 update_zonelist ($hbox2);
2294 my $hbox3 = Gtk3::HBox->new (0, 0);
2295 $label = Gtk3::Label->new ("Keyboard Layout");
2296 $label->set_size_request (150, -1);
2297 $label->set_alignment (1, 0.5);
2298 $hbox3->pack_start ($label, 0, 0, 10);
2300 my $kmapcb = Gtk3::ComboBoxText->new();
2301 $kmapcb->set_size_request (200, -1);
2302 foreach my $layout (sort keys %{$cmap->{kmaphash}}) {
2303 $kmapcb->append_text ($layout);
2306 update_layout ($kmapcb);
2307 $hbox3->pack_start ($kmapcb, 0, 0, 0);
2309 $kmapcb->signal_connect ('changed' => sub {
2310 my $sel = $kmapcb->get_active_text();
2311 if (my $kmap = $cmap->{kmaphash}->{$sel}) {
2312 my $xkmap = $cmap->{kmap}->{$kmap}->{x11};
2313 my $xvar = $cmap->{kmap}->{$kmap}->{x11var};
2314 syscmd ("setxkbmap $xkmap $xvar") if !$opt_testmode;
2319 $w->signal_connect ('changed' => sub {
2320 my ($entry, $event) = @_;
2321 my $text = $entry->get_text;
2323 if (my $cc = $countryhash->{lc($text)}) {
2324 update_zonelist ($hbox2, $cc);
2325 my $kmap = $ctr->{$cc}->{kmap} || 'en-us';
2326 update_layout ($kmapcb, $kmap);
2330 $w->signal_connect (key_press_event => sub {
2331 my ($entry, $event) = @_;
2332 my $text = $entry->get_text;
2334 my $val = $event->get_keyval;
2336 if ($val == Gtk3::Gdk::KEY_Tab) {
2337 my $cc = $countryhash->{lc($text)};
2344 $compl = $ctr->{$cc}->{name};
2346 foreach my $cc (keys %$ctr) {
2347 my $ct = $ctr->{$cc}->{name};
2348 if ($ct =~ m/^\Q$text\E.*$/i) {
2357 $entry->set_text($compl);
2362 print chr(7); # beep ?
2367 my $buf = $w->get_buffer();
2368 $buf->insert_text(-1, '', -1); # popup selection
2376 my $ls = Gtk3::ListStore->new('Glib::String');
2377 foreach my $cc (sort {$ctr->{$a}->{name} cmp $ctr->{$b}->{name} } keys %$ctr) {
2378 my $iter = $ls->append();
2379 $ls->set ($iter, 0, $ctr->{$cc}->{name});
2381 $c->set_model ($ls);
2383 $w->set_completion ($c);
2385 my $hbox = Gtk3::HBox->new (0, 0);
2387 $label = Gtk3::Label->new ("Country");
2388 $label->set_alignment (1, 0.5);
2389 $label->set_size_request (150, -1);
2390 $hbox->pack_start ($label, 0, 0, 10);
2391 $hbox->pack_start ($w, 0, 0, 0);
2393 $vbox->pack_start ($hbox, 0, 0, 5);
2394 $vbox->pack_start ($hbox2, 0, 0, 5);
2395 $vbox->pack_start ($hbox3, 0, 0, 5);
2397 if ($country && $ctr->{$country}) {
2398 $w->set_text ($ctr->{$country}->{name});
2403 display_html ("country.htm");
2404 set_next (undef, sub {
2406 my $text = $w->get_text;
2408 if (my $cc = $countryhash->{lc($text)}) {
2410 create_password_view();
2413 display_message ("Please select a country first.");
2421 my $target_hd_combo;
2422 my $target_hd_label;
2424 my $hdopion_first_setup = 1;
2426 my $create_basic_grid = sub {
2427 my $grid = Gtk3::Grid->new();
2428 $grid->set_visible(1);
2429 $grid->set_column_spacing(10);
2430 $grid->set_row_spacing(10);
2431 $grid->set_hexpand(1);
2433 $grid->set_margin_start(5);
2434 $grid->set_margin_end(5);
2435 $grid->set_margin_top(5);
2436 $grid->set_margin_bottom(5);
2441 my $create_label_widget_grid = sub {
2442 my ($labeled_widgets) = @_;
2444 my $grid = &$create_basic_grid();
2447 for (my $i = 0; $i < @$labeled_widgets; $i += 2) {
2448 my $widget = @$labeled_widgets[$i+1];
2449 my $label = Gtk3::Label->new(@$labeled_widgets[$i]);
2450 $label->set_visible(1);
2451 $label->set_alignment (1, 0.5);
2452 $grid->attach($label, 0, $row, 1, 1);
2453 $widget->set_visible(1);
2454 $grid->attach($widget, 1, $row, 1, 1);
2461 my $create_raid_disk_grid = sub {
2462 my $disk_labeled_widgets = [];
2463 for (my $i = 0; $i < @$hds; $i++) {
2464 my $disk_selector = Gtk3::ComboBoxText->new();
2465 $disk_selector->append_text("-- do not use --");
2466 $disk_selector->set_active(0);
2467 $disk_selector->set_visible(1);
2468 foreach my $hd (@$hds) {
2469 my ($disk, $devname, $size, $model) = @$hd;
2470 $disk_selector->append_text(get_device_desc ($devname, $size, $model));
2471 $disk_selector->{pve_disk_id} = $i;
2472 $disk_selector->signal_connect (changed => sub {
2474 my $diskid = $w->{pve_disk_id};
2475 my $a = $w->get_active - 1;
2476 $config_options->{"disksel${diskid}"} = ($a >= 0) ? $hds->[$a] : undef;
2480 if ($hdopion_first_setup) {
2481 $disk_selector->set_active ($i+1) if $hds->[$i];
2484 if (my $cur_hd = $config_options->{"disksel$i"}) {
2485 foreach my $hd (@$hds) {
2486 if (@$hd[1] eq @$cur_hd[1]) {
2487 $disk_selector->set_active($hdind+1);
2495 push @$disk_labeled_widgets, "Harddisk $i", $disk_selector;
2498 my $scrolled_window = Gtk3::ScrolledWindow->new();
2499 $scrolled_window->set_hexpand(1);
2500 $scrolled_window->set_propagate_natural_height(1) if @$hds > 4;
2501 $scrolled_window->add(&$create_label_widget_grid($disk_labeled_widgets));
2502 $scrolled_window->set_policy('never', 'automatic');
2504 return $scrolled_window;
2505 # &$create_label_widget_grid($disk_labeled_widgets)
2508 my $create_raid_advanced_grid = sub {
2509 my $labeled_widgets = [];
2510 my $spinbutton_ashift = Gtk3::SpinButton->new_with_range(9,13,1);
2511 $spinbutton_ashift->set_tooltip_text("zpool ashift property (pool sector size, default 2^12)");
2512 $spinbutton_ashift->signal_connect ("value-changed" => sub {
2514 $config_options->{ashift} = $w->get_value_as_int();
2516 $config_options->{ashift} = 12 if ! defined($config_options->{ashift});
2517 $spinbutton_ashift->set_value($config_options->{ashift});
2518 push @$labeled_widgets, "ashift";
2519 push @$labeled_widgets, $spinbutton_ashift;
2521 my $combo_compress = Gtk3::ComboBoxText->new();
2522 $combo_compress->set_tooltip_text("zfs compression algorithm for rpool dataset");
2523 # note: gzip / lze not allowed for bootfs vdevs
2524 my $comp_opts = ["on","off","lzjb","lz4"];
2525 foreach my $opt (@$comp_opts) {
2526 $combo_compress->append($opt, $opt);
2528 $config_options->{compress} = "on" if !defined($config_options->{compress});
2529 $combo_compress->set_active_id($config_options->{compress});
2530 $combo_compress->signal_connect (changed => sub {
2532 $config_options->{compress} = $w->get_active_text();
2534 push @$labeled_widgets, "compress";
2535 push @$labeled_widgets, $combo_compress;
2537 my $combo_checksum = Gtk3::ComboBoxText->new();
2538 $combo_checksum->set_tooltip_text("zfs checksum algorithm for rpool dataset");
2539 my $csum_opts = ["on", "off","fletcher2", "fletcher4", "sha256"];
2540 foreach my $opt (@$csum_opts) {
2541 $combo_checksum->append($opt, $opt);
2543 $config_options->{checksum} = "on" if !($config_options->{checksum});
2544 $combo_checksum->set_active_id($config_options->{checksum});
2545 $combo_checksum->signal_connect (changed => sub {
2547 $config_options->{checksum} = $w->get_active_text();
2549 push @$labeled_widgets, "checksum";
2550 push @$labeled_widgets, $combo_checksum;
2552 my $spinbutton_copies = Gtk3::SpinButton->new_with_range(1,3,1);
2553 $spinbutton_copies->set_tooltip_text("zfs copies property for rpool dataset (in addition to RAID redundancy!)");
2554 $spinbutton_copies->signal_connect ("value-changed" => sub {
2556 $config_options->{copies} = $w->get_value_as_int();
2558 $config_options->{copies} = 1 if !defined($config_options->{copies});
2559 $spinbutton_copies->set_value($config_options->{copies});
2560 push @$labeled_widgets, "copies", $spinbutton_copies;
2562 return &$create_label_widget_grid($labeled_widgets);;
2565 sub create_hdoption_view {
2567 my $dialog = Gtk3::Dialog->new();
2569 $dialog->set_title("Harddisk options");
2571 $dialog->add_button("_OK", 1);
2573 my $contarea = $dialog->get_content_area();
2575 my $hbox2 = Gtk3::Box->new('horizontal', 0);
2576 $contarea->pack_start($hbox2, 1, 1, 10);
2578 my $grid = Gtk3::Grid->new();
2579 $grid->set_column_spacing(10);
2580 $grid->set_row_spacing(10);
2582 $hbox2->pack_start($grid, 1, 0, 10);
2588 my $label0 = Gtk3::Label->new ("Filesystem");
2589 $label0->set_alignment (1, 0.5);
2590 $grid->attach($label0, 0, $row, 1, 1);
2592 my $fstypecb = Gtk3::ComboBoxText->new();
2594 my $fstype = ['ext3', 'ext4', 'xfs',
2595 'zfs (RAID0)', 'zfs (RAID1)',
2596 'zfs (RAID10)', 'zfs (RAIDZ-1)',
2597 'zfs (RAIDZ-2)', 'zfs (RAIDZ-3)'];
2599 push @$fstype, 'btrfs (RAID0)', 'btrfs (RAID1)', 'btrfs (RAID10)'
2600 if $setup->{enable_btrfs};
2603 foreach my $tmp (@$fstype) {
2604 $fstypecb->append_text($tmp);
2605 $fstypecb->set_active ($tcount)
2606 if $config_options->{filesys} eq $tmp;
2610 $grid->attach($fstypecb, 1, $row, 1, 1);
2616 my $sep = Gtk3::HSeparator->new();
2617 $sep->set_visible(1);
2618 $grid->attach($sep, 0, $row, 2, 1);
2621 my $hdsize_labeled_widgets = [];
2625 if ( -b $target_hd) {
2626 $hdsize = int(hd_size ($target_hd) / (1024*1024.0)); # size in GB
2627 } elsif ($target_hd) {
2628 $hdsize = int((-s $target_hd) / (1024*1024*1024.0));
2631 my $hdsize_size_adj = Gtk3::Adjustment->new($config_options->{hdsize} || $hdsize, 0, $hdsize+1, 1, 1, 1);
2632 my $spinbutton_hdsize = Gtk3::SpinButton->new($hdsize_size_adj, 1, 1);
2633 $spinbutton_hdsize->set_tooltip_text("only use specified size (GB) of the harddisk (rest left unpartitioned)");
2634 push @$hdsize_labeled_widgets, "hdsize", $spinbutton_hdsize;
2636 my $entry_swapsize = Gtk3::Entry->new();
2637 $entry_swapsize->set_tooltip_text("maximum SWAP size (GB)");
2638 $entry_swapsize->signal_connect (key_press_event => \&check_float);
2639 $entry_swapsize->set_text($config_options->{swapsize}) if $config_options->{swapsize};
2640 push @$hdsize_labeled_widgets, "swapsize", $entry_swapsize;
2642 my $entry_maxroot = Gtk3::Entry->new();
2643 $entry_maxroot->set_tooltip_text("maximum size (GB) for LVM root volume");
2644 $entry_maxroot->signal_connect (key_press_event => \&check_float);
2645 $entry_maxroot->set_text($config_options->{maxroot}) if $config_options->{maxroot};
2646 push @$hdsize_labeled_widgets, "maxroot", $entry_maxroot;
2648 my $entry_minfree = Gtk3::Entry->new();
2649 $entry_minfree->set_tooltip_text("minimum free LVM space (GB, required for LVM snapshots)");
2650 $entry_minfree->signal_connect (key_press_event => \&check_float);
2651 $entry_minfree->set_text($config_options->{minfree}) if $config_options->{minfree};
2652 push @$hdsize_labeled_widgets, "minfree", $entry_minfree;
2654 my $entry_maxvz = Gtk3::Entry->new();
2655 $entry_maxvz->set_tooltip_text("maximum size (GB) for LVM data volume");
2656 $entry_maxvz->signal_connect (key_press_event => \&check_float);
2657 $entry_maxvz->set_text($config_options->{maxvz}) if $config_options->{maxvz};
2658 push @$hdsize_labeled_widgets, "maxvz", $entry_maxvz;
2660 my $options_stack = Gtk3::Stack->new();
2661 $options_stack->set_visible(1);
2662 $options_stack->set_hexpand(1);
2663 $options_stack->set_vexpand(1);
2664 $options_stack->add_titled(&$create_raid_disk_grid(), "raiddisk", "Disk Setup");
2665 $options_stack->add_titled(&$create_label_widget_grid($hdsize_labeled_widgets), "hdsize", "Size Options");
2666 $options_stack->add_titled(&$create_raid_advanced_grid("zfs"), "raidzfsadvanced", "Advanced Options");
2667 $options_stack->set_visible_child_name("raiddisk");
2668 my $options_stack_switcher = Gtk3::StackSwitcher->new();
2669 $options_stack_switcher->set_halign('center');
2670 $options_stack_switcher->set_stack($options_stack);
2671 $grid->attach($options_stack_switcher, 0, $row, 2, 1);
2673 $grid->attach($options_stack, 0, $row, 2, 1);
2676 $hdopion_first_setup = 0;
2678 my $switch_view = sub {
2679 my $raid = $config_options->{filesys} =~ m/zfs|btrfs/;
2680 my $enable_zfs_opts = $config_options->{filesys} =~ m/zfs/;
2682 $target_hd_combo->set_visible(!$raid);
2683 $options_stack->get_child_by_name("hdsize")->set_visible(!$raid);
2684 $options_stack->get_child_by_name("raiddisk")->set_visible($raid);
2685 $options_stack_switcher->set_visible($enable_zfs_opts);
2686 $options_stack->get_child_by_name("raidzfsadvanced")->set_visible($enable_zfs_opts);
2688 $target_hd_label->set_text("Target: $config_options->{filesys} ");
2689 $options_stack->set_visible_child_name("raiddisk");
2691 $target_hd_label->set_text("Target Harddisk: ");
2693 my (undef, $pref_width) = $dialog->get_preferred_width();
2694 my (undef, $pref_height) = $dialog->get_preferred_height();
2695 $pref_height = 750 if $pref_height > 750;
2696 $dialog->resize($pref_width, $pref_height);
2701 $fstypecb->signal_connect (changed => sub {
2702 $config_options->{filesys} = $fstypecb->get_active_text();
2710 my $get_float = sub {
2713 my $text = $entry->get_text();
2714 return undef if !defined($text);
2719 return undef if $text !~ m/^\d+(\.\d+)?$/;
2726 if (($tmp = &$get_float($spinbutton_hdsize)) && ($tmp != $hdsize)) {
2727 $config_options->{hdsize} = $tmp;
2729 delete $config_options->{hdsize};
2732 if (defined($tmp = &$get_float($entry_swapsize))) {
2733 $config_options->{swapsize} = $tmp;
2735 delete $config_options->{swapsize};
2738 if (defined($tmp = &$get_float($entry_maxroot))) {
2739 $config_options->{maxroot} = $tmp;
2741 delete $config_options->{maxroot};
2744 if (defined($tmp = &$get_float($entry_minfree))) {
2745 $config_options->{minfree} = $tmp;
2747 delete $config_options->{minfree};
2750 if (defined($tmp = &$get_float($entry_maxvz))) {
2751 $config_options->{maxvz} = $tmp;
2753 delete $config_options->{maxvz};
2759 my $get_raid_devlist = sub {
2761 my $dev_name_hash = {};
2764 for (my $i = 0; $i < @$hds; $i++) {
2765 if (my $hd = $config_options->{"disksel$i"}) {
2766 my ($disk, $devname, $size, $model) = @$hd;
2767 die "device '$devname' is used more than once\n"
2768 if $dev_name_hash->{$devname};
2769 $dev_name_hash->{$devname} = $hd;
2770 push @$devlist, $hd;
2777 sub zfs_mirror_size_check {
2778 my ($expected, $actual) = @_;
2780 die "mirrored disks must have same size\n"
2781 if abs($expected - $actual) > $expected / 10;
2784 sub get_zfs_raid_setup {
2786 my $filesys = $config_options->{filesys};
2788 my $devlist = &$get_raid_devlist();
2790 my $diskcount = scalar(@$devlist);
2791 die "$filesys needs at least one device\n" if $diskcount < 1;
2793 my $bootdevlist = [];
2796 if ($filesys eq 'zfs (RAID0)') {
2797 push @$bootdevlist, @$devlist[0];
2798 foreach my $hd (@$devlist) {
2801 } elsif ($filesys eq 'zfs (RAID1)') {
2802 die "zfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
2804 my $hd = @$devlist[0];
2805 my $expected_size = @$hd[2]; # all disks need approximately same size
2806 foreach $hd (@$devlist) {
2807 zfs_mirror_size_check($expected_size, @$hd[2]);
2809 push @$bootdevlist, $hd;
2811 } elsif ($filesys eq 'zfs (RAID10)') {
2812 die "zfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
2813 die "zfs (RAID10) needs an even number of devices\n" if $diskcount & 1;
2815 push @$bootdevlist, @$devlist[0], @$devlist[1];
2817 for (my $i = 0; $i < $diskcount; $i+=2) {
2818 my $hd1 = @$devlist[$i];
2819 my $hd2 = @$devlist[$i+1];
2820 zfs_mirror_size_check(@$hd1[2], @$hd2[2]); # pairs need approximately same size
2821 $cmd .= ' mirror ' . @$hd1[1] . ' ' . @$hd2[1];
2824 } elsif ($filesys =~ m/^zfs \(RAIDZ-([123])\)$/) {
2826 my $mindisks = 2 + $level;
2827 die "zfs (RAIDZ-$level) needs at least $mindisks devices\n" if scalar(@$devlist) < $mindisks;
2828 my $hd = @$devlist[0];
2829 my $expected_size = @$hd[2]; # all disks need approximately same size
2830 $cmd .= " raidz$level";
2831 foreach $hd (@$devlist) {
2832 zfs_mirror_size_check($expected_size, @$hd[2]);
2834 push @$bootdevlist, $hd;
2837 die "unknown zfs mode '$filesys'\n";
2840 return ($devlist, $bootdevlist, $cmd);
2843 sub get_btrfs_raid_setup {
2845 my $filesys = $config_options->{filesys};
2847 my $devlist = &$get_raid_devlist();
2849 my $diskcount = scalar(@$devlist);
2850 die "$filesys needs at least one device\n" if $diskcount < 1;
2854 if ($diskcount == 1) {
2857 if ($filesys eq 'btrfs (RAID0)') {
2859 } elsif ($filesys eq 'btrfs (RAID1)') {
2860 die "btrfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
2862 } elsif ($filesys eq 'btrfs (RAID10)') {
2863 die "btrfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
2866 die "unknown btrfs mode '$filesys'\n";
2870 return ($devlist, $mode);
2873 sub create_hdsel_view {
2877 my $vbox = Gtk3::VBox->new (0, 0);
2878 $inbox->pack_start ($vbox, 1, 0, 0);
2879 my $hbox = Gtk3::HBox->new (0, 0);
2880 $vbox->pack_start ($hbox, 0, 0, 10);
2882 my ($disk, $devname, $size, $model) = @{@$hds[0]};
2883 $target_hd = $devname;
2885 $target_hd_label = Gtk3::Label->new ("Target Harddisk: ");
2886 $hbox->pack_start ($target_hd_label, 0, 0, 0);
2888 $target_hd_combo = Gtk3::ComboBoxText->new();
2890 foreach my $hd (@$hds) {
2891 ($disk, $devname, $size, $model) = @$hd;
2892 $target_hd_combo->append_text (get_device_desc ($devname, $size, $model));
2895 $target_hd_combo->set_active (0);
2896 $target_hd_combo->signal_connect (changed => sub {
2897 $a = shift->get_active;
2898 my ($disk, $devname) = @{@$hds[$a]};
2899 $target_hd = $devname;
2902 $hbox->pack_start ($target_hd_combo, 0, 0, 10);
2904 my $options = Gtk3::Button->new ('_Options');
2905 $options->signal_connect (clicked => \&create_hdoption_view);
2906 $hbox->pack_start ($options, 0, 0, 0);
2911 display_html ("page1.htm");
2913 set_next (undef, sub {
2915 if ($config_options->{filesys} =~ m/zfs/) {
2916 eval { get_zfs_raid_setup(); };
2918 display_message ("Warning: $err\n" .
2919 "Please fix ZFS setup first.");
2921 create_country_view();
2923 } elsif ($config_options->{filesys} =~ m/btrfs/) {
2924 eval { get_btrfs_raid_setup(); };
2926 display_message ("Warning: $err\n" .
2927 "Please fix BTRFS setup first.");
2929 create_country_view();
2932 create_country_view();
2937 sub create_extract_view {
2941 display_html ("extract1-license.htm");
2942 $next->set_sensitive (0);
2944 my $vbox = Gtk3::VBox->new (0, 0);
2945 $inbox->pack_start ($vbox, 1, 0, 0);
2946 my $hbox = Gtk3::HBox->new (0, 0);
2947 $vbox->pack_start ($hbox, 0, 0, 10);
2949 my $vbox2 = Gtk3::VBox->new (0, 0);
2950 $hbox->pack_start ($vbox2, 0, 0, 0);
2952 $progress_status = Gtk3::Label->new ('');
2953 $vbox2->pack_start ($progress_status, 1, 1, 0);
2955 $progress = Gtk3::ProgressBar->new;
2956 $progress->set_show_text(1);
2957 $progress->set_size_request (600, -1);
2959 $vbox2->pack_start ($progress, 0, 0, 0);
2963 my $tdir = $opt_testmode ? "target" : "/target";
2965 my $base = "${proxmox_cddir}/$setup->{product}-base.squashfs";
2967 eval { extract_data ($base, $tdir); };
2970 $next->set_sensitive (1);
2972 set_next ("_Reboot", sub { exit (0); } );
2975 display_html ("fail.htm");
2976 display_error ($err);
2979 display_html ("success.htm");
2983 sub create_intro_view {
2987 if ($setup->{product} eq 'pve') {
2989 my $cpuinfo = file_get_contents('/proc/cpuinfo');
2990 if ($cpuinfo && !($cpuinfo =~ /^flags\s*:.*(vmx|svm)/m)) {
2991 display_error("No support for KVM virtualisation detected.\n\n" .
2992 "Check BIOS settings for Intel VT / AMD-V / SVM.")
2997 display_html ("license.htm");
2999 set_next ("I a_gree", \&create_hdsel_view);
3002 $ipconf = get_ip_config ();
3004 $country = detect_country() if $ipconf->{default} || $opt_testmode;
3006 # read country, kmap and timezone infos
3007 $cmap = read_cmap ();
3009 if (!defined($cmap->{country}->{$country})) {
3010 print $logfd "ignoring detected country '$country', invalid or unknown\n";
3014 create_main_window ();
3016 my $initial_error = 0;
3018 if (!defined ($hds) || (scalar (@$hds) <= 0)) {
3019 print "no hardisks found\n";
3021 display_html ("nohds.htm");
3022 set_next ("Reboot", sub { exit (0); } );
3024 foreach my $hd (@$hds) {
3025 my ($disk, $devname) = @$hd;
3026 next if $devname =~ m|^/dev/md\d+$|;
3027 print "found Disk$disk N:$devname\n";
3031 if (!$initial_error && (scalar keys %{ $ipconf->{ifaces} } == 0)) {
3032 print "no network interfaces found\n";
3034 display_html ("nonics.htm");
3035 set_next ("Reboot", sub { exit (0); } );
3038 create_intro_view () if !$initial_error;