]>
git.proxmox.com Git - pve-installer.git/blob - proxinstall
5fcc21ad0573bb335d451b44a457a4109dbc122d
3 $ENV{DEBIAN_FRONTEND
} = 'noninteractive';
16 use String
::ShellQuote
;
22 my $kapi = `uname -r`;
27 if (!$ENV{G_SLICE
} || $ENV{G_SLICE
} ne "always-malloc") {
28 die "do not use slice allocator (run with 'G_SLICE=always-malloc ./proxinstall ...')\n";
31 if (!GetOptions
('testmode=s' => \
$opt_testmode)) {
36 sub file_read_firstline
{
39 my $fh = IO
::File-
>new ($filename, "r");
47 my $logfd = IO
::File-
>new (">/tmp/install.log");
49 my $proxmox_dir = $opt_testmode ? Cwd
::cwd
() : "/var/lib/pve-installer";
51 my $grub_plattform = "pc"; # pc, efi-amd64 or efi-ia32
53 $grub_plattform = "efi-amd64" if -d
"/sys/firmware/efi";
55 my $IPV4OCTET = "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])";
56 my $IPV4RE = "(?:(?:$IPV4OCTET\\.){3}$IPV4OCTET)";
57 my $ipv4_mask_hash = {
74 '255.255.128.0' => 17,
75 '255.255.192.0' => 18,
76 '255.255.224.0' => 19,
77 '255.255.240.0' => 20,
78 '255.255.248.0' => 21,
79 '255.255.252.0' => 22,
80 '255.255.254.0' => 23,
81 '255.255.255.0' => 24,
82 '255.255.255.128' => 25,
83 '255.255.255.192' => 26,
84 '255.255.255.224' => 27,
85 '255.255.255.240' => 28,
86 '255.255.255.248' => 29,
87 '255.255.255.252' => 30
90 my ($window, $cmdbox, $inbox, $htmlview);
91 my ($next, $next_fctn, $target_hd);
92 my ($progress, $progress_status);
93 my ($ipaddress, $ipconf_entry_addr);
94 my ($netmask, $ipconf_entry_mask);
95 my ($gateway, $ipconf_entry_gw);
96 my ($dnsserver, $ipconf_entry_dns);
97 my $hostname = 'proxmox';
98 my $domain = 'domain.tld';
99 my $cmdline = file_read_firstline
("/proc/cmdline");
102 my $timezone = 'Europe/Vienna';
105 my $keymap = 'en-us';
108 # parse command line args
110 my $config_options = {};
112 if ($cmdline =~ m/\s(ext3|ext4|zfs)(\s.*)?$/) {
113 $config_options->{filesys
} = $1;
115 $config_options->{filesys
} = 'ext3';
118 if ($cmdline =~ m/hdsize=(\d+(\.\d+)?)[\s\n]/i) {
119 $config_options->{hdsize
} = $1;
122 if ($cmdline =~ m/swapsize=(\d+(\.\d+)?)[\s\n]/i) {
123 $config_options->{swapsize
} = $1;
126 if ($cmdline =~ m/maxroot=(\d+(\.\d+)?)[\s\n]/i) {
127 $config_options->{maxroot
} = $1;
130 if ($cmdline =~ m/minfree=(\d+(\.\d+)?)[\s\n]/i) {
131 $config_options->{minfree
} = $1;
134 if ($cmdline =~ m/maxvz=(\d+(\.\d+)?)[\s\n]/i) {
135 $config_options->{maxvz
} = $1;
138 my $postfix_main_cf = <<_EOD;
139 # See /usr/share/postfix/main.cf.dist for a commented, more complete version
143 smtpd_banner = \$myhostname ESMTP \$mail_name (Debian/GNU)
146 # appending .domain is the MUA's job.
147 append_dot_mydomain = no
149 # Uncomment the next line to generate "delayed mail" warnings
150 #delay_warning_time = 4h
152 alias_maps = hash:/etc/aliases
153 alias_database = hash:/etc/aliases
154 mydestination = \$myhostname, localhost.\$mydomain, localhost
156 mynetworks = 127.0.0.0/8
157 inet_interfaces = loopback-only
158 recipient_delimiter = +
165 return String
::ShellQuote
::shell_quote
($str);
171 die "no arguments" if !$cmd;
173 return $cmd if !ref($cmd);
176 foreach my $arg (@$cmd) { push @qa, shellquote
($arg); }
178 return join (' ', @qa);
184 return run_command
($cmd, undef, undef, 1);
188 my ($cmd, $func, $input, $noout) = @_;
194 # see 'man bash' for option pipefail
195 $cmd = [ '/bin/bash', '-c', "set -o pipefail && $cmd" ];
200 $cmdstr = cmd2string
($cmd);
204 if ($input && ($cmdstr !~ m/chpasswd/)) {
205 $cmdtxt = "# $cmdstr <<EOD\n$input";
207 $cmdtxt .= "\nEOD\n";
209 $cmdtxt = "# $cmdstr\n";
217 print $logfd $cmdtxt;
219 my $reader = IO
::File-
>new();
220 my $writer = IO
::File-
>new();
221 my $error = IO
::File-
>new();
227 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
233 if ($orig_pid != $$) {
240 print $writer $input if defined $input;
243 my $select = new IO
::Select
;
244 $select->add ($reader);
245 $select->add ($error);
247 my ($ostream, $logout) = ('', '', '');
249 while ($select->count) {
250 my @handles = $select->can_read (0.2);
252 Gtk3
::main_iteration
() while Gtk3
::events_pending
();
254 next if !scalar (@handles); # timeout
256 foreach my $h (@handles) {
258 my $count = sysread ($h, $buf, 4096);
259 if (!defined ($count)) {
263 die "command '$cmd' failed: $err";
265 $select->remove ($h) if !$count;
267 $ostream .= $buf if !($noout || $func);
269 while ($logout =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
271 &$func($line) if $func;
274 } elsif ($h eq $error) {
275 $ostream .= $buf if !($noout || $func);
283 &$func($logout) if $func;
285 my $rv = waitpid ($pid, 0);
287 return $? if $noout; # behave like standard system();
292 die "command '$cmdstr' failed with exit code $ec";
300 print "trying to detect country...\n";
301 my $cpid = open2
(\
*TMP
, undef, "traceroute -N 1 -q 1 -n 8.8.8.8");
302 return undef if !$cpid;
306 my $previous_alarm = alarm (10);
308 local $SIG{ALRM
} = sub { die "timed out!\n" };
310 while (defined ($line = <TMP
>)) {
311 print $logfd "DC TRACEROUTE: $line";
312 if ($line =~ m/\s*\d+\s+(\d+\.\d+\.\d+\.\d+)\s/) {
313 my $geoip = `geoiplookup $1`;
314 print $logfd "DC GEOIP: $geoip";
315 if ($geoip =~ m/GeoIP Country Edition:\s*([A-Z]+),/) {
317 print $logfd "DC FOUND: $country\n";
326 alarm ($previous_alarm);
331 print "unable to detect country - $err\n";
333 print "detected country: " . uc($country) . "\n";
335 print "unable to detect country\n";
343 open (MEMINFO, "/proc/meminfo");
345 my $res = 512; # default to 512 if something goes wrong
346 while (my $line = <MEMINFO>) {
347 if ($line =~ m/^MemTotal:\s+(\d+)\s*kB/i) {
348 $res = int ($1 / 1024);
357 my $total_memory = get_memtotal();
360 my ($src, $dest) = @_;
362 my ($dev1,$ino1) = stat ($src);
363 my ($dev2,$ino2) = stat ($dest);
365 return 0 if !($dev1 && $dev2 && $ino1 && $ino2);
367 return $ino1 == $ino2 && $dev1 == $dev2;
370 sub find_stable_path {
371 my ($stabledir, $bdev) = @_;
373 foreach my $path (<$stabledir/*>) {
374 if (link_points_to ($path, $bdev)) {
375 return wantarray ? ($path, basename($path)) : $path;
380 sub find_dev_by_uuid {
383 my ($full_path, $name) = find_stable_path ("/dev/disk/by-uuid", $bdev);
393 push @$res, [-1, $opt_testmode, int((-s $opt_testmode)/512), "TESTDISK"];
398 foreach my $bd (</sys/block/*>) {
399 next if $bd =~ m|^/sys/block/ram\d+$|;
400 next if $bd =~ m|^/sys/block/loop\d+$|;
401 next if $bd =~ m|^/sys/block/md\d+$|;
402 next if $bd =~ m|^/sys/block/dm-.*$|;
403 next if $bd =~ m|^/sys/block/fd\d+$|;
404 next if $bd =~ m|^/sys/block/sr\d+$|;
406 my $dev = file_read_firstline("$bd/dev");
411 my $info = `udevadm info
--path
$bd --query all
`;
414 next if $info !~ m/^E: DEVTYPE=disk$/m;
416 next if $info =~ m/^E: ID_CDROM/m;
418 my ($name) = $info =~ m/^N: (\S+)$/m;
421 my $real_name = "/dev/$name";
423 my $size = file_read_firstline("$bd/size");
425 $size = undef if !($size && $size =~ m/^\d+$/);
427 my $model = file_read_firstline("$bd/device/model") || '';
430 if (length ($model) > 30) {
431 $model = substr ($model, 0, 30);
433 push @$res, [$count++, $real_name, $size, $model] if $size;
435 print STDERR "ERROR: unable to map device $dev ($bd)\n";
443 my $countryfn = $opt_testmode ? "/usr/share/pve-manager/country.dat" :
444 "/proxmox/country.dat";
445 open (TMP, "<$countryfn") || die "unable to open '$countryfn' - $!\n";
448 my $countryhash = {};
451 while (defined ($line = <TMP>)) {
452 if ($line =~ m|^map:([^\s:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]*):$|) {
460 $kmaphash->{$2} = $1;
461 } elsif ($line =~ m|^([a-z]{2}):([^:]+):([^:]*):([^:]*):$|) {
467 $countryhash->{lc($2)} = $1;
469 warn "unable to parse 'country.dat' line: $line";
476 my $zonefn = "/usr/share/zoneinfo/zone.tab";
477 open (TMP, "<$zonefn") || die "unable to open '$zonefn' - $!\n";
478 while (defined ($line = <TMP>)) {
479 next if $line =~ m/^\#/;
480 next if $line =~ m/^\s*$/;
481 if ($line =~ m|^([A-Z][A-Z])\s+\S+\s+(([^/]+)/\S+)\s|) {
483 $cczones->{$cc}->{$2} = 1;
484 $country->{$cc}->{zone} = $2 if !defined ($country->{$cc}->{zone});
495 countryhash => $countryhash,
497 kmaphash => $kmaphash,
501 # search for Harddisks
502 my $hds = hd_list ();
507 foreach my $hd (@$hds) {
508 my ($disk, $devname, $size, $model) = @$hd;
509 return int($size/2) if $devname eq $dev;
512 die "no such device '$dev'";
515 sub get_partition_dev {
516 my ($dev, $partnum) = @_;
518 if ($dev =~ m|^/dev/[hxsev]d[a-z]$|) {
519 return "${dev}$partnum";
520 } elsif ($dev =~ m|^/dev/[^/]+/c\d+d\d+$|) {
521 return "${dev}p$partnum";
522 } elsif ($dev =~ m|^/dev/[^/]+/d\d+$|) {
523 return "${dev}p$partnum";
524 } elsif ($dev =~ m|^/dev/[^/]+/hd[a-z]$|) {
525 return "${dev}$partnum";
527 die "unable to get device for partition $partnum on device $dev\n";
532 sub file_get_contents {
533 my ($filename, $max) = @_;
535 my $fh = IO::File->new($filename, "r") ||
536 die "can't open '$filename' - $!\n";
538 local $/; # slurp mode
548 my ($text, $filename) = @_;
550 my $fd = IO::File->new (">$filename") ||
551 die "unable to open file '$filename' - $!";
556 sub update_progress {
557 my ($frac, $start, $end, $text) = @_;
559 my $part = $end - $start;
560 my $res = $start + $frac*$part;
562 $progress->set_fraction ($res);
563 $progress->set_text (sprintf ("%d%%", int ($res*100)));
564 $progress_status->set_text ($text) if defined ($text);
566 Gtk3::main_iteration() while Gtk3::events_pending();
569 sub create_filesystem {
570 my ($dev, $name, $type, $start, $end, $fs, $fe, $opts) = @_;
572 $opts = '' if !$opts;
574 my $range = $end - $start;
575 my $rs = $start + $range*$fs;
576 my $re = $start + $range*$fe;
579 update_progress (0, $rs, $re, "creating $name filesystem");
581 run_command ("mkfs.$type $opts -F $dev", sub {
584 if ($line =~ m/Writing inode tables:\s+(\d+)\/(\d+)/) {
586 } elsif ($max && $line =~ m/(\d+)\/$max/) {
587 update_progress (($1/$max)*0.9, $rs, $re);
588 } elsif ($line =~ m/Creating journal.*done/) {
589 update_progress (0.95, $rs, $re);
590 } elsif ($line =~ m/Writing superblocks and filesystem.*done/) {
591 update_progress (1, $rs, $re);
597 my ($targetdir, $dcdata) = @_;
599 my $cfgfile = "/tmp/debconf.txt";
600 write_config ($dcdata, "$targetdir/$cfgfile");
601 syscmd ("chroot $targetdir debconf-set-selections $cfgfile");
602 unlink "$targetdir/$cfgfile";
606 my ($targetdir, $cmd, $new_cmd) = @_;
608 syscmd ("chroot $targetdir dpkg-divert --package proxmox " .
609 "--add --rename $cmd") == 0 ||
610 die "unable to exec dpkg-divert\n";
612 syscmd ("ln -sf ${new_cmd} $targetdir/$cmd") == 0 ||
613 die "unable to link diversion to ${new_cmd}\n";
616 sub diversion_remove {
617 my ($targetdir, $cmd) = @_;
619 syscmd ("mv $targetdir/${cmd}.distrib $targetdir/${cmd};") == 0 ||
620 die "unable to remove $cmd diversion\n";
622 syscmd ("chroot $targetdir dpkg-divert --remove $cmd") == 0 ||
623 die "unable to remove $cmd diversion\n";
626 sub zfs_create_rpool {
627 my ($zfspoolname, $vdev) = @_;
629 syscmd ("zpool create -f -o ashift=12 $zfspoolname $vdev") == 0 ||
630 die "unable to create zfs root pool\n";
632 syscmd ("zfs create $zfspoolname/ROOT") == 0 ||
633 die "unable to create zfs $zfspoolname/ROOT volume\n";
635 syscmd ("zfs create $zfspoolname/ROOT/pve-1") == 0 ||
636 die "unable to create zfs $zfspoolname/ROOT/pve-1 volume\n";
638 # disable atime during insatll
639 syscmd ("zfs set atime=off $zfspoolname") == 0 ||
640 die "unable to set zfs properties\n";
641 syscmd ("zfs set compression=lz4 $zfspoolname") == 0 ||
642 die "unable to set zfs properties\n";
645 sub zfs_create_swap {
646 my ($zfspoolname, $swapsize) = @_;
648 syscmd ("zfs create -V ${swapsize}K -b 4K $zfspoolname/swap") == 0 ||
649 die "unable to create zfs swap device\n";
651 syscmd ("zfs set com.sun:auto-snapshot=false $zfspoolname/swap") == 0 ||
652 die "unable to set zfs properties\n";
654 # reduces memory pressure
655 syscmd ("zfs set sync=always $zfspoolname/swap") == 0 ||
656 die "unable to set zfs properties\n";
658 return "/dev/zvol/$zfspoolname/swap";
661 sub partition_bootable_disk {
662 my ($target_dev, $maxhdsize, $use_zfs) = @_;
664 die "too dangerous" if $opt_testmode;
666 syscmd("sgdisk -Z ${target_dev}");
667 my $hdsize = hd_size($target_dev); # size in blocks (1024 bytes)
669 if ($maxhdsize && ($maxhdsize < $hdsize)) {
670 $hdsize = $maxhdsize;
673 my $hdgb = int($hdsize/(1024*1024));
674 die "hardisk '$target_dev' too small (${hdsize}GB)" if $hdgb < 8;
676 # 1 - GRUB boot partition: 1M
678 # 3 - OS/Data partition
680 my $grubbootdev = get_partition_dev($target_dev, 1);
681 my $efibootdev = get_partition_dev($target_dev, 2);
682 my $osdev = get_partition_dev ($target_dev, 3);
684 my $hdsize_mb = $hdsize/1024;
686 my $pcmd = ['sgdisk', '-a1'];
689 push @$pcmd, "-n$pnum:34:2047", "-t$pnum:EF02";
692 # Note: from 128M to end
693 push @$pcmd, "-n$pnum:128M:0", "-t$pnum:8E00";
697 # Note: from sector 2048 to 128M (0 mean till next partition)
698 push @$pcmd, "-n$pnum:2048:0", "-t$pnum:EF00";
700 push @$pcmd, $target_dev;
702 my $os_size = $hdsize - 128*1024;
704 syscmd($pcmd) == 0 ||
705 die "unable to partition harddisk '${target_dev}'\n";
707 return ($os_size, $osdev, $efibootdev);
710 # ZFS has this use_whole_disk concept, so we try to partition the same
711 # way as zfs does by default. There is room at start of disk to insert
712 # a grub boot partition. But adding a EFI ESP is not possible.
714 # Note: zfs people think this is just a waste of space an not
715 # required. Instead, you should put the ESP on another disk (log,
718 sub partition_bootable_zfs_disk {
719 my ($target_dev) = @_;
721 die "too dangerous" if $opt_testmode;
723 syscmd("sgdisk -Z ${target_dev}");
724 my $hdsize = hd_size($target_dev); # size in blocks (1024 bytes)
726 my $hdgb = int($hdsize/(1024*1024));
727 die "hardisk '$target_dev' too small (${hdsize}GB)" if $hdgb < 8;
729 # 1 - GRUB boot partition: 1M
730 # 2 - OS/Data partition
731 # 9 - ZFS reserved partition
733 my $grubbootdev = get_partition_dev($target_dev, 1);
734 my $osdev = get_partition_dev ($target_dev, 2);
736 my $pcmd = ['sgdisk', '-a1'];
739 push @$pcmd, "-n$pnum:34:2047", "-t$pnum:EF02";
742 push @$pcmd, "-n$pnum:-8M:0", "-t$pnum:BF07";
745 push @$pcmd, "-n$pnum:2048:0", "-t$pnum:BF01", '-c', "$pnum:zfs";
747 push @$pcmd, $target_dev;
749 my $os_size = $hdsize - 1024 - 1024*8;
751 syscmd($pcmd) == 0 ||
752 die "unable to partition harddisk '${target_dev}'\n";
754 return ($os_size, $osdev);
757 sub create_lvm_volumes {
758 my ($lvmdev, $os_size, $swap_size) = @_;
760 my $rootdev = '/dev/pve/root';
761 my $datadev = '/dev/pve/data';
762 my $swapfile = '/dev/pve/swap';
764 # we use --metadatasize 250k, which reseults in "pe_start = 512"
765 # so pe_start is aligned on a 128k boundary (advantage for SSDs)
766 syscmd ("/sbin/pvcreate --metadatasize 250k -y -ff $lvmdev") == 0 ||
767 die "unable to initialize physical volume $lvmdev";
768 syscmd ("/sbin/vgcreate pve $lvmdev") == 0 ||
769 die "unable to create volume group";
771 my $hdgb = int($os_size/(1024*1024));
772 my $space = (($hdgb > 128) ? 16 : ($hdgb/8))*1024*1024;
775 if ($config_options->{maxroot}) {
776 $maxroot = $config_options->{maxroot};
781 my $rootsize = (($hdgb > ($maxroot*4)) ? $maxroot : $hdgb/4)*1024*1024;
783 my $rest = $os_size - $swap_size - $rootsize; # in KB
786 if ($config_options->{minfree}) {
787 $minfree = (($config_options->{minfree}*1024*1024) >= $rest ) ? $space :
788 $config_options->{minfree}*1024*1024 ;
793 $rest = $rest - $minfree;
795 if ($config_options->{maxvz}) {
796 $rest = (($config_options->{maxvz}*1024*1024) <= $rest) ?
797 $config_options->{maxvz}*1024*1024 : $rest;
800 syscmd ("/sbin/lvcreate -L${swap_size}K -nswap pve") == 0 ||
801 die "unable to create swap volume";
803 syscmd ("/sbin/lvcreate -L${rootsize}K -nroot pve") == 0 ||
804 die "unable to create root volume";
806 syscmd ("/sbin/lvcreate -L${rest}K -ndata pve") == 0 ||
807 die "unable to create data volume";
809 syscmd ("/sbin/vgchange -a y pve") == 0 ||
810 die "unable to activate volume group";
812 return ($rootdev, $datadev, $swapfile);
815 sub compute_swapsize {
818 my $hdgb = int($hdsize/(1024*1024));
821 if ($config_options->{swapsize}) {
822 $swapsize = $config_options->{swapsize}*1024*1024;
824 my $ss = int ($total_memory / 1024);
826 $ss = ($hdgb/8) if $ss > ($hdgb/8);
827 $swapsize = $ss*1024*1024;
832 my ($tgzfile, $targetdir) = @_;
834 die "target '$targetdir' does not exist\n" if ! -d $targetdir;
836 my $bootdevinfo = [];
843 my $zfspoolname = $opt_testmode ? "test_rpool" : 'rpool';
845 my $filesys = $config_options->{filesys};
847 if ($filesys =~ m/zfs/) {
848 $target_hd = undef; # do not use this config
850 $targetdir = "/$zfspoolname/ROOT/pve-1";
857 for ($i = 5; $i > 0; $i--) {
858 syscmd("modprobe zfs");
859 last if -c "/dev/zfs";
863 die "unable to load zfs kernel module\n" if !$i;
871 update_progress (0, 0, $maxper, "create partitions");
875 $rootdev = abs_path($target_hd);
876 syscmd ("umount $rootdev");
880 die "unsupported zfs mode (for testing environment)\n"
881 if $filesys ne 'zfs (RAID0)';
883 syscmd ("zpool destroy $zfspoolname") if $opt_testmode;
885 zfs_create_rpool($zfspoolname, $rootdev);
890 my ($devlist, $bootdevlist, $vdev) = get_zfs_raid_setup();
893 foreach my $hd (@$bootdevlist) {
894 my $devname = @$hd[1];
896 partition_bootable_zfs_disk($devname);
897 die "unable to mirror disks with different sizes!\n"
898 if $disksize && ($size != $disksize);
899 push @$bootdevinfo, { devname => $devname, osdev => $osdev};
903 sleep(1); # give kernel time to reread part table
905 # trigger udev to create /dev/disk/by-uuid
906 syscmd ("udevadm trigger --subsystem-match block");
907 syscmd ("udevadm settle --timeout 10");
909 foreach my $di (@$bootdevinfo) {
910 my $devname = $di->{devname};
911 $di->{by_id} = find_stable_path ("/dev/disk/by-id", $devname);
913 # Note: using /dev/disk/by-id/ does not work for unknown reason, we get
914 # cannot create 'rpool': no such pool or dataset
915 #my $osdev = find_stable_path ("/dev/disk/by-id", $di->{osdev}) || $di->{osdev};
917 my $osdev = $di->{osdev};
918 $vdev =~ s/ $devname/ $osdev/;
921 zfs_create_rpool($zfspoolname, $vdev);
923 my $swap_size = compute_swapsize($disksize);
924 $swapfile = zfs_create_swap($zfspoolname, $swap_size);
928 die "target '$target_hd' is not a valid block device\n" if ! -b $target_hd;
931 if ($config_options->{hdsize}) {
932 # max hdsize passed on cmdline (GB)
933 $maxhdsize = $config_options->{hdsize}*1024*1024;
936 my ($os_size, $osdev, $efidev);
937 ($os_size, $osdev, $efidev) =
938 partition_bootable_disk($target_hd, $maxhdsize);
940 sleep(1); # give kernel time to reread part table
942 # trigger udev to create /dev/disk/by-uuid
943 syscmd ("udevadm trigger --subsystem-match block");
944 syscmd ("udevadm settle --timeout 10");
946 my $by_id = find_stable_path ("/dev/disk/by-id", $target_hd);
947 push @$bootdevinfo, { esp => $efidev, devname => $target_hd,
948 osdev => $osdev, by_id => $by_id };
950 my $swap_size = compute_swapsize($os_size);
951 ($rootdev, $datadev, $swapfile) =
952 create_lvm_volumes($osdev, $os_size, $swap_size);
954 # trigger udev to create /dev/disk/by-uuid
955 syscmd ("udevadm trigger --subsystem-match block");
956 syscmd ("udevadm settle --timeout 10");
960 # to be fast during installation
961 syscmd ("zfs set sync=disabled $zfspoolname") == 0 ||
962 die "unable to set zfs properties\n";
965 update_progress (0.03, 0, $maxper, "create swap space");
967 syscmd ("mkswap -f $swapfile") == 0 ||
968 die "unable to create swap space\n";
971 update_progress (0.05, 0, $maxper, "creating filesystems");
973 foreach my $di (@$bootdevinfo) {
975 syscmd ("mkfs.vfat -F32 $di->{esp}") == 0 ||
976 die "unable to initialize EFI ESP on device $di->{esp}\n";
981 if ( -b $target_hd) {
983 create_filesystem ($rootdev, 'root', $filesys, 0.05, $maxper, 0, 0.5);
984 create_filesystem ($datadev, 'data', $filesys, 0.05, $maxper, 0.5, 1, '-m 0');
988 create_filesystem ($rootdev, 'root', $filesys, 0.05, $maxper, 0, 1, '-m 0');
992 update_progress (1, 0.05, $maxper, "mounting target $rootdev");
995 syscmd ("mount -n $rootdev -o noatime,barrier=0 $targetdir") == 0 ||
996 die "unable to mount $rootdev\n";
999 mkdir "$targetdir/boot";
1000 mkdir "$targetdir/boot/efi";
1004 mkdir "$targetdir/var";
1005 mkdir "$targetdir/var/lib";
1006 mkdir "$targetdir/var/lib/vz";
1007 syscmd ("mount -n $datadev $targetdir/var/lib/vz") == 0 ||
1008 die "unable to mount $datadev\n";
1011 display_html ("extract2-rulesystem.htm");
1012 update_progress (1, 0.05, $maxper, "extracting base system");
1014 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = stat ($tgzfile);
1015 $ino || die "unable to open file '$tgzfile' - $!\n";
1018 if ($opt_testmode) {
1019 $files = file_read_firstline("/pve/$release/install/pve-base.cnt");
1021 $files = file_read_firstline("/proxmox/pve-base.cnt");
1027 run_command ("tar xvf $tgzfile -C $targetdir", sub {
1030 my $nper = int (($count *100)/$files);
1031 if ($nper != $per) {
1033 my $frac = $per > 100 ? 100 : $per/100;
1034 update_progress ($frac, $maxper, 0.5);
1038 syscmd ("mount -n -t tmpfs tmpfs $targetdir/tmp") == 0 ||
1039 die "unable to mount tmpfs on $targetdir/tmp\n";
1040 syscmd ("mount -n -t proc proc $targetdir/proc") == 0 ||
1041 die "unable to mount proc on $targetdir/proc\n";
1042 syscmd ("mount -n -t sysfs sysfs $targetdir/sys") == 0 ||
1043 die "unable to mount sysfs on $targetdir/sys\n";
1045 display_html ("extract3-spam.htm");
1046 update_progress (1, $maxper, 0.5, "configuring base system");
1051 "127.0.0.1 localhost.localdomain localhost\n" .
1052 "$ipaddress $hostname.$domain $hostname pvelocalhost\n\n" .
1053 "# The following lines are desirable for IPv6 capable hosts\n\n" .
1054 "::1 ip6-localhost ip6-loopback\n" .
1055 "fe00::0 ip6-localnet\n" .
1056 "ff00::0 ip6-mcastprefix\n" .
1057 "ff02::1 ip6-allnodes\n" .
1058 "ff02::2 ip6-allrouters\n" .
1059 "ff02::3 ip6-allhosts\n";
1061 write_config ($hosts, "$targetdir/etc/hosts");
1063 write_config ("$hostname\n", "$targetdir/etc/hostname");
1065 syscmd ("/bin/hostname $hostname") if !$opt_testmode;
1067 # configure interfaces
1070 "auto lo\niface lo inet loopback\n\n" .
1071 "auto vmbr0\niface vmbr0 inet static\n" .
1072 "\taddress $ipaddress\n" .
1073 "\tnetmask $netmask\n" .
1074 "\tgateway $gateway\n" .
1075 "\tbridge_ports eth0\n" .
1076 "\tbridge_stp off\n" .
1079 write_config ($ifaces, "$targetdir/etc/network/interfaces");
1083 my $resolfconf = "search $domain\nnameserver $dnsserver\n";
1084 write_config ($resolfconf, "$targetdir/etc/resolv.conf");
1088 my $fstab = "# <file system> <mount point> <type> <options> <dump> <pass>\n";
1091 $fstab .= "$rootdev / $filesys errors=remount-ro 0 1\n";
1092 $fstab .= "$datadev /var/lib/vz $filesys defaults 0 1\n" if $datadev;
1096 # Note: this is required by current grub, but really dangerous, because
1097 # vfat does not have journaling, so it triggers manual fsck after each crash
1098 # so we only mount /boot/efi if really required (efi systems).
1099 if ($grub_plattform =~ m/^efi-/) {
1100 if (scalar(@$bootdevinfo)) {
1101 my $di = @$bootdevinfo[0]; # simply use first disk
1103 my $efi_boot_uuid = $di->{esp};
1104 if (my $uuid = find_dev_by_uuid ($di->{esp})) {
1105 $efi_boot_uuid = "UUID=$uuid";
1108 $fstab .= "${efi_boot_uuid} /boot/efi vfat defaults 0 1\n";
1114 $fstab .= "$swapfile none swap sw 0 0\n" if $swapfile;
1116 $fstab .= "proc /proc proc defaults 0 0\n";
1118 write_config ($fstab, "$targetdir/etc/fstab");
1119 write_config ("", "$targetdir/etc/mtab");
1121 syscmd ("cp ${proxmox_dir}/policy-disable-rc.d " .
1122 "$targetdir/usr/sbin/policy-rc.d") == 0 ||
1123 die "unable to copy policy-rc.d\n";
1124 syscmd ("cp ${proxmox_dir}/fake-start-stop-daemon " .
1125 "$targetdir/sbin/") == 0 ||
1126 die "unable to copy start-stop-daemon\n";
1128 diversion_add ($targetdir, "/sbin/start-stop-daemon", "/sbin/fake-start-stop-daemon");
1129 diversion_add ($targetdir, "/usr/sbin/update-grub", "/bin/true");
1130 diversion_add ($targetdir, "/usr/sbin/update-initramfs", "/bin/true");
1132 syscmd ("touch $targetdir/proxmox_install_mode");
1134 my $grub_install_devices_txt = '';
1135 foreach my $di (@$bootdevinfo) {
1136 $grub_install_devices_txt .= ', ' if $grub_install_devices_txt;
1137 $grub_install_devices_txt .= $di->{by_id} || $di->{devname};
1140 # Note: debian-installer/locale is used by console-setup
1142 debconfig_set ($targetdir, <<_EOD);
1143 locales locales/default_environment_locale select en_US.UTF-8
1144 locales locales/locales_to_be_generated select en_US.UTF-8 UTF-8
1145 samba-common samba-common/dhcp boolean false
1146 samba-common samba-common/workgroup string WORKGROUP
1147 postfix postfix/main_mailer_type select Local only
1148 keyboard-configuration keyboard-configuration/xkb-keymap select $keymap
1149 d-i debian-installer/locale select en_US.UTF-8
1150 grub-pc grub-pc/install_devices select $grub_install_devices_txt
1153 my $pkgdir = $opt_testmode ?
"packages" : "/proxmox/packages";
1155 while (<$pkgdir/*.deb
>) { $pkg_count++ };
1158 while (<$pkgdir/*.deb
>) {
1161 my ($deb) = $path =~ m/$pkgdir\/(.*\
.deb
)/;
1162 # if ($deb =~ m/^grub-efi-/ && $deb !~ m/^grub-${grub_plattform}/) {
1166 update_progress
($count/$pkg_count, 0.5, 0.75, "extracting $deb");
1167 print "extracting: $deb\n";
1168 syscmd
("cp $path $targetdir/tmp/$deb") == 0 ||
1169 die "installation of package $deb failed\n";
1170 syscmd
("chroot $targetdir dpkg --force-depends --no-triggers --unpack /tmp/$deb") == 0 ||
1171 die "installation of package $deb failed\n";
1172 update_progress
((++$count)/$pkg_count, 0.5, 0.75);
1175 display_html
("extract4-virus.htm");
1177 my $cmd = "chroot $targetdir dpkg --force-confold --configure -a";
1179 run_command
($cmd, sub {
1181 if ($line =~ m/Setting up\s+(\S+)/) {
1182 update_progress
((++$count)/$pkg_count, 0.75, 0.95,
1187 debconfig_set
($targetdir, <<_EOD);
1188 postfix postfix/main_mailer_type select No configuration
1191 unlink "$targetdir/etc/mailname";
1192 $postfix_main_cf =~ s/__FQDN__/${hostname}.${domain}/;
1193 write_config
($postfix_main_cf, "$targetdir/etc/postfix/main.cf");
1195 # make sure we have all postfix directories
1196 syscmd
("chroot $targetdir /usr/sbin/postfix check");
1197 # cleanup mail queue
1198 syscmd
("chroot $targetdir /usr/sbin/postsuper -d ALL");
1200 unlink "$targetdir/proxmox_install_mode";
1203 unlink ("$targetdir/etc/localtime");
1204 symlink ("/usr/share/zoneinfo/$timezone", "$targetdir/etc/localtime");
1205 write_config
("$timezone\n", "$targetdir/etc/timezone");
1208 if (my $mirror = $cmap->{country
}->{$country}->{mirror
}) {
1209 my $fn = "$targetdir/etc/apt/sources.list";
1210 syscmd
("sed -i 's/ftp\\.debian\\.org/$mirror/' '$fn'");
1213 # create extended_states for apt (avoid cron job warning if that
1214 # file does not exist)
1215 write_config
('', "$targetdir/var/lib/apt/extended_states");
1217 # save installer settings
1218 my $ucc = uc ($country);
1219 debconfig_set
($targetdir, <<_EOD);
1220 pve-manager pve-manager/country string $ucc
1223 update_progress
(0.8, 0.95, 1, "make system bootable");
1225 # update default grub settings
1226 syscmd
("sed -i -e 's/^GRUB_DISTRIBUTOR.*/GRUB_DISTRIBUTOR=\"Proxmox Virtual Environment\"/' -e 's/#GRUB_DISABLE_RECOVERY=.*/GRUB_DISABLE_RECOVERY=\"true\"/' $targetdir/etc/default/grub") == 0 ||
1227 die "unable to update /etc/default/grub\n";
1230 syscmd
("sed -i -e 's/^GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"root=ZFS=$zfspoolname\\/ROOT\\/pve-1 boot=zfs\"/' $targetdir/etc/default/grub") == 0 ||
1231 die "unable to update /etc/default/grub\n";
1235 diversion_remove
($targetdir, "/usr/sbin/update-grub");
1236 diversion_remove
($targetdir, "/usr/sbin/update-initramfs");
1238 if (!$opt_testmode) {
1240 unlink ("$targetdir/etc/mtab");
1241 symlink ("/proc/mounts", "$targetdir/etc/mtab");
1242 syscmd
("mount -n --bind /dev $targetdir/dev");
1244 syscmd
("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0 ||
1245 die "unable to install initramfs\n";
1247 foreach my $di (@$bootdevinfo) {
1248 my $dev = $di->{devname
};
1249 syscmd
("chroot $targetdir /usr/sbin/grub-install --target i386-pc --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
1250 die "unable to install the i386-pc boot loader on '$dev'\n";
1253 syscmd
("mount -n $di->{esp} $targetdir/boot/efi") == 0 ||
1254 die "unable to mount $di->{esp}\n";
1255 syscmd
("chroot $targetdir /usr/sbin/grub-install --target x86_64-efi --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
1256 die "unable to install the EFI boot loader on '$dev'\n";
1257 syscmd
("umount $targetdir/boot/efi") == 0 ||
1258 die "unable to umount $targetdir/boot/efi\n";
1262 syscmd
("chroot $targetdir /usr/sbin/update-grub") == 0 ||
1263 die "unable to update boot loader config\n";
1265 syscmd
("umount $targetdir/dev");
1270 # hack: remove dead.letter from sshd installation
1271 syscmd
("rm -rf $targetdir/dead.letter");
1273 unlink "$targetdir/usr/sbin/policy-rc.d";
1275 diversion_remove
($targetdir, "/sbin/start-stop-daemon");
1278 my $octets = encode
("utf-8", $password);
1279 run_command
("chroot $targetdir /usr/sbin/chpasswd", undef,
1284 my $tmpdir = "$targetdir/tmp/pve";
1287 # write vnc keymap to datacenter.cfg
1288 my $vnckmap = $cmap->{kmap
}->{$keymap}->{kvm
} || 'en-us';
1289 write_config
("keyboard: $vnckmap\n",
1290 "$tmpdir/datacenter.cfg");
1293 write_config
("user:root\@pam:1:0:::${mailto}::\n",
1294 "$tmpdir/user.cfg");
1296 run_command
("chroot $targetdir /usr/bin/create_pmxcfs_db /tmp/pve /var/lib/pve-cluster/config.db");
1298 syscmd
("rm -rf $tmpdir");
1303 update_progress
(1, 0, 1, "");
1307 if ($opt_testmode) {
1308 syscmd
("chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> pve-final.pkglist");
1311 syscmd
("umount $targetdir/var/lib/vz");
1312 syscmd
("umount $targetdir/tmp");
1313 syscmd
("umount $targetdir/proc");
1314 syscmd
("umount $targetdir/sys");
1317 syscmd
("zfs umount -a") == 0 ||
1318 die "unable to unmount zfs\n";
1320 syscmd
("umount -d $targetdir");
1323 if (!$err && $use_zfs) {
1324 syscmd
("zfs set sync=standard $zfspoolname") == 0 ||
1325 die "unable to set zfs properties\n";
1327 syscmd
("zfs set mountpoint=/ $zfspoolname/ROOT/pve-1") == 0 ||
1328 die "zfs set mountpoint failed\n";
1330 syscmd
("zpool set bootfs=$zfspoolname/ROOT/pve-1 $zfspoolname") == 0 ||
1331 die "zfs set bootfs failed\n";
1338 my ($filename) = @_;
1340 my $path = "${proxmox_dir}/html/$filename";
1341 my $url = "file://$path";
1343 my $data = file_get_contents
($path);
1345 if ($filename eq 'license.htm') {
1346 my $licensefn = -f
"/EULA" ?
"/EULA" :
1347 $opt_testmode ?
"./copyright" :
1348 "/usr/share/doc/pve-installer/copyright";
1349 my $license = decode
('utf8', file_get_contents
($licensefn));
1350 $license =~ m/^\s+(.+\n)/;
1351 my $title = $licensefn eq '/EULA' ?
"END USER LICENSE AGREEMENT (EULA)": $1;
1352 $data =~ s/__LICENSE__/$license/;
1353 $data =~ s/__LICENSE_TITLE__/$title/;
1356 $htmlview->load_html_string($data, $url);
1360 my ($text, $fctn) = @_;
1363 $text = "_Next" if !$text;
1364 $next->set_label ($text);
1366 $next->grab_focus ();
1370 my ($doc, $url, $stream) = @_;
1372 $stream->set_cancel_func (sub {}); # hack: avoid warning
1374 my $path = "${proxmox_dir}/html/$url";
1377 open (HTMLTMP
, $path) ||
1378 die "unable to open file '$path' - $! ";
1380 while (my $i = read (HTMLTMP
, $buf, 4096)) {
1381 $stream->write ($buf);
1382 Gtk3
::main_iteration
() while Gtk3
::events_pending
();
1387 #$stream->close(); # hack: dont close - avoid crash
1390 sub create_main_window
{
1392 $window = Gtk3
::Window-
>new ();
1393 $window->set_default_size (1024, 768);
1394 $window->set_has_resize_grip(0);
1395 $window->set_decorated (0) if !$opt_testmode;
1397 my $vbox = Gtk3
::VBox-
>new (0, 0);
1399 my $image = Gtk3
::Image-
>new_from_file ("${proxmox_dir}/proxlogo.xpm");
1400 $vbox->pack_start ($image, 0, 0, 0);
1402 my $hbox = Gtk3
::HBox-
>new (0, 0);
1403 $vbox->pack_start ($hbox, 1, 1, 0);
1405 # my $f1 = Gtk3::Frame->new ('test');
1406 # $f1->set_shadow_type ('none');
1407 # $hbox->pack_start ($f1, 1, 1, 0);
1409 my $sep1 = Gtk3
::HSeparator-
>new;
1410 $vbox->pack_start ($sep1, 0, 0, 0);
1412 $cmdbox = Gtk3
::HBox-
>new ();
1413 $vbox->pack_start ($cmdbox, 0, 0, 10);
1415 $next = Gtk3
::Button-
>new ('_Next');
1416 $next->signal_connect (clicked
=> sub { &$next_fctn (); });
1417 $cmdbox->pack_end ($next, 0, 0, 10);
1418 my $abort = Gtk3
::Button-
>new ('_Abort');
1419 $abort->set_can_focus (0);
1420 $cmdbox->pack_start ($abort, 0, 0, 10);
1421 $abort->signal_connect (clicked
=> sub { exit (-1); });
1423 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1424 $hbox->add ($vbox2);
1426 $htmlview = Gtk3
::WebKit
::WebView-
>new();
1427 my $scrolls = Gtk3
::ScrolledWindow-
>new();
1428 $scrolls->add($htmlview);
1430 my $hbox2 = Gtk3
::HBox-
>new (0, 0);
1431 $hbox2->pack_start ($scrolls, 1, 1, 0);
1433 $vbox2->pack_start ($hbox2, 1, 1, 0);
1435 my $vbox3 = Gtk3
::VBox-
>new (0, 0);
1436 $vbox2->pack_start ($vbox3, 0, 0, 0);
1438 my $sep2 = Gtk3
::HSeparator-
>new;
1439 $vbox3->pack_start ($sep2, 0, 0, 0);
1441 $inbox = Gtk3
::HBox-
>new (0, 0);
1442 $vbox3->pack_start ($inbox, 0, 0, 0);
1444 $window->add ($vbox);
1447 $window->realize ();
1451 $inbox->foreach(sub {
1453 $inbox->remove ($child);
1457 # fixme: newer GTK3 has special properties to handle numbers with Entry
1458 # only allow floating point numbers with Gtk3::Entry
1460 my ($entry, $event) = @_;
1463 my $val = $event->get_keyval;
1465 if ($val == ord '.' ||
1466 $val == Gtk3
::Gdk
::KEY_ISO_Left_Tab
||
1467 $val == Gtk3
::Gdk
::KEY_Shift_L
||
1468 $val == Gtk3
::Gdk
::KEY_Tab
||
1469 $val == Gtk3
::Gdk
::KEY_Left
||
1470 $val == Gtk3
::Gdk
::KEY_Right
||
1471 $val == Gtk3
::Gdk
::KEY_BackSpace
||
1472 $val == Gtk3
::Gdk
::KEY_Delete
||
1473 ($val >= ord '0' && $val <= ord '9') ||
1474 ($val >= Gtk3
::Gdk
::KEY_KP_0
&&
1475 $val <= Gtk3
::Gdk
::KEY_KP_9
)) {
1482 sub create_text_input
{
1483 my ($default, $text) = @_;
1485 my $hbox = Gtk3
::HBox-
>new (0, 0);
1487 my $label = Gtk3
::Label-
>new ($text);
1488 $label->set_size_request (150, -1);
1489 $label->set_alignment (1, 0.5);
1490 $hbox->pack_start ($label, 0, 0, 10);
1491 my $e1 = Gtk3
::Entry-
>new ();
1492 $e1->set_width_chars (30);
1493 $hbox->pack_start ($e1, 0, 0, 0);
1494 $e1->set_text ($default);
1496 return ($hbox, $e1);
1501 my $ifconfig = `ifconfig eth0`;
1503 my ($addr) = $ifconfig =~ m/inet addr:(\S*)/m;
1504 my ($mask) = $ifconfig =~ m/Mask:(\S*)/m;
1506 my $route = `route -n`;
1507 my ($gateway) = $route =~ m/^0\.0\.0\.0\s+(\d+\.\d+\.\d+\.\d+)\s+/m;
1509 my $resolvconf = `cat /etc/resolv.conf`;
1510 my ($dnsserver) = $resolvconf =~ m/^nameserver\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/m;
1511 my ($domain) = $resolvconf =~ m/^domain\s+(\S+)$/m;
1516 gateway
=> $gateway,
1517 dnsserver
=> $dnsserver,
1522 sub display_message
{
1525 my $dialog = Gtk3
::MessageDialog-
>new ($window, 'modal',
1526 'info', 'ok', $msg);
1534 my $dialog = Gtk3
::MessageDialog-
>new ($window, 'modal',
1535 'error', 'ok', $msg);
1540 sub create_ipconf_view
{
1543 display_html
("ipconf.htm");
1545 my $vbox = Gtk3
::VBox-
>new (0, 0);
1546 $inbox->pack_start ($vbox, 1, 0, 0);
1547 my $hbox = Gtk3
::HBox-
>new (0, 0);
1548 $vbox->pack_start ($hbox, 0, 0, 10);
1549 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1550 $hbox->add ($vbox2);
1552 my $addr = $ipconf->{addr
} || '192.168.100.2';
1553 my $mask = $ipconf->{mask
} || '255.255.255.0';
1555 my $hn = $ipconf->{domain
} ?
"pve.$ipconf->{domain}" : 'pve.domain.tld';
1557 my ($hostbox, $hostentry) =
1558 create_text_input
($hn, 'Hostname (FQDN):');
1559 $vbox2->pack_start ($hostbox, 0, 0, 2);
1562 ($ipbox, $ipconf_entry_addr) =
1563 create_text_input
($addr, 'IP Address:');
1564 $vbox2->pack_start ($ipbox, 0, 0, 2);
1567 ($maskbox, $ipconf_entry_mask) =
1568 create_text_input
($mask, 'Netmask:');
1569 $vbox2->pack_start ($maskbox, 0, 0, 2);
1571 $gateway = $ipconf->{gateway
} || '192.168.100.1';
1574 ($gwbox, $ipconf_entry_gw) =
1575 create_text_input
($gateway, 'Gateway:');
1577 $vbox2->pack_start ($gwbox, 0, 0, 2);
1579 $dnsserver = $ipconf->{dnsserver
} || $gateway;
1582 ($dnsbox, $ipconf_entry_dns) =
1583 create_text_input
($dnsserver, 'DNS Server:');
1585 $vbox2->pack_start ($dnsbox, 0, 0, 0);
1588 set_next
(undef, sub {
1592 my $text = $hostentry->get_text();
1597 my $namere = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
1599 if ($text && $text =~ m/^(${namere}\.)*${namere}$/ && $text !~ m/.domain.tld$/ &&
1600 $text =~ m/^([^\.]+)\.(\S+)$/) {
1604 display_message
("Hostname does not look like a fully qualified domain name.");
1605 $hostentry->grab_focus();
1611 $text = $ipconf_entry_addr->get_text();
1614 if ($text =~ m!^($IPV4RE)$!) {
1617 display_message
("IP address is not valid.");
1618 $ipconf_entry_addr->grab_focus();
1622 $text = $ipconf_entry_mask->get_text();
1625 if (defined($ipv4_mask_hash->{$text})) {
1628 display_message
("Netmask is not valid.");
1629 $ipconf_entry_mask->grab_focus();
1633 $text = $ipconf_entry_gw->get_text();
1636 if ($text =~ m!^($IPV4RE)$!) {
1639 display_message
("Gateway is not valid.");
1640 $ipconf_entry_gw->grab_focus();
1644 $text = $ipconf_entry_dns->get_text();
1647 if ($text =~ m!^($IPV4RE)$!) {
1650 display_message
("DNS server is not valid.");
1651 $ipconf_entry_dns->grab_focus();
1655 #print "TEST $ipaddress $netmask $gateway $dnsserver\n";
1657 create_extract_view
();
1660 $hostentry->grab_focus();
1663 sub get_device_desc
{
1664 my ($devname, $size, $model) = @_;
1666 if ($size && ($size > 0)) {
1667 $size = int($size/2048); # size in MB
1669 my $text = "$devname (";
1670 if ($size >= 1024) {
1671 $size = int($size/1024); # size in GB
1672 $text .= "${size}GB";
1674 $text .= "${size}MB";
1677 $text .= ", $model" if $model;
1686 my ($cb, $kmap) = @_;
1691 my $kmaphash = $cmap->{kmaphash
};
1692 foreach my $layout (sort keys %$kmaphash) {
1693 $def = $i if $kmaphash->{$layout} eq 'en-us';
1694 $ind = $i if $kmap && $kmaphash->{$layout} eq $kmap;
1698 $cb->set_active ($ind || $def || 0);
1702 sub update_zonelist
{
1703 my ($box, $cc) = @_;
1705 my $cczones = $cmap->{cczones
};
1706 my $zones = $cmap->{zones
};
1710 $sel = $lastzonecb->get_active_text();
1711 $box->remove ($lastzonecb);
1713 $sel = $timezone; # used once to select default
1716 my $cb = $lastzonecb = Gtk3
::ComboBoxText-
>new();
1717 $cb->set_size_request (200, -1);
1719 $cb->signal_connect ('changed' => sub {
1720 $timezone = $cb->get_active_text();
1724 if ($cc && defined ($cczones->{$cc})) {
1725 @za = keys %{$cczones->{$cc}};
1731 foreach my $zone (sort @za) {
1732 $ind = $i if $sel && $zone eq $sel;
1733 $cb->append_text ($zone);
1737 $cb->set_active ($ind || 0);
1740 $box->pack_start ($cb, 0, 0, 0);
1743 sub create_password_view
{
1747 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1748 $inbox->pack_start ($vbox2, 1, 0, 0);
1749 my $vbox = Gtk3
::VBox-
>new (0, 0);
1750 $vbox2->pack_start ($vbox, 0, 0, 10);
1752 my $hbox1 = Gtk3
::HBox-
>new (0, 0);
1753 my $label = Gtk3
::Label-
>new ("Password");
1754 $label->set_size_request (150, -1);
1755 $label->set_alignment (1, 0.5);
1756 $hbox1->pack_start ($label, 0, 0, 10);
1757 my $pwe1 = Gtk3
::Entry-
>new ();
1758 $pwe1->set_visibility (0);
1759 $pwe1->set_size_request (200, -1);
1760 $hbox1->pack_start ($pwe1, 0, 0, 0);
1762 my $hbox2 = Gtk3
::HBox-
>new (0, 0);
1763 $label = Gtk3
::Label-
>new ("Confirm");
1764 $label->set_size_request (150, -1);
1765 $label->set_alignment (1, 0.5);
1766 $hbox2->pack_start ($label, 0, 0, 10);
1767 my $pwe2 = Gtk3
::Entry-
>new ();
1768 $pwe2->set_visibility (0);
1769 $pwe2->set_size_request (200, -1);
1770 $hbox2->pack_start ($pwe2, 0, 0, 0);
1772 my $hbox3 = Gtk3
::HBox-
>new (0, 0);
1773 $label = Gtk3
::Label-
>new ("E-Mail");
1774 $label->set_size_request (150, -1);
1775 $label->set_alignment (1, 0.5);
1776 $hbox3->pack_start ($label, 0, 0, 10);
1777 my $eme = Gtk3
::Entry-
>new ();
1778 $eme->set_size_request (200, -1);
1779 $hbox3->pack_start ($eme, 0, 0, 0);
1782 $vbox->pack_start ($hbox1, 0, 0, 5);
1783 $vbox->pack_start ($hbox2, 0, 0, 5);
1784 $vbox->pack_start ($hbox3, 0, 0, 15);
1788 display_html
("passwd.htm");
1790 set_next
(undef, sub {
1792 my $t1 = $pwe1->get_text;
1793 my $t2 = $pwe2->get_text;
1795 if (length ($t1) < 5) {
1796 display_message
("Password is too short.");
1797 $pwe1->grab_focus();
1802 display_message
("Password does not match.");
1803 $pwe1->grab_focus();
1807 my $t3 = $eme->get_text;
1808 if ($t3 !~ m/^\S+\@\S+\.\S+$/) {
1809 display_message
("E-Mail does not look like a vaild address" .
1810 " (user\@domain.tld)");
1819 create_ipconf_view
();
1822 $pwe1->grab_focus();
1826 sub create_country_view
{
1830 my $countryhash = $cmap->{countryhash
};
1831 my $ctr = $cmap->{country
};
1833 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
1834 $inbox->pack_start ($vbox2, 1, 0, 0);
1835 my $vbox = Gtk3
::VBox-
>new (0, 0);
1836 $vbox2->pack_start ($vbox, 0, 0, 10);
1838 my $w = Gtk3
::Entry-
>new ();
1839 $w->set_size_request (200, -1);
1841 my $c = Gtk3
::EntryCompletion-
>new ();
1842 $c->set_text_column (0);
1843 $c->set_minimum_key_length(0);
1844 $c->set_popup_set_width (1);
1845 $c->set_inline_completion (1);
1847 my $hbox2 = Gtk3
::HBox-
>new (0, 0);
1848 my $label = Gtk3
::Label-
>new ("Time zone");
1849 $label->set_size_request (150, -1);
1850 $label->set_alignment (1, 0.5);
1851 $hbox2->pack_start ($label, 0, 0, 10);
1852 update_zonelist
($hbox2);
1854 my $hbox3 = Gtk3
::HBox-
>new (0, 0);
1855 $label = Gtk3
::Label-
>new ("Keyboard Layout");
1856 $label->set_size_request (150, -1);
1857 $label->set_alignment (1, 0.5);
1858 $hbox3->pack_start ($label, 0, 0, 10);
1860 my $kmapcb = Gtk3
::ComboBoxText-
>new();
1861 $kmapcb->set_size_request (200, -1);
1862 foreach my $layout (sort keys %{$cmap->{kmaphash
}}) {
1863 $kmapcb->append_text ($layout);
1866 update_layout
($kmapcb);
1867 $hbox3->pack_start ($kmapcb, 0, 0, 0);
1869 $kmapcb->signal_connect ('changed' => sub {
1870 my $sel = $kmapcb->get_active_text();
1871 if (my $kmap = $cmap->{kmaphash
}->{$sel}) {
1872 my $xkmap = $cmap->{kmap
}->{$kmap}->{x11
};
1873 my $xvar = $cmap->{kmap
}->{$kmap}->{x11var
};
1874 syscmd
("setxkbmap $xkmap $xvar") if !$opt_testmode;
1879 $w->signal_connect ('changed' => sub {
1880 my ($entry, $event) = @_;
1881 my $text = $entry->get_text;
1883 if (my $cc = $countryhash->{lc($text)}) {
1884 update_zonelist
($hbox2, $cc);
1885 my $kmap = $ctr->{$cc}->{kmap
} || 'en-us';
1886 update_layout
($kmapcb, $kmap);
1890 $w->signal_connect (key_press_event
=> sub {
1891 my ($entry, $event) = @_;
1892 my $text = $entry->get_text;
1894 my $val = $event->get_keyval;
1896 if ($val == Gtk3
::Gdk
::KEY_Tab
) {
1897 my $cc = $countryhash->{lc($text)};
1904 $compl = $ctr->{$cc}->{name
};
1906 foreach my $cc (keys %$ctr) {
1907 my $ct = $ctr->{$cc}->{name
};
1908 if ($ct =~ m/^\Q$text\E.*$/i) {
1917 $entry->set_text($compl);
1922 print chr(7); # beep ?
1927 my $buf = $w->get_buffer();
1928 $buf->insert_text(-1, '', -1); # popup selection
1936 my $ls = Gtk3
::ListStore-
>new('Glib::String');
1937 foreach my $cc (sort {$ctr->{$a}->{name
} cmp $ctr->{$b}->{name
} } keys %$ctr) {
1938 my $iter = $ls->append();
1939 $ls->set ($iter, 0, $ctr->{$cc}->{name
});
1941 $c->set_model ($ls);
1943 $w->set_completion ($c);
1945 my $hbox = Gtk3
::HBox-
>new (0, 0);
1947 $label = Gtk3
::Label-
>new ("Country");
1948 $label->set_alignment (1, 0.5);
1949 $label->set_size_request (150, -1);
1950 $hbox->pack_start ($label, 0, 0, 10);
1951 $hbox->pack_start ($w, 0, 0, 0);
1953 $vbox->pack_start ($hbox, 0, 0, 5);
1954 $vbox->pack_start ($hbox2, 0, 0, 5);
1955 $vbox->pack_start ($hbox3, 0, 0, 5);
1958 $w->set_text ($ctr->{$country}->{name
});
1963 display_html
("country.htm");
1964 set_next
(undef, sub {
1966 my $text = $w->get_text;
1968 if (my $cc = $countryhash->{lc($text)}) {
1970 create_password_view
();
1973 display_message
("Please select a country first.");
1981 my $target_hd_combo;
1982 my $target_hd_label;
1984 my $hdopion_first_setup = 1;
1986 sub create_hdoption_view
{
1988 my $dialog = Gtk3
::Dialog-
>new();
1990 $dialog->set_title("Harddisk options");
1992 $dialog->add_button("_OK", 1);
1994 my $contarea = $dialog->get_content_area();
1996 my $hbox2 = Gtk3
::Box-
>new('horizontal', 0);
1997 $contarea->pack_start($hbox2, 1, 1, 10);
1999 my $grid = Gtk3
::Grid-
>new();
2000 $grid->set_column_spacing(10);
2001 $grid->set_row_spacing(10);
2003 $hbox2->pack_start($grid, 1, 0, 10);
2009 my $label0 = Gtk3
::Label-
>new ("Filesystem");
2010 $label0->set_alignment (1, 0.5);
2011 $grid->attach($label0, 0, $row, 1, 1);
2013 my $fstypecb = Gtk3
::ComboBoxText-
>new();
2015 my $fstype = ['ext3', 'ext4', 'zfs (RAID0)', 'zfs (RAID1)',
2016 'zfs (RAID10)', 'zfs (RAIDZ-1)',
2017 'zfs (RAIDZ-2)', 'zfs (RAIDZ-3)'];
2020 foreach my $tmp (@$fstype) {
2021 $fstypecb->append_text($tmp);
2022 $fstypecb->set_active ($tcount)
2023 if $config_options->{filesys
} eq $tmp;
2027 $grid->attach($fstypecb, 1, $row, 1, 1);
2035 for (my $i = 0; $i < 6; $i++) {
2036 $disk_label[$i] = Gtk3
::Label-
>new ("Hardisk $i");
2037 $disk_label[$i]->set_alignment (1, 0.5);
2038 $grid->attach($disk_label[$i], 0, $row, 1, 1);
2039 $disk_selector[$i] = Gtk3
::ComboBoxText-
>new();
2040 $disk_selector[$i]->append_text("-- do not use --");
2041 $disk_selector[$i]->set_active(0);
2042 foreach my $hd (@$hds) {
2043 my ($disk, $devname, $size, $model) = @$hd;
2044 $disk_selector[$i]->append_text(get_device_desc
($devname, $size, $model));
2045 $disk_selector[$i]->{pve_disk_id
} = $i;
2046 $disk_selector[$i]->signal_connect (changed
=> sub {
2048 my $diskid = $w->{pve_disk_id
};
2049 my $a = $w->get_active - 1;
2050 $config_options->{"disksel${diskid}"} = ($a >= 0) ?
$hds->[$a] : undef;
2054 if ($hdopion_first_setup) {
2055 $disk_selector[$i]->set_active ($i+1) if $hds->[$i];
2058 if (my $cur_hd = $config_options->{"disksel$i"}) {
2059 foreach my $hd (@$hds) {
2060 if (@$hd[1] eq @$cur_hd[1]) {
2061 $disk_selector[$i]->set_active($hdind+1);
2070 $grid->attach($disk_selector[$i], 1, $row, 1, 1);
2075 $hdopion_first_setup = 0;
2077 my $label_hdsize = Gtk3
::Label-
>new ("hdsize");
2078 $label_hdsize->set_alignment (1, 0.5);
2079 $grid->attach($label_hdsize, 0, $row, 1, 1);
2083 if ( -b
$target_hd) {
2084 $hdsize = int(hd_size
($target_hd) / (1024*1024.0)); # size in GB
2085 } elsif ($target_hd) {
2086 $hdsize = int((-s
$target_hd) / (1024*1024*1024.0));
2089 my $hdsize_size_adj = Gtk3
::Adjustment-
>new($config_options->{hdsize
} || $hdsize, 0, $hdsize+1, 1, 1, 1);
2090 my $spinbutton_hdsize = Gtk3
::SpinButton-
>new($hdsize_size_adj, 1, 1);
2091 $spinbutton_hdsize->set_tooltip_text("only use specified size (GB) of the harddisk (rest left unpartitioned)");
2092 $grid->attach($spinbutton_hdsize, 1, $row, 1, 1);
2095 my $label_swapsize = Gtk3
::Label-
>new ("swapsize");
2096 $label_swapsize->set_alignment (1, 0.5);
2097 $grid->attach($label_swapsize, 0, $row, 1, 1);
2099 my $entry_swapsize = Gtk3
::Entry-
>new();
2100 $entry_swapsize->set_tooltip_text("maximum SWAP size (GB)");
2101 $entry_swapsize->signal_connect (key_press_event
=> \
&check_float
);
2102 $entry_swapsize->set_text($config_options->{swapsize
}) if $config_options->{swapsize
};
2103 $grid->attach($entry_swapsize, 1, $row, 1, 1);
2106 my $label_maxroot = Gtk3
::Label-
>new ("maxroot");
2107 $label_maxroot->set_alignment (1, 0.5);
2108 $grid->attach($label_maxroot, 0, $row, 1, 1);
2110 my $entry_maxroot = Gtk3
::Entry-
>new();
2111 $entry_maxroot->set_tooltip_text("maximum size (GB) for LVM root volume");
2112 $entry_maxroot->signal_connect (key_press_event
=> \
&check_float
);
2113 $entry_maxroot->set_text($config_options->{maxroot
}) if $config_options->{maxroot
};
2114 $grid->attach($entry_maxroot, 1, $row, 1, 1);
2117 my $label_minfree = Gtk3
::Label-
>new ("minfree");
2118 $label_minfree->set_alignment (1, 0.5);
2119 $grid->attach($label_minfree, 0, $row, 1, 1);
2121 my $entry_minfree = Gtk3
::Entry-
>new();
2122 $entry_minfree->set_tooltip_text("minumum free LVM space (GB, required for LVM snapshots)");
2123 $entry_minfree->signal_connect (key_press_event
=> \
&check_float
);
2124 $entry_minfree->set_text($config_options->{minfree
}) if $config_options->{minfree
};
2125 $grid->attach($entry_minfree, 1, $row, 1, 1);
2128 my $label_maxvz = Gtk3
::Label-
>new ("maxvz");
2129 $label_maxvz->set_alignment (1, 0.5);
2130 $grid->attach($label_maxvz, 0, $row, 1, 1);
2132 my $entry_maxvz = Gtk3
::Entry-
>new();
2133 $entry_maxvz->set_tooltip_text("maximum size (GB) for LVM data volume");
2134 $entry_maxvz->signal_connect (key_press_event
=> \
&check_float
);
2135 $entry_maxvz->set_text($config_options->{maxvz
}) if $config_options->{maxvz
};
2136 $grid->attach($entry_maxvz, 1, $row, 1, 1);
2139 my $set_sensitive_flag = sub {
2140 my $enable_size_hints = $config_options->{filesys
} !~ m/zfs/;
2142 if ($config_options->{filesys
} =~ m/zfs/) {
2143 $target_hd_combo->set_visible(0);
2144 $target_hd_label->set_text("Target: $config_options->{filesys} ");
2145 foreach my $w (@disk_selector) { $w->set_visible(1); }
2146 foreach my $w (@disk_label) { $w->set_visible(1); }
2148 $target_hd_combo->set_visible(1);
2149 foreach my $w (@disk_selector) { $w->set_visible(0); }
2150 foreach my $w (@disk_label) { $w->set_visible(0); }
2151 $target_hd_label->set_text("Target Harddisk: ");
2154 $spinbutton_hdsize->set_visible($enable_size_hints);
2155 $label_hdsize->set_visible($enable_size_hints);
2156 $entry_swapsize->set_visible($enable_size_hints);
2157 $label_swapsize->set_visible($enable_size_hints);
2158 $entry_maxroot->set_visible($enable_size_hints);
2159 $label_maxroot->set_visible($enable_size_hints);
2160 $entry_minfree->set_visible($enable_size_hints);
2161 $label_minfree->set_visible($enable_size_hints);
2162 $entry_maxvz->set_visible($enable_size_hints);
2163 $label_maxvz->set_visible($enable_size_hints);
2166 &$set_sensitive_flag();
2168 $fstypecb->signal_connect (changed
=> sub {
2169 $config_options->{filesys
} = $fstypecb->get_active_text();
2170 &$set_sensitive_flag();
2177 my $get_float = sub {
2180 my $text = $entry->get_text();
2181 return undef if !defined($text);
2186 return undef if $text !~ m/^\d+(\.\d+)?$/;
2193 if (($tmp = &$get_float($spinbutton_hdsize)) && ($tmp != $hdsize)) {
2194 $config_options->{hdsize
} = $tmp;
2196 delete $config_options->{hdsize
};
2199 if (defined($tmp = &$get_float($entry_swapsize))) {
2200 $config_options->{swapsize
} = $tmp;
2202 delete $config_options->{swapsize
};
2205 if (defined($tmp = &$get_float($entry_maxroot))) {
2206 $config_options->{maxroot
} = $tmp;
2208 delete $config_options->{maxroot
};
2211 if (defined($tmp = &$get_float($entry_minfree))) {
2212 $config_options->{minfree
} = $tmp;
2214 delete $config_options->{minfree
};
2217 if (defined($tmp = &$get_float($entry_maxvz))) {
2218 $config_options->{maxvz
} = $tmp;
2220 delete $config_options->{maxvz
};
2226 sub get_zfs_raid_setup
{
2228 my $filesys = $config_options->{filesys
};
2230 my $dev_name_hash = {};
2233 my $bootdevlist = [];
2234 for (my $i = 0; $i < 6; $i++) {
2235 if (my $hd = $config_options->{"disksel$i"}) {
2236 my ($disk, $devname, $size, $model) = @$hd;
2237 die "device '$devname' is used more than once\n"
2238 if $dev_name_hash->{$devname};
2239 $dev_name_hash->{$devname} = $hd;
2240 push @$devlist, $hd;
2244 my $diskcount = scalar(@$devlist);
2245 die "$filesys need at least one device\n" if $diskcount < 1;
2248 if ($filesys eq 'zfs (RAID0)') {
2249 push @$bootdevlist, @$devlist[0];
2250 foreach my $hd (@$devlist) {
2253 } elsif ($filesys eq 'zfs (RAID1)') {
2254 die "zfs (RAID1) need at least 2 device\n" if $diskcount < 2;
2256 my $hd = @$devlist[0];
2257 my $expected_size = @$hd[2]; # all disks needs same size
2258 foreach $hd (@$devlist) {
2259 die "mirrored disks must have same size\n" if @$hd[2] != $expected_size;
2261 push @$bootdevlist, $hd;
2263 } elsif ($filesys eq 'zfs (RAID10)') {
2264 my $half = int($diskcount/2);
2265 die "zfs (RAID10) need at least 4 device\n" if $diskcount < 4;
2266 die "zfs (RAID10) need at an even numver of devices\n" if $half*2 != $diskcount;
2268 push @$bootdevlist, @$devlist[0], @$devlist[1];
2270 for (my $i = 0; $i < $diskcount; $i+=2) {
2271 my $hd1 = @$devlist[$i];
2272 my $hd2 = @$devlist[$i+1];
2273 die "mirrored disks must have same size\n" if @$hd1[2] != @$hd2[2];
2274 $cmd .= ' mirror ' . @$hd1[1] . ' ' . @$hd2[1];
2277 } elsif ($filesys =~ m/^zfs \(RAIDZ-([123])\)$/) {
2279 my $mindisks = 2 + $level;
2280 die "zfs (RAIDZ-$level) need at least $mindisks devices\n" if scalar(@$devlist) < $mindisks;
2281 my $hd = @$devlist[0];
2282 my $expected_size = @$hd[2]; # all disks needs same size
2283 $cmd .= " raidz$level";
2284 foreach $hd (@$devlist) {
2285 die "mirrored disks must have same size\n" if @$hd[2] != $expected_size;
2287 push @$bootdevlist, $hd;
2290 die "unknown zfs mode '$filesys'\n";
2293 return ($devlist, $bootdevlist, $cmd);
2296 sub create_hdsel_view
{
2300 my $vbox = Gtk3
::VBox-
>new (0, 0);
2301 $inbox->pack_start ($vbox, 1, 0, 0);
2302 my $hbox = Gtk3
::HBox-
>new (0, 0);
2303 $vbox->pack_start ($hbox, 0, 0, 10);
2305 my ($disk, $devname, $size, $model) = @{@$hds[0]};
2306 $target_hd = $devname;
2308 $target_hd_label = Gtk3
::Label-
>new ("Target Harddisk: ");
2309 $hbox->pack_start ($target_hd_label, 0, 0, 0);
2311 $target_hd_combo = Gtk3
::ComboBoxText-
>new();
2313 foreach my $hd (@$hds) {
2314 ($disk, $devname, $size, $model) = @$hd;
2315 $target_hd_combo->append_text (get_device_desc
($devname, $size, $model));
2318 $target_hd_combo->set_active (0);
2319 $target_hd_combo->signal_connect (changed
=> sub {
2320 $a = shift-
>get_active;
2321 my ($disk, $devname) = @{@$hds[$a]};
2322 $target_hd = $devname;
2325 $hbox->pack_start ($target_hd_combo, 0, 0, 10);
2327 my $options = Gtk3
::Button-
>new ('_Options');
2328 $options->signal_connect (clicked
=> \
&create_hdoption_view
);
2329 $hbox->pack_start ($options, 0, 0, 0);
2334 display_html
("page1.htm");
2336 set_next
(undef, sub {
2338 if ($config_options->{filesys
} =~ m/zfs/) {
2339 eval { get_zfs_raid_setup
(); };
2341 display_message
("Warning: $err\n" .
2342 "Please fix ZFS setup first.");
2344 create_country_view
();
2347 create_country_view
();
2352 sub create_extract_view
{
2356 display_html
("extract1-license.htm");
2357 $next->set_sensitive (0);
2359 my $vbox = Gtk3
::VBox-
>new (0, 0);
2360 $inbox->pack_start ($vbox, 1, 0, 0);
2361 my $hbox = Gtk3
::HBox-
>new (0, 0);
2362 $vbox->pack_start ($hbox, 0, 0, 10);
2364 my $vbox2 = Gtk3
::VBox-
>new (0, 0);
2365 $hbox->pack_start ($vbox2, 0, 0, 0);
2367 $progress_status = Gtk3
::Label-
>new ('');
2368 $vbox2->pack_start ($progress_status, 1, 1, 0);
2370 $progress = Gtk3
::ProgressBar-
>new;
2371 $progress->set_show_text(1);
2372 $progress->set_size_request (600, -1);
2374 $vbox2->pack_start ($progress, 0, 0, 0);
2378 my $tdir = $opt_testmode ?
"target" : "/target";
2380 my $base = $opt_testmode ?
"/pve/$release/install/pve-base.tar" : "/proxmox/pve-base.tar";
2382 eval { extract_data
($base, $tdir); };
2385 $next->set_sensitive (1);
2387 set_next
("_Reboot", sub { exit (0); } );
2390 display_html
("fail.htm");
2391 display_error
($err);
2394 display_html
("success.htm");
2398 sub create_intro_view
{
2402 display_html
("license.htm");
2404 set_next
("I a_gree", \
&create_hdsel_view
);
2407 $ipconf = get_ip_config
();
2409 $country = detect_country
() if $ipconf->{addr
} || $opt_testmode;;
2411 # read country, kmap and timezone infos
2412 $cmap = read_cmap
();
2414 create_main_window
();
2416 if (!defined ($hds) || (scalar (@$hds) <= 0)) {
2417 print "no hardisks found\n";
2418 display_html
("nohds.htm");
2419 set_next
("Reboot", sub { exit (0); } );
2422 foreach my $hd (@$hds) {
2423 my ($disk, $devname) = @$hd;
2424 next if $devname =~ m
|^/dev/md\d
+$|;
2425 print "found Disk$disk N:$devname\n";
2428 create_intro_view
();