]> git.proxmox.com Git - pve-installer.git/blobdiff - proxinstall
factor out storage config generation and handling
[pve-installer.git] / proxinstall
index c6da822859f6962ced7d42df8c813d0fc35d294c..908b719299608dd370050bba0d3fe8da9f29452f 100755 (executable)
@@ -3,9 +3,6 @@
 use strict;
 use warnings;
 
-$ENV{DEBIAN_FRONTEND} = 'noninteractive';
-$ENV{LC_ALL} = 'C';
-
 use Getopt::Long;
 use IPC::Open2;
 use IO::File;
@@ -19,12 +16,18 @@ use File::Path;
 use Time::HiRes;
 use POSIX ":sys_wait_h";
 
-use Proxmox::Install::Env;
 use Proxmox::Log;
-use Proxmox::Sys::Block qw(get_cached_disks);
+Proxmox::Log::init("/tmp/install.log");
+
+use Proxmox::Install::ISOEnv;
+use Proxmox::Install::RunEnv;
+use Proxmox::Install::StorageConfig;
+
+use Proxmox::Sys::Block qw(get_cached_disks wipe_disk partition_bootable_disk);
 use Proxmox::Sys::Command qw(run_command syscmd);
 use Proxmox::Sys::File qw(file_read_firstline file_read_all file_write_all);
 use Proxmox::Sys::Net qw(parse_ip_address parse_ip_mask);
+use Proxmox::UI;
 
 if (!$ENV{G_SLICE} ||  $ENV{G_SLICE} ne "always-malloc") {
     die "do not use slice allocator (run with 'G_SLICE=always-malloc ./proxinstall ...')\n";
@@ -36,64 +39,16 @@ if (!$ENV{G_SLICE} ||  $ENV{G_SLICE} ne "always-malloc") {
        'test-image|t=s' => \$test_image
     ) or die "usage error\n";
 
-    Proxmox::Install::Env::set_test_image($test_image) if $test_image;
+    Proxmox::Install::ISOEnv::set_test_image($test_image) if $test_image;
 }
 
-$ENV{'LVM_SUPPRESS_FD_WARNINGS'} = '1';
-
-my $env = Proxmox::Install::Env::setup();
-
-my $zfstestpool = "test_rpool";
-my $zfspoolname = is_test_mode() ? $zfstestpool : 'rpool';
-my $zfsrootvolname = "$env->{product}-1";
-
-my $storage_cfg_zfs = <<__EOD__;
-dir: local
-       path /var/lib/vz
-       content iso,vztmpl,backup
-
-zfspool: local-zfs
-       pool $zfspoolname/data
-       sparse
-       content images,rootdir
-__EOD__
-
-my $storage_cfg_btrfs = <<__EOD__;
-dir: local
-       path /var/lib/vz
-       content iso,vztmpl,backup
-       disable
-
-btrfs: local-btrfs
-       path /var/lib/pve/local-btrfs
-       content iso,vztmpl,backup,images,rootdir
-__EOD__
-
-my $storage_cfg_lvmthin = <<__EOD__;
-dir: local
-       path /var/lib/vz
-       content iso,vztmpl,backup
-
-lvmthin: local-lvm
-       thinpool data
-       vgname pve
-       content rootdir,images
-__EOD__
-
-my $storage_cfg_local = <<__EOD__;
-dir: local
-       path /var/lib/vz
-       content iso,vztmpl,backup,rootdir,images
-__EOD__
+my $iso_env = Proxmox::Install::ISOEnv::get(); # init singleton
+my $run_env = Proxmox::Install::RunEnv::query_installation_environment();
 
-Proxmox::Log::init("/tmp/install.log");
-
-my $proxmox_libdir = $env->{locations}->{lib};
-my $proxmox_cddir = $env->{locations}->{iso};
+my $proxmox_libdir = $iso_env->{locations}->{lib};
+my $proxmox_cddir = $iso_env->{locations}->{iso};
 my $proxmox_pkgdir = "${proxmox_cddir}/proxmox/packages/";
 
-my $boot_type = -d '/sys/firmware/efi' ? 'efi' : 'bios';
-
 my $step_number = 0; # Init number for global function list
 
 my @steps = (
@@ -137,10 +92,9 @@ my @steps = (
 );
 
 # GUI global variables
-my ($window, $cmdbox, $inbox, $htmlview);
-my $prev_btn;
-my ($next, $next_fctn, $target_hd);
-my ($progress, $progress_status);
+my $gtk_state = {};
+
+my $target_hd;
 
 my ($ipversion, $ipaddress, $cidr, $ipconf_entry_addr);
 my ($netmask, $ipconf_entry_mask);
@@ -150,12 +104,11 @@ my $hostname = 'proxmox';
 my $domain = 'domain.tld';
 my $cmdline = file_read_firstline("/proc/cmdline");
 my $ipconf;
-my $country;
+my $country = $run_env->{country};
 my $timezone = 'Europe/Vienna';
 my $keymap = 'en-us';
 my $password;
 my $mailto = 'mail@example.invalid';
-my $cmap;
 my $autoreboot_seconds = 5;
 
 my $config = {
@@ -203,7 +156,7 @@ if ($cmdline =~ m/minfree=(\d+(\.\d+)?)[\s\n]/i) {
     $config_options->{minfree} = $1;
 }
 
-if ($env->{product} eq 'pve') {
+if ($iso_env->{product} eq 'pve') {
     if ($cmdline =~ m/maxvz=(\d+(\.\d+)?)[\s\n]/i) {
        $config_options->{maxvz} = $1;
     }
@@ -236,135 +189,26 @@ compatibility_level = 2
 _EOD
 
 
-sub detect_country {
-
-    print "trying to detect country...\n";
-    my $cpid = open2(\*TMP, undef, "traceroute -N 1 -q 1 -n 8.8.8.8");
-    return undef if !$cpid;
-
-    my $country;
-
-    my $previous_alarm = alarm (10);
-    eval  {
-       local $SIG{ALRM} = sub { die "timed out!\n" };
-       my $line;
-       while (defined ($line = <TMP>)) {
-           log_debug("DC TRACEROUTE: $line");
-           if ($line =~ m/\s*\d+\s+(\d+\.\d+\.\d+\.\d+)\s/) {
-               my $geoip = `geoiplookup $1`;
-               log_debug("DC GEOIP: $geoip");
-               if ($geoip =~ m/GeoIP Country Edition:\s*([A-Z]+),/) {
-                   $country = lc ($1);
-                   log_info("DC FOUND: $country\n");
-                   last;
-               }
-           }
-       }
-    };
-
-    my $err = $@;
-
-    alarm ($previous_alarm);
-
-    close (TMP);
-
-    if ($err) {
-       print "unable to detect country - $err\n";
-    } elsif ($country) {
-       print "detected country: " . uc($country) . "\n";
-    } else {
-       print "unable to detect country\n";
-    }
-
-    return $country;
-}
-
-sub get_memtotal {
+sub app_quit {
+    my ($exit_code) = @_;
 
-    open (my $MEMINFO, '<', '/proc/meminfo');
+    Gtk3->main_quit() if Gtk3->main_level() > 0;
 
-    my $res = 512; # default to 512 if something goes wrong
-    while (my $line = <$MEMINFO>) {
-       if ($line =~ m/^MemTotal:\s+(\d+)\s*kB/i) {
-           $res = int ($1 / 1024);
-       }
-    }
-
-    close($MEMINFO);
-
-    return $res;
-}
-
-my $total_memory = get_memtotal();
-
-sub read_cmap {
-    my $countryfn = "${proxmox_libdir}/country.dat";
-    open (my $TMP, "<:encoding(utf8)", "$countryfn") || die "unable to open '$countryfn' - $!\n";
-    my ($country, $countryhash, $kmap, $kmaphash) = ({}, {}, {}, {});
-    while (defined (my $line = <$TMP>)) {
-       if ($line =~ m|^map:([^\s:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]*):$|) {
-           $kmap->{$1} = {
-               name => $2,
-               kvm => $3,
-               console => $4,
-               x11 => $5,
-               x11var => $6,
-           };
-           $kmaphash->{$2} = $1;
-       } elsif ($line =~ m|^([a-z]{2}):([^:]+):([^:]*):([^:]*):$|) {
-           $country->{$1} = {
-               name => $2,
-               kmap => $3,
-               mirror => $4,
-           };
-           $countryhash->{lc($2)} = $1;
-       } else {
-           warn "unable to parse 'country.dat' line: $line";
-       }
-    }
-    close ($TMP);
-    $TMP = undef;
-
-    my $zones = {};
-    my $cczones = {};
-    my $zonefn = "/usr/share/zoneinfo/zone.tab";
-    open ($TMP, '<', "$zonefn") || die "unable to open '$zonefn' - $!\n";
-    while (defined (my $line = <$TMP>)) {
-       next if $line =~ m/^\#/;
-       next if $line =~ m/^\s*$/;
-       if ($line =~ m|^([A-Z][A-Z])\s+\S+\s+(([^/]+)/\S+)\s|) {
-           my $cc = lc($1);
-           $cczones->{$cc}->{$2} = 1;
-           $country->{$cc}->{zone} = $2 if !defined ($country->{$cc}->{zone});
-           $zones->{$2} = 1;
-
-       }
-    }
-    close ($TMP);
-
-    return {
-       zones => $zones,
-       cczones => $cczones,
-       country => $country,
-       countryhash => $countryhash,
-       kmap => $kmap,
-       kmaphash => $kmaphash,
+    # reap left over zombie processes
+    while ((my $child = waitpid(-1, POSIX::WNOHANG)) > 0) {
+       print STDERR "reaped child $child\n";
     }
+    exit($exit_code);
 }
 
 sub update_progress {
     my ($frac, $start, $end, $text) = @_;
 
-    my $part = $end - $start;
-    my $res = $start + $frac * $part;
-
-    $progress->set_fraction ($res);
-    $progress->set_text (sprintf ("%d%%", int ($res*100)));
-    $progress_status->set_text ($text) if defined ($text);
+    my $res = Proxmox::UI::progress($frac, $start, $end, $text);
 
     display_info() if $res < 0.9;
 
-    Gtk3::main_iteration() while Gtk3::events_pending();
+    Proxmox::UI::process_events();
 }
 
 my $fssetup = {
@@ -455,41 +299,41 @@ sub btrfs_create {
 }
 
 sub zfs_create_rpool {
-    my ($vdev) = @_;
+    my ($vdev, $pool_name, $root_volume_name) = @_;
 
     my $cmd = "zpool create -f -o cachefile=none";
 
     $cmd .= " -o ashift=$config_options->{ashift}"
         if defined($config_options->{ashift});
 
-    syscmd("$cmd $zfspoolname $vdev") == 0 ||
+    syscmd("$cmd $pool_name $vdev") == 0 ||
        die "unable to create zfs root pool\n";
 
-    syscmd("zfs create $zfspoolname/ROOT")  == 0 ||
-        die "unable to create zfs $zfspoolname/ROOT volume\n";
+    syscmd("zfs create $pool_name/ROOT")  == 0 ||
+        die "unable to create zfs $pool_name/ROOT volume\n";
 
-    if ($env->{product} eq 'pve') {
-       syscmd("zfs create $zfspoolname/data")  == 0 ||
-           die "unable to create zfs $zfspoolname/data volume\n";
+    if ($iso_env->{product} eq 'pve') {
+       syscmd("zfs create $pool_name/data")  == 0 ||
+           die "unable to create zfs $pool_name/data volume\n";
     }
 
-    syscmd("zfs create $zfspoolname/ROOT/$zfsrootvolname")  == 0 ||
-       die "unable to create zfs $zfspoolname/ROOT/$zfsrootvolname volume\n";
+    syscmd("zfs create $pool_name/ROOT/$root_volume_name")  == 0 ||
+       die "unable to create zfs $pool_name/ROOT/$root_volume_name volume\n";
 
     # default to `relatime` on, fast enough for the installer and production
-    syscmd("zfs set atime=on relatime=on $zfspoolname") == 0 ||
+    syscmd("zfs set atime=on relatime=on $pool_name") == 0 ||
        die "unable to set zfs properties\n";
 
     my $value = $config_options->{compress};
-    syscmd("zfs set compression=$value $zfspoolname")
+    syscmd("zfs set compression=$value $pool_name")
         if defined($value) && $value ne 'off';
 
     $value = $config_options->{checksum};
-    syscmd("zfs set checksum=$value $zfspoolname")
+    syscmd("zfs set checksum=$value $pool_name")
         if defined($value) && $value ne 'on';
 
     $value = $config_options->{copies};
-    syscmd("zfs set copies=$value $zfspoolname")
+    syscmd("zfs set copies=$value $pool_name")
         if defined($value) && $value != 1;
 }
 
@@ -539,7 +383,7 @@ sub ask_existing_vg_rename_or_abort {
     }
     $message .= "or cancel the installation?";
 
-    my $response = display_prompt($message);
+    my $response = Proxmox::UI::prompt($message);
 
     if ($response eq 'ok') {
        for my $vg_uuid (keys %$duplicate_vgs) {
@@ -550,16 +394,15 @@ sub ask_existing_vg_rename_or_abort {
                die "could not rename VG from '$vg->{pvs}' ($vg_uuid) to '$new_vgname'!\n";
        }
     } else {
-       set_next("_Reboot", sub { exit (0); } );
-       display_html("fail.htm");
-       die "Cancled installation by user, due to already existing volume group '$vgname'\n";
+       warn "Canceled installation by user, due to already existing volume group '$vgname'\n";
+       die "\n"; # causes abort without re-showing an error dialogue
     }
 }
 
 sub create_lvm_volumes {
     my ($lvmdev, $os_size, $swap_size) = @_;
 
-    my $vgname = $env->{product};
+    my $vgname = $iso_env->{product};
 
     ask_existing_vg_rename_or_abort($vgname);
 
@@ -583,7 +426,7 @@ sub create_lvm_volumes {
     my $rootsize;
     my $datasize = 0;
 
-    if ($env->{product} eq 'pve') {
+    if ($iso_env->{product} eq 'pve') {
 
        my $maxroot_mb;
        if ($config_options->{maxroot}) {
@@ -657,8 +500,8 @@ sub create_lvm_volumes {
        syscmd("/sbin/lvconvert --yes --type thin-pool --poolmetadatasize ${metadatasize}K $vgname/data") == 0 ||
            die "unable to create data thin-pool\n";
     } else {
-       if ($env->{product} eq 'pve' && !defined($config_options->{maxvz})) {
-           display_message("Skipping auto-creation of LVM thinpool for guest data due to low space.");
+       if ($iso_env->{product} eq 'pve' && !defined($config_options->{maxvz})) {
+           Proxmox::UI::message("Skipping auto-creation of LVM thinpool for guest data due to low space.");
        }
        $datadev = undef;
     }
@@ -678,7 +521,7 @@ sub compute_swapsize {
     if (defined($config_options->{swapsize})) {
        $swapsize_kb = $config_options->{swapsize} * 1024 * 1024;
     } else {
-       my $ss = int($total_memory);
+       my $ss = int($run_env->{total_memory});
        $ss = 4096 if $ss < 4096 && $hdgb >= 64;
        $ss = 2048 if $ss < 2048 && $hdgb >= 32;
        $ss = 1024 if $ss >= 2048 && $hdgb <= 16;
@@ -730,7 +573,7 @@ sub prepare_grub_efi_boot_esp {
     eval {
        my $rc = syscmd("chroot $targetdir /usr/sbin/grub-install --target x86_64-efi --no-floppy --bootloader-id='proxmox' $dev");
        if ($rc != 0) {
-           if ($boot_type eq 'efi') {
+           if ($run_env->{boot_type} eq 'efi') {
                die "unable to install the EFI boot loader on '$dev'\n";
            } else {
                warn "unable to install the EFI boot loader on '$dev', ignoring (not booted using UEFI)\n";
@@ -761,19 +604,18 @@ sub extract_data {
 
     my $bootdevinfo = [];
 
-    my $swapfile;
-    my $rootdev;
-    my $datadev;
-
-    my $use_zfs = 0;
-    my $use_btrfs = 0;
+    my ($swapfile, $rootdev, $datadev);
+    my ($use_zfs, $use_btrfs) = (0, 0);
 
     my $filesys = $config_options->{filesys};
 
+    my $zfs_pool_name = Proxmox::Install::StorageConfig::get_zfs_pool_name();
+    my $zfs_root_volume_name = Proxmox::Install::StorageConfig::get_zfs_root_volume_name();
+
     if ($filesys =~ m/zfs/) {
        $target_hd = undef; # do not use this config
        $use_zfs = 1;
-       $targetdir = "/$zfspoolname/ROOT/$zfsrootvolname";
+       $targetdir = "/$zfs_pool_name/ROOT/$zfs_root_volume_name";
     } elsif ($filesys =~ m/btrfs/) {
        $target_hd = undef; # do not use this config
        $use_btrfs = 1;
@@ -801,7 +643,7 @@ sub extract_data {
 
        if (is_test_mode()) {
 
-           my $test_images = Proxmox::Install::Env::get_test_images();
+           my $test_images = Proxmox::Install::ISOEnv::get_test_images();
            $rootdev = abs_path($test_images->[0]); # FIXME: use all selected for test too!
            syscmd("umount $rootdev");
 
@@ -817,9 +659,9 @@ sub extract_data {
                die "unsupported zfs mode (for testing environment)\n"
                    if $filesys ne 'zfs (RAID0)';
 
-               syscmd("zpool destroy $zfstestpool");
+               syscmd("zpool destroy $zfs_pool_name");
 
-               zfs_create_rpool($rootdev);
+               zfs_create_rpool($rootdev, $zfs_pool_name, $zfs_root_volume_name);
 
            } else {
 
@@ -907,7 +749,7 @@ sub extract_data {
 
            update_progress(0, 0.03, $maxper, "create rpool");
 
-           zfs_create_rpool($vdev);
+           zfs_create_rpool($vdev, $zfs_pool_name);
 
        } else {
 
@@ -917,7 +759,7 @@ sub extract_data {
 
            update_progress(0, 0.02, $maxper, "create partitions");
 
-           my $logical_bsize = logical_blocksize($target_hd);
+           my $logical_bsize = Proxmox::Sys::Block::logical_blocksize($target_hd);
 
            my ($os_size, $osdev, $efidev) =
                partition_bootable_disk($target_hd, $config_options->{hdsize}, '8E00');
@@ -945,7 +787,7 @@ sub extract_data {
 
        if ($use_zfs) {
            # to be fast during installation
-           syscmd("zfs set sync=disabled $zfspoolname") == 0 ||
+           syscmd("zfs set sync=disabled $zfs_pool_name") == 0 ||
                die "unable to set zfs properties\n";
        }
 
@@ -992,7 +834,7 @@ sub extract_data {
        mkdir "$targetdir/var";
        mkdir "$targetdir/var/lib";
 
-       if ($env->{product} eq 'pve') {
+       if ($iso_env->{product} eq 'pve') {
            mkdir "$targetdir/var/lib/vz";
            mkdir "$targetdir/var/lib/pve";
 
@@ -1012,7 +854,7 @@ sub extract_data {
        my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = stat ($basefile);
        $ino || die "unable to open file '$basefile' - $!\n";
 
-       my $files = file_read_firstline("${proxmox_cddir}/proxmox/$env->{product}-base.cnt") ||
+       my $files = file_read_firstline("${proxmox_cddir}/proxmox/$iso_env->{product}-base.cnt") ||
            die "unable to read base file count\n";
 
        my $per = 0;
@@ -1037,7 +879,7 @@ sub extract_data {
            || die "unable to bind-mount packages on $targetdir/tmp/pkg\n";
        syscmd("mount -n -t proc proc $targetdir/proc") == 0 || die "unable to mount proc on $targetdir/proc\n";
        syscmd("mount -n -t sysfs sysfs $targetdir/sys") == 0 || die "unable to mount sysfs on $targetdir/sys\n";
-       if ($boot_type eq 'efi') {
+       if ($run_env->{boot_type} eq 'efi') {
            syscmd("mount -n -t efivarfs efivarfs $targetdir/sys/firmware/efi/efivars") == 0 ||
                die "unable to mount efivarfs on $targetdir/sys/firmware/efi/efivars: $!\n";
        }
@@ -1073,7 +915,7 @@ sub extract_data {
 
        my $ethdev = $ipconf->{ifaces}->{$ipconf->{selected}}->{name};
 
-       if ($env->{cfg}->{bridged_network}) {
+       if ($iso_env->{cfg}->{bridged_network}) {
            $ifaces .= "iface $ethdev $ntype manual\n";
 
            $ifaces .=
@@ -1133,7 +975,7 @@ sub extract_data {
        # Note: this is required by current grub, but really dangerous, because
        # vfat does not have journaling, so it triggers manual fsck after each crash
        # so we only mount /boot/efi if really required (efi systems).
-       if ($boot_type eq 'efi' && !$use_zfs) {
+       if ($run_env->{boot_type} eq 'efi' && !$use_zfs) {
            if (scalar(@$bootdevinfo)) {
                my $di = @$bootdevinfo[0]; # simply use first disk
 
@@ -1181,7 +1023,7 @@ sub extract_data {
        }
 
        # Note: keyboard-configuration/xbkb-keymap is used by console-setup
-       my $xkmap = $cmap->{kmap}->{$keymap}->{x11} // 'us';
+       my $xkmap = $iso_env->{locales}->{kmap}->{$keymap}->{x11} // 'us';
 
        debconfig_set ($targetdir, <<_EOD);
 locales locales/default_environment_locale select en_US.UTF-8
@@ -1206,7 +1048,7 @@ _EOD
            my $path = $_;
            my ($deb) = $path =~ m/${proxmox_pkgdir}\/(.*\.deb)/;
            update_progress($count/$pkg_count, 0.5, 0.75, "extracting $deb");
-           print "extracting: $deb\n";
+           print STDERR "extracting: $deb\n";
            syscmd("chroot $targetdir dpkg $dpkg_opts --force-depends --no-triggers --unpack /tmp/pkg/$deb") == 0
                || die "installation of package $deb failed\n";
            update_progress((++$count)/$pkg_count, 0.5, 0.75);
@@ -1243,7 +1085,7 @@ _EOD
        file_write_all("$targetdir/etc/timezone", "$timezone\n");
 
        # set apt mirror
-       if (my $mirror = $cmap->{country}->{$country}->{mirror}) {
+       if (my $mirror = $iso_env->{locales}->{country}->{$country}->{mirror}) {
            my $fn = "$targetdir/etc/apt/sources.list";
            syscmd("sed -i 's/ftp\\.debian\\.org/$mirror/' '$fn'");
        }
@@ -1255,7 +1097,7 @@ _EOD
        # allow ssh root login
        syscmd(['sed', '-i', 's/^#\?PermitRootLogin.*/PermitRootLogin yes/', "$targetdir/etc/ssh/sshd_config"]);
 
-       if ($env->{product} eq 'pmg') {
+       if ($iso_env->{product} eq 'pmg') {
            # install initial clamav DB
            my $srcdir = "${proxmox_cddir}/proxmox/clamav";
            foreach my $fn ("main.cvd", "bytecode.cvd", "daily.cvd", "safebrowsing.cvd") {
@@ -1266,7 +1108,7 @@ _EOD
                die "unable to set owner for clamav database files\n";
        }
 
-       if ($env->{product} eq 'pve') {
+       if ($iso_env->{product} eq 'pve') {
            # save installer settings
            my $ucc = uc ($country);
            debconfig_set($targetdir, "pve-manager pve-manager/country string $ucc\n");
@@ -1276,10 +1118,10 @@ _EOD
 
        if ($use_zfs) {
            # add ZFS options while preserving existing kernel cmdline
-           my $zfs_snippet = "GRUB_CMDLINE_LINUX=\"\$GRUB_CMDLINE_LINUX root=ZFS=$zfspoolname/ROOT/$zfsrootvolname boot=zfs\"";
+           my $zfs_snippet = "GRUB_CMDLINE_LINUX=\"\$GRUB_CMDLINE_LINUX root=ZFS=$zfs_pool_name/ROOT/$zfs_root_volume_name boot=zfs\"";
            file_write_all("$targetdir/etc/default/grub.d/zfs.cfg", $zfs_snippet);
 
-           file_write_all("$targetdir/etc/kernel/cmdline", "root=ZFS=$zfspoolname/ROOT/$zfsrootvolname boot=zfs\n");
+           file_write_all("$targetdir/etc/kernel/cmdline", "root=ZFS=$zfs_pool_name/ROOT/$zfs_root_volume_name boot=zfs\n");
 
        }
 
@@ -1324,13 +1166,11 @@ _EOD
                            push @$bootloader_err_list, $@ if $@;
                        }
 
-                   eval {
                        if (my $esp = $di->{esp}) {
-                               prepare_grub_efi_boot_esp($dev, $esp, $targetdir);
-                           }
+                           eval { prepare_grub_efi_boot_esp($dev, $esp, $targetdir) };
+                           push @$bootloader_err_list, $@ if $@;
                        }
-                   };
-                   push @$bootloader_err_list, $@ if $@;
+                   }
                }
 
                syscmd("chroot $targetdir /usr/sbin/update-grub") == 0 ||
@@ -1358,11 +1198,11 @@ _EOD
        run_command("chroot $targetdir /usr/sbin/chpasswd", undef,
                    "root:$octets\n");
 
-       if ($env->{product} eq 'pmg') {
+       if ($iso_env->{product} eq 'pmg') {
            # save admin email
            file_write_all("$targetdir/etc/pmg/pmg.conf", "section: admin\n\temail ${mailto}\n");
 
-       } elsif ($env->{product} eq 'pve') {
+       } elsif ($iso_env->{product} eq 'pve') {
 
            # create pmxcfs DB
 
@@ -1370,7 +1210,7 @@ _EOD
            mkdir $tmpdir;
 
            # write vnc keymap to datacenter.cfg
-           my $vnckmap = $cmap->{kmap}->{$keymap}->{kvm} || 'en-us';
+           my $vnckmap = $iso_env->{locales}->{kmap}->{$keymap}->{kvm} || 'en-us';
            file_write_all("$tmpdir/datacenter.cfg", "keyboard: $vnckmap\n");
 
            # save admin email
@@ -1379,20 +1219,20 @@ _EOD
            # write storage.cfg
            my $storage_cfg;
            if ($use_zfs) {
-               $storage_cfg = $storage_cfg_zfs;
+               $storage_cfg = Proxmox::Install::StorageConfig::get_zfs_config($iso_env);
            } elsif ($use_btrfs) {
-               $storage_cfg = $storage_cfg_btrfs;
+               $storage_cfg = Proxmox::Install::StorageConfig::get_btrfs_config();
            } elsif ($datadev) {
-               $storage_cfg = $storage_cfg_lvmthin;
+               $storage_cfg = Proxmox::Install::StorageConfig::get_lvm_thin_config();
            } else {
-               $storage_cfg = $storage_cfg_local;
+               $storage_cfg = Proxmox::Install::StorageConfig::get_local_config();
            }
            file_write_all("$tmpdir/storage.cfg", $storage_cfg);
 
            run_command("chroot $targetdir /usr/bin/create_pmxcfs_db /tmp/pve /var/lib/pve-cluster/config.db");
 
            syscmd("rm -rf $tmpdir");
-       } elsif ($env->{product} eq 'pbs') {
+       } elsif ($iso_env->{product} eq 'pbs') {
            my $base_cfg_path = "/etc/proxmox-backup";
            mkdir "$targetdir/$base_cfg_path";
 
@@ -1410,11 +1250,11 @@ _EOD
 
     update_progress(1, 0, 1, "");
 
-    print $err if $err;
+    print STDERR $err if $err && $err ne "\n";
 
     if (is_test_mode()) {
        my $elapsed = Time::HiRes::tv_interval($starttime);
-       print "Elapsed extract time: $elapsed\n";
+       print STDERR "Elapsed extract time: $elapsed\n";
 
        syscmd("chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> final.pkglist");
     }
@@ -1436,19 +1276,19 @@ _EOD
     }
 
     if (!$err && $use_zfs) {
-       syscmd("zfs set sync=standard $zfspoolname") == 0 ||
+       syscmd("zfs set sync=standard $zfs_pool_name") == 0 ||
            die "unable to set zfs properties\n";
 
-       syscmd("zfs set mountpoint=/ $zfspoolname/ROOT/$zfsrootvolname") == 0 ||
+       syscmd("zfs set mountpoint=/ $zfs_pool_name/ROOT/$zfs_root_volume_name") == 0 ||
            die "zfs set mountpoint failed\n";
 
-       syscmd("zpool set bootfs=$zfspoolname/ROOT/$zfsrootvolname $zfspoolname") == 0 ||
+       syscmd("zpool set bootfs=$zfs_pool_name/ROOT/$zfs_root_volume_name $zfs_pool_name") == 0 ||
            die "zpool set bootfs failed\n";
-       syscmd("zpool export $zfspoolname");
+       syscmd("zpool export $zfs_pool_name");
     }
 
     if ($bootloader_err) {
-       $err = $err ? "$err\n$bootloader_err" : $bootloader_err;
+       $err = $err && $err ne "\n" ? "$err\n$bootloader_err" : $bootloader_err;
     }
 
     die $err if $err;
@@ -1476,49 +1316,7 @@ sub display_info {
     my $page = $display_info_items->[$display_info_counter % scalar(@$display_info_items)];
 
     $display_info_counter++;
-
-    display_html($page);
-}
-
-sub display_html {
-    my ($filename) = @_;
-
-    $filename = $steps[$step_number]->{html} if !$filename;
-
-    my $htmldir = "${proxmox_libdir}/html";
-    my $path;
-    if (-f "$htmldir/$env->{product}/$filename") {
-       $path = "$htmldir/$env->{product}/$filename";
-    } else {
-       $path = "$htmldir/$filename";
-    }
-
-    my $data = file_read_all($path);
-
-    if ($filename eq 'license.htm') {
-       my $license = eval { decode('utf8', file_read_all("${proxmox_cddir}/EULA")) };
-       if (my $err = $@) {
-           die $err if !is_test_mode();
-           $license = "TESTMODE: Ignore non existent EULA...\n";
-       }
-       my $title = "END USER LICENSE AGREEMENT (EULA)";
-       $data =~ s/__LICENSE__/$license/;
-       $data =~ s/__LICENSE_TITLE__/$title/;
-    } elsif ($filename eq 'success.htm') {
-       my $addr = $ipversion == 6 ? "[${ipaddress}]" : "$ipaddress";
-       $data =~ s/__IPADDR__/$addr/g;
-       $data =~ s/__PORT__/$env->{cfg}->{port}/g;
-
-       my $autoreboot_msg = $config_options->{autoreboot}
-           ? "Automatic reboot scheduled in $autoreboot_seconds seconds."
-           : '';
-       $data =~ s/__AUTOREBOOT_MSG__/$autoreboot_msg/;
-    }
-    $data =~ s/__FULL_PRODUCT_NAME__/$env->{cfg}->{fullname}/g;
-
-    # always set base-path to common path, all resources are accesible from there.
-    $htmlview->load_html($data,  "file://$htmldir/");
-
+    Proxmox::UI::display_html($page);
     $last_display_change = time();
 }
 
@@ -1528,36 +1326,37 @@ sub prev_function {
 
     $fctn = $step_number if !$fctn;
     $text = "_Previous" if !$text;
-    $prev_btn->set_label ($text);
+    $gtk_state->{prev_btn}->set_label($text);
 
     $step_number--;
     $steps[$step_number]->{function}();
 
-    $prev_btn->grab_focus();
+    $gtk_state->{prev_btn}->grab_focus();
 }
 
 sub set_next {
     my ($text, $fctn) = @_;
 
-    $next_fctn = $fctn;
+    $gtk_state->{next_btn_callback} = $fctn;
     my $step = $steps[$step_number];
     $text //= $steps[$step_number]->{next_button} // '_Next';
-    $next->set_label($text);
+    $gtk_state->{next_btn}->set_label($text);
 
-    $next->grab_focus();
+    $gtk_state->{next_btn}->grab_focus();
 }
 
 sub create_main_window {
 
-    $window = Gtk3::Window->new();
+    my $window = Gtk3::Window->new();
     $window->set_default_size(1024, 768);
-    $window->set_has_resize_grip(0);
+    $window->signal_connect(map => sub { $window->set_resizable(0); });
     $window->fullscreen() if !is_test_mode();
     $window->set_decorated(0) if !is_test_mode();
+    $window->signal_connect(destroy => sub { Gtk3->main_quit(); });
 
-    my $vbox = Gtk3::VBox->new(0, 0);
+    my $vbox = Gtk3::Box->new('vertical', 0);
 
-    my $logofn = "$env->{product}-banner.png";
+    my $logofn = "$iso_env->{product}-banner.png";
     my $image = Gtk3::Image->new_from_file("${proxmox_libdir}/$logofn");
 
     my $provider = Gtk3::CssProvider->new();
@@ -1568,25 +1367,24 @@ sub create_main_window {
 
     $vbox->pack_start($image, 0, 0, 0);
 
-    my $hbox = Gtk3::HBox->new(0, 0);
+    my $hbox = Gtk3::Box->new('horizontal', 0);
     $vbox->pack_start($hbox, 1, 1, 0);
 
  #  my $f1 = Gtk3::Frame->new ('test');
  #  $f1->set_shadow_type ('none');
  #  $hbox->pack_start ($f1, 1, 1, 0);
 
-    my $sep1 = Gtk3::HSeparator->new();
+    my $sep1 = Gtk3::Separator->new('horizontal');
     $vbox->pack_start($sep1, 0, 0, 0);
 
-    $cmdbox = Gtk3::HBox->new();
+    my $cmdbox = Gtk3::Box->new('horizontal', 0);
     $vbox->pack_start($cmdbox, 0, 0, 10);
 
-    $next = Gtk3::Button->new('_Next');
-    $next->signal_connect(clicked => sub { $last_display_change = 0; &$next_fctn (); });
-    $cmdbox->pack_end($next, 0, 0, 10);
-
+    my $next_btn = Gtk3::Button->new('_Next');
+    $next_btn->signal_connect(clicked => sub { $last_display_change = 0; $gtk_state->{next_btn_callback}->(); });
+    $cmdbox->pack_end($next_btn, 0, 0, 10);
 
-    $prev_btn = Gtk3::Button->new('_Previous');
+    my $prev_btn = Gtk3::Button->new('_Previous');
     $prev_btn->signal_connect(clicked => sub { $last_display_change = 0; &prev_function (); });
     $cmdbox->pack_end($prev_btn, 0, 0, 10);
 
@@ -1594,39 +1392,50 @@ sub create_main_window {
     my $abort = Gtk3::Button->new('_Abort');
     $abort->set_can_focus(0);
     $cmdbox->pack_start($abort, 0, 0, 10);
-    $abort->signal_connect(clicked => sub { exit (-1); });
+    $abort->signal_connect(clicked => sub { app_quit(-1); });
 
-    my $vbox2 = Gtk3::VBox->new(0, 0);
+    my $vbox2 = Gtk3::Box->new('vertical', 0);
     $hbox->add($vbox2);
 
-    $htmlview = Gtk3::WebKit2::WebView->new();
+    my $html_view = Gtk3::WebKit2::WebView->new();
+    $html_view->set_hexpand(1);
     my $scrolls = Gtk3::ScrolledWindow->new();
-    $scrolls->add($htmlview);
+    $scrolls->add($html_view);
 
-    my $hbox2 = Gtk3::HBox->new(0, 0);
+    my $hbox2 = Gtk3::Box->new('horizontal', 0);
     $hbox2->pack_start($scrolls, 1, 1, 0);
 
     $vbox2->pack_start($hbox2, 1, 1, 0);
 
-    my $vbox3 = Gtk3::VBox->new(0, 0);
+    my $vbox3 = Gtk3::Box->new('vertical', 0);
     $vbox2->pack_start($vbox3, 0, 0, 0);
 
-    my $sep2 = Gtk3::HSeparator->new;
+    my $sep2 = Gtk3::Separator->new('horizontal');
     $vbox3->pack_start($sep2, 0, 0, 0);
 
-    $inbox = Gtk3::HBox->new(0, 0);
+    my $inbox = Gtk3::Box->new('horizontal', 0);
     $vbox3->pack_start($inbox, 0, 0, 0);
 
     $window->add($vbox);
 
+    $gtk_state->{window} = $window;
+    $gtk_state->{html_view} = $html_view;
+    $gtk_state->{inbox} = $inbox;
+    $gtk_state->{prev_btn} = $prev_btn;
+    $gtk_state->{next_btn} = $next_btn;
+    $gtk_state->{progress_bar} = Gtk3::ProgressBar->new();
+    $gtk_state->{progress_status} = Gtk3::Label->new('');
+
+    Proxmox::UI::init_gtk($gtk_state, $iso_env);
+
     $window->show_all;
-    $window->realize();
+    $window->present();
 }
 
 sub cleanup_view {
-    $inbox->foreach(sub {
+    $gtk_state->{inbox}->foreach(sub {
        my $child = shift;
-       $inbox->remove ($child);
+       $gtk_state->{inbox}->remove ($child);
     });
 }
 
@@ -1674,7 +1483,7 @@ sub create_text_input {
 
     my $label = Gtk3::Label->new($text);
     $label->set_size_request(150, -1);
-    $label->set_alignment(1, 0.5);
+    $label->set_xalign(1.0);
     $hbox->pack_start($label, 0, 0, 10);
     my $e1 = Gtk3::Entry->new();
     $e1->set_width_chars(35);
@@ -1690,7 +1499,7 @@ sub create_cidr_inputs {
 
     my $label = Gtk3::Label->new('IP Address (CIDR)');
     $label->set_size_request(150, -1);
-    $label->set_alignment(1, 0.5);
+    $label->set_xalign(1.0);
     $hbox->pack_start($label, 0, 0, 10);
 
     my $ip_el = Gtk3::Entry->new();
@@ -1700,7 +1509,6 @@ sub create_cidr_inputs {
 
     $label = Gtk3::Label->new('/');
     $label->set_size_request(10, -1);
-    $label->set_alignment(0.5, 0.5);
     $hbox->pack_start($label, 0, 0, 2);
 
     my $cidr_el = Gtk3::Entry->new();
@@ -1711,41 +1519,15 @@ sub create_cidr_inputs {
     return ($hbox, $ip_el, $cidr_el);
 }
 
-sub display_message {
-    my ($msg) = @_;
-
-    my $dialog = Gtk3::MessageDialog->new($window, 'modal', 'info', 'ok', $msg);
-    $dialog->run();
-    $dialog->destroy();
-}
-
-sub display_error {
-    my ($msg) = @_;
-
-    my $dialog = Gtk3::MessageDialog->new($window, 'modal', 'error', 'ok', $msg);
-    $dialog->run();
-    $dialog->destroy();
-}
-
-sub display_prompt {
-    my ($query) = @_;
-
-    my $dialog = Gtk3::MessageDialog->new($window, 'modal', 'question', 'ok-cancel', $query);
-    my $response = $dialog->run();
-    $dialog->destroy();
-
-    return $response;
-}
-
 my $ipconf_first_view = 1;
 
 sub create_ipconf_view {
 
     cleanup_view();
-    display_html();
+    Proxmox::UI::display_html('ipconf.htm');
 
     my $vcontainer = Gtk3::Box->new('vertical', 0);
-    $inbox->pack_start($vcontainer, 1, 0, 0);
+    $gtk_state->{inbox}->pack_start($vcontainer, 1, 0, 0);
     my $hcontainer =  Gtk3::Box->new('horizontal', 0);
     $vcontainer->pack_start($hcontainer, 0, 0, 10);
     my $vbox =  Gtk3::Box->new('vertical', 0);
@@ -1804,16 +1586,16 @@ sub create_ipconf_view {
        $device_cb->set_active(0);
     }
 
-    my $devicebox = Gtk3::HBox->new(0, 0);
+    my $devicebox = Gtk3::Box->new('horizontal', 0);
     my $label = Gtk3::Label->new("Management Interface:");
     $label->set_size_request(150, -1);
-    $label->set_alignment(1, 0.5);
+    $label->set_xalign(1.0);
     $devicebox->pack_start($label, 0, 0, 10);
     $devicebox->pack_start($device_cb, 0, 0, 0);
 
     $vbox->pack_start($devicebox, 0, 0, 2);
 
-    my $hn = $config->{fqdn} // "$env->{product}." . ($ipconf->{domain} // "example.invalid");
+    my $hn = $config->{fqdn} // "$iso_env->{product}." . ($ipconf->{domain} // "example.invalid");
 
     my ($hostbox, $hostentry) = create_text_input($hn, 'Hostname (FQDN):');
     $vbox->pack_start($hostbox, 0, 0, 2);
@@ -1836,7 +1618,7 @@ sub create_ipconf_view {
 
     $vbox->pack_start($dnsbox, 0, 0, 0);
 
-    $inbox->show_all;
+    $gtk_state->{inbox}->show_all;
     set_next(undef, sub {
 
        # verify hostname
@@ -1852,7 +1634,7 @@ sub create_ipconf_view {
 
        # Debian does not support purely numeric hostnames
        if ($text && $text =~ /^[0-9]+(?:\.|$)/) {
-           display_message("Purely numeric hostnames are not allowed.");
+           Proxmox::UI::message("Purely numeric hostnames are not allowed.");
            $hostentry->grab_focus();
            return;
        }
@@ -1862,7 +1644,7 @@ sub create_ipconf_view {
            $hostname = $1;
            $domain = $2;
        } else {
-           display_message("Hostname does not look like a fully qualified domain name.");
+           Proxmox::UI::message("Hostname does not look like a fully qualified domain name.");
            $hostentry->grab_focus();
            return;
        }
@@ -1871,7 +1653,7 @@ sub create_ipconf_view {
        $text = $ipconf_entry_addr->get_text();
        ($ipaddress, $ipversion) = parse_ip_address($text);
        if (!defined($ipaddress)) {
-           display_message("IP address is not valid.");
+           Proxmox::UI::message("IP address is not valid.");
            $ipconf_entry_addr->grab_focus();
            return;
        }
@@ -1880,7 +1662,7 @@ sub create_ipconf_view {
        $text = $ipconf_entry_mask->get_text();
        $netmask = parse_ip_mask($text, $ipversion);
        if (!defined($netmask)) {
-           display_message("Netmask is not valid.");
+           Proxmox::UI::message("Netmask is not valid.");
            $ipconf_entry_mask->grab_focus();
            return;
        }
@@ -1893,7 +1675,7 @@ sub create_ipconf_view {
            my $msg = defined($gateway_ip)
                ? "Gateway and host IP version must not differ (IPv$gateway_ip_version != IPv$ipversion)."
                : "Gateway is not valid.";
-           display_message($msg);
+           Proxmox::UI::message($msg);
            $ipconf_entry_gw->grab_focus();
            return;
        }
@@ -1905,13 +1687,13 @@ sub create_ipconf_view {
            my $msg = defined($gateway_ip)
                ? "DNS and host IP version must not differ (IPv$gateway_ip_version != IPv$ipversion)."
                : "DNS IP is not valid.";
-           display_message($msg);
+           Proxmox::UI::message($msg);
            $ipconf_entry_dns->grab_focus();
            return;
        }
        $config->{dnsserver} = $dnsserver = $dns_ip;
 
-       #print "TEST $ipaddress $netmask $gateway $dnsserver\n";
+       #print STDERR "TEST $ipaddress $netmask $gateway $dnsserver\n";
 
        $step_number++;
        create_ack_view();
@@ -1924,8 +1706,8 @@ sub create_ack_view {
 
     cleanup_view();
 
-    my $vbox =  Gtk3::VBox->new(0, 0);
-    $inbox->pack_start($vbox, 1, 0, 0);
+    my $vbox =  Gtk3::Box->new('vertical', 0);
+    $gtk_state->{inbox}->pack_start($vbox, 1, 0, 0);
 
     my $reboot_checkbox = Gtk3::CheckButton->new('Automatically reboot after successful installation');
     $reboot_checkbox->set_active(1);
@@ -1936,13 +1718,13 @@ sub create_ack_view {
     $vbox->pack_start($reboot_checkbox, 0, 0, 2);
 
     my $ack_template = "${proxmox_libdir}/html/ack_template.htm";
-    my $ack_html = "${proxmox_libdir}/html/$env->{product}/$steps[$step_number]->{html}";
+    my $ack_html = "${proxmox_libdir}/html/$iso_env->{product}/$steps[$step_number]->{html}";
     my $html_data = file_read_all($ack_template);
 
     my %config_values = (
        __target_hd__ => join(' | ', @{$config_options->{target_hds}}),
        __target_fs__ => $config_options->{filesys},
-       __country__ => $cmap->{country}->{$country}->{name},
+       __country__ => $iso_env->{locales}->{country}->{$country}->{name},
        __timezone__ => $timezone,
        __keymap__ => $keymap,
        __mailto__ => $mailto,
@@ -1961,9 +1743,9 @@ sub create_ack_view {
 
     file_write_all($ack_html, $html_data);
 
-    display_html();
+    Proxmox::UI::display_html('ack.htm');
 
-    $inbox->show_all;
+    $gtk_state->{inbox}->show_all;
 
     set_next(undef, sub {
        $step_number++;
@@ -2007,7 +1789,7 @@ sub update_layout {
     my $ind;
     my $def;
     my $i = 0;
-    my $kmaphash = $cmap->{kmaphash};
+    my $kmaphash = $iso_env->{locales}->{kmaphash};
     foreach my $layout (sort keys %$kmaphash) {
        $def = $i if $kmaphash->{$layout} eq 'en-us';
        $ind = $i if $kmap && $kmaphash->{$layout} eq $kmap;
@@ -2028,34 +1810,24 @@ my $lastzonecb;
 sub update_zonelist {
     my ($box, $cc) = @_;
 
-    my $cczones = $cmap->{cczones};
-    my $zones = $cmap->{zones};
-
-    my $sel;
+    my $sel = $timezone; # initial default
     if ($lastzonecb) {
        $sel = $lastzonecb->get_active_text();
-       $box->remove ($lastzonecb);
-    } else {
-       $sel = $timezone; # used once to select default
+       $box->remove($lastzonecb);
     }
 
     my $cb = $lastzonecb = Gtk3::ComboBoxText->new();
     $cb->set_size_request(200, -1);
-
     $cb->signal_connect('changed' => sub {
        $timezone = $cb->get_active_text();
     });
 
-    my @za;
-    if ($cc && defined ($cczones->{$cc})) {
-       @za = keys %{$cczones->{$cc}};
-    } else {
-       @za = keys %$zones;
-    }
-    my $ind;
-    my $i = 0;
-    foreach my $zone (sort @za) {
-       $ind = $i if $sel && $zone eq $sel;
+    my ($cczones, $zones) = $iso_env->{locales}->@{'cczones', 'zones'};
+    my @available_zones = $cc && defined($cczones->{$cc}) ? keys %{$cczones->{$cc}} : keys %$zones;
+
+    my ($i, $selected_index) = (0, undef);
+    for my $zone (sort @available_zones) {
+       $selected_index = $i if $sel && $zone eq $sel;
        $cb->append_text($zone);
        $i++;
     }
@@ -2063,7 +1835,7 @@ sub update_zonelist {
     # Append UTC here, so it is always the last item and never the default for any country.
     $cb->append_text('UTC');
 
-    $cb->set_active($ind || 0);
+    $cb->set_active($selected_index || 0);
 
     $cb->show;
     $box->pack_start($cb, 0, 0, 0);
@@ -2073,15 +1845,15 @@ sub create_password_view {
 
     cleanup_view();
 
-    my $vbox2 =  Gtk3::VBox->new(0, 0);
-    $inbox->pack_start($vbox2, 1, 0, 0);
-    my $vbox =  Gtk3::VBox->new(0, 0);
+    my $vbox2 =  Gtk3::Box->new('vertical', 0);
+    $gtk_state->{inbox}->pack_start($vbox2, 1, 0, 0);
+    my $vbox =  Gtk3::Box->new('vertical', 0);
     $vbox2->pack_start($vbox, 0, 0, 10);
 
-    my $hbox1 = Gtk3::HBox->new(0, 0);
+    my $hbox1 = Gtk3::Box->new('horizontal', 0);
     my $label = Gtk3::Label->new("Password");
     $label->set_size_request(150, -1);
-    $label->set_alignment(1, 0.5);
+    $label->set_xalign(1.0);
     $hbox1->pack_start($label, 0, 0, 10);
     my $pwe1 = Gtk3::Entry->new();
     $pwe1->set_visibility(0);
@@ -2089,10 +1861,10 @@ sub create_password_view {
     $pwe1->set_size_request(200, -1);
     $hbox1->pack_start($pwe1, 0, 0, 0);
 
-    my $hbox2 = Gtk3::HBox->new(0, 0);
+    my $hbox2 = Gtk3::Box->new('horizontal', 0);
     $label = Gtk3::Label->new("Confirm");
     $label->set_size_request(150, -1);
-    $label->set_alignment(1, 0.5);
+    $label->set_xalign(1.0);
     $hbox2->pack_start($label, 0, 0, 10);
     my $pwe2 = Gtk3::Entry->new();
     $pwe2->set_visibility(0);
@@ -2100,10 +1872,10 @@ sub create_password_view {
     $pwe2->set_size_request(200, -1);
     $hbox2->pack_start($pwe2, 0, 0, 0);
 
-    my $hbox3 = Gtk3::HBox->new(0, 0);
+    my $hbox3 = Gtk3::Box->new('horizontal', 0);
     $label = Gtk3::Label->new("Email");
     $label->set_size_request(150, -1);
-    $label->set_alignment(1, 0.5);
+    $label->set_xalign(1.0);
     $hbox3->pack_start($label, 0, 0, 10);
     my $eme = Gtk3::Entry->new();
     $eme->set_size_request(200, -1);
@@ -2115,9 +1887,9 @@ sub create_password_view {
     $vbox->pack_start($hbox2, 0, 0, 5);
     $vbox->pack_start($hbox3, 0, 0, 15);
 
-    $inbox->show_all;
+    $gtk_state->{inbox}->show_all;
 
-    display_html();
+    Proxmox::UI::display_html('passwd.htm');
 
     set_next (undef,  sub {
 
@@ -2125,27 +1897,27 @@ sub create_password_view {
        my $t2 = $pwe2->get_text;
 
        if (length ($t1) < 5) {
-           display_message("Password is too short.");
+           Proxmox::UI::message("Password is too short.");
            $pwe1->grab_focus();
            return;
        }
 
        if ($t1 ne $t2) {
-           display_message("Password does not match.");
+           Proxmox::UI::message("Password does not match.");
            $pwe1->grab_focus();
            return;
        }
 
        my $t3 = $eme->get_text;
        if ($t3 !~ m/^[\w\+\-\~]+(\.[\w\+\-\~]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*$/) {
-           display_message("Email does not look like a valid address" .
+           Proxmox::UI::message("Email does not look like a valid address" .
                             " (user\@domain.tld)");
            $eme->grab_focus();
            return;
        }
 
        if ($t3 eq 'mail@example.invalid') {
-           display_message("Please enter a valid Email address");
+           Proxmox::UI::message("Please enter a valid Email address");
            $eme->grab_focus();
            return;
        }
@@ -2166,12 +1938,11 @@ sub create_country_view {
 
     cleanup_view();
 
-    my $countryhash = $cmap->{countryhash};
-    my $ctr = $cmap->{country};
+    my $locales = $iso_env->{locales};
 
-    my $vbox2 =  Gtk3::VBox->new(0, 0);
-    $inbox->pack_start($vbox2, 1, 0, 0);
-    my $vbox =  Gtk3::VBox->new(0, 0);
+    my $vbox2 =  Gtk3::Box->new('vertical', 0);
+    $gtk_state->{inbox}->pack_start($vbox2, 1, 0, 0);
+    my $vbox =  Gtk3::Box->new('vertical', 0);
     $vbox2->pack_start($vbox, 0, 0, 10);
 
     my $w = Gtk3::Entry->new();
@@ -2183,23 +1954,23 @@ sub create_country_view {
     $c->set_popup_set_width(1);
     $c->set_inline_completion(1);
 
-    my $hbox2 = Gtk3::HBox->new(0, 0);
+    my $hbox2 = Gtk3::Box->new('horizontal', 0);
     my $label = Gtk3::Label->new("Time zone");
     $label->set_size_request(150, -1);
-    $label->set_alignment(1, 0.5);
+    $label->set_xalign(1.0);
     $hbox2->pack_start($label, 0, 0, 10);
     update_zonelist ($hbox2);
 
-    my $hbox3 = Gtk3::HBox->new(0, 0);
+    my $hbox3 = Gtk3::Box->new('horizontal', 0);
     $label = Gtk3::Label->new("Keyboard Layout");
     $label->set_size_request(150, -1);
-    $label->set_alignment(1, 0.5);
+    $label->set_xalign(1.0);
     $hbox3->pack_start($label, 0, 0, 10);
 
     my $kmapcb = Gtk3::ComboBoxText->new();
     $kmapcb->set_size_request (200, -1);
-    foreach my $layout (sort keys %{$cmap->{kmaphash}}) {
-       $kmapcb->append_text ($layout);
+    for my $layout (sort keys %{$locales->{kmaphash}}) {
+       $kmapcb->append_text($layout);
     }
 
     update_layout($kmapcb);
@@ -2208,9 +1979,9 @@ sub create_country_view {
     $kmapcb->signal_connect ('changed' => sub {
        my $sel = $kmapcb->get_active_text();
        $last_layout = $kmapcb->get_active();
-       if (my $kmap = $cmap->{kmaphash}->{$sel}) {
-           my $xkmap = $cmap->{kmap}->{$kmap}->{x11};
-           my $xvar = $cmap->{kmap}->{$kmap}->{x11var};
+       if (my $kmap = $locales->{kmaphash}->{$sel}) {
+           my $xkmap = $locales->{kmap}->{$kmap}->{x11};
+           my $xvar = $locales->{kmap}->{$kmap}->{x11var};
            $keymap = $kmap;
 
            return if (defined($installer_kmap) && $installer_kmap eq $kmap);
@@ -2239,9 +2010,9 @@ sub create_country_view {
        my ($entry, $event) = @_;
        my $text = $entry->get_text;
 
-       if (my $cc = $countryhash->{lc($text)}) {
+       if (my $cc = $locales->{countryhash}->{lc($text)}) {
            update_zonelist($hbox2, $cc);
-           my $kmap = $ctr->{$cc}->{kmap} || 'en-us';
+           my $kmap = $locales->{country}->{$cc}->{kmap} || 'en-us';
            update_layout($kmapcb, $kmap);
        }
     });
@@ -2253,20 +2024,19 @@ sub create_country_view {
        my $val = $event->get_keyval;
 
        if ($val == Gtk3::Gdk::KEY_Tab) {
-           my $cc = $countryhash->{lc($text)};
+           my $cc = $locales->{countryhash}->{lc($text)};
 
            my $found = 0;
            my $compl;
 
            if ($cc) {
                $found = 1;
-               $compl = $ctr->{$cc}->{name};
+               $compl = $locales->{country}->{$cc}->{name};
            } else {
-               foreach my $cc (keys %$ctr) {
-                   my $ct = $ctr->{$cc}->{name};
-                   if ($ct =~ m/^\Q$text\E.*$/i) {
+               for my $country (values $locales->{country}->%*) {
+                   if ($country->{name} =~ m/^\Q$text\E.*$/i) {
                        $found++;
-                       $compl = $ct;
+                       $compl = $country->{name};
                    }
                    last if $found > 1;
                }
@@ -2277,8 +2047,7 @@ sub create_country_view {
                $c->complete();
                return undef;
            } else {
-               #Gtk3::Gdk::beep();
-               print chr(7); # beep ?
+               # beep ?
            }
 
            $c->complete();
@@ -2292,19 +2061,20 @@ sub create_country_view {
        return undef;
     });
 
-    my $ls = Gtk3::ListStore->new('Glib::String');
-    foreach my $cc (sort {$ctr->{$a}->{name} cmp $ctr->{$b}->{name} } keys %$ctr) {
-       my $iter = $ls->append();
-       $ls->set ($iter, 0, $ctr->{$cc}->{name});
+    my $country_store = Gtk3::ListStore->new('Glib::String');
+    my $countries = $locales->{country};
+    for my $cc (sort { $countries->{$a}->{name} cmp $countries->{$b}->{name} } keys %$countries) {
+       my $iter = $country_store->append();
+       $country_store->set($iter, 0, $countries->{$cc}->{name});
     }
-    $c->set_model ($ls);
+    $c->set_model($country_store);
 
     $w->set_completion ($c);
 
-    my $hbox =  Gtk3::HBox->new(0, 0);
+    my $hbox =  Gtk3::Box->new('horizontal', 0);
 
     $label = Gtk3::Label->new("Country");
-    $label->set_alignment(1, 0.5);
+    $label->set_xalign(1.0);
     $label->set_size_request(150, -1);
     $hbox->pack_start($label, 0, 0, 10);
     $hbox->pack_start($w, 0, 0, 0);
@@ -2313,24 +2083,24 @@ sub create_country_view {
     $vbox->pack_start($hbox2, 0, 0, 5);
     $vbox->pack_start($hbox3, 0, 0, 5);
 
-    if ($country && $ctr->{$country}) {
-       $w->set_text ($ctr->{$country}->{name});
+    if ($country && (my $entry = $locales->{country}->{$country})) {
+       $w->set_text($entry->{name});
     }
 
-    $inbox->show_all;
+    $gtk_state->{inbox}->show_all;
 
-    display_html();
+    Proxmox::UI::display_html('country.htm');
     set_next (undef,  sub {
 
        my $text = $w->get_text;
 
-       if (my $cc = $countryhash->{lc($text)}) {
+       if (my $cc = $locales->{countryhash}->{lc($text)}) {
            $country = $cc;
            $step_number++;
            create_password_view();
            return;
        } else {
-           display_message("Please select a country first.");
+           Proxmox::UI::message("Please select a country first.");
            $w->grab_focus();
        }
     });
@@ -2368,7 +2138,7 @@ my $create_label_widget_grid = sub {
        my $widget = @$labeled_widgets[$i+1];
        my $label = Gtk3::Label->new(@$labeled_widgets[$i]);
        $label->set_visible(1);
-       $label->set_alignment (1, 0.5);
+       $label->set_xalign(1.0);
        $grid->attach($label, 0, $row, 1, 1);
        $widget->set_visible(1);
        $grid->attach($widget, 1, $row, 1, 1);
@@ -2596,7 +2366,7 @@ sub create_hdoption_view {
 
     # Filesystem type
     my $label0 = Gtk3::Label->new("Filesystem");
-    $label0->set_alignment (1, 0.5);
+    $label0->set_xalign(1.0);
     $grid->attach($label0, 0, $row, 1, 1);
 
     my $fstypecb = Gtk3::ComboBoxText->new();
@@ -2611,7 +2381,7 @@ sub create_hdoption_view {
        'zfs (RAIDZ-3)',
     ];
     push @$fstype, 'btrfs (RAID0)', 'btrfs (RAID1)', 'btrfs (RAID10)'
-       if $env->{cfg}->{enable_btrfs};
+       if $iso_env->{cfg}->{enable_btrfs};
 
     my $tcount = 0;
     foreach my $tmp (@$fstype) {
@@ -2626,7 +2396,7 @@ sub create_hdoption_view {
 
     $row++;
 
-    my $sep = Gtk3::HSeparator->new();
+    my $sep = Gtk3::Separator->new('horizontal');
     $sep->set_visible(1);
     $grid->attach($sep, 0, $row, 2, 1);
     $row++;
@@ -2642,7 +2412,7 @@ sub create_hdoption_view {
     # size compute
     my $hdsize = 0;
     if ( -b $target_hd) {
-       $hdsize = int(hd_size($target_hd) / (1024 * 1024.0)); # size in GB
+       $hdsize = int(Proxmox::Sys::Block::hd_size($target_hd) / (1024 * 1024.0)); # size in GB
     } elsif ($target_hd) {
        $hdsize = int((-s $target_hd) / (1024 * 1024 * 1024.0));
     }
@@ -2658,7 +2428,7 @@ sub create_hdoption_view {
     push @$hdsize_labeled_widgets, "swapsize", $entry_swapsize;
 
     my $entry_maxroot = Gtk3::Entry->new();
-    if ($env->{product} eq 'pve') {
+    if ($iso_env->{product} eq 'pve') {
        $entry_maxroot->set_tooltip_text("maximum size (GB) for LVM root volume");
        $entry_maxroot->signal_connect (key_press_event => \&check_float);
        $entry_maxroot->set_text($config_options->{maxroot}) if $config_options->{maxroot};
@@ -2672,7 +2442,7 @@ sub create_hdoption_view {
     push @$hdsize_labeled_widgets, "minfree", $entry_minfree;
 
     my $entry_maxvz;
-    if ($env->{product} eq 'pve') {
+    if ($iso_env->{product} eq 'pve') {
        $entry_maxvz = Gtk3::Entry->new();
        $entry_maxvz->set_tooltip_text("maximum size (GB) for LVM data volume");
        $entry_maxvz->signal_connect (key_press_event => \&check_float);
@@ -2713,7 +2483,7 @@ sub create_hdoption_view {
        if ($raid) {
            my $msg = "<b>Note</b>: " . ($is_zfs
                ? "ZFS is not compatible with hardware RAID controllers, for details see the documentation."
-               : "BTRFS integration in $env->{cfg}->{fullname} is a technology preview!"
+               : "BTRFS integration in $iso_env->{cfg}->{fullname} is a technology preview!"
            );
            $hw_raid_note->set_markup($msg);
        }
@@ -2747,7 +2517,7 @@ sub create_hdoption_view {
        &$switch_view();
     });
 
-    my $sep2 = Gtk3::HSeparator->new();
+    my $sep2 = Gtk3::Separator->new('horizontal');
     $sep2->set_visible(1);
     $contarea->pack_end($sep2, 1, 1, 10);
 
@@ -2833,7 +2603,7 @@ sub zfs_mirror_size_check {
 sub legacy_bios_4k_check {
     my ($lbs) = @_;
     die "Booting from 4kn drive in legacy BIOS mode is not supported.\n"
-       if $boot_type ne 'efi' && $lbs == 4096;
+       if $run_env->{boot_type} ne 'efi' && $lbs == 4096;
 }
 
 sub get_zfs_raid_setup {
@@ -2925,13 +2695,13 @@ sub get_btrfs_raid_setup {
 my $last_hd_selected = 0;
 sub create_hdsel_view {
 
-    $prev_btn->set_sensitive(1); # enable previous button at this point
+    $gtk_state->{prev_btn}->set_sensitive(1); # enable previous button at this point
 
     cleanup_view();
 
-    my $vbox =  Gtk3::VBox->new(0, 0);
-    $inbox->pack_start($vbox, 1, 0, 0);
-    my $hbox =  Gtk3::HBox->new(0, 0);
+    my $vbox =  Gtk3::Box->new('vertical', 0);
+    $gtk_state->{inbox}->pack_start($vbox, 1, 0, 0);
+    my $hbox =  Gtk3::Box->new('horizontal', 0);
     $vbox->pack_start($hbox, 0, 0, 10);
 
     my $cached_disks = get_cached_disks();
@@ -2969,23 +2739,23 @@ sub create_hdsel_view {
     $hbox->pack_start ($options, 0, 0, 0);
 
 
-    $inbox->show_all;
+    $gtk_state->{inbox}->show_all;
 
-    display_html();
+    Proxmox::UI::display_html('page1.htm');
 
     set_next(undef, sub {
 
        if ($config_options->{filesys} =~ m/zfs/) {
            my ($devlist) = eval { get_zfs_raid_setup() };
            if (my $err = $@) {
-               display_message("Warning: $err\nPlease fix ZFS setup first.");
+               Proxmox::UI::message("Warning: $err\nPlease fix ZFS setup first.");
                return;
            }
            $config_options->{target_hds} = [ map { $_->[1] } @$devlist ];
        } elsif ($config_options->{filesys} =~ m/btrfs/) {
            my ($devlist) = eval { get_btrfs_raid_setup() };
            if (my $err = $@) {
-               display_message("Warning: $err\nPlease fix BTRFS setup first.");
+               Proxmox::UI::message("Warning: $err\nPlease fix BTRFS setup first.");
                return;
            }
            $config_options->{target_hds} = [ map { $_->[1] } @$devlist ];
@@ -2995,7 +2765,7 @@ sub create_hdsel_view {
                legacy_bios_4k_check($target_block_size);
            };
            if (my $err = $@) {
-               display_message("Warning: $err\n");
+               Proxmox::UI::message("Warning: $err\n");
                return;
            }
            $config_options->{target_hds} = [ $target_hd ];
@@ -3010,56 +2780,71 @@ sub create_extract_view {
 
     cleanup_view();
 
-    display_info();
+    Proxmox::Install::display_info();
 
-    $next->set_sensitive(0);
-    $prev_btn->set_sensitive(0);
-    $prev_btn->hide();
+    $gtk_state->{next_btn}->set_sensitive(0);
+    $gtk_state->{prev_btn}->set_sensitive(0);
+    $gtk_state->{prev_btn}->hide();
 
-    my $vbox =  Gtk3::VBox->new(0, 0);
-    $inbox->pack_start ($vbox, 1, 0, 0);
-    my $hbox =  Gtk3::HBox->new(0, 0);
+    my $vbox =  Gtk3::Box->new('vertical', 0);
+    $gtk_state->{inbox}->pack_start ($vbox, 1, 0, 0);
+    my $hbox =  Gtk3::Box->new('horizontal', 0);
     $vbox->pack_start ($hbox, 0, 0, 10);
 
-    my $vbox2 =  Gtk3::VBox->new(0, 0);
+    my $vbox2 =  Gtk3::Box->new('vertical', 0);
     $hbox->pack_start ($vbox2, 0, 0, 0);
 
-    $progress_status = Gtk3::Label->new('');
-    $vbox2->pack_start ($progress_status, 1, 1, 0);
+    $vbox2->pack_start($gtk_state->{progress_status}, 1, 1, 0);
 
-    $progress = Gtk3::ProgressBar->new;
-    $progress->set_show_text(1);
-    $progress->set_size_request (600, -1);
+    $gtk_state->{progress_bar}->set_show_text(1);
+    $gtk_state->{progress_bar}->set_size_request (600, -1);
 
-    $vbox2->pack_start($progress, 0, 0, 0);
+    $vbox2->pack_start($gtk_state->{progress_bar}, 0, 0, 0);
 
-    $inbox->show_all();
+    $gtk_state->{inbox}->show_all();
 
     my $tdir = is_test_mode() ? "target" : "/target";
     mkdir $tdir;
-    my $base = "${proxmox_cddir}/$env->{product}-base.squashfs";
+    my $base = "${proxmox_cddir}/$iso_env->{product}-base.squashfs";
 
     eval  { extract_data($base, $tdir); };
     my $err = $@;
 
-    $next->set_sensitive(1);
+    $gtk_state->{next_btn}->set_sensitive(1);
+
+    set_next("_Reboot", sub { app_quit(0); } );
+
+    my $success_transform = sub {
+       my ($raw_html, $iso_env) = @_;
+
+       my $addr = $ipversion == 6 ? "[${ipaddress}]" : "$ipaddress";
+       $raw_html =~ s/__IPADDR__/$addr/g;
+       $raw_html =~ s/__PORT__/$iso_env->{cfg}->{port}/g;
 
-    set_next("_Reboot", sub { exit (0); } );
+       my $autoreboot_msg = $config_options->{autoreboot}
+           ? "Automatic reboot scheduled in $autoreboot_seconds seconds."
+           : '';
+       $raw_html =~ s/__AUTOREBOOT_MSG__/$autoreboot_msg/;
+
+       return $raw_html;
+    };
 
     if ($err) {
-       display_html("fail.htm");
-       display_error($err);
+       Proxmox::UI::display_html("fail.htm");
+       # suppress "empty" error as we got some case where the user choose to abort on a prompt,
+       # there it doesn't make sense to show them an error again, they "caused" it after all.
+       Proxmox::UI::error($err) if $err ne "\n";
     } else {
        cleanup_view();
-       display_html("success.htm");
+       Proxmox::UI::display_html("success.htm", $success_transform);
 
         if ($config_options->{autoreboot}) {
            Glib::Timeout->add(1000, sub {
                if ($autoreboot_seconds > 0) {
                    $autoreboot_seconds--;
-                   display_html("success.htm");
+                   Proxmox::UI::display_html("success.htm", $success_transform);
                } else {
-                   exit(0);
+                   app_quit(0);
                }
            });
        }
@@ -3068,26 +2853,39 @@ sub create_extract_view {
 
 sub create_intro_view {
 
-    $prev_btn->set_sensitive(0);
+    $gtk_state->{prev_btn}->set_sensitive(0);
 
     cleanup_view();
 
-    if (int($total_memory) < 1024) {
-       display_error("Less than 1 GiB of usable memory detected, installation will probably fail.\n\n".
-           "See 'System Requirements' in the $env->{cfg}->{fullname} documentation.");
+    if (int($run_env->{total_memory}) < 1024) {
+       Proxmox::UI::error("Less than 1 GiB of usable memory detected, installation will probably fail.\n\n".
+           "See 'System Requirements' in the $iso_env->{cfg}->{fullname} documentation.");
     }
 
-    if ($env->{product} eq 'pve') {
+    if ($iso_env->{product} eq 'pve') {
        my $cpuinfo = eval { file_read_all('/proc/cpuinfo') };
        if (!$cpuinfo || $cpuinfo !~ /^flags\s*:.*(vmx|svm)/m) {
-           display_error(
+           Proxmox::UI::error(
                "No support for hardware-accelerated KVM virtualization detected.\n\n"
                ."Check BIOS settings for Intel VT / AMD-V / SVM."
            );
        }
     }
 
-    display_html();
+    Proxmox::UI::display_html('license.htm', sub {
+       my ($raw_html, $iso_env) = @_;
+
+       my $license = eval { decode('utf8', file_read_all("${proxmox_cddir}/EULA")) };
+       if (my $err = $@) {
+           die $err if !is_test_mode();
+           $license = "TESTMODE: Ignore non existent EULA...\n";
+       }
+       my $title = "END USER LICENSE AGREEMENT (EULA)";
+       $raw_html =~ s/__LICENSE__/$license/;
+       $raw_html =~ s/__LICENSE_TITLE__/$title/;
+
+       return $raw_html;
+    });
 
     $step_number++;
     set_next("I a_gree", \&create_hdsel_view);
@@ -3095,12 +2893,7 @@ sub create_intro_view {
 
 $ipconf = Proxmox::Sys::Net::get_ip_config();
 
-$country = detect_country() if $ipconf->{default} || is_test_mode();
-
-# read country, kmap and timezone infos
-$cmap = read_cmap();
-
-if (!defined($cmap->{country}->{$country})) {
+if (!defined($iso_env->{locales}->{country}->{$country})) {
     log_warn("ignoring detected country '$country', invalid or unknown\n");
     $country = undef;
 }
@@ -3114,33 +2907,28 @@ my $initial_error = 0;
 {
     my $cached_disks = get_cached_disks();
     if (!defined($cached_disks) || (scalar (@$cached_disks) <= 0)) {
-       print "no harddisks found\n";
+       print STDERR "no harddisks found\n";
        $initial_error = 1;
-       display_html("nohds.htm");
-       set_next("Reboot", sub { exit(0); } );
+       Proxmox::UI::display_html("nohds.htm");
+       set_next("Reboot", sub { app_quit(0); } );
     } else {
        foreach my $hd (@$cached_disks) {
            my ($disk, $devname) = @$hd;
            next if $devname =~ m|^/dev/md\d+$|;
-           print "found Disk$disk N:$devname\n";
+           print STDERR "found Disk$disk N:$devname\n";
        }
     }
 }
 
 if (!$initial_error && (scalar keys %{ $ipconf->{ifaces} } == 0)) {
-    print "no network interfaces found\n";
+    print STDERR "no network interfaces found\n";
     $initial_error = 1;
-    display_html("nonics.htm");
-    set_next("Reboot", sub { exit(0); } );
+    Proxmox::UI::display_html("nonics.htm");
+    set_next("Reboot", sub { app_quit(0); } );
 }
 
 create_intro_view () if !$initial_error;
 
 Gtk3->main;
 
-# reap left over zombie processes
-while ((my $child = waitpid(-1, POSIX::WNOHANG)) > 0) {
-    print "reaped child $child\n";
-}
-
-exit 0;
+app_quit(0);