6 $ENV{DEBIAN_FRONTEND
} = 'noninteractive';
19 use String
::ShellQuote
;
24 use POSIX
":sys_wait_h";
26 use ProxmoxInstallerSetup
;
28 my $setup = ProxmoxInstallerSetup
::setup
();
32 if (!$ENV{G_SLICE
} || $ENV{G_SLICE
} ne "always-malloc") {
33 die "do not use slice allocator (run with 'G_SLICE=always-malloc ./proxinstall ...')\n";
36 if (!GetOptions
('testmode=s' => \
$opt_testmode)) {
41 my $zfstestpool = "test_rpool";
42 my $zfspoolname = $opt_testmode ?
$zfstestpool : 'rpool';
43 my $zfsrootvolname = "$setup->{product}-1";
47 fullname
=> 'Proxmox VE',
51 fullname
=> 'Proxmox Mail Gateway',
55 fullname
=> 'Proxmox Backup Server',
60 my $storage_cfg_zfs = <<__EOD__;
63 content iso,vztmpl,backup
66 pool $zfspoolname/data
68 content images,rootdir
71 my $storage_cfg_btrfs = <<__EOD__;
74 content iso,vztmpl,backup
78 path /var/lib/pve/local-btrfs
79 content iso,vztmpl,backup,images,rootdir
82 my $storage_cfg_lvmthin = <<__EOD__;
85 content iso,vztmpl,backup
90 content rootdir,images
93 my $storage_cfg_local = <<__EOD__;
96 content iso,vztmpl,backup,rootdir,images
99 sub file_read_firstline
{
102 my $fh = IO
::File-
>new ($filename, "r");
103 return undef if !$fh;
110 my $logfd = IO
::File-
>new(">/tmp/install.log");
112 my $proxmox_libdir = $opt_testmode ?
113 Cwd
::cwd
() . "/testdir/var/lib/pve-installer" : "/var/lib/pve-installer";
114 my $proxmox_cddir = $opt_testmode ?
"../pve-cd-builder/tmp/data-gz/" : "/cdrom";
115 my $proxmox_pkgdir = "${proxmox_cddir}/proxmox/packages/";
117 my $boot_type = -d
'/sys/firmware/efi' ?
'efi' : 'bios';
119 my $IPV4OCTET = "(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9])?[0-9])";
120 my $IPV4RE = "(?:(?:$IPV4OCTET\\.){3}$IPV4OCTET)";
121 my $IPV6H16 = "(?:[0-9a-fA-F]{1,4})";
122 my $IPV6LS32 = "(?:(?:$IPV4RE|$IPV6H16:$IPV6H16))";
125 "(?:(?:" . "(?:$IPV6H16:){6})$IPV6LS32)|" .
126 "(?:(?:" . "::(?:$IPV6H16:){5})$IPV6LS32)|" .
127 "(?:(?:(?:" . "$IPV6H16)?::(?:$IPV6H16:){4})$IPV6LS32)|" .
128 "(?:(?:(?:(?:$IPV6H16:){0,1}$IPV6H16)?::(?:$IPV6H16:){3})$IPV6LS32)|" .
129 "(?:(?:(?:(?:$IPV6H16:){0,2}$IPV6H16)?::(?:$IPV6H16:){2})$IPV6LS32)|" .
130 "(?:(?:(?:(?:$IPV6H16:){0,3}$IPV6H16)?::(?:$IPV6H16:){1})$IPV6LS32)|" .
131 "(?:(?:(?:(?:$IPV6H16:){0,4}$IPV6H16)?::" . ")$IPV6LS32)|" .
132 "(?:(?:(?:(?:$IPV6H16:){0,5}$IPV6H16)?::" . ")$IPV6H16)|" .
133 "(?:(?:(?:(?:$IPV6H16:){0,6}$IPV6H16)?::" . ")))";
135 my $IPRE = "(?:$IPV4RE|$IPV6RE)";
138 my $ipv4_mask_hash = {
155 '255.255.128.0' => 17,
156 '255.255.192.0' => 18,
157 '255.255.224.0' => 19,
158 '255.255.240.0' => 20,
159 '255.255.248.0' => 21,
160 '255.255.252.0' => 22,
161 '255.255.254.0' => 23,
162 '255.255.255.0' => 24,
163 '255.255.255.128' => 25,
164 '255.255.255.192' => 26,
165 '255.255.255.224' => 27,
166 '255.255.255.240' => 28,
167 '255.255.255.248' => 29,
168 '255.255.255.252' => 30,
169 '255.255.255.254' => 31,
170 '255.255.255.255' => 32
173 my $ipv4_reverse_mask = [
209 my $step_number = 0; # Init number for global function list
214 html
=> 'license.htm',
215 next_button
=> 'I a_gree',
216 function
=> \
&create_intro_view
,
221 function
=> \
&create_hdsel_view
,
225 html
=> 'country.htm',
226 function
=> \
&create_country_view
,
230 html
=> 'passwd.htm',
231 function
=> \
&create_password_view
,
235 html
=> 'ipconf.htm',
236 function
=> \
&create_ipconf_view
,
241 next_button
=> '_Install',
242 function
=> \
&create_ack_view
,
246 next_button
=> '_Reboot',
247 function
=> \
&create_extract_view
,
251 # GUI global variables
252 my ($window, $cmdbox, $inbox, $htmlview);
254 my ($next, $next_fctn, $target_hd);
255 my ($progress, $progress_status);
257 my ($ipversion, $ipaddress, $cidr, $ipconf_entry_addr);
258 my ($netmask, $ipconf_entry_mask);
259 my ($gateway, $ipconf_entry_gw);
260 my ($dnsserver, $ipconf_entry_dns);
261 my $hostname = 'proxmox';
262 my $domain = 'domain.tld';
263 my $cmdline = file_read_firstline
("/proc/cmdline");
266 my $timezone = 'Europe/Vienna';
267 my $keymap = 'en-us';
269 my $mailto = 'mail@example.invalid';
271 my $autoreboot_seconds = 5;
274 # TODO: add all the user-provided options for previous button
276 timezone
=> $timezone,
279 password
=> $password,
283 hostname
=> $hostname,
290 # parse command line args
292 my $config_options = {
296 if ($cmdline =~ m/\s(ext4|xfs)(\s.*)?$/) {
297 $config_options->{filesys
} = $1;
299 $config_options->{filesys
} = 'ext4';
302 if ($cmdline =~ m/hdsize=(\d+(\.\d+)?)[\s\n]/i) {
303 $config_options->{hdsize
} = $1;
306 if ($cmdline =~ m/swapsize=(\d+(\.\d+)?)[\s\n]/i) {
307 $config_options->{swapsize
} = $1;
310 if ($cmdline =~ m/maxroot=(\d+(\.\d+)?)[\s\n]/i) {
311 $config_options->{maxroot
} = $1;
314 if ($cmdline =~ m/minfree=(\d+(\.\d+)?)[\s\n]/i) {
315 $config_options->{minfree
} = $1;
318 if ($setup->{product
} eq 'pve') {
319 if ($cmdline =~ m/maxvz=(\d+(\.\d+)?)[\s\n]/i) {
320 $config_options->{maxvz
} = $1;
324 my $postfix_main_cf = <<_EOD;
325 # See /usr/share/postfix/main.cf.dist for a commented, more complete version
329 smtpd_banner = \$myhostname ESMTP \$mail_name (Debian/GNU)
332 # appending .domain is the MUA's job.
333 append_dot_mydomain = no
335 # Uncomment the next line to generate "delayed mail" warnings
336 #delay_warning_time = 4h
338 alias_maps = hash:/etc/aliases
339 alias_database = hash:/etc/aliases
340 mydestination = \$myhostname, localhost.\$mydomain, localhost
342 mynetworks = 127.0.0.0/8
343 inet_interfaces = loopback-only
344 recipient_delimiter = +
346 compatibility_level = 2
353 return String
::ShellQuote
::shell_quote
($str);
359 die "no arguments" if !$cmd;
361 return $cmd if !ref($cmd);
364 foreach my $arg (@$cmd) { push @qa, shellquote
($arg); }
366 return join (' ', @qa);
372 return run_command
($cmd, undef, undef, 1);
376 my ($cmd, $func, $input, $noout) = @_;
382 # see 'man bash' for option pipefail
383 $cmd = [ '/bin/bash', '-c', "set -o pipefail && $cmd" ];
388 $cmdstr = cmd2string
($cmd);
392 if ($input && ($cmdstr !~ m/chpasswd/)) {
393 $cmdtxt = "# $cmdstr <<EOD\n$input";
395 $cmdtxt .= "\nEOD\n";
397 $cmdtxt = "# $cmdstr\n";
405 print $logfd $cmdtxt;
407 my $reader = IO
::File-
>new();
408 my $writer = IO
::File-
>new();
409 my $error = IO
::File-
>new();
415 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
421 if ($orig_pid != $$) {
428 print $writer $input if defined $input;
431 my $select = IO
::Select-
>new();
432 $select->add($reader);
433 $select->add($error);
435 my ($ostream, $logout) = ('', '', '');
437 while ($select->count) {
438 my @handles = $select->can_read (0.2);
440 Gtk3
::main_iteration
() while Gtk3
::events_pending
();
442 next if !scalar (@handles); # timeout
444 foreach my $h (@handles) {
446 my $count = sysread ($h, $buf, 4096);
447 if (!defined ($count)) {
451 die "command '$cmd' failed: $err";
453 $select->remove($h) if !$count;
455 $ostream .= $buf if !($noout || $func);
457 while ($logout =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
459 &$func($line) if $func;
462 } elsif ($h eq $error) {
463 $ostream .= $buf if !($noout || $func);
471 &$func($logout) if $func;
473 my $rv = waitpid ($pid, 0);
475 return $? if $noout; # behave like standard system();
478 die "command '$cmdstr' failed to execute\n";
479 } elsif (my $sig = ($? & 127)) {
480 die "command '$cmdstr' failed - got signal $sig\n";
481 } elsif (my $exitcode = ($? >> 8)) {
482 die "command '$cmdstr' failed with exit code $exitcode";
488 # forks and runs the provided coderef in the child
489 # do not use syscmd or run_command as both confuse the GTK mainloop if
490 # run from a child process
491 sub run_in_background
{
494 my $pid = fork() // die "fork failed: $!\n";
498 warn "run_in_background error: $err\n";
507 print "trying to detect country...\n";
508 my $cpid = open2
(\
*TMP
, undef, "traceroute -N 1 -q 1 -n 8.8.8.8");
509 return undef if !$cpid;
513 my $previous_alarm = alarm (10);
515 local $SIG{ALRM
} = sub { die "timed out!\n" };
517 while (defined ($line = <TMP
>)) {
518 print $logfd "DC TRACEROUTE: $line";
519 if ($line =~ m/\s*\d+\s+(\d+\.\d+\.\d+\.\d+)\s/) {
520 my $geoip = `geoiplookup $1`;
521 print $logfd "DC GEOIP: $geoip";
522 if ($geoip =~ m/GeoIP Country Edition:\s*([A-Z]+),/) {
524 print $logfd "DC FOUND: $country\n";
533 alarm ($previous_alarm);
538 print "unable to detect country - $err\n";
540 print "detected country: " . uc($country) . "\n";
542 print "unable to detect country\n";
550 open (my $MEMINFO, '<', '/proc/meminfo');
552 my $res = 512; # default to 512 if something goes wrong
553 while (my $line = <$MEMINFO>) {
554 if ($line =~ m/^MemTotal:\s+(\d+)\s*kB/i) {
555 $res = int ($1 / 1024);
564 my $total_memory = get_memtotal();
567 my ($src, $dest) = @_;
569 my ($dev1,$ino1) = stat ($src);
570 my ($dev2,$ino2) = stat ($dest);
572 return 0 if !($dev1 && $dev2 && $ino1 && $ino2);
574 return $ino1 == $ino2 && $dev1 == $dev2;
577 sub find_stable_path {
578 my ($stabledir, $bdev) = @_;
580 foreach my $path (<$stabledir/*>) {
581 if (link_points_to($path, $bdev)) {
582 return wantarray ? ($path, basename($path)) : $path;
587 sub find_dev_by_uuid {
590 my ($full_path, $name) = find_stable_path("/dev/disk/by-uuid", $bdev);
600 my @disks = split /,/, $opt_testmode;
602 for my $disk (@disks) {
603 push @$res, [-1, $disk, int((-s $disk)/512), "TESTDISK", 512];
610 foreach my $bd (</sys/block/*>) {
611 next if $bd =~ m|^/sys/block/ram\d+$|;
612 next if $bd =~ m|^/sys/block/loop\d+$|;
613 next if $bd =~ m|^/sys/block/md\d+$|;
614 next if $bd =~ m|^/sys/block/dm-.*$|;
615 next if $bd =~ m|^/sys/block/fd\d+$|;
616 next if $bd =~ m|^/sys/block/sr\d+$|;
618 my $dev = file_read_firstline("$bd/dev");
623 my $info = `udevadm info
--path
$bd --query all
`;
626 next if $info !~ m/^E: DEVTYPE=disk$/m;
628 next if $info =~ m/^E: ID_CDROM/m;
629 next if $info =~ m/^E: ID_FS_TYPE=iso9660/m;
631 my ($name) = $info =~ m/^N: (\S+)$/m;
634 my $real_name = "/dev/$name";
636 my $size = file_read_firstline("$bd/size");
638 $size = undef if !($size && $size =~ m/^\d+$/);
640 my $model = file_read_firstline("$bd/device/model") || '';
643 if (length ($model) > 30) {
644 $model = substr ($model, 0, 30);
647 my $logical_bsize = file_read_firstline("$bd/queue/logical_block_size") // '';
648 chomp $logical_bsize;
649 $logical_bsize = undef if !($logical_bsize && $logical_bsize =~ m/^\d+$/);
651 push @$res, [$count++, $real_name, $size, $model, $logical_bsize] if $size;
653 print STDERR "ERROR: unable to map device $dev ($bd)\n";
661 my $countryfn = "${proxmox_libdir}/country.dat";
662 open (my $TMP, "<:encoding(utf8)", "$countryfn") || die "unable to open '$countryfn' - $!\n";
665 my $countryhash = {};
668 while (defined ($line = <$TMP>)) {
669 if ($line =~ m|^map:([^\s:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]*):$|) {
677 $kmaphash->{$2} = $1;
678 } elsif ($line =~ m|^([a-z]{2}):([^:]+):([^:]*):([^:]*):$|) {
684 $countryhash->{lc($2)} = $1;
686 warn "unable to parse 'country.dat' line: $line";
694 my $zonefn = "/usr/share/zoneinfo/zone.tab";
695 open ($TMP, '<', "$zonefn") || die "unable to open '$zonefn' - $!\n";
696 while (defined ($line = <$TMP>)) {
697 next if $line =~ m/^\#/;
698 next if $line =~ m/^\s*$/;
699 if ($line =~ m|^([A-Z][A-Z])\s+\S+\s+(([^/]+)/\S+)\s|) {
701 $cczones->{$cc}->{$2} = 1;
702 $country->{$cc}->{zone} = $2 if !defined ($country->{$cc}->{zone});
713 countryhash => $countryhash,
715 kmaphash => $kmaphash,
719 # search for Harddisks
725 foreach my $hd (@$hds) {
726 my ($disk, $devname, $size, $model, $logical_bsize) = @$hd;
727 # size is always (also for 4kn disks) in 512B "sectors"! convert to KB
728 return int($size/2) if $devname eq $dev;
731 die "no such device '$dev'\n";
734 sub logical_blocksize {
737 foreach my $hd (@$hds) {
738 my ($disk, $devname, $size, $model, $logical_bsize) = @$hd;
739 return $logical_bsize if $devname eq $dev;
742 die "no such device '$dev'\n";
745 sub get_partition_dev {
746 my ($dev, $partnum) = @_;
748 if ($dev =~ m|^/dev/sd([a-h]?[a-z]\|i[a-v])$|) {
749 return "${dev}$partnum";
750 } elsif ($dev =~ m|^/dev/xvd[a-z]$|) {
751 # Citrix Hypervisor blockdev
752 return "${dev}$partnum";
753 } elsif ($dev =~ m|^/dev/[hxev]d[a-z]$|) {
754 return "${dev}$partnum";
755 } elsif ($dev =~ m|^/dev/[^/]+/c\d+d\d+$|) {
756 return "${dev}p$partnum";
757 } elsif ($dev =~ m|^/dev/[^/]+/d\d+$|) {
758 return "${dev}p$partnum";
759 } elsif ($dev =~ m|^/dev/[^/]+/hd[a-z]$|) {
760 return "${dev}$partnum";
761 } elsif ($dev =~ m|^/dev/nvme\d+n\d+$|) {
762 return "${dev}p$partnum";
764 die "unable to get device for partition $partnum on device $dev\n";
769 sub file_get_contents {
770 my ($filename, $max) = @_;
772 my $fh = IO::File->new($filename, "r") ||
773 die "can't open '$filename' - $!\n";
775 local $/; # slurp mode
785 my ($text, $filename) = @_;
787 my $fd = IO::File->new(">$filename") ||
788 die "unable to open file '$filename' - $!\n";
793 sub update_progress {
794 my ($frac, $start, $end, $text) = @_;
796 my $part = $end - $start;
797 my $res = $start + $frac*$part;
799 $progress->set_fraction ($res);
800 $progress->set_text (sprintf ("%d%%", int ($res*100)));
801 $progress_status->set_text ($text) if defined ($text);
803 display_info() if $res < 0.9;
805 Gtk3::main_iteration() while Gtk3::events_pending();
810 mkfs => 'mkfs.ext4 -F',
812 mkfs_data_opt => '-m 0',
813 root_mountopt => 'errors=remount-ro',
816 mkfs => 'mkfs.xfs -f',
823 sub create_filesystem {
824 my ($dev, $name, $type, $start, $end, $fs, $fe) = @_;
826 my $range = $end - $start;
827 my $rs = $start + $range*$fs;
828 my $re = $start + $range*$fe;
831 my $fsdata = $fssetup->{$type} || die "internal error - unknown file system '$type'";
832 my $opts = $name eq 'root' ? $fsdata->{mkfs_root_opt} : $fsdata->{mkfs_data_opt};
834 update_progress(0, $rs, $re, "creating $name filesystem");
836 run_command("$fsdata->{mkfs} $opts $dev", sub {
839 if ($line =~ m/Writing inode tables:\s+(\d+)\/(\d+)/) {
841 } elsif ($max && $line =~ m/(\d+)\/$max/) {
842 update_progress(($1/$max)*0.9, $rs, $re);
843 } elsif ($line =~ m/Creating journal.*done/) {
844 update_progress(0.95, $rs, $re);
845 } elsif ($line =~ m/Writing superblocks and filesystem.*done/) {
846 update_progress(1, $rs, $re);
852 my ($targetdir, $dcdata) = @_;
854 my $cfgfile = "/tmp/debconf.txt";
855 write_config($dcdata, "$targetdir/$cfgfile");
856 syscmd("chroot $targetdir debconf-set-selections $cfgfile");
857 unlink "$targetdir/$cfgfile";
861 my ($targetdir, $cmd, $new_cmd) = @_;
863 syscmd("chroot $targetdir dpkg-divert --package proxmox " .
864 "--add --rename $cmd") == 0 ||
865 die "unable to exec dpkg-divert\n";
867 syscmd("ln -sf ${new_cmd} $targetdir/$cmd") == 0 ||
868 die "unable to link diversion to ${new_cmd}\n";
871 sub diversion_remove {
872 my ($targetdir, $cmd) = @_;
874 syscmd("mv $targetdir/${cmd}.distrib $targetdir/${cmd};") == 0 ||
875 die "unable to remove $cmd diversion\n";
877 syscmd("chroot $targetdir dpkg-divert --remove $cmd") == 0 ||
878 die "unable to remove $cmd diversion\n";
882 my ($partitions, $mode) = @_;
884 die "unknown btrfs mode '$mode'"
885 if !($mode eq 'single' || $mode eq 'raid0' ||
886 $mode eq 'raid1' || $mode eq 'raid10');
888 my $cmd = ['mkfs.btrfs', '-f'];
890 push @$cmd, '-d', $mode, '-m', $mode;
892 push @$cmd, @$partitions;
897 sub zfs_create_rpool {
900 my $cmd = "zpool create -f -o cachefile=none";
902 $cmd .= " -o ashift=$config_options->{ashift}"
903 if defined($config_options->{ashift});
905 syscmd("$cmd $zfspoolname $vdev") == 0 ||
906 die "unable to create zfs root pool\n";
908 syscmd("zfs create $zfspoolname/ROOT") == 0 ||
909 die "unable to create zfs $zfspoolname/ROOT volume\n";
911 if ($setup->{product} eq 'pve') {
912 syscmd("zfs create $zfspoolname/data") == 0 ||
913 die "unable to create zfs $zfspoolname/data volume\n";
916 syscmd("zfs create $zfspoolname/ROOT/$zfsrootvolname") == 0 ||
917 die "unable to create zfs $zfspoolname/ROOT/$zfsrootvolname volume\n";
919 # disable atime during install
920 syscmd("zfs set atime=off $zfspoolname") == 0 ||
921 die "unable to set zfs properties\n";
923 my $value = $config_options->{compress};
924 syscmd("zfs set compression=$value $zfspoolname")
925 if defined($value) && $value ne 'off';
927 $value = $config_options->{checksum};
928 syscmd("zfs set checksum=$value $zfspoolname")
929 if defined($value) && $value ne 'on';
931 $value = $config_options->{copies};
932 syscmd("zfs set copies=$value $zfspoolname")
933 if defined($value) && $value != 1;
936 my $udevadm_trigger_block = sub {
939 sleep(1) if !$nowait; # give kernel time to reread part table
941 # trigger udev to create /dev/disk/by-uuid
942 syscmd("udevadm trigger --subsystem-match block");
943 syscmd("udevadm settle --timeout 10");
946 my $clean_disk = sub {
949 my $partitions = `lsblk
--output kname
--noheadings
--path
--list
$disk`;
950 foreach my $part (split "\n", $partitions) {
951 next if $part eq $disk;
952 next if $part !~ /^\Q$disk\E/;
953 eval { syscmd
("pvremove -ff -y $part"); };
954 eval { syscmd
("zpool labelclear -f $part"); };
955 eval { syscmd
("dd if=/dev/zero of=$part bs=1M count=16"); };
959 sub partition_bootable_disk
{
960 my ($target_dev, $maxhdsizegb, $ptype) = @_;
962 die "too dangerous" if $opt_testmode;
964 die "unknown partition type '$ptype'"
965 if !($ptype eq '8E00' || $ptype eq '8300' || $ptype eq 'BF01');
967 my $hdsize = hd_size
($target_dev); # size in KB (1024 bytes)
969 my $restricted_hdsize_mb = 0; # 0 ==> end of partition
971 my $maxhdsize = $maxhdsizegb * 1024 * 1024;
972 if ($maxhdsize < $hdsize) {
973 $hdsize = $maxhdsize;
974 $restricted_hdsize_mb = int($hdsize/1024) . 'M';
978 my $hdgb = int($hdsize/(1024*1024));
979 die "hardisk '$target_dev' too small (${hdgb}GB)\n" if $hdgb < 8;
981 syscmd
("sgdisk -Z ${target_dev}");
983 # 1 - BIOS boot partition (Grub Stage2): first free 1M
984 # 2 - EFI ESP: next free 512M
985 # 3 - OS/Data partition: rest, up to $maxhdsize in MB
987 my $grubbootdev = get_partition_dev
($target_dev, 1);
988 my $efibootdev = get_partition_dev
($target_dev, 2);
989 my $osdev = get_partition_dev
($target_dev, 3);
991 my $pcmd = ['sgdisk'];
994 push @$pcmd, "-n${pnum}:1M:+512M", "-t$pnum:EF00";
997 push @$pcmd, "-n${pnum}:513M:${restricted_hdsize_mb}", "-t$pnum:$ptype";
999 push @$pcmd, $target_dev;
1001 my $os_size = $hdsize - 513*1024; # 512M efi + 1M bios_boot + 1M alignment
1003 syscmd
($pcmd) == 0 ||
1004 die "unable to partition harddisk '${target_dev}'\n";
1006 my $blocksize = logical_blocksize
($target_dev);
1008 if ($blocksize != 4096) {
1010 $pcmd = ['sgdisk', '-a1', "-n$pnum:34:2047", "-t$pnum:EF02" , $target_dev];
1012 syscmd
($pcmd) == 0 ||
1013 die "unable to create bios_boot partition '${target_dev}'\n";
1016 &$udevadm_trigger_block();
1018 foreach my $part ($efibootdev, $osdev) {
1019 syscmd
("dd if=/dev/zero of=$part bs=1M count=256") if -b
$part;
1022 return ($os_size, $osdev, $efibootdev);
1025 sub get_pv_list_from_vgname
{
1035 my ($pv, $vg_uuid) = split(/\s+/, $line);
1037 if (!defined($res->{$vg_uuid}->{pvs
})) {
1038 $res->{$vg_uuid}->{pvs
} = "$pv";
1040 $res->{$vg_uuid}->{pvs
} .= ", $pv";
1043 run_command
("pvs --noheadings -o pv_name,vg_uuid -S vg_name='$vgname'", $parser, undef, 1);
1048 sub ask_existing_vg_rename_or_abort
{
1051 # this normally only happens if one put a disk with a PVE installation in
1052 # this server and that disk is not the installation target.
1053 my $duplicate_vgs = get_pv_list_from_vgname
($vgname);
1054 return if !$duplicate_vgs;
1056 my $message = "Detected existing '$vgname' Volume Group(s)! Do you want to:\n";
1058 for my $vg_uuid (keys %$duplicate_vgs) {
1059 my $vg = $duplicate_vgs->{$vg_uuid};
1061 # no high randomnes properties, but this is only for the cases where
1062 # we either have multiple "$vgname" vgs from multiple old PVE disks, or
1063 # we have a disk with both a "$vgname" and "$vgname-old"...
1064 my $short_uid = sprintf "%08X", rand(0xffffffff);
1065 $vg->{new_vgname
} = "$vgname-OLD-$short_uid";
1067 $message .= "rename VG backed by PV '$vg->{pvs}' to '$vg->{new_vgname}'\n";
1069 $message .= "or cancel the installation?";
1071 my $dialog = Gtk3
::MessageDialog-
>new($window, 'modal', 'question', 'ok-cancel', $message);
1072 my $response = $dialog->run();
1075 if ($response eq 'ok') {
1076 for my $vg_uuid (keys %$duplicate_vgs) {
1077 my $vg = $duplicate_vgs->{$vg_uuid};
1078 my $new_vgname = $vg->{new_vgname
};
1080 syscmd
("vgrename $vg_uuid $new_vgname") == 0 ||
1081 die "could not rename VG from '$vg->{pvs}' ($vg_uuid) to '$new_vgname'!\n";
1084 set_next
("_Reboot", sub { exit (0); } );
1085 display_html
("fail.htm");
1086 die "Cancled installation by user, due to already existing volume group '$vgname'\n";
1090 sub create_lvm_volumes
{
1091 my ($lvmdev, $os_size, $swap_size) = @_;
1093 my $vgname = $setup->{product
};
1095 ask_existing_vg_rename_or_abort
($vgname);
1097 my $rootdev = "/dev/$vgname/root";
1098 my $datadev = "/dev/$vgname/data";
1101 # we use --metadatasize 250k, which results in "pe_start = 512"
1102 # so pe_start is aligned on a 128k boundary (advantage for SSDs)
1103 syscmd
("/sbin/pvcreate --metadatasize 250k -y -ff $lvmdev") == 0 ||
1104 die "unable to initialize physical volume $lvmdev\n";
1105 syscmd
("/sbin/vgcreate $vgname $lvmdev") == 0 ||
1106 die "unable to create volume group '$vgname'\n";
1108 my $hdgb = int($os_size/(1024*1024));
1109 my $space = (($hdgb > 128) ?
16 : ($hdgb/8))*1024*1024;
1114 if ($setup->{product
} eq 'pve') {
1117 if ($config_options->{maxroot
}) {
1118 $maxroot = $config_options->{maxroot
};
1123 $rootsize = (($hdgb > ($maxroot*4)) ?
$maxroot : $hdgb/4)*1024*1024;
1125 my $rest = $os_size - $swap_size - $rootsize; # in KB
1128 if (defined($config_options->{minfree
})) {
1129 $minfree = (($config_options->{minfree
}*1024*1024) >= $rest ) ?
$space :
1130 $config_options->{minfree
}*1024*1024 ;
1135 $rest = $rest - $minfree;
1137 if (defined($config_options->{maxvz
})) {
1138 $rest = (($config_options->{maxvz
}*1024*1024) <= $rest) ?
1139 $config_options->{maxvz
}*1024*1024 : $rest;
1145 my $minfree = defined($config_options->{minfree
}) ?
$config_options->{minfree
}*1024*1024 : $space;
1146 $rootsize = $os_size - $minfree - $swap_size; # in KB
1150 syscmd
("/sbin/lvcreate -L${swap_size}K -nswap $vgname") == 0 ||
1151 die "unable to create swap volume\n";
1153 $swapfile = "/dev/$vgname/swap";
1156 syscmd
("/sbin/lvcreate -L${rootsize}K -nroot $vgname") == 0 ||
1157 die "unable to create root volume\n";
1159 if ($datasize > 4*1024*1024) {
1160 my $metadatasize = $datasize/100; # default 1% of data
1161 $metadatasize = 1024*1024 if $metadatasize < 1024*1024; # but at least 1G
1162 $metadatasize = 16*1024*1024 if $metadatasize > 16*1024*1024; # but at most 16G
1164 # otherwise the metadata is taken out of $minfree
1165 $datasize -= 2*$metadatasize;
1167 # 1 4MB PE to allow for rounding
1168 $datasize -= 4*1024;
1170 syscmd
("/sbin/lvcreate -L${datasize}K -ndata $vgname") == 0 ||
1171 die "unable to create data volume\n";
1173 syscmd
("/sbin/lvconvert --yes --type thin-pool --poolmetadatasize ${metadatasize}K $vgname/data") == 0 ||
1174 die "unable to create data thin-pool\n";
1179 syscmd
("/sbin/vgchange -a y $vgname") == 0 ||
1180 die "unable to activate volume group\n";
1182 return ($rootdev, $swapfile, $datadev);
1185 sub compute_swapsize
{
1188 my $hdgb = int($hdsize/(1024*1024));
1191 if (defined($config_options->{swapsize
})) {
1192 $swapsize = $config_options->{swapsize
}*1024*1024;
1194 my $ss = int ($total_memory / 1024);
1196 $ss = ($hdgb/8) if $ss > ($hdgb/8);
1198 $swapsize = $ss*1024*1024;
1204 my sub chroot_chown
{
1205 my ($root, $path, %param) = @_;
1207 my $recursive = $param{recursive
} ?
' -R' : '';
1208 my $user = $param{user
};
1209 die "can not chown without user parameter\n" if !defined($user);
1210 my $group = $param{group
} // $user;
1212 syscmd
("chroot $root /bin/chown $user:$group $recursive $path") == 0 ||
1213 die "chroot: unable to change owner for '$path'\n";
1216 my sub chroot_chmod
{
1217 my ($root, $path, %param) = @_;
1219 my $recursive = $param{recursive
} ?
' -R' : '';
1220 my $mode = $param{mode
};
1221 die "can not chmod without mode parameter\n" if !defined($mode);
1223 syscmd
("chroot $root /bin/chmod $mode $recursive $path") == 0 ||
1224 die "chroot: unable to change permission mode for '$path'\n";
1227 sub prepare_proxmox_boot_esp
{
1228 my ($espdev, $targetdir) = @_;
1230 syscmd
("chroot $targetdir proxmox-boot-tool init $espdev") == 0 ||
1231 die "unable to init ESP and install proxmox-boot loader on '$espdev'\n";
1234 sub prepare_grub_efi_boot_esp
{
1235 my ($dev, $espdev, $targetdir) = @_;
1237 syscmd
("mount -n $espdev -t vfat $targetdir/boot/efi") == 0 ||
1238 die "unable to mount $espdev\n";
1241 my $rc = syscmd
("chroot $targetdir /usr/sbin/grub-install --target x86_64-efi --no-floppy --bootloader-id='proxmox' $dev");
1243 if ($boot_type eq 'efi') {
1244 die "unable to install the EFI boot loader on '$dev'\n";
1246 warn "unable to install the EFI boot loader on '$dev', ignoring (not booted using UEFI)\n";
1249 # also install fallback boot file (OVMF does not boot without)
1250 mkdir("$targetdir/boot/efi/EFI/BOOT");
1251 syscmd
("cp $targetdir/boot/efi/EFI/proxmox/grubx64.efi $targetdir/boot/efi/EFI/BOOT/BOOTx64.EFI") == 0 ||
1252 die "unable to copy efi boot loader\n";
1257 syscmd
("umount $targetdir/boot/efi") == 0 ||
1258 die "unable to umount $targetdir/boot/efi\n";
1262 die "failed to prepare EFI boot using Grub on '$espdev': $err" if $err;
1266 my ($basefile, $targetdir) = @_;
1268 die "target '$targetdir' does not exist\n" if ! -d
$targetdir;
1270 my $starttime = [Time
::HiRes
::gettimeofday
];
1272 my $bootdevinfo = [];
1281 my $filesys = $config_options->{filesys
};
1283 if ($filesys =~ m/zfs/) {
1284 $target_hd = undef; # do not use this config
1286 $targetdir = "/$zfspoolname/ROOT/$zfsrootvolname";
1287 } elsif ($filesys =~ m/btrfs/) {
1288 $target_hd = undef; # do not use this config
1294 for ($i = 5; $i > 0; $i--) {
1295 syscmd
("modprobe zfs");
1296 last if -c
"/dev/zfs";
1300 die "unable to load zfs kernel module\n" if !$i;
1310 update_progress
(0, 0, $maxper, "create partitions");
1312 syscmd
("vgchange -an") if !$opt_testmode; # deactivate all detected VGs
1314 if ($opt_testmode) {
1316 $rootdev = abs_path
($opt_testmode);
1317 syscmd
("umount $rootdev");
1321 die "unsupported btrfs mode (for testing environment)\n"
1322 if $filesys ne 'btrfs (RAID0)';
1324 btrfs_create
([$rootdev], 'single');
1326 } elsif ($use_zfs) {
1328 die "unsupported zfs mode (for testing environment)\n"
1329 if $filesys ne 'zfs (RAID0)';
1331 syscmd
("zpool destroy $zfstestpool");
1333 zfs_create_rpool
($rootdev);
1340 } elsif ($use_btrfs) {
1342 my ($devlist, $btrfs_mode) = get_btrfs_raid_setup
();
1343 my $btrfs_partitions = [];
1345 foreach my $hd (@$devlist) {
1346 my $devname = @$hd[1];
1347 my $logical_bsize = @$hd[4];
1349 &$clean_disk($devname);
1350 my ($size, $osdev, $efidev) =
1351 partition_bootable_disk
($devname, undef, '8300');
1352 $rootdev = $osdev if !defined($rootdev); # simply point to first disk
1353 my $by_id = find_stable_path
("/dev/disk/by-id", $devname);
1354 push @$bootdevinfo, {
1356 devname
=> $devname,
1359 logical_bsize
=> $logical_bsize,
1361 push @$btrfs_partitions, $osdev;
1365 $udevadm_trigger_block->();
1367 btrfs_create
($btrfs_partitions, $btrfs_mode);
1369 } elsif ($use_zfs) {
1371 my ($devlist, $vdev) = get_zfs_raid_setup
();
1373 foreach my $hd (@$devlist) {
1374 $clean_disk->(@$hd[1]);
1377 # install esp/boot part on all, we can only win!
1379 for my $hd (@$devlist) {
1380 my $devname = @$hd[1];
1381 my $logical_bsize = @$hd[4];
1383 my ($size, $osdev, $efidev) =
1384 partition_bootable_disk
($devname, $config_options->{hdsize
}, 'BF01');
1386 zfs_mirror_size_check
($disksize, $size) if $disksize;
1388 push @$bootdevinfo, {
1390 devname
=> $devname,
1392 logical_bsize
=> $logical_bsize,
1397 $udevadm_trigger_block->();
1399 foreach my $di (@$bootdevinfo) {
1400 my $devname = $di->{devname
};
1401 $di->{by_id
} = find_stable_path
("/dev/disk/by-id", $devname);
1403 my $osdev = find_stable_path
("/dev/disk/by-id", $di->{osdev
}) || $di->{osdev
};
1405 $vdev =~ s/ $devname/ $osdev/;
1408 foreach my $hd (@$devlist) {
1409 my $devname = @$hd[1];
1410 my $by_id = find_stable_path
("/dev/disk/by-id", $devname);
1412 $vdev =~ s/ $devname/ $by_id/ if $by_id;
1415 zfs_create_rpool
($vdev);
1419 die "target '$target_hd' is not a valid block device\n" if ! -b
$target_hd;
1421 &$clean_disk($target_hd);
1423 my $logical_bsize = logical_blocksize
($target_hd);
1425 my ($os_size, $osdev, $efidev);
1426 ($os_size, $osdev, $efidev) =
1427 partition_bootable_disk
($target_hd, $config_options->{hdsize
}, '8E00');
1429 &$udevadm_trigger_block();
1431 my $by_id = find_stable_path
("/dev/disk/by-id", $target_hd);
1432 push @$bootdevinfo, {
1434 devname
=> $target_hd,
1437 logical_bsize
=> $logical_bsize,
1440 my $swap_size = compute_swapsize
($os_size);
1441 ($rootdev, $swapfile, $datadev) =
1442 create_lvm_volumes
($osdev, $os_size, $swap_size);
1444 # trigger udev to create /dev/disk/by-uuid
1445 &$udevadm_trigger_block(1);
1449 # to be fast during installation
1450 syscmd
("zfs set sync=disabled $zfspoolname") == 0 ||
1451 die "unable to set zfs properties\n";
1454 update_progress
(0.03, 0, $maxper, "create swap space");
1456 syscmd
("mkswap -f $swapfile") == 0 ||
1457 die "unable to create swap space\n";
1460 update_progress
(0.05, 0, $maxper, "creating filesystems");
1462 foreach my $di (@$bootdevinfo) {
1463 next if !$di->{esp
};
1464 # FIXME remove '-s1' once https://github.com/dosfstools/dosfstools/issues/111 is fixed
1465 my $vfat_extra_opts = ($di->{logical_bsize
} == 4096) ?
'-s1' : '';
1466 syscmd
("mkfs.vfat $vfat_extra_opts -F32 $di->{esp}") == 0 ||
1467 die "unable to initialize EFI ESP on device $di->{esp}\n";
1472 } elsif ($use_btrfs) {
1475 create_filesystem
($rootdev, 'root', $filesys, 0.05, $maxper, 0, 1);
1478 update_progress
(1, 0.05, $maxper, "mounting target $rootdev");
1483 my $mount_opts = 'noatime';
1484 $mount_opts .= ',nobarrier'
1485 if $use_btrfs || $filesys =~ /^ext\d$/;
1487 syscmd
("mount -n $rootdev -o $mount_opts $targetdir") == 0 ||
1488 die "unable to mount $rootdev\n";
1491 mkdir "$targetdir/boot";
1492 mkdir "$targetdir/boot/efi";
1494 mkdir "$targetdir/var";
1495 mkdir "$targetdir/var/lib";
1497 if ($setup->{product
} eq 'pve') {
1498 mkdir "$targetdir/var/lib/vz";
1499 mkdir "$targetdir/var/lib/pve";
1502 syscmd
("btrfs subvolume create $targetdir/var/lib/pve/local-btrfs") == 0 ||
1503 die "unable to create btrfs subvolume\n";
1507 mkdir "$targetdir/mnt";
1508 mkdir "$targetdir/mnt/hostrun";
1509 syscmd
("mount --bind /run $targetdir/mnt/hostrun") == 0 ||
1510 die "unable to bindmount run on $targetdir/mnt/hostrun\n";
1512 update_progress
(1, 0.05, $maxper, "extracting base system");
1514 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = stat ($basefile);
1515 $ino || die "unable to open file '$basefile' - $!\n";
1517 my $files = file_read_firstline
("${proxmox_cddir}/proxmox/$setup->{product}-base.cnt") ||
1518 die "unable to read base file count\n";
1523 run_command
("unsquashfs -f -dest $targetdir -i $basefile", sub {
1525 return if $line !~ m/^$targetdir/;
1527 my $nper = int (($count *100)/$files);
1528 if ($nper != $per) {
1530 my $frac = $per > 100 ?
1 : $per/100;
1531 update_progress
($frac, $maxper, 0.5);
1535 syscmd
("mount -n -t tmpfs tmpfs $targetdir/tmp") == 0 ||
1536 die "unable to mount tmpfs on $targetdir/tmp\n";
1537 syscmd
("mount -n -t proc proc $targetdir/proc") == 0 ||
1538 die "unable to mount proc on $targetdir/proc\n";
1539 syscmd
("mount -n -t sysfs sysfs $targetdir/sys") == 0 ||
1540 die "unable to mount sysfs on $targetdir/sys\n";
1541 if ($boot_type eq 'efi') {
1542 syscmd
("mount -n -t efivarfs efivarfs $targetdir/sys/firmware/efi/efivars") == 0 ||
1543 die "unable to mount efivarfs on $targetdir/sys/firmware/efi/efivars: $!\n";
1545 syscmd
("chroot $targetdir mount --bind /mnt/hostrun /run") == 0 ||
1546 die "unable to re-bindmount hostrun on /run in chroot\n";
1548 update_progress
(1, $maxper, 0.5, "configuring base system");
1553 "127.0.0.1 localhost.localdomain localhost\n" .
1554 "$ipaddress $hostname.$domain $hostname\n\n" .
1555 "# The following lines are desirable for IPv6 capable hosts\n\n" .
1556 "::1 ip6-localhost ip6-loopback\n" .
1557 "fe00::0 ip6-localnet\n" .
1558 "ff00::0 ip6-mcastprefix\n" .
1559 "ff02::1 ip6-allnodes\n" .
1560 "ff02::2 ip6-allrouters\n" .
1561 "ff02::3 ip6-allhosts\n";
1563 write_config
($hosts, "$targetdir/etc/hosts");
1565 write_config
("$hostname\n", "$targetdir/etc/hostname");
1567 syscmd
("/bin/hostname $hostname") if !$opt_testmode;
1569 # configure interfaces
1571 my $ifaces = "auto lo\niface lo inet loopback\n\n";
1573 my $ntype = $ipversion == 4 ?
'inet' : 'inet6';
1575 my $ethdev = $ipconf->{ifaces
}->{$ipconf->{selected
}}->{name
};
1577 if ($setup->{bridged_network
}) {
1578 $ifaces .= "iface $ethdev $ntype manual\n";
1581 "\nauto vmbr0\niface vmbr0 $ntype static\n" .
1582 "\taddress $cidr\n" .
1583 "\tgateway $gateway\n" .
1584 "\tbridge_ports $ethdev\n" .
1585 "\tbridge_stp off\n" .
1588 $ifaces .= "auto $ethdev\n" .
1589 "iface $ethdev $ntype static\n" .
1590 "\taddress $cidr\n" .
1591 "\tgateway $gateway\n";
1594 foreach my $iface (sort keys %{$ipconf->{ifaces
}}) {
1595 my $name = $ipconf->{ifaces
}->{$iface}->{name
};
1596 next if $name eq $ethdev;
1598 $ifaces .= "\niface $name $ntype manual\n";
1601 write_config
($ifaces, "$targetdir/etc/network/interfaces");
1605 my $resolvconf = "search $domain\nnameserver $dnsserver\n";
1606 write_config
($resolvconf, "$targetdir/etc/resolv.conf");
1610 my $fstab = "# <file system> <mount point> <type> <options> <dump> <pass>\n";
1614 } elsif ($use_btrfs) {
1616 my $cmd = "blkid -u filesystem -t TYPE=btrfs -o export $rootdev";
1617 run_command
($cmd, sub {
1620 if ($line =~ m/^UUID=([A-Fa-f0-9\-]+)$/) {
1625 die "unable to detect FS UUID" if !defined($fsuuid);
1627 $fstab .= "UUID=$fsuuid / btrfs defaults 0 1\n";
1629 my $root_mountopt = $fssetup->{$filesys}->{root_mountopt
} || 'defaults';
1630 $fstab .= "$rootdev / $filesys ${root_mountopt} 0 1\n";
1634 # Note: this is required by current grub, but really dangerous, because
1635 # vfat does not have journaling, so it triggers manual fsck after each crash
1636 # so we only mount /boot/efi if really required (efi systems).
1637 if ($boot_type eq 'efi' && !$use_zfs) {
1638 if (scalar(@$bootdevinfo)) {
1639 my $di = @$bootdevinfo[0]; # simply use first disk
1642 my $efi_boot_uuid = $di->{esp
};
1643 if (my $uuid = find_dev_by_uuid
($di->{esp
})) {
1644 $efi_boot_uuid = "UUID=$uuid";
1647 $fstab .= "${efi_boot_uuid} /boot/efi vfat defaults 0 1\n";
1653 $fstab .= "$swapfile none swap sw 0 0\n" if $swapfile;
1655 $fstab .= "proc /proc proc defaults 0 0\n";
1657 write_config
($fstab, "$targetdir/etc/fstab");
1658 write_config
("", "$targetdir/etc/mtab");
1660 syscmd
("cp ${proxmox_libdir}/policy-disable-rc.d " .
1661 "$targetdir/usr/sbin/policy-rc.d") == 0 ||
1662 die "unable to copy policy-rc.d\n";
1663 syscmd
("cp ${proxmox_libdir}/fake-start-stop-daemon " .
1664 "$targetdir/sbin/") == 0 ||
1665 die "unable to copy start-stop-daemon\n";
1667 diversion_add
($targetdir, "/sbin/start-stop-daemon", "/sbin/fake-start-stop-daemon");
1668 diversion_add
($targetdir, "/usr/sbin/update-grub", "/bin/true");
1669 diversion_add
($targetdir, "/usr/sbin/update-initramfs", "/bin/true");
1671 my $machine_id = run_command
("systemd-id128 new");
1672 die "unable to create a new machine-id\n" if ! $machine_id;
1673 write_config
($machine_id, "$targetdir/etc/machine-id");
1675 syscmd
("cp /etc/hostid $targetdir/etc/") == 0 ||
1676 die "unable to copy hostid\n";
1678 syscmd
("touch $targetdir/proxmox_install_mode");
1680 my $grub_install_devices_txt = '';
1681 foreach my $di (@$bootdevinfo) {
1682 $grub_install_devices_txt .= ', ' if $grub_install_devices_txt;
1683 $grub_install_devices_txt .= $di->{by_id
} || $di->{devname
};
1686 # Note: keyboard-configuration/xbkb-keymap is used by console-setup
1687 my $xkmap = $cmap->{kmap
}->{$keymap}->{x11
} // 'us';
1689 debconfig_set
($targetdir, <<_EOD);
1690 locales locales/default_environment_locale select en_US.UTF-8
1691 locales locales/locales_to_be_generated select en_US.UTF-8 UTF-8
1692 samba-common samba-common/dhcp boolean false
1693 samba-common samba-common/workgroup string WORKGROUP
1694 postfix postfix/main_mailer_type select No configuration
1695 keyboard-configuration keyboard-configuration/xkb-keymap select $xkmap
1696 d-i debian-installer/locale select en_US.UTF-8
1697 grub-pc grub-pc/install_devices select $grub_install_devices_txt
1701 while (<${proxmox_pkgdir
}/*.deb
>) { $pkg_count++ };
1703 # btrfs/dpkg is extremely slow without --force-unsafe-io
1704 my $dpkg_opts = $use_btrfs ?
"--force-unsafe-io" : "";
1707 while (<${proxmox_pkgdir
}/*.deb
>) {
1710 my ($deb) = $path =~ m/${proxmox_pkgdir}\/(.*\
.deb
)/;
1711 update_progress
($count/$pkg_count, 0.5, 0.75, "extracting $deb");
1712 print "extracting: $deb\n";
1713 syscmd
("cp $path $targetdir/tmp/$deb") == 0 ||
1714 die "installation of package $deb failed\n";
1715 syscmd
("chroot $targetdir dpkg $dpkg_opts --force-depends --no-triggers --unpack /tmp/$deb") == 0 ||
1716 die "installation of package $deb failed\n";
1717 update_progress
((++$count)/$pkg_count, 0.5, 0.75);
1720 # needed for postfix postinst in case no other NIC is active
1721 syscmd
("chroot $targetdir ifup lo");
1723 my $cmd = "chroot $targetdir dpkg $dpkg_opts --force-confold --configure -a";
1725 run_command
($cmd, sub {
1727 if ($line =~ m/Setting up\s+(\S+)/) {
1728 update_progress
((++$count)/$pkg_count, 0.75, 0.95,
1733 unlink "$targetdir/etc/mailname";
1734 $postfix_main_cf =~ s/__FQDN__/${hostname}.${domain}/;
1735 write_config
($postfix_main_cf, "$targetdir/etc/postfix/main.cf");
1737 # make sure we have all postfix directories
1738 syscmd
("chroot $targetdir /usr/sbin/postfix check");
1739 # cleanup mail queue
1740 syscmd
("chroot $targetdir /usr/sbin/postsuper -d ALL");
1741 # create /etc/aliases.db (/etc/aliases is shipped in the base squashfs)
1742 syscmd
("chroot $targetdir /usr/bin/newaliases");
1744 # enable NTP (timedatectl set-ntp true does not work without DBUS)
1745 syscmd
("chroot $targetdir /bin/systemctl enable systemd-timesyncd.service");
1747 unlink "$targetdir/proxmox_install_mode";
1750 unlink ("$targetdir/etc/localtime");
1751 symlink ("/usr/share/zoneinfo/$timezone", "$targetdir/etc/localtime");
1752 write_config
("$timezone\n", "$targetdir/etc/timezone");
1755 if (my $mirror = $cmap->{country
}->{$country}->{mirror
}) {
1756 my $fn = "$targetdir/etc/apt/sources.list";
1757 syscmd
("sed -i 's/ftp\\.debian\\.org/$mirror/' '$fn'");
1760 # create extended_states for apt (avoid cron job warning if that
1761 # file does not exist)
1762 write_config
('', "$targetdir/var/lib/apt/extended_states");
1764 # allow ssh root login
1765 syscmd
(['sed', '-i', 's/^#\?PermitRootLogin.*/PermitRootLogin yes/', "$targetdir/etc/ssh/sshd_config"]);
1767 if ($setup->{product
} eq 'pmg') {
1768 # install initial clamav DB
1769 my $srcdir = "${proxmox_cddir}/proxmox/clamav";
1770 foreach my $fn ("main.cvd", "bytecode.cvd", "daily.cvd", "safebrowsing.cvd") {
1771 syscmd
("cp \"$srcdir/$fn\" \"$targetdir/var/lib/clamav\"") == 0 ||
1772 die "installation of clamav db file '$fn' failed\n";
1774 syscmd
("chroot $targetdir /bin/chown clamav:clamav -R /var/lib/clamav") == 0 ||
1775 die "unable to set owner for clamav database files\n";
1778 if ($setup->{product
} eq 'pve') {
1779 # save installer settings
1780 my $ucc = uc ($country);
1781 debconfig_set
($targetdir, "pve-manager pve-manager/country string $ucc\n");
1784 update_progress
(0.8, 0.95, 1, "make system bootable");
1787 syscmd
("sed -i -e 's/^GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"root=ZFS=$zfspoolname\\/ROOT\\/$zfsrootvolname boot=zfs\"/' $targetdir/etc/default/grub") == 0 ||
1788 die "unable to update /etc/default/grub\n";
1790 write_config
("root=ZFS=$zfspoolname/ROOT/$zfsrootvolname boot=zfs", "$targetdir/etc/kernel/cmdline");
1794 diversion_remove
($targetdir, "/usr/sbin/update-grub");
1795 diversion_remove
($targetdir, "/usr/sbin/update-initramfs");
1798 foreach my $fn (<$targetdir/lib/modules/*>) {
1799 if ($fn =~ m!/(\d+\.\d+\.\d+-\d+-pve)$!) {
1800 die "found multiple kernels\n" if defined($kapi);
1804 die "unable to detect kernel version\n" if !defined($kapi);
1806 if (!$opt_testmode) {
1808 unlink ("$targetdir/etc/mtab");
1809 symlink ("/proc/mounts", "$targetdir/etc/mtab");
1810 syscmd
("mount -n --bind /dev $targetdir/dev");
1812 my $bootloader_err_list = [];
1814 syscmd
("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0 ||
1815 die "unable to install initramfs\n";
1817 my $native_4k_disk_bootable = 0;
1818 foreach my $di (@$bootdevinfo) {
1819 $native_4k_disk_bootable |= ($di->{logical_bsize
} == 4096);
1822 foreach my $di (@$bootdevinfo) {
1823 my $dev = $di->{devname
};
1825 prepare_proxmox_boot_esp
($di->{esp
}, $targetdir);
1827 if (!$native_4k_disk_bootable) {
1829 syscmd
("chroot $targetdir /usr/sbin/grub-install --target i386-pc --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
1830 die "unable to install the i386-pc boot loader on '$dev'\n";
1832 push @$bootloader_err_list, $@ if $@;
1836 if (my $esp = $di->{esp
}) {
1837 prepare_grub_efi_boot_esp
($dev, $esp, $targetdir);
1841 push @$bootloader_err_list, $@ if $@;
1844 syscmd
("chroot $targetdir /usr/sbin/update-grub") == 0 ||
1845 die "unable to update boot loader config\n";
1847 push @$bootloader_err_list, $@ if $@;
1849 if (scalar(@$bootloader_err_list) > 0) {
1850 $bootloader_err = "bootloader setup errors:\n";
1851 map { $bootloader_err .= "- $_" } @$bootloader_err_list;
1852 warn $bootloader_err;
1855 syscmd
("umount $targetdir/dev");
1860 unlink "$targetdir/usr/sbin/policy-rc.d";
1862 diversion_remove
($targetdir, "/sbin/start-stop-daemon");
1865 my $octets = encode
("utf-8", $password);
1866 run_command
("chroot $targetdir /usr/sbin/chpasswd", undef,
1869 if ($setup->{product
} eq 'pmg') {
1871 write_config
("section: admin\n\temail ${mailto}\n",
1872 "$targetdir/etc/pmg/pmg.conf");
1874 } elsif ($setup->{product
} eq 'pve') {
1878 my $tmpdir = "$targetdir/tmp/pve";
1881 # write vnc keymap to datacenter.cfg
1882 my $vnckmap = $cmap->{kmap
}->{$keymap}->{kvm
} || 'en-us';
1883 write_config
("keyboard: $vnckmap\n",
1884 "$tmpdir/datacenter.cfg");
1887 write_config
("user:root\@pam:1:0:::${mailto}::\n", "$tmpdir/user.cfg");
1890 my $storage_cfg_fn = "$tmpdir/storage.cfg";
1892 write_config
($storage_cfg_zfs, $storage_cfg_fn);
1893 } elsif ($use_btrfs) {
1894 write_config
($storage_cfg_btrfs, $storage_cfg_fn);
1895 } elsif ($datadev) {
1896 write_config
($storage_cfg_lvmthin, $storage_cfg_fn);
1898 write_config
($storage_cfg_local, $storage_cfg_fn);
1901 run_command
("chroot $targetdir /usr/bin/create_pmxcfs_db /tmp/pve /var/lib/pve-cluster/config.db");
1903 syscmd
("rm -rf $tmpdir");
1904 } elsif ($setup->{product
} eq 'pbs') {
1905 my $base_cfg_path = "/etc/proxmox-backup";
1906 mkdir "$targetdir/$base_cfg_path";
1908 chroot_chown
($targetdir, $base_cfg_path, user
=> 'backup', recursive
=> 1);
1909 chroot_chmod
($targetdir, $base_cfg_path, mode
=> '0700');
1911 my $user_cfg_fn = "$base_cfg_path/user.cfg";
1912 write_config
("user: root\@pam\n\temail ${mailto}\n", "$targetdir/$user_cfg_fn");
1913 chroot_chown
($targetdir, $user_cfg_fn, user
=> 'root', group
=> 'backup');
1914 chroot_chmod
($targetdir, $user_cfg_fn, mode
=> '0640');
1920 update_progress
(1, 0, 1, "");
1924 if ($opt_testmode) {
1925 my $elapsed = Time
::HiRes
::tv_interval
($starttime);
1926 print "Elapsed extract time: $elapsed\n";
1928 syscmd
("chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> final.pkglist");
1931 syscmd
("umount $targetdir/run");
1932 syscmd
("umount $targetdir/mnt/hostrun");
1933 syscmd
("umount $targetdir/tmp");
1934 syscmd
("umount $targetdir/proc");
1935 syscmd
("umount $targetdir/sys/firmware/efi/efivars");
1936 syscmd
("umount $targetdir/sys");
1939 syscmd
("zfs umount -a") == 0 ||
1940 die "unable to unmount zfs\n";
1942 syscmd
("umount -d $targetdir");
1945 if (!$err && $use_zfs) {
1946 syscmd
("zfs set sync=standard $zfspoolname") == 0 ||
1947 die "unable to set zfs properties\n";
1949 syscmd
("zfs set mountpoint=/ $zfspoolname/ROOT/$zfsrootvolname") == 0 ||
1950 die "zfs set mountpoint failed\n";
1952 syscmd
("zpool set bootfs=$zfspoolname/ROOT/$zfsrootvolname $zfspoolname") == 0 ||
1953 die "zfs set bootfs failed\n";
1954 syscmd
("zpool export $zfspoolname");
1957 if ($bootloader_err) {
1958 $err = $err ?
"$err\n$bootloader_err" : $bootloader_err;
1964 my $last_display_change = 0;
1966 my $display_info_counter = 0;
1968 my $display_info_items = [
1969 "extract1-license.htm",
1970 "extract2-rulesystem.htm",
1971 "extract3-spam.htm",
1972 "extract4-virus.htm",
1977 my $min_display_time = 15;
1981 return if ($ctime - $last_display_change) < $min_display_time;
1983 my $page = $display_info_items->[$display_info_counter % scalar(@$display_info_items)];
1985 $display_info_counter++;
1987 display_html
($page);
1991 my ($filename) = @_;
1993 $filename = $steps[$step_number]->{html
} if !$filename;
1995 my $path = "${proxmox_libdir}/html/$filename";
1997 my $url = "file://$path";
1999 my $data = file_get_contents
($path);
2001 my $product = $product_cfg->{$setup->{product
}};
2003 if ($filename eq 'license.htm') {
2004 my $license = eval { decode
('utf8', file_get_contents
("${proxmox_cddir}/EULA")) };
2006 die $err if !$opt_testmode;
2007 $license = "TESTMODE: Ignore non existent EULA...\n";
2009 my $title = "END USER LICENSE AGREEMENT (EULA)";
2010 $data =~ s/__LICENSE__/$license/;
2011 $data =~ s/__LICENSE_TITLE__/$title/;
2012 } elsif ($filename eq 'success.htm') {
2013 my $addr = $ipversion == 6 ?
"[${ipaddress}]" : "$ipaddress";
2014 $data =~ s/__IPADDR__/$addr/g;
2015 $data =~ s/__PORT__/$product->{port}/g;
2017 my $autoreboot_msg = $config_options->{autoreboot
}
2018 ?
"Automatic reboot scheduled in $autoreboot_seconds seconds."
2020 $data =~ s/__AUTOREBOOT_MSG__/$autoreboot_msg/;
2022 $data =~ s/__FULL_PRODUCT_NAME__/$product->{fullname}/g;
2024 $htmlview->load_html($data, $url);
2026 $last_display_change = time();
2031 my ($text, $fctn) = @_;
2033 $fctn = $step_number if !$fctn;
2034 $text = "_Previous" if !$text;
2035 $prev_btn->set_label ($text);
2038 $steps[$step_number]->{function
}();
2040 $prev_btn->grab_focus();
2044 my ($text, $fctn) = @_;
2047 my $step = $steps[$step_number];
2048 $text //= $steps[$step_number]->{next_button
} // '_Next';
2049 $next->set_label($text);
2051 $next->grab_focus();
2054 sub create_main_window
{
2056 $window = Gtk3
::Window-
>new();
2057 $window->set_default_size(1024, 768);
2058 $window->set_has_resize_grip(0);
2059 $window->fullscreen() if !$opt_testmode;
2060 $window->set_decorated(0) if !$opt_testmode;
2062 my $vbox = Gtk3
::VBox-
>new(0, 0);
2064 my $logofn = "$setup->{product}-banner.png";
2065 my $image = Gtk3
::Image-
>new_from_file("${proxmox_libdir}/$logofn");
2066 $vbox->pack_start($image, 0, 0, 0);
2068 my $hbox = Gtk3
::HBox-
>new(0, 0);
2069 $vbox->pack_start($hbox, 1, 1, 0);
2071 # my $f1 = Gtk3::Frame->new ('test');
2072 # $f1->set_shadow_type ('none');
2073 # $hbox->pack_start ($f1, 1, 1, 0);
2075 my $sep1 = Gtk3
::HSeparator-
>new();
2076 $vbox->pack_start($sep1, 0, 0, 0);
2078 $cmdbox = Gtk3
::HBox-
>new();
2079 $vbox->pack_start($cmdbox, 0, 0, 10);
2081 $next = Gtk3
::Button-
>new('_Next');
2082 $next->signal_connect(clicked
=> sub { $last_display_change = 0; &$next_fctn (); });
2083 $cmdbox->pack_end($next, 0, 0, 10);
2086 $prev_btn = Gtk3
::Button-
>new('_Previous');
2087 $prev_btn->signal_connect(clicked
=> sub { $last_display_change = 0; &prev_function
(); });
2088 $cmdbox->pack_end($prev_btn, 0, 0, 10);
2091 my $abort = Gtk3
::Button-
>new('_Abort');
2092 $abort->set_can_focus(0);
2093 $cmdbox->pack_start($abort, 0, 0, 10);
2094 $abort->signal_connect(clicked
=> sub { exit (-1); });
2096 my $vbox2 = Gtk3
::VBox-
>new(0, 0);
2099 $htmlview = Gtk3
::WebKit2
::WebView-
>new();
2100 my $scrolls = Gtk3
::ScrolledWindow-
>new();
2101 $scrolls->add($htmlview);
2103 my $hbox2 = Gtk3
::HBox-
>new(0, 0);
2104 $hbox2->pack_start($scrolls, 1, 1, 0);
2106 $vbox2->pack_start($hbox2, 1, 1, 0);
2108 my $vbox3 = Gtk3
::VBox-
>new(0, 0);
2109 $vbox2->pack_start($vbox3, 0, 0, 0);
2111 my $sep2 = Gtk3
::HSeparator-
>new;
2112 $vbox3->pack_start($sep2, 0, 0, 0);
2114 $inbox = Gtk3
::HBox-
>new(0, 0);
2115 $vbox3->pack_start($inbox, 0, 0, 0);
2117 $window->add($vbox);
2124 $inbox->foreach(sub {
2126 $inbox->remove ($child);
2130 # fixme: newer GTK3 has special properties to handle numbers with Entry
2131 # only allow floating point numbers with Gtk3::Entry
2134 my ($entry, $event) = @_;
2136 return check_number
($entry, $event, 1);
2140 my ($entry, $event) = @_;
2142 return check_number
($entry, $event, 0);
2146 my ($entry, $event, $float) = @_;
2148 my $val = $event->get_keyval;
2150 if (($float && $val == ord '.') ||
2151 $val == Gtk3
::Gdk
::KEY_ISO_Left_Tab
||
2152 $val == Gtk3
::Gdk
::KEY_Shift_L
||
2153 $val == Gtk3
::Gdk
::KEY_Tab
||
2154 $val == Gtk3
::Gdk
::KEY_Left
||
2155 $val == Gtk3
::Gdk
::KEY_Right
||
2156 $val == Gtk3
::Gdk
::KEY_BackSpace
||
2157 $val == Gtk3
::Gdk
::KEY_Delete
||
2158 ($val >= ord '0' && $val <= ord '9') ||
2159 ($val >= Gtk3
::Gdk
::KEY_KP_0
&&
2160 $val <= Gtk3
::Gdk
::KEY_KP_9
)) {
2167 sub create_text_input
{
2168 my ($default, $text) = @_;
2170 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
2172 my $label = Gtk3
::Label-
>new($text);
2173 $label->set_size_request(150, -1);
2174 $label->set_alignment(1, 0.5);
2175 $hbox->pack_start($label, 0, 0, 10);
2176 my $e1 = Gtk3
::Entry-
>new();
2177 $e1->set_width_chars(35);
2178 $hbox->pack_start($e1, 0, 0, 0);
2179 $e1->set_text($default);
2181 return ($hbox, $e1);
2183 sub create_cidr_inputs
{
2184 my ($default_ip, $default_mask) = @_;
2186 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
2188 my $label = Gtk3
::Label-
>new('IP Address (CIDR)');
2189 $label->set_size_request(150, -1);
2190 $label->set_alignment(1, 0.5);
2191 $hbox->pack_start($label, 0, 0, 10);
2193 my $ip_el = Gtk3
::Entry-
>new();
2194 $ip_el->set_width_chars(28);
2195 $hbox->pack_start($ip_el, 0, 0, 0);
2196 $ip_el->set_text($default_ip);
2198 $label = Gtk3
::Label-
>new('/');
2199 $label->set_size_request(10, -1);
2200 $label->set_alignment(0.5, 0.5);
2201 $hbox->pack_start($label, 0, 0, 2);
2203 my $cidr_el = Gtk3
::Entry-
>new();
2204 $cidr_el->set_width_chars(3);
2205 $hbox->pack_start($cidr_el, 0, 0, 0);
2206 $cidr_el->set_text($default_mask);
2208 return ($hbox, $ip_el, $cidr_el);
2216 my $links = `ip -o l`;
2217 foreach my $l (split /\n/,$links) {
2218 my ($index, $name, $flags, $state, $mac) = $l =~ m/^(\d+):\s+(\S+):\s+<(\S+)>.*\s+state\s+(\S+)\s+.*\s+link\/ether\s
+(\S
+)\s
+/;
2219 next if !$name || $name eq 'lo';
2221 my $driver = readlink "/sys/class/net/$name/device/driver" || 'unknown';
2222 $driver =~ s!^.*/!!;
2224 $ifaces->{"$index"} = {
2232 my $addresses = `ip -o a s $name`;
2233 foreach my $a (split /\n/,$addresses) {
2234 my ($family, $ip, $prefix) = $a =~ m/^\Q$index\E:\s+\Q$name\E\s+(inet|inet6)\s+($IPRE)\/(\d+)\s+/;
2236 next if $a =~ /scope\s+link/; # ignore link local
2240 if ($family eq 'inet') {
2241 next if !$ip =~ /$IPV4RE/;
2242 next if $prefix < 8 || $prefix > 32;
2243 $mask = @$ipv4_reverse_mask[$prefix];
2245 next if !$ip =~ /$IPV6RE/;
2248 $default = $index if !$default;
2250 $ifaces->{"$index"}->{"$family"} = {
2259 my $route = `ip route
`;
2260 my ($gateway) = $route =~ m/^default\s+via\s+(\S+)\s+/m;
2262 my $resolvconf = `cat
/etc/resolv
.conf
`;
2263 my ($dnsserver) = $resolvconf =~ m/^nameserver\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/m;
2264 my ($domain) = $resolvconf =~ m/^domain\s+(\S+)$/m;
2267 default => $default,
2269 gateway => $gateway,
2270 dnsserver => $dnsserver,
2275 sub display_message {
2278 my $dialog = Gtk3::MessageDialog->new($window, 'modal',
2279 'info', 'ok', $msg);
2287 my $dialog = Gtk3::MessageDialog->new($window, 'modal',
2288 'error', 'ok', $msg);
2293 my $ipconf_first_view = 1;
2295 sub create_ipconf_view {
2300 my $vcontainer = Gtk3::Box->new('vertical', 0);
2301 $inbox->pack_start($vcontainer, 1, 0, 0);
2302 my $hcontainer = Gtk3::Box->new('horizontal', 0);
2303 $vcontainer->pack_start($hcontainer, 0, 0, 10);
2304 my $vbox = Gtk3::Box->new('vertical', 0);
2305 $hcontainer->add($vbox);
2307 my $ipaddr_text = $config->{ipaddress} // "192.168.100.2";
2308 my $netmask_text = $config->{netmask} // "24";
2310 ($cidr_box, $ipconf_entry_addr, $ipconf_entry_mask) =
2311 create_cidr_inputs($ipaddr_text, $netmask_text);
2313 my $device_cb = Gtk3::ComboBoxText->new();
2314 $device_cb->set_active(0);
2315 $device_cb->set_visible(1);
2317 my $get_device_desc = sub {
2319 return "$iface->{name} - $iface->{mac} ($iface->{driver})";
2322 my $device_active_map = {};
2323 my $device_active_reverse_map = {};
2325 my $device_change_handler = sub {
2326 my $current = shift;
2328 my $new = $device_active_map->{$current->get_active()};
2329 return if defined($ipconf->{selected}) && $new eq $ipconf->{selected};
2331 $ipconf->{selected} = $new;
2332 my $iface = $ipconf->{ifaces}->{$ipconf->{selected}};
2333 $config->{mngmt_nic} = $iface->{name};
2334 $ipconf_entry_addr->set_text($iface->{inet}->{addr} || $iface->{inet6}->{addr})
2335 if $iface->{inet}->{addr} || $iface->{inet6}->{addr};
2336 $ipconf_entry_mask->set_text($iface->{inet}->{prefix} || $iface->{inet6}->{prefix})
2337 if $iface->{inet}->{prefix} || $iface->{inet6}->{prefix};
2341 foreach my $index (sort keys %{$ipconf->{ifaces}}) {
2342 $device_cb->append_text(&$get_device_desc($ipconf->{ifaces}->{$index}));
2343 $device_active_map->{$i} = $index;
2344 $device_active_reverse_map->{$ipconf->{ifaces}->{$index}->{name}} = $i;
2345 if ($ipconf_first_view && $index == $ipconf->{default}) {
2346 $device_cb->set_active($i);
2347 &$device_change_handler($device_cb);
2348 $ipconf_first_view = 0;
2350 $device_cb->signal_connect('changed' => $device_change_handler);
2354 if (my $nic = $config->{mngmt_nic}) {
2355 $device_cb->set_active($device_active_reverse_map->{$nic} // 0);
2357 $device_cb->set_active(0);
2360 my $devicebox = Gtk3::HBox->new(0, 0);
2361 my $label = Gtk3::Label->new("Management Interface:");
2362 $label->set_size_request(150, -1);
2363 $label->set_alignment(1, 0.5);
2364 $devicebox->pack_start($label, 0, 0, 10);
2365 $devicebox->pack_start($device_cb, 0, 0, 0);
2367 $vbox->pack_start($devicebox, 0, 0, 2);
2369 my $hn = $config->{fqdn} // "$setup->{product}." . ($ipconf->{domain} // "example.invalid");
2371 my ($hostbox, $hostentry) = create_text_input($hn, 'Hostname (FQDN):');
2372 $vbox->pack_start($hostbox, 0, 0, 2);
2374 $vbox->pack_start($cidr_box, 0, 0, 2);
2376 $gateway = $config->{gateway} // $ipconf->{gateway} || '192.168.100.1';
2379 ($gwbox, $ipconf_entry_gw) =
2380 create_text_input($gateway, 'Gateway:');
2382 $vbox->pack_start($gwbox, 0, 0, 2);
2384 $dnsserver = $config->{dnsserver} // $ipconf->{dnsserver} || $gateway;
2387 ($dnsbox, $ipconf_entry_dns) =
2388 create_text_input($dnsserver, 'DNS Server:');
2390 $vbox->pack_start($dnsbox, 0, 0, 0);
2393 set_next(undef, sub {
2397 my $text = $hostentry->get_text();
2402 $config->{fqdn} = $text;
2404 my $namere = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
2406 # Debian does not support purely numeric hostnames
2407 if ($text && $text =~ /^[0-9]+(?:\.|$)/) {
2408 display_message("Purely numeric hostnames are not allowed.");
2409 $hostentry->grab_focus();
2413 if ($text && $text =~ m/^(${namere}\.)*${namere}$/ && $text !~ m/.example.invalid$/ &&
2414 $text =~ m/^([^\.]+)\.(\S+)$/) {
2418 display_message("Hostname does not look like a fully qualified domain name.");
2419 $hostentry->grab_focus();
2425 $text = $ipconf_entry_addr->get_text();
2428 if ($text =~ m!^($IPV4RE)$!) {
2431 } elsif ($text =~ m!^($IPV6RE)$!) {
2435 display_message("IP address is not valid.");
2436 $ipconf_entry_addr->grab_focus();
2439 $config->{ipaddress} = $ipaddress;
2441 $text = $ipconf_entry_mask->get_text();
2444 if ($ipversion == 6 && ($text =~ m/^(\d+)$/) && $1 >= 8 && $1 <= 126) {
2446 } elsif ($ipversion == 4 && ($text =~ m/^(\d+)$/) && $1 >= 8 && $1 <= 32) {
2448 } elsif ($ipversion == 4 && defined($ipv4_mask_hash->{$text})) {
2449 # costs nothing to handle 255.x.y.z style masks, so continue to allow it
2450 $netmask = $ipv4_mask_hash->{$text};
2452 display_message("Netmask is not valid.");
2453 $ipconf_entry_mask->grab_focus();
2456 $cidr = "$ipaddress/$netmask";
2457 $config->{netmask} = $netmask;
2459 $text = $ipconf_entry_gw->get_text();
2462 if (($ipversion == 4) && ($text =~ m!^($IPV4RE)$!)) {
2464 } elsif (($ipversion == 6) && ($text =~ m!^($IPV6RE)$!)) {
2467 display_message("Gateway is not valid.");
2468 $ipconf_entry_gw->grab_focus();
2471 $config->{gateway} = $gateway;
2473 $text = $ipconf_entry_dns->get_text();
2476 if (($ipversion == 4) && ($text =~ m!^($IPV4RE)$!)) {
2478 } elsif (($ipversion == 6) && ($text =~ m!^($IPV6RE)$!)) {
2481 display_message("DNS server is not valid.");
2482 $ipconf_entry_dns->grab_focus();
2485 $config->{dnsserver} = $dnsserver;
2487 #print "TEST $ipaddress $netmask $gateway $dnsserver\n";
2493 $hostentry->grab_focus();
2496 sub create_ack_view {
2500 my $vbox = Gtk3::VBox->new(0, 0);
2501 $inbox->pack_start($vbox, 1, 0, 0);
2502 #my $hbox = Gtk3::HBox->new(0, 0);
2503 #$vbox->pack_start($hbox, 0, 0, 10);
2505 my $reboot_checkbox = Gtk3::CheckButton->new('Automatically reboot after successful installation');
2506 $reboot_checkbox->set_active(1);
2507 $reboot_checkbox->signal_connect ("toggled" => sub {
2509 $config_options->{autoreboot} = $cb->get_active();
2511 $vbox->pack_start($reboot_checkbox, 0, 0, 2);
2513 my $ack_template = "${proxmox_libdir}/html/ack_template.htm";
2514 my $ack_html = "${proxmox_libdir}/html/$steps[$step_number]->{html}";
2515 my $html_data = file_get_contents($ack_template);
2517 my %config_values = (
2518 __target_hd__ => join(' | ', @{$config_options->{target_hds}}),
2519 __target_fs__ => $config_options->{filesys},
2520 __country__ => $cmap->{country}->{$country}->{name},
2521 __timezone__ => $timezone,
2522 __keymap__ => $keymap,
2523 __mailto__ => $mailto,
2524 __interface__ => $ipconf->{ifaces}->{$ipconf->{selected}}->{name},
2525 __hostname__ => $hostname,
2526 __ip__ => $ipaddress,
2528 __netmask__ => $netmask,
2529 __gateway__ => $gateway,
2530 __dnsserver__ => $dnsserver,
2533 while ( my ($k, $v) = each %config_values) {
2534 $html_data =~ s/$k/$v/g;
2537 write_config($html_data, $ack_html);
2543 set_next(undef, sub {
2545 create_extract_view();
2549 sub get_device_desc {
2550 my ($devname, $size, $model) = @_;
2552 if ($size && ($size > 0)) {
2553 $size = int($size/2048); # size in MB, from 512B "sectors"
2555 my $text = "$devname (";
2556 if ($size >= 1024) {
2557 $size = int($size/1024); # size in GB
2558 if ($size >= 1024) {
2559 $size = int($size/1024); # size in GB
2560 $text .= "${size}TiB";
2562 $text .= "${size}GiB";
2565 $text .= "${size}MiB";
2568 $text .= ", $model" if $model;
2579 my ($cb, $kmap) = @_;
2584 my $kmaphash = $cmap->{kmaphash};
2585 foreach my $layout (sort keys %$kmaphash) {
2586 $def = $i if $kmaphash->{$layout} eq 'en-us';
2587 $ind = $i if $kmap && $kmaphash->{$layout} eq $kmap;
2591 my $val = $ind || $def || 0;
2593 if (!defined($kmap)) {
2594 $last_layout //= $val;
2595 } elsif (!defined($country_layout) || $country_layout != $val) {
2596 $last_layout = $country_layout = $val;
2598 $cb->set_active($last_layout);
2602 sub update_zonelist {
2603 my ($box, $cc) = @_;
2605 my $cczones = $cmap->{cczones};
2606 my $zones = $cmap->{zones};
2610 $sel = $lastzonecb->get_active_text();
2611 $box->remove ($lastzonecb);
2613 $sel = $timezone; # used once to select default
2616 my $cb = $lastzonecb = Gtk3::ComboBoxText->new();
2617 $cb->set_size_request(200, -1);
2619 $cb->signal_connect('changed' => sub {
2620 $timezone = $cb->get_active_text();
2624 if ($cc && defined ($cczones->{$cc})) {
2625 @za = keys %{$cczones->{$cc}};
2631 foreach my $zone (sort @za) {
2632 $ind = $i if $sel && $zone eq $sel;
2633 $cb->append_text($zone);
2637 $cb->set_active($ind || 0);
2640 $box->pack_start($cb, 0, 0, 0);
2643 sub create_password_view {
2647 my $vbox2 = Gtk3::VBox->new(0, 0);
2648 $inbox->pack_start($vbox2, 1, 0, 0);
2649 my $vbox = Gtk3::VBox->new(0, 0);
2650 $vbox2->pack_start($vbox, 0, 0, 10);
2652 my $hbox1 = Gtk3::HBox->new(0, 0);
2653 my $label = Gtk3::Label->new("Password");
2654 $label->set_size_request(150, -1);
2655 $label->set_alignment(1, 0.5);
2656 $hbox1->pack_start($label, 0, 0, 10);
2657 my $pwe1 = Gtk3::Entry->new();
2658 $pwe1->set_visibility(0);
2659 $pwe1->set_text($password) if $password;
2660 $pwe1->set_size_request(200, -1);
2661 $hbox1->pack_start($pwe1, 0, 0, 0);
2663 my $hbox2 = Gtk3::HBox->new(0, 0);
2664 $label = Gtk3::Label->new("Confirm");
2665 $label->set_size_request(150, -1);
2666 $label->set_alignment(1, 0.5);
2667 $hbox2->pack_start($label, 0, 0, 10);
2668 my $pwe2 = Gtk3::Entry->new();
2669 $pwe2->set_visibility(0);
2670 $pwe2->set_text($password) if $password;
2671 $pwe2->set_size_request(200, -1);
2672 $hbox2->pack_start($pwe2, 0, 0, 0);
2674 my $hbox3 = Gtk3::HBox->new(0, 0);
2675 $label = Gtk3::Label->new("Email");
2676 $label->set_size_request(150, -1);
2677 $label->set_alignment(1, 0.5);
2678 $hbox3->pack_start($label, 0, 0, 10);
2679 my $eme = Gtk3::Entry->new();
2680 $eme->set_size_request(200, -1);
2681 $eme->set_text($mailto);
2682 $hbox3->pack_start($eme, 0, 0, 0);
2685 $vbox->pack_start($hbox1, 0, 0, 5);
2686 $vbox->pack_start($hbox2, 0, 0, 5);
2687 $vbox->pack_start($hbox3, 0, 0, 15);
2693 set_next (undef, sub {
2695 my $t1 = $pwe1->get_text;
2696 my $t2 = $pwe2->get_text;
2698 if (length ($t1) < 5) {
2699 display_message("Password is too short.");
2700 $pwe1->grab_focus();
2705 display_message("Password does not match.");
2706 $pwe1->grab_focus();
2710 my $t3 = $eme->get_text;
2711 if ($t3 !~ m/^[\w\+\-\~]+(\.[\w\+\-\~]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*$/) {
2712 display_message("Email does not look like a valid address" .
2713 " (user\@domain.tld)");
2718 if ($t3 eq 'mail@example.invalid') {
2719 display_message("Please enter a valid Email address");
2728 create_ipconf_view();
2731 $pwe1->grab_focus();
2736 sub create_country_view {
2740 my $countryhash = $cmap->{countryhash};
2741 my $ctr = $cmap->{country};
2743 my $vbox2 = Gtk3::VBox->new(0, 0);
2744 $inbox->pack_start($vbox2, 1, 0, 0);
2745 my $vbox = Gtk3::VBox->new(0, 0);
2746 $vbox2->pack_start($vbox, 0, 0, 10);
2748 my $w = Gtk3::Entry->new();
2749 $w->set_size_request(200, -1);
2751 my $c = Gtk3::EntryCompletion->new();
2752 $c->set_text_column(0);
2753 $c->set_minimum_key_length(0);
2754 $c->set_popup_set_width(1);
2755 $c->set_inline_completion(1);
2757 my $hbox2 = Gtk3::HBox->new(0, 0);
2758 my $label = Gtk3::Label->new("Time zone");
2759 $label->set_size_request(150, -1);
2760 $label->set_alignment(1, 0.5);
2761 $hbox2->pack_start($label, 0, 0, 10);
2762 update_zonelist ($hbox2);
2764 my $hbox3 = Gtk3::HBox->new(0, 0);
2765 $label = Gtk3::Label->new("Keyboard Layout");
2766 $label->set_size_request(150, -1);
2767 $label->set_alignment(1, 0.5);
2768 $hbox3->pack_start($label, 0, 0, 10);
2770 my $kmapcb = Gtk3::ComboBoxText->new();
2771 $kmapcb->set_size_request (200, -1);
2772 foreach my $layout (sort keys %{$cmap->{kmaphash}}) {
2773 $kmapcb->append_text ($layout);
2776 update_layout($kmapcb);
2777 $hbox3->pack_start ($kmapcb, 0, 0, 0);
2779 $kmapcb->signal_connect ('changed' => sub {
2780 my $sel = $kmapcb->get_active_text();
2781 $last_layout = $kmapcb->get_active();
2782 if (my $kmap = $cmap->{kmaphash}->{$sel}) {
2783 my $xkmap = $cmap->{kmap}->{$kmap}->{x11};
2784 my $xvar = $cmap->{kmap}->{$kmap}->{x11var};
2787 return if (defined($installer_kmap) && $installer_kmap eq $kmap);
2789 $installer_kmap = $keymap;
2791 if (! $opt_testmode) {
2792 syscmd ("setxkbmap $xkmap $xvar");
2794 my $kbd_config = qq{
2799 $kbd_config =~ s/^\s+//gm;
2801 run_in_background
( sub {
2802 write_config
($kbd_config, '/etc/default/keyboard');
2809 $w->signal_connect ('changed' => sub {
2810 my ($entry, $event) = @_;
2811 my $text = $entry->get_text;
2813 if (my $cc = $countryhash->{lc($text)}) {
2814 update_zonelist
($hbox2, $cc);
2815 my $kmap = $ctr->{$cc}->{kmap
} || 'en-us';
2816 update_layout
($kmapcb, $kmap);
2820 $w->signal_connect (key_press_event
=> sub {
2821 my ($entry, $event) = @_;
2822 my $text = $entry->get_text;
2824 my $val = $event->get_keyval;
2826 if ($val == Gtk3
::Gdk
::KEY_Tab
) {
2827 my $cc = $countryhash->{lc($text)};
2834 $compl = $ctr->{$cc}->{name
};
2836 foreach my $cc (keys %$ctr) {
2837 my $ct = $ctr->{$cc}->{name
};
2838 if ($ct =~ m/^\Q$text\E.*$/i) {
2847 $entry->set_text($compl);
2852 print chr(7); # beep ?
2857 my $buf = $w->get_buffer();
2858 $buf->insert_text(-1, '', -1); # popup selection
2866 my $ls = Gtk3
::ListStore-
>new('Glib::String');
2867 foreach my $cc (sort {$ctr->{$a}->{name
} cmp $ctr->{$b}->{name
} } keys %$ctr) {
2868 my $iter = $ls->append();
2869 $ls->set ($iter, 0, $ctr->{$cc}->{name
});
2871 $c->set_model ($ls);
2873 $w->set_completion ($c);
2875 my $hbox = Gtk3
::HBox-
>new(0, 0);
2877 $label = Gtk3
::Label-
>new("Country");
2878 $label->set_alignment(1, 0.5);
2879 $label->set_size_request(150, -1);
2880 $hbox->pack_start($label, 0, 0, 10);
2881 $hbox->pack_start($w, 0, 0, 0);
2883 $vbox->pack_start($hbox, 0, 0, 5);
2884 $vbox->pack_start($hbox2, 0, 0, 5);
2885 $vbox->pack_start($hbox3, 0, 0, 5);
2887 if ($country && $ctr->{$country}) {
2888 $w->set_text ($ctr->{$country}->{name
});
2894 set_next
(undef, sub {
2896 my $text = $w->get_text;
2898 if (my $cc = $countryhash->{lc($text)}) {
2901 create_password_view
();
2904 display_message
("Please select a country first.");
2912 my $target_hd_combo;
2913 my $target_hd_label;
2915 my $hdoption_first_setup = 1;
2917 my $create_basic_grid = sub {
2918 my $grid = Gtk3
::Grid-
>new();
2919 $grid->set_visible(1);
2920 $grid->set_column_spacing(10);
2921 $grid->set_row_spacing(10);
2922 $grid->set_hexpand(1);
2924 $grid->set_margin_start(10);
2925 $grid->set_margin_end(20);
2926 $grid->set_margin_top(5);
2927 $grid->set_margin_bottom(5);
2932 my $create_label_widget_grid = sub {
2933 my ($labeled_widgets) = @_;
2935 my $grid = &$create_basic_grid();
2938 for (my $i = 0; $i < @$labeled_widgets; $i += 2) {
2939 my $widget = @$labeled_widgets[$i+1];
2940 my $label = Gtk3
::Label-
>new(@$labeled_widgets[$i]);
2941 $label->set_visible(1);
2942 $label->set_alignment (1, 0.5);
2943 $grid->attach($label, 0, $row, 1, 1);
2944 $widget->set_visible(1);
2945 $grid->attach($widget, 1, $row, 1, 1);
2952 my $create_raid_disk_grid = sub {
2953 my $hd_count = scalar(@$hds);
2954 my $disk_labeled_widgets = [];
2955 for (my $i = 0; $i < $hd_count; $i++) {
2956 my $disk_selector = Gtk3
::ComboBoxText-
>new();
2957 $disk_selector->append_text("-- do not use --");
2958 $disk_selector->set_active(0);
2959 $disk_selector->set_visible(1);
2960 foreach my $hd (@$hds) {
2961 my ($disk, $devname, $size, $model, $logical_bsize) = @$hd;
2962 $disk_selector->append_text(get_device_desc
($devname, $size, $model));
2963 $disk_selector->{pve_disk_id
} = $i;
2964 $disk_selector->signal_connect (changed
=> sub {
2966 my $diskid = $w->{pve_disk_id
};
2967 my $a = $w->get_active - 1;
2968 $config_options->{"disksel${diskid}"} = ($a >= 0) ?
$hds->[$a] : undef;
2972 if ($hdoption_first_setup) {
2973 $disk_selector->set_active ($i+1) if $hds->[$i];
2976 if (my $cur_hd = $config_options->{"disksel$i"}) {
2977 foreach my $hd (@$hds) {
2978 if (@$hd[1] eq @$cur_hd[1]) {
2979 $disk_selector->set_active($hdind+1);
2987 push @$disk_labeled_widgets, "Harddisk $i", $disk_selector;
2990 my $clear_all_button = Gtk3
::Button-
>new('_Deselect All');
2991 if ($hd_count > 3) {
2992 $clear_all_button->signal_connect('clicked', sub {
2994 for my $disk_selector (@$disk_labeled_widgets) {
2995 $disk_selector->set_active(0) if $is_widget;
2999 $clear_all_button->set_visible(1);
3002 my $scrolled_window = Gtk3
::ScrolledWindow-
>new();
3003 $scrolled_window->set_hexpand(1);
3004 $scrolled_window->set_propagate_natural_height(1) if $hd_count > 4;
3006 my $diskgrid = $create_label_widget_grid->($disk_labeled_widgets);
3008 $scrolled_window->add($diskgrid);
3009 $scrolled_window->set_policy('never', 'automatic');
3010 $scrolled_window->set_visible(1);
3011 $scrolled_window->set_min_content_height(190);
3013 my $vbox = Gtk3
::Box-
>new('vertical', 0);
3014 $vbox->pack_start($scrolled_window, 1, 1, 10);
3016 my $hbox = Gtk3
::Box-
>new('horizontal', 0);
3017 $hbox->pack_end($clear_all_button, 0, 0, 20);
3018 $hbox->set_visible(1);
3019 $vbox->pack_end($hbox, 0, 0, 0);
3024 # shared between different ui parts (e.g., ZFS and "normal" single disk FS)
3025 my $hdsize_size_adj;
3026 my $hdsize_entry_buffer;
3028 my $get_hdsize_spinbtn = sub {
3031 $hdsize_entry_buffer //= Gtk3
::EntryBuffer-
>new(undef, 1);
3033 if (defined($hdsize)) {
3034 $hdsize_size_adj = Gtk3
::Adjustment-
>new($config_options->{hdsize
} || $hdsize, 0, $hdsize+1, 1, 1, 1);
3036 die "called get_hdsize_spinbtn with \$hdsize_size_adj not defined but did not pass hdsize!\n"
3037 if !defined($hdsize_size_adj);
3040 my $spinbutton_hdsize = Gtk3
::SpinButton-
>new($hdsize_size_adj, 1, 1);
3041 $spinbutton_hdsize->set_buffer($hdsize_entry_buffer);
3042 $spinbutton_hdsize->set_adjustment($hdsize_size_adj);
3043 $spinbutton_hdsize->set_tooltip_text("only use specified size (GB) of the harddisk (rest left unpartitioned)");
3044 return $spinbutton_hdsize;
3047 my $create_raid_advanced_grid = sub {
3048 my $labeled_widgets = [];
3049 my $spinbutton_ashift = Gtk3
::SpinButton-
>new_with_range(9, 13, 1);
3050 $spinbutton_ashift->set_tooltip_text("zpool ashift property (pool sector size, default 2^12)");
3051 $spinbutton_ashift->signal_connect ("value-changed" => sub {
3053 $config_options->{ashift
} = $w->get_value_as_int();
3055 $config_options->{ashift
} = 12 if ! defined($config_options->{ashift
});
3056 $spinbutton_ashift->set_value($config_options->{ashift
});
3057 push @$labeled_widgets, "ashift";
3058 push @$labeled_widgets, $spinbutton_ashift;
3060 my $combo_compress = Gtk3
::ComboBoxText-
>new();
3061 $combo_compress->set_tooltip_text("zfs compression algorithm for rpool dataset");
3062 # note: gzip / lze not allowed for bootfs vdevs
3063 my $comp_opts = ["on","off","lzjb","lz4"];
3064 foreach my $opt (@$comp_opts) {
3065 $combo_compress->append($opt, $opt);
3067 $config_options->{compress
} = "on" if !defined($config_options->{compress
});
3068 $combo_compress->set_active_id($config_options->{compress
});
3069 $combo_compress->signal_connect (changed
=> sub {
3071 $config_options->{compress
} = $w->get_active_text();
3073 push @$labeled_widgets, "compress";
3074 push @$labeled_widgets, $combo_compress;
3076 my $combo_checksum = Gtk3
::ComboBoxText-
>new();
3077 $combo_checksum->set_tooltip_text("zfs checksum algorithm for rpool dataset");
3078 my $csum_opts = ["on", "off","fletcher2", "fletcher4", "sha256"];
3079 foreach my $opt (@$csum_opts) {
3080 $combo_checksum->append($opt, $opt);
3082 $config_options->{checksum
} = "on" if !($config_options->{checksum
});
3083 $combo_checksum->set_active_id($config_options->{checksum
});
3084 $combo_checksum->signal_connect (changed
=> sub {
3086 $config_options->{checksum
} = $w->get_active_text();
3088 push @$labeled_widgets, "checksum";
3089 push @$labeled_widgets, $combo_checksum;
3091 my $spinbutton_copies = Gtk3
::SpinButton-
>new_with_range(1,3,1);
3092 $spinbutton_copies->set_tooltip_text("zfs copies property for rpool dataset (in addition to RAID redundancy!)");
3093 $spinbutton_copies->signal_connect ("value-changed" => sub {
3095 $config_options->{copies
} = $w->get_value_as_int();
3097 $config_options->{copies
} = 1 if !defined($config_options->{copies
});
3098 $spinbutton_copies->set_value($config_options->{copies
});
3099 push @$labeled_widgets, "copies", $spinbutton_copies;
3101 push @$labeled_widgets, "hdsize", $get_hdsize_spinbtn->();
3102 return $create_label_widget_grid->($labeled_widgets);;
3105 sub create_hdoption_view
{
3107 my $dialog = Gtk3
::Dialog-
>new();
3109 $dialog->set_title("Harddisk options");
3111 $dialog->add_button("_OK", 1);
3113 my $contarea = $dialog->get_content_area();
3115 my $hbox2 = Gtk3
::Box-
>new('horizontal', 0);
3116 $contarea->pack_start($hbox2, 1, 1, 5);
3118 my $grid = Gtk3
::Grid-
>new();
3119 $grid->set_column_spacing(10);
3120 $grid->set_row_spacing(10);
3122 $hbox2->pack_start($grid, 1, 0, 5);
3127 my $label0 = Gtk3
::Label-
>new("Filesystem");
3128 $label0->set_alignment (1, 0.5);
3129 $grid->attach($label0, 0, $row, 1, 1);
3131 my $fstypecb = Gtk3
::ComboBoxText-
>new();
3142 push @$fstype, 'btrfs (RAID0)', 'btrfs (RAID1)', 'btrfs (RAID10)'
3143 if $setup->{enable_btrfs
};
3146 foreach my $tmp (@$fstype) {
3147 $fstypecb->append_text($tmp);
3148 $fstypecb->set_active ($tcount) if $config_options->{filesys
} eq $tmp;
3152 $grid->attach($fstypecb, 1, $row, 1, 1);
3158 my $sep = Gtk3
::HSeparator-
>new();
3159 $sep->set_visible(1);
3160 $grid->attach($sep, 0, $row, 2, 1);
3163 my $hw_raid_note = Gtk3
::Label-
>new(
3164 "Note: ZFS is not compatible with hardware RAID controllers, for details see the documentation."
3166 $hw_raid_note->set_line_wrap(1);
3167 $hw_raid_note->set_max_width_chars(30);
3168 $hw_raid_note->set_visible(0);
3169 $grid->attach($hw_raid_note, 0, $row++, 2, 1);
3171 my $hdsize_labeled_widgets = [];
3175 if ( -b
$target_hd) {
3176 $hdsize = int(hd_size
($target_hd) / (1024*1024.0)); # size in GB
3177 } elsif ($target_hd) {
3178 $hdsize = int((-s
$target_hd) / (1024*1024*1024.0));
3181 my $spinbutton_hdsize = $get_hdsize_spinbtn->($hdsize);
3182 push @$hdsize_labeled_widgets, "hdsize", $spinbutton_hdsize;
3184 my $entry_swapsize = Gtk3
::Entry-
>new();
3185 $entry_swapsize->set_tooltip_text("maximum SWAP size (GB)");
3186 $entry_swapsize->signal_connect (key_press_event
=> \
&check_float
);
3187 $entry_swapsize->set_text($config_options->{swapsize
}) if defined($config_options->{swapsize
});
3188 push @$hdsize_labeled_widgets, "swapsize", $entry_swapsize;
3190 my $entry_maxroot = Gtk3
::Entry-
>new();
3191 if ($setup->{product
} eq 'pve') {
3192 $entry_maxroot->set_tooltip_text("maximum size (GB) for LVM root volume");
3193 $entry_maxroot->signal_connect (key_press_event
=> \
&check_float
);
3194 $entry_maxroot->set_text($config_options->{maxroot
}) if $config_options->{maxroot
};
3195 push @$hdsize_labeled_widgets, "maxroot", $entry_maxroot;
3198 my $entry_minfree = Gtk3
::Entry-
>new();
3199 $entry_minfree->set_tooltip_text("minimum free LVM space (GB, required for LVM snapshots)");
3200 $entry_minfree->signal_connect (key_press_event
=> \
&check_float
);
3201 $entry_minfree->set_text($config_options->{minfree
}) if defined($config_options->{minfree
});
3202 push @$hdsize_labeled_widgets, "minfree", $entry_minfree;
3205 if ($setup->{product
} eq 'pve') {
3206 $entry_maxvz = Gtk3
::Entry-
>new();
3207 $entry_maxvz->set_tooltip_text("maximum size (GB) for LVM data volume");
3208 $entry_maxvz->signal_connect (key_press_event
=> \
&check_float
);
3209 $entry_maxvz->set_text($config_options->{maxvz
}) if defined($config_options->{maxvz
});
3210 push @$hdsize_labeled_widgets, "maxvz", $entry_maxvz;
3213 my $options_stack = Gtk3
::Stack-
>new();
3214 $options_stack->set_visible(1);
3215 $options_stack->set_hexpand(1);
3216 $options_stack->set_vexpand(1);
3217 $options_stack->add_titled(&$create_raid_disk_grid(), "raiddisk", "Disk Setup");
3218 $options_stack->add_titled(&$create_label_widget_grid($hdsize_labeled_widgets), "hdsize", "Size Options");
3219 $options_stack->add_titled(&$create_raid_advanced_grid("zfs"), "raidzfsadvanced", "Advanced Options");
3220 $options_stack->set_visible_child_name("raiddisk");
3221 my $options_stack_switcher = Gtk3
::StackSwitcher-
>new();
3222 $options_stack_switcher->set_halign('center');
3223 $options_stack_switcher->set_stack($options_stack);
3224 $grid->attach($options_stack_switcher, 0, $row, 2, 1);
3226 $grid->attach($options_stack, 0, $row, 2, 1);
3229 $hdoption_first_setup = 0;
3231 my $switch_view = sub {
3232 my $raid = $config_options->{filesys
} =~ m/zfs|btrfs/;
3233 my $enable_zfs_opts = $config_options->{filesys
} =~ m/zfs/;
3235 $target_hd_combo->set_visible(!$raid);
3236 $options_stack->get_child_by_name("hdsize")->set_visible(!$raid);
3237 $options_stack->get_child_by_name("raiddisk")->set_visible($raid);
3238 $hw_raid_note->set_visible($raid);
3239 $options_stack_switcher->set_visible($enable_zfs_opts);
3240 $options_stack->get_child_by_name("raidzfsadvanced")->set_visible($enable_zfs_opts);
3242 $target_hd_label->set_text("Target: $config_options->{filesys} ");
3243 $options_stack->set_visible_child_name("raiddisk");
3245 $target_hd_label->set_text("Target Harddisk: ");
3247 my (undef, $pref_width) = $dialog->get_preferred_width();
3248 my (undef, $pref_height) = $dialog->get_preferred_height();
3249 $pref_height = 750 if $pref_height > 750;
3250 $dialog->resize($pref_width, $pref_height);
3255 $fstypecb->signal_connect (changed
=> sub {
3256 $config_options->{filesys
} = $fstypecb->get_active_text();
3260 my $sep2 = Gtk3
::HSeparator-
>new();
3261 $sep2->set_visible(1);
3262 $contarea->pack_end($sep2, 1, 1, 10);
3268 my $get_float = sub {
3271 my $text = $entry->get_text();
3272 return undef if !defined($text);
3277 return undef if $text !~ m/^\d+(\.\d+)?$/;
3284 if (($tmp = &$get_float($spinbutton_hdsize)) && ($tmp != $hdsize)) {
3285 $config_options->{hdsize
} = $tmp;
3287 delete $config_options->{hdsize
};
3290 if (defined($tmp = &$get_float($entry_swapsize))) {
3291 $config_options->{swapsize
} = $tmp;
3293 delete $config_options->{swapsize
};
3296 if (defined($tmp = &$get_float($entry_maxroot))) {
3297 $config_options->{maxroot
} = $tmp;
3299 delete $config_options->{maxroot
};
3302 if (defined($tmp = &$get_float($entry_minfree))) {
3303 $config_options->{minfree
} = $tmp;
3305 delete $config_options->{minfree
};
3308 if ($entry_maxvz && defined($tmp = &$get_float($entry_maxvz))) {
3309 $config_options->{maxvz
} = $tmp;
3311 delete $config_options->{maxvz
};
3317 my $get_raid_devlist = sub {
3319 my $dev_name_hash = {};
3322 for (my $i = 0; $i < @$hds; $i++) {
3323 if (my $hd = $config_options->{"disksel$i"}) {
3324 my ($disk, $devname, $size, $model, $logical_bsize) = @$hd;
3325 die "device '$devname' is used more than once\n"
3326 if $dev_name_hash->{$devname};
3327 $dev_name_hash->{$devname} = $hd;
3328 push @$devlist, $hd;
3335 sub zfs_mirror_size_check
{
3336 my ($expected, $actual) = @_;
3338 die "mirrored disks must have same size\n"
3339 if abs($expected - $actual) > $expected / 10;
3342 sub legacy_bios_4k_check
{
3344 die "Booting from 4kn drive in legacy BIOS mode is not supported.\n"
3345 if (($boot_type ne 'efi') && ($lbs == 4096));
3348 sub get_zfs_raid_setup
{
3349 my $filesys = $config_options->{filesys
};
3351 my $devlist = &$get_raid_devlist();
3353 my $diskcount = scalar(@$devlist);
3354 die "$filesys needs at least one device\n" if $diskcount < 1;
3357 if ($filesys eq 'zfs (RAID0)') {
3358 foreach my $hd (@$devlist) {
3359 legacy_bios_4k_check
(@$hd[4]);
3362 } elsif ($filesys eq 'zfs (RAID1)') {
3363 die "zfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
3365 my $hd = @$devlist[0];
3366 my $expected_size = @$hd[2]; # all disks need approximately same size
3367 foreach my $hd (@$devlist) {
3368 zfs_mirror_size_check
($expected_size, @$hd[2]);
3369 legacy_bios_4k_check
(@$hd[4]);
3372 } elsif ($filesys eq 'zfs (RAID10)') {
3373 die "zfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
3374 die "zfs (RAID10) needs an even number of devices\n" if $diskcount & 1;
3376 for (my $i = 0; $i < $diskcount; $i+=2) {
3377 my $hd1 = @$devlist[$i];
3378 my $hd2 = @$devlist[$i+1];
3379 zfs_mirror_size_check
(@$hd1[2], @$hd2[2]); # pairs need approximately same size
3380 legacy_bios_4k_check
(@$hd1[4]);
3381 legacy_bios_4k_check
(@$hd2[4]);
3382 $cmd .= ' mirror ' . @$hd1[1] . ' ' . @$hd2[1];
3385 } elsif ($filesys =~ m/^zfs \(RAIDZ-([123])\)$/) {
3387 my $mindisks = 2 + $level;
3388 die "zfs (RAIDZ-$level) needs at least $mindisks devices\n" if scalar(@$devlist) < $mindisks;
3389 my $hd = @$devlist[0];
3390 my $expected_size = @$hd[2]; # all disks need approximately same size
3391 $cmd .= " raidz$level";
3392 foreach my $hd (@$devlist) {
3393 zfs_mirror_size_check
($expected_size, @$hd[2]);
3394 legacy_bios_4k_check
(@$hd[4]);
3398 die "unknown zfs mode '$filesys'\n";
3401 return ($devlist, $cmd);
3404 sub get_btrfs_raid_setup
{
3406 my $filesys = $config_options->{filesys
};
3408 my $devlist = &$get_raid_devlist();
3410 my $diskcount = scalar(@$devlist);
3411 die "$filesys needs at least one device\n" if $diskcount < 1;
3415 if ($diskcount == 1) {
3418 if ($filesys eq 'btrfs (RAID0)') {
3420 } elsif ($filesys eq 'btrfs (RAID1)') {
3421 die "btrfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
3423 } elsif ($filesys eq 'btrfs (RAID10)') {
3424 die "btrfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
3427 die "unknown btrfs mode '$filesys'\n";
3431 return ($devlist, $mode);
3434 my $last_hd_selected = 0;
3435 sub create_hdsel_view
{
3437 $prev_btn->set_sensitive(1); # enable previous button at this point
3441 my $vbox = Gtk3
::VBox-
>new(0, 0);
3442 $inbox->pack_start($vbox, 1, 0, 0);
3443 my $hbox = Gtk3
::HBox-
>new(0, 0);
3444 $vbox->pack_start($hbox, 0, 0, 10);
3446 my ($disk, $devname, $size, $model, $logical_bsize) = @{@$hds[0]};
3447 $target_hd = $devname if !defined($target_hd);
3449 $target_hd_label = Gtk3
::Label-
>new("Target Harddisk: ");
3450 $hbox->pack_start($target_hd_label, 0, 0, 0);
3452 $target_hd_combo = Gtk3
::ComboBoxText-
>new();
3454 foreach my $hd (@$hds) {
3455 ($disk, $devname, $size, $model, $logical_bsize) = @$hd;
3456 $target_hd_combo->append_text (get_device_desc
($devname, $size, $model));
3459 my $raid = $config_options->{filesys
} =~ m/zfs|btrfs/;
3461 $target_hd_label->set_text("Target: $config_options->{filesys} ");
3462 $target_hd_combo->set_visible(0);
3463 $target_hd_combo->set_no_show_all(1);
3465 $target_hd_combo->set_active($last_hd_selected);
3466 $target_hd_combo->signal_connect(changed
=> sub {
3467 $a = shift-
>get_active;
3468 my ($disk, $devname) = @{@$hds[$a]};
3469 $last_hd_selected = $a;
3470 $target_hd = $devname;
3473 $hbox->pack_start($target_hd_combo, 0, 0, 10);
3475 my $options = Gtk3
::Button-
>new('_Options');
3476 $options->signal_connect (clicked
=> \
&create_hdoption_view
);
3477 $hbox->pack_start ($options, 0, 0, 0);
3484 set_next
(undef, sub {
3486 if ($config_options->{filesys
} =~ m/zfs/) {
3487 my ($devlist) = eval { get_zfs_raid_setup
() };
3489 display_message
("Warning: $err\nPlease fix ZFS setup first.");
3492 $config_options->{target_hds
} = [ map { $_->[1] } @$devlist ];
3493 } elsif ($config_options->{filesys
} =~ m/btrfs/) {
3494 my ($devlist) = eval { get_btrfs_raid_setup
() };
3496 display_message
("Warning: $err\nPlease fix BTRFS setup first.");
3499 $config_options->{target_hds
} = [ map { $_->[1] } @$devlist ];
3501 eval { legacy_bios_4k_check
(logical_blocksize
($target_hd)) };
3503 display_message
("Warning: $err\n");
3506 $config_options->{target_hds
} = [ $target_hd ];
3510 create_country_view
();
3514 sub create_extract_view
{
3520 $next->set_sensitive(0);
3521 $prev_btn->set_sensitive(0);
3524 my $vbox = Gtk3
::VBox-
>new(0, 0);
3525 $inbox->pack_start ($vbox, 1, 0, 0);
3526 my $hbox = Gtk3
::HBox-
>new(0, 0);
3527 $vbox->pack_start ($hbox, 0, 0, 10);
3529 my $vbox2 = Gtk3
::VBox-
>new(0, 0);
3530 $hbox->pack_start ($vbox2, 0, 0, 0);
3532 $progress_status = Gtk3
::Label-
>new('');
3533 $vbox2->pack_start ($progress_status, 1, 1, 0);
3535 $progress = Gtk3
::ProgressBar-
>new;
3536 $progress->set_show_text(1);
3537 $progress->set_size_request (600, -1);
3539 $vbox2->pack_start($progress, 0, 0, 0);
3543 my $tdir = $opt_testmode ?
"target" : "/target";
3545 my $base = "${proxmox_cddir}/$setup->{product}-base.squashfs";
3547 eval { extract_data
($base, $tdir); };
3550 $next->set_sensitive(1);
3552 set_next
("_Reboot", sub { exit (0); } );
3555 display_html
("fail.htm");
3556 display_error
($err);
3559 display_html
("success.htm");
3561 if ($config_options->{autoreboot
}) {
3562 Glib
::Timeout-
>add(1000, sub {
3563 if ($autoreboot_seconds > 0) {
3564 $autoreboot_seconds--;
3565 display_html
("success.htm");
3574 sub create_intro_view
{
3576 $prev_btn->set_sensitive(0);
3580 if (int($total_memory) < 1024) {
3581 my $product = $product_cfg->{$setup->{product
}};
3583 display_error
("Less than 1 GiB of usable memory detected, installation will probably fail.\n\n".
3584 "See 'System Requirements' in the $product->{fullname} documentation.");
3587 if ($setup->{product
} eq 'pve') {
3589 my $cpuinfo = file_get_contents
('/proc/cpuinfo');
3590 if ($cpuinfo && !($cpuinfo =~ /^flags\s*:.*(vmx|svm)/m)) {
3591 display_error
("No support for KVM virtualization detected.\n\n" .
3592 "Check BIOS settings for Intel VT / AMD-V / SVM.")
3600 set_next
("I a_gree", \
&create_hdsel_view
);
3603 $ipconf = get_ip_config
();
3605 $country = detect_country
() if $ipconf->{default} || $opt_testmode;
3607 # read country, kmap and timezone infos
3608 $cmap = read_cmap
();
3610 if (!defined($cmap->{country
}->{$country})) {
3611 print $logfd "ignoring detected country '$country', invalid or unknown\n";
3615 create_main_window
();
3617 my $initial_error = 0;
3619 if (!defined ($hds) || (scalar (@$hds) <= 0)) {
3620 print "no hardisks found\n";
3622 display_html
("nohds.htm");
3623 set_next
("Reboot", sub { exit(0); } );
3625 foreach my $hd (@$hds) {
3626 my ($disk, $devname) = @$hd;
3627 next if $devname =~ m
|^/dev/md\d
+$|;
3628 print "found Disk$disk N:$devname\n";
3632 if (!$initial_error && (scalar keys %{ $ipconf->{ifaces
} } == 0)) {
3633 print "no network interfaces found\n";
3635 display_html
("nonics.htm");
3636 set_next
("Reboot", sub { exit(0); } );
3639 create_intro_view
() if !$initial_error;
3643 # reap left over zombie processes
3644 while ((my $child = waitpid(-1, POSIX
::WNOHANG
)) > 0) {
3645 print "reaped child $child\n";