$grub_plattform = "efi-amd64" if -d "/sys/firmware/efi";
my ($window, $cmdbox, $inbox, $htmlview);
-my ($next, $next_fctn, $target_hd, $master_hd);
+my ($next, $next_fctn, $target_hd);
my ($progress, $progress_status);
my ($ipaddress, $ip_1, $ip_2, $ip_3, $ip_4);
my ($netmask, $mask_1, $mask_2, $mask_3, $mask_4);
die "no such device '$dev'";
}
-# find the master boot disk - return the first found scsi/ide disk
-sub find_master {
- my ($target_hd) = @_;
-
- foreach my $hd (sort { ${$a}[1] cmp ${$b}[1] } @$hds) {
- my ($disk, $devname) = @$hd;
- next if $disk < 0;
-
- if ($target_hd =~ m|^/dev/sd|) {
- return $devname if $devname =~ m|^/dev/sd|;
- } elsif ($target_hd =~ m|^/dev/hd|) {
- return $devname if $devname =~ m|^/dev/hd|;
- } elsif ($target_hd =~ m|^/dev/i2o/|) {
- return $devname if $devname =~ m|^/dev/i2o/|;
- } elsif ($target_hd =~ m|^/dev/ataraid/|) {
- return $devname if $devname =~ m|^/dev/ataraid/|;
- } elsif ($target_hd =~ m|^/dev/ida/|) {
- return $devname if $devname =~ m|^/dev/ida/|;
- } elsif ($target_hd =~ m|^/dev/cciss/|) {
- return $devname if $devname =~ m|^/dev/cciss/|;
- } elsif ($target_hd =~ m|^/dev/rd/|) {
- return $devname if $devname =~ m|^/dev/rd/|;
- }
- }
-
- return $target_hd;
-}
-
sub get_partition_dev {
- my ($target_hd, $partnum) = @_;
-
- if ($target_hd =~ m|^/dev/[hxsev]d[a-z]$|) {
- return "${target_hd}$partnum";
- } elsif ($target_hd =~ m|^/dev/[^/]+/c\d+d\d+$|) {
- return "${target_hd}p$partnum";
- } elsif ($target_hd =~ m|^/dev/[^/]+/d\d+$|) {
- return "${target_hd}p$partnum";
- } elsif ($target_hd =~ m|^/dev/[^/]+/hd[a-z]$|) {
- return "${target_hd}$partnum";
+ my ($dev, $partnum) = @_;
+
+ if ($dev =~ m|^/dev/[hxsev]d[a-z]$|) {
+ return "${dev}$partnum";
+ } elsif ($dev =~ m|^/dev/[^/]+/c\d+d\d+$|) {
+ return "${dev}p$partnum";
+ } elsif ($dev =~ m|^/dev/[^/]+/d\d+$|) {
+ return "${dev}p$partnum";
+ } elsif ($dev =~ m|^/dev/[^/]+/hd[a-z]$|) {
+ return "${dev}$partnum";
} else {
- die "unable to get device for partition $partnum on device $target_hd\n";
+ die "unable to get device for partition $partnum on device $dev\n";
}
}
}
sub zfs_create_rpool {
- my ($zfspoolname, $targetdev) = @_;
+ my ($zfspoolname, $vdev) = @_;
- # Note: using /dev/disk/by-id/ does not work for unknown reason, we get
- # cannot create 'rpool': no such pool or dataset
- # my $full_path = find_stable_path ("/dev/disk/by-id", $targetdev) || $targetdev;
-
- my $full_path = $targetdev;
-
- syscmd ("zpool create -f -o ashift=12 $zfspoolname ${full_path}") == 0 ||
+ syscmd ("zpool create -f -o ashift=12 $zfspoolname $vdev") == 0 ||
die "unable to create zfs root pool\n";
syscmd ("zfs create $zfspoolname/ROOT") == 0 ||
return "/dev/zvol/$zfspoolname/swap";
}
-sub extract_data {
- my ($tgzfile, $targetdir) = @_;
+sub partition_bootable_disk {
+ my ($target_dev, $maxhdsize, $use_zfs) = @_;
- die "target '$targetdir' does not exist\n" if ! -d $targetdir;
+ die "too dangerous" if $opt_testmode;
- my $rootdev;
- my $efibootdev;
+ syscmd("dd if=/dev/zero of=${target_dev} bs=512 count=256");
+ my $hdsize = hd_size($target_dev); # size in blocks (1024 bytes)
+
+ if ($maxhdsize && ($maxhdsize < $hdsize)) {
+ $hdsize = $maxhdsize;
+ }
+
+ my $hdgb = int($hdsize/(1024*1024));
+ die "hardisk '$target_dev' too small (${hdsize}GB)" if $hdgb < 8;
+
+ # 1 - GRUB boot partition: 1M
+ # 2 - EFI ESP: 100M
+ # 3 - Linux boot fixme: remove
+ # 4 - OS/Data partition
+
+ my $grubbootdev = get_partition_dev($target_dev, 1);
+ my $efibootdev = get_partition_dev($target_dev, 2);
+
+ my $osdev;
my $bootdev;
- my $datadev;
- my $swapfile;
- my $filesys = $config_options->{filesys};
+ if ($use_zfs) {
+ $osdev = get_partition_dev ($target_dev, 3);
+ } else {
+ $bootdev = get_partition_dev ($target_dev, 3);
+ $osdev = get_partition_dev ($target_dev, 4);
+ }
- my $zfspoolname = $opt_testmode ? "test_rpool" : 'rpool';
-
- my $use_zfs = $filesys eq 'zfs' ? 1 : 0;
+ my $bootsize_mb = 512;
+ my $efibootsize_mb = 128;
+ my $grubbootsize_mb = 1;
- $targetdir = "/$zfspoolname/ROOT/pve-1" if $use_zfs;
+ my $hdsize_mb = $hdsize/1024;
- eval {
+ my $pcmd = ['parted', '--script', '--align', 'optimal', $target_dev];
+ push @$pcmd, 'unit', 'MiB';
+ push @$pcmd, 'mklabel', 'gpt';
- if ($use_zfs) {
- my $i;
- for ($i = 5; $i > 0; $i--) {
- syscmd("modprobe zfs");
- last if -c "/dev/zfs";
- sleep(1);
- }
+ my $pnum = 0;
+ my $cpos = 1;
- die "unable to load zfs kernel module\n" if !$i;
+ my $mkpart = sub {
+ my ($fstype, $size) = @_;
+ $pnum++;
+ my $end = defined($size) ? $cpos + $size : $hdsize_mb;
+ if ($fstype) {
+ push @$pcmd, 'mkpart', 'primary', $fstype, $cpos, $end;
+ } else {
+ push @$pcmd, 'mkpart', 'primary', $cpos, $end;
}
+ $cpos = $end;
+ };
+ &$mkpart(undef, $grubbootsize_mb);
+ push @$pcmd, 'set', $pnum, 'bios_grub', 'on';
+ push @$pcmd, 'name', $pnum, 'Grub-Boot-Partition';
- my $maxper = 0.25;
+ &$mkpart('fat32', $efibootsize_mb);
+ push @$pcmd, 'set', $pnum, 'boot', 'on';
+ push @$pcmd, 'name', $pnum, 'EFI-System-Partition';
- update_progress (0, 0, $maxper, "create partitions");
+ my $os_size;
- if ( -b $target_hd) {
+ if ($use_zfs) {
- syscmd ("dd if=/dev/zero of=${target_hd} bs=512 count=256");
- my $hdsize = hd_size ($target_hd); # size in blocks (1024 bytes)
+ my $data_start = $cpos;
+ &$mkpart('zfs');
+ push @$pcmd, 'name', $pnum, 'PVE-ZFS-Partition';
+ $os_size = ($cpos - $data_start)*1024;
- if ($config_options->{hdsize}) {
- # max hdsize passed on cmdline (GB)
- my $maxhdsize= $config_options->{hdsize}*1024*1024;
+ } else {
+
+ &$mkpart('ext2', $bootsize_mb);
+ push @$pcmd, 'name', $pnum, 'PVE-Boot-Partition';
+
+ my $data_start = $cpos;
+ &$mkpart('ext2');
+ push @$pcmd, 'set', $pnum, 'lvm', 'on';
+ push @$pcmd, 'name', $pnum, 'PVE-LVM2-Partition';
+ $os_size = ($cpos - $data_start)*1024;
+ }
- # use $maxhdsize if specified size is lower than hdsize
- if ($maxhdsize < $hdsize) {
- $hdsize = $maxhdsize;
- }
- }
+ syscmd($pcmd) == 0 ||
+ die "unable to partition harddisk '${target_dev}'\n";
- if ($grub_plattform =~ m/^efi/) {
- $efibootdev = get_partition_dev($target_hd, 1);
- }
+ return ($os_size, $osdev, $bootdev, $efibootdev);
+}
- my $lvmdev;
+sub create_lvm_volumes {
+ my ($lvmdev, $os_size, $swap_size) = @_;
- if ($use_zfs) {
- $lvmdev = get_partition_dev ($target_hd, 2);
- } else {
- $bootdev = get_partition_dev ($target_hd, 2);
- $lvmdev = get_partition_dev ($target_hd, 3);
- }
- my $efibootsize_mb = 512;
- my $bootsize_mb = $use_zfs ? 0 : 512;
+ my $rootdev = '/dev/pve/root';
+ my $datadev = '/dev/pve/data';
+ my $swapfile = '/dev/pve/swap';
- my $hdsize_mb = $hdsize/1024;
+ # we use --metadatasize 250k, which reseults in "pe_start = 512"
+ # so pe_start is aligned on a 128k boundary (advantage for SSDs)
+ syscmd ("/sbin/pvcreate --metadatasize 250k -y -ff $lvmdev") == 0 ||
+ die "unable to initialize physical volume $lvmdev";
+ syscmd ("/sbin/vgcreate pve $lvmdev") == 0 ||
+ die "unable to create volume group";
- my $pcmd = ['parted', '--script', '--align', 'optimal', $target_hd];
- push @$pcmd, 'unit', 'MiB';
- push @$pcmd, 'mklabel', 'gpt';
+ my $hdgb = int($os_size/(1024*1024));
+ my $space = (($hdgb > 128) ? 16 : ($hdgb/8))*1024*1024;
- my $pnum = 1;
+ my $maxroot;
+ if ($config_options->{maxroot}) {
+ $maxroot = $config_options->{maxroot};
+ } else {
+ $maxroot = 96;
+ }
- if ($efibootdev) {
- push @$pcmd, 'mkpart', 'primary', 'fat32', 1, $efibootsize_mb;
- push @$pcmd, 'set', $pnum, 'boot', 'on';
- push @$pcmd, 'name', $pnum, 'EFI-System-Partition';
- } else {
- push @$pcmd, 'mkpart', 'primary', 1, 2;
- push @$pcmd, 'set', $pnum, 'bios_grub', 'on';
- push @$pcmd, 'name', $pnum, 'Grub-Boot-Partition';
- }
- $pnum++;
+ my $rootsize = (($hdgb > ($maxroot*4)) ? $maxroot : $hdgb/4)*1024*1024;
- if ($use_zfs) {
+ my $rest = $os_size - $swap_size - $rootsize; # in KB
- if ($efibootdev) {
- push @$pcmd, 'mkpart', 'primary', 'zfs', $efibootsize_mb, $hdsize_mb;
- } else {
- push @$pcmd, 'mkpart', 'primary', 'zfs', 2, $hdsize_mb;
- }
- push @$pcmd, 'name', $pnum, 'zfs';
+ my $minfree;
+ if ($config_options->{minfree}) {
+ $minfree = (($config_options->{minfree}*1024*1024) >= $rest ) ? $space :
+ $config_options->{minfree}*1024*1024 ;
+ } else {
+ $minfree = $space;
+ }
- } else {
+ $rest = $rest - $minfree;
- if ($efibootdev) {
- push @$pcmd, 'mkpart', 'primary', 'ext2', $efibootsize_mb, $efibootsize_mb + $bootsize_mb;
- } else {
- push @$pcmd, 'mkpart', 'primary', 'ext2', 2, $bootsize_mb;
- push @$pcmd, 'set', $pnum, 'boot', 'on';
- }
- push @$pcmd, 'name', $pnum, 'PVE-Boot-Partition';
- $pnum++;
-
- if ($efibootdev) {
- push @$pcmd, 'mkpart', 'primary', 'ext2', $efibootsize_mb + $bootsize_mb, $hdsize_mb;
- } else {
- push @$pcmd, 'mkpart', 'primary', 'ext2', $bootsize_mb, $hdsize_mb;
- }
+ if ($config_options->{maxvz}) {
+ $rest = (($config_options->{maxvz}*1024*1024) <= $rest) ?
+ $config_options->{maxvz}*1024*1024 : $rest;
+ }
- push @$pcmd, 'set', $pnum, 'lvm', 'on';
- push @$pcmd, 'name', $pnum, 'PVE-LVM2-Partition';
- }
+ syscmd ("/sbin/lvcreate -L${swap_size}K -nswap pve") == 0 ||
+ die "unable to create swap volume";
- syscmd($pcmd) == 0 ||
- die "unable to partition harddisk '${target_hd}'\n";
+ syscmd ("/sbin/lvcreate -L${rootsize}K -nroot pve") == 0 ||
+ die "unable to create root volume";
- sleep(1); # give kernel time to reread part table
+ syscmd ("/sbin/lvcreate -L${rest}K -ndata pve") == 0 ||
+ die "unable to create data volume";
- # trigger udev to create /dev/disk/by-uuid
- syscmd ("udevadm trigger --subsystem-match block");
- syscmd ("udevadm settle --timeout 10");
+ syscmd ("/sbin/vgchange -a y pve") == 0 ||
+ die "unable to activate volume group";
- my $hdgb = int($hdsize/(1024*1024));
- die "hardisk too small (${hdgb}GB)" if $hdgb < 4;
+ return ($rootdev, $datadev, $swapfile);
+}
- my $swapsize;
- if ($config_options->{swapsize}) {
- $swapsize = $config_options->{swapsize}*1024*1024;
- } else {
- my $ss = int ($total_memory / 1024);
- $ss = 4 if $ss < 4;
- $ss = ($hdgb/8) if $ss > ($hdgb/8);
- $swapsize = $ss*1024*1024;
- }
+sub compute_swapsize {
+ my ($hdsize) = @_;
- if ($use_zfs) {
- zfs_create_rpool($zfspoolname, $lvmdev);
- $swapfile = zfs_create_swap($zfspoolname, $swapsize);
- } else {
- $rootdev = '/dev/pve/root';
- $datadev = '/dev/pve/data';
- $swapfile = '/dev/pve/swap';
+ my $hdgb = int($hdsize/(1024*1024));
- # we use --metadatasize 250k, which reseults in "pe_start = 512"
- # so pe_start is aligned on a 128k boundary (advantage for SSDs)
- syscmd ("/sbin/pvcreate --metadatasize 250k -y -ff $lvmdev") == 0 ||
- die "unable to initialize physical volume $lvmdev";
- syscmd ("/sbin/vgcreate pve $lvmdev") == 0 ||
- die "unable to create volume group";
+ my $swapsize;
+ if ($config_options->{swapsize}) {
+ $swapsize = $config_options->{swapsize}*1024*1024;
+ } else {
+ my $ss = int ($total_memory / 1024);
+ $ss = 4 if $ss < 4;
+ $ss = ($hdgb/8) if $ss > ($hdgb/8);
+ $swapsize = $ss*1024*1024;
+ }
+}
+
+sub extract_data {
+ my ($tgzfile, $targetdir) = @_;
+ die "target '$targetdir' does not exist\n" if ! -d $targetdir;
- my $space = (($hdgb > 128) ? 16 : ($hdgb/8))*1024*1024;
+ my $bootdevinfo = [];
- my $maxroot;
- if ($config_options->{maxroot}) {
- $maxroot = $config_options->{maxroot};
- } else {
- $maxroot = 96;
- }
+ my $bootdev;
+ my $datadev;
+ my $swapfile;
+ my $rootdev;
- my $rootsize = (($hdgb > ($maxroot*4)) ? $maxroot : $hdgb/4)*1024*1024;
+ my $use_zfs;
+ my $zfspoolname = $opt_testmode ? "test_rpool" : 'rpool';
- my $bootsize = $bootsize_mb * 1024;
- $bootsize += $efibootsize_mb * 1024 if $efibootdev;
+ my $filesys = $config_options->{filesys};
- my $rest = int($hdsize) - $bootsize - $swapsize - $rootsize; # in KB
+ if ($filesys =~ m/zfs/) {
+ $target_hd = undef; # do not use this config
+ $use_zfs = 1;
+ $targetdir = "/$zfspoolname/ROOT/pve-1";
+ } else {
+ $use_zfs = 0;
+ }
+
+ if ($use_zfs) {
+ my $i;
+ for ($i = 5; $i > 0; $i--) {
+ syscmd("modprobe zfs");
+ last if -c "/dev/zfs";
+ sleep(1);
+ }
- my $minfree;
- if ($config_options->{minfree}) {
- $minfree = (($config_options->{minfree}*1024*1024) >= $rest ) ? $space :
- $config_options->{minfree}*1024*1024 ;
- } else {
- $minfree = $space;
- }
+ die "unable to load zfs kernel module\n" if !$i;
+ }
- $rest = $rest - $minfree;
+ eval {
- if ($config_options->{maxvz}) {
- $rest = (($config_options->{maxvz}*1024*1024) <= $rest) ?
- $config_options->{maxvz}*1024*1024 : $rest;
- }
- syscmd ("/sbin/lvcreate -L${swapsize}K -nswap pve") == 0 ||
- die "unable to create swap volume";
+ my $maxper = 0.25;
- syscmd ("/sbin/lvcreate -L${rootsize}K -nroot pve") == 0 ||
- die "unable to create root volume";
+ update_progress (0, 0, $maxper, "create partitions");
- syscmd ("/sbin/lvcreate -L${rest}K -ndata pve") == 0 ||
- die "unable to create data volume";
+ if ($opt_testmode) {
- syscmd ("/sbin/vgchange -a y pve") == 0 ||
- die "unable to activate volume group";
- }
- } else {
$rootdev = abs_path($target_hd);
syscmd ("umount $rootdev");
if ($use_zfs) {
+ die "unsupported zfs mode (for testing environment)\n"
+ if $filesys ne 'zfs (RAID0)';
+
syscmd ("zpool destroy $zfspoolname") if $opt_testmode;
zfs_create_rpool($zfspoolname, $rootdev);
}
+
+ } elsif ($use_zfs) {
+
+ # Note: using /dev/disk/by-id/ does not work for unknown reason, we get
+ # cannot create 'rpool': no such pool or dataset
+ # my $full_path = find_stable_path ("/dev/disk/by-id", $targetdev);
+
+ my ($devlist, $bootdevlist, $vdev) = get_zfs_raid_setup();
+
+ my $disksize;
+ foreach my $hd (@$bootdevlist) {
+ my $devname = @$hd[1];
+ my ($size, $osdev, undef, $efidev) =
+ partition_bootable_disk($devname, undef, 1);
+ die "unable to mirror disks with different sizes!\n"
+ if $disksize && ($size != $disksize);
+ push @$bootdevinfo, { esp => $efidev, devname => $devname };
+ $disksize = $size;
+ $vdev =~ s/ $devname/ $osdev/;
+ }
+
+ sleep(1); # give kernel time to reread part table
+
+ # trigger udev to create /dev/disk/by-uuid
+ syscmd ("udevadm trigger --subsystem-match block");
+ syscmd ("udevadm settle --timeout 10");
+
+ zfs_create_rpool($zfspoolname, $vdev);
+
+ my $swap_size = compute_swapsize($disksize);
+ $swapfile = zfs_create_swap($zfspoolname, $swap_size);
+
+ } else {
+
+ die "target '$target_hd' is not a valid block device\n" if ! -b $target_hd;
+
+ my $maxhdsize;
+ if ($config_options->{hdsize}) {
+ # max hdsize passed on cmdline (GB)
+ $maxhdsize = $config_options->{hdsize}*1024*1024;
+ }
+
+ my ($os_size, $osdev, $efidev);
+ ($os_size, $osdev, $bootdev, $efidev) =
+ partition_bootable_disk($target_hd, $maxhdsize, $use_zfs);
+
+ push @$bootdevinfo, { esp => $efidev, devname => $target_hd };
+
+ sleep(1); # give kernel time to reread part table
+
+ # trigger udev to create /dev/disk/by-uuid
+ syscmd ("udevadm trigger --subsystem-match block");
+ syscmd ("udevadm settle --timeout 10");
+
+ my $swap_size = compute_swapsize($os_size);
+
+ if ($use_zfs) {
+
+ zfs_create_rpool($zfspoolname, $osdev);
+ $swapfile = zfs_create_swap($zfspoolname, $swap_size);
+
+ } else {
+
+ ($rootdev, $datadev, $swapfile) =
+ create_lvm_volumes($osdev, $os_size, $swap_size);
+ }
+
}
if ($use_zfs) {
update_progress (0.05, 0, $maxper, "creating filesystems");
- if ( -b $target_hd) {
- if ($efibootdev) {
- syscmd ("mkfs.vfat -F32 $efibootdev");
- }
- if (!$use_zfs) {
+ foreach my $di (@$bootdevinfo) {
+ syscmd ("mkfs.vfat -F32 $di->{esp}") == 0 ||
+ die "unable to initialize EFI ESP on device $di->{esp}\n";
+ }
+
+
+ if (!$use_zfs) {
+
+ if ( -b $target_hd) {
+
create_filesystem ($bootdev, 'boot', $filesys, 0.05, $maxper, 0, 0.1, '-m 0');
create_filesystem ($rootdev, 'root', $filesys, 0.05, $maxper, 0.1, 0.5);
create_filesystem ($datadev, 'data', $filesys, 0.05, $maxper, 0.5, 1, '-m 0');
- }
- } else {
- if (!$use_zfs) {
+
+ } else {
+
create_filesystem ($rootdev, 'root', $filesys, 0.05, $maxper, 0, 1, '-m 0');
}
}
die "unable to mount $bootdev\n";
}
- if ($efibootdev) {
+ if (scalar(@$bootdevinfo)) {
mkdir "$targetdir/boot/efi";
- syscmd ("mount -n $efibootdev $targetdir/boot/efi") == 0 ||
- die "unable to mount $efibootdev\n";
+ my $di = @$bootdevinfo[0]; # simply use first disk
+ syscmd ("mount -n $di->{esp} $targetdir/boot/efi") == 0 ||
+ die "unable to mount $di->{esp}\n";
}
if (!$use_zfs) {
}
}
+
display_html ("extract2-rulesystem.htm");
update_progress (1, 0.05, $maxper, "extracting base system");
$fstab .= "${boot_uuid} /boot $filesys defaults 0 1\n" if $boot_uuid;
}
- if ($efibootdev) {
- my $efi_boot_uuid = $efibootdev;
- if (my $uuid = find_dev_by_uuid ($efibootdev)) {
+ if (scalar(@$bootdevinfo)) {
+ my $di = @$bootdevinfo[0]; # simply use first disk
+ my $efi_boot_uuid = $di->{esp};
+ if (my $uuid = find_dev_by_uuid ($di->{esp})) {
$efi_boot_uuid = "UUID=$uuid";
}
diversion_remove ($targetdir, "/usr/sbin/update-grub");
diversion_remove ($targetdir, "/usr/sbin/update-initramfs");
- if (!$opt_testmode && -b $target_hd) {
+ if (!$opt_testmode) {
unlink ("$targetdir/etc/mtab");
symlink ("/proc/mounts", "$targetdir/etc/mtab");
syscmd ("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0 ||
die "unable to install initramfs\n";
- syscmd ("chroot $targetdir /usr/sbin/grub-install --no-floppy --bootloader-id='proxmox' ${target_hd}") == 0 ||
- die "unable to install the boot loader\n";
+ foreach my $di (@$bootdevinfo) {
+ my $dev = $di->{devname};
+ syscmd ("chroot $targetdir /usr/sbin/grub-install --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
+ die "unable to install the boot loader\n";
+ }
syscmd ("chroot $targetdir /usr/sbin/update-grub") == 0 ||
- die "unable to install the boot loader\n";
+ die "unable to update boot loader config\n";
syscmd ("umount $targetdir/dev");
}
-
# cleanup
# hack: remove dead.letter from sshd installation
syscmd ("chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> pve-final.pkglist");
}
- syscmd ("umount $targetdir/boot/efi") if $efibootdev;
+ syscmd ("umount $targetdir/boot/efi") if scalar(@$bootdevinfo);
syscmd ("umount $targetdir/boot") if !$use_zfs;
syscmd ("umount $targetdir/var/lib/vz");
syscmd ("umount $targetdir/tmp");
$w->grab_focus();
}
+my $target_hd_combo;
+my $target_hd_label;
+
+my $hdopion_first_setup = 1;
+
sub create_hdoption_view {
my $dialog = Gtk3::Dialog->new();
my $grid = Gtk3::Grid->new();
$grid->set_column_spacing(10);
$grid->set_row_spacing(10);
-
+
$hbox2->pack_start($grid, 1, 0, 10);
-
+
+ my $row = 0;
+
# Filesystem type
my $label0 = Gtk3::Label->new ("Filesystem");
$label0->set_alignment (1, 0.5);
- $grid->attach($label0, 0, 0, 1, 1);
-
+ $grid->attach($label0, 0, $row, 1, 1);
+
my $fstypecb = Gtk3::ComboBoxText->new_with_entry ();
- $fstypecb->append_text ('ext3');
- $fstypecb->append_text ('ext4');
- $fstypecb->append_text ('zfs');
+ my $fstype = ['ext3', 'ext4', 'zfs (RAID0)', 'zfs (RAID1)',
+ 'zfs (RAID10)', 'zfs (RAIDZ-1)',
+ 'zfs (RAIDZ-2)', 'zfs (RAIDZ-3)'];
- if ($config_options->{filesys} eq 'zfs') {
- $fstypecb->set_active (2);
- } elsif ($config_options->{filesys} eq 'ext4') {
- $fstypecb->set_active (1);
- } else {
- $fstypecb->set_active (0);
+ my $tcount = 0;
+ foreach my $tmp (@$fstype) {
+ $fstypecb->append_text($tmp);
+ $fstypecb->set_active ($tcount)
+ if $config_options->{filesys} eq $tmp;
+ $tcount++;
+ }
+
+ $grid->attach($fstypecb, 1, $row, 1, 1);
+
+ $hbox2->show_all();
+
+ $row++;
+
+ my @disk_label;
+ my @disk_selector;
+ for (my $i = 0; $i < 6; $i++) {
+ $disk_label[$i] = Gtk3::Label->new ("Hardisk $i");
+ $disk_label[$i]->set_alignment (1, 0.5);
+ $grid->attach($disk_label[$i], 0, $row, 1, 1);
+ $disk_selector[$i] = Gtk3::ComboBoxText->new_with_entry();
+ my $e = $disk_selector[$i]->get_child();
+ $e->set_width_chars(40);
+ foreach my $hd (@$hds) {
+ my ($disk, $devname, $size, $model) = @$hd;
+ $disk_selector[$i]->append_text (get_device_desc ($devname, $size, $model));
+ $disk_selector[$i]->{pve_disk_id} = $i;
+ $disk_selector[$i]->signal_connect (changed => sub {
+ my $w = shift;
+ my $diskid = $w->{pve_disk_id};
+ my $a = $w->get_active;
+ $config_options->{"disksel${diskid}"} = ($a >= 0) ? $hds->[$a] : undef;
+ });
+ }
+
+ if ($hdopion_first_setup) {
+ $disk_selector[$i]->set_active ($i) if $hds->[$i];
+ } else {
+ my $hdind = 0;
+ if (my $cur_hd = $config_options->{"disksel$i"}) {
+ foreach my $hd (@$hds) {
+ if (@$hd[1] eq @$cur_hd[1]) {
+ $disk_selector[$i]->set_active($hdind);
+ last;
+ }
+ $hdind++;
+ }
+
+ }
+ }
+
+ $grid->attach($disk_selector[$i], 1, $row, 1, 1);
+
+ $row++;
}
- $grid->attach($fstypecb, 1, 0, 1, 1);
+ $hdopion_first_setup = 0;
my $label_hdsize = Gtk3::Label->new ("hdsize");
$label_hdsize->set_alignment (1, 0.5);
- $grid->attach($label_hdsize, 0, 1, 1, 1);
+ $grid->attach($label_hdsize, 0, $row, 1, 1);
# size compute
- my $hdsize;
+ my $hdsize = 0;
if ( -b $target_hd) {
$hdsize = int(hd_size ($target_hd) / (1024*1024.0)); # size in GB
- } else {
+ } elsif ($target_hd) {
$hdsize = int((-s $target_hd) / (1024*1024*1024.0));
}
my $hdsize_size_adj = Gtk3::Adjustment->new($config_options->{hdsize} || $hdsize, 0, $hdsize+1, 1, 1, 1);
my $spinbutton_hdsize = Gtk3::SpinButton->new($hdsize_size_adj, 1, 1);
$spinbutton_hdsize->set_tooltip_text("only use specified size (GB) of the harddisk (rest left unpartitioned)");
- $grid->attach($spinbutton_hdsize, 1, 1, 1, 1);
+ $grid->attach($spinbutton_hdsize, 1, $row, 1, 1);
+ $row++;
my $label_swapsize = Gtk3::Label->new ("swapsize");
$label_swapsize->set_alignment (1, 0.5);
- $grid->attach($label_swapsize, 0, 2, 1, 1);
+ $grid->attach($label_swapsize, 0, $row, 1, 1);
my $entry_swapsize = Gtk3::Entry->new();
$entry_swapsize->set_tooltip_text("maximum SWAP size (GB)");
$entry_swapsize->signal_connect (key_press_event => \&check_float);
$entry_swapsize->set_text($config_options->{swapsize}) if $config_options->{swapsize};
- $grid->attach($entry_swapsize, 1, 2, 1, 1);
+ $grid->attach($entry_swapsize, 1, $row, 1, 1);
+ $row++;
my $label_maxroot = Gtk3::Label->new ("maxroot");
$label_maxroot->set_alignment (1, 0.5);
- $grid->attach($label_maxroot, 0, 3, 1, 1);
+ $grid->attach($label_maxroot, 0, $row, 1, 1);
my $entry_maxroot = Gtk3::Entry->new();
$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};
- $grid->attach($entry_maxroot, 1, 3, 1, 1);
+ $grid->attach($entry_maxroot, 1, $row, 1, 1);
+ $row++;
my $label_minfree = Gtk3::Label->new ("minfree");
$label_minfree->set_alignment (1, 0.5);
- $grid->attach($label_minfree, 0, 4, 1, 1);
+ $grid->attach($label_minfree, 0, $row, 1, 1);
my $entry_minfree = Gtk3::Entry->new();
$entry_minfree->set_tooltip_text("minumum free LVM space (GB, required for LVM snapshots)");
$entry_minfree->signal_connect (key_press_event => \&check_float);
$entry_minfree->set_text($config_options->{minfree}) if $config_options->{minfree};
- $grid->attach($entry_minfree, 1, 4, 1, 1);
+ $grid->attach($entry_minfree, 1, $row, 1, 1);
+ $row++;
my $label_maxvz = Gtk3::Label->new ("maxvz");
$label_maxvz->set_alignment (1, 0.5);
- $grid->attach($label_maxvz, 0, 5, 1, 1);
+ $grid->attach($label_maxvz, 0, $row, 1, 1);
my $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);
$entry_maxvz->set_text($config_options->{maxvz}) if $config_options->{maxvz};
- $grid->attach($entry_maxvz, 1, 5, 1, 1);
+ $grid->attach($entry_maxvz, 1, $row, 1, 1);
+ $row++;
my $set_sensitive_flag = sub {
- my $sensitive = $config_options->{filesys} ne 'zfs';
- $spinbutton_hdsize->set_sensitive($sensitive);
- $entry_swapsize->set_sensitive($sensitive);
- $entry_maxroot->set_sensitive($sensitive);
- $entry_minfree->set_sensitive($sensitive);
- $label_maxvz->set_sensitive($sensitive);
- $entry_maxvz->set_sensitive($sensitive);
+ my $enable_size_hints = $config_options->{filesys} !~ m/zfs/;
+
+ if ($config_options->{filesys} =~ m/zfs/) {
+ $target_hd_combo->set_visible(0);
+ $target_hd_label->set_text("Target: $config_options->{filesys} ");
+ foreach my $w (@disk_selector) { $w->set_visible(1); }
+ foreach my $w (@disk_label) { $w->set_visible(1); }
+ } else {
+ $target_hd_combo->set_visible(1);
+ foreach my $w (@disk_selector) { $w->set_visible(0); }
+ foreach my $w (@disk_label) { $w->set_visible(0); }
+ $target_hd_label->set_text("Target Harddisk: ");
+ }
+
+ $spinbutton_hdsize->set_visible($enable_size_hints);
+ $label_hdsize->set_visible($enable_size_hints);
+ $entry_swapsize->set_visible($enable_size_hints);
+ $label_swapsize->set_visible($enable_size_hints);
+ $entry_maxroot->set_visible($enable_size_hints);
+ $label_maxroot->set_visible($enable_size_hints);
+ $entry_minfree->set_visible($enable_size_hints);
+ $label_minfree->set_visible($enable_size_hints);
+ $entry_maxvz->set_visible($enable_size_hints);
+ $label_maxvz->set_visible($enable_size_hints);
};
&$set_sensitive_flag();
&$set_sensitive_flag();
});
- $dialog->show_all;
+ $dialog->show();
$dialog->run();
$dialog->destroy();
}
+sub get_zfs_raid_setup {
+
+ my $filesys = $config_options->{filesys};
+
+ my $dev_name_hash = {};
+
+ my $devlist = [];
+ my $bootdevlist = [];
+ for (my $i = 0; $i < 6; $i++) {
+ if (my $hd = $config_options->{"disksel$i"}) {
+ my ($disk, $devname, $size, $model) = @$hd;
+ die "device '$devname' is used more than once\n"
+ if $dev_name_hash->{$devname};
+ $dev_name_hash->{$devname} = $hd;
+ push @$devlist, $hd;
+ }
+ }
+
+ die "$filesys need at least one device\n" if scalar(@$devlist) < 1;
+
+ my $cmd= '';
+ if ($filesys eq 'zfs (RAID0)') {
+ push @$bootdevlist, @$devlist[0];
+ foreach my $hd (@$devlist) {
+ $cmd .= " @$hd[1]";
+ }
+ } elsif ($filesys eq 'zfs (RAID1)') {
+ $cmd .= ' mirror ';
+ foreach my $hd (@$devlist) {
+ $cmd .= " @$hd[1]";
+ push @$bootdevlist, $hd;
+ }
+ } elsif ($filesys eq 'zfs (RAID10)') {
+ my $count = scalar(@$devlist);
+ my $half = int($count/2);
+ die "zfs (RAID10) need at least 2 device\n" if $count < 2;
+ die "zfs (RAID10) need at an even numver of devices\n" if $half*2 != $count;
+
+ push @$bootdevlist, @$devlist[0], @$devlist[1];
+
+ for (my $i = 0; $i < $count; $i+=2) {
+ my $hd1 = @$devlist[$i];
+ my $hd2 = @$devlist[$i+1];
+ $cmd .= ' mirror ' . @$hd1[1] . ' ' . @$hd2[1];
+ }
+
+ } elsif ($filesys =~ m/^zfs \(RAIDZ-([123])\)$/) {
+ my $level = $1;
+ my $mindisks = 2 + $level;
+ die "zfs (RAIDZ-$level) need at least $mindisks devices\n" if scalar(@$devlist) < $mindisks;
+ $cmd .= ' raidz$level';
+ foreach my $hd (@$devlist) {
+ $cmd .= " @$hd[1]";
+ push @$bootdevlist, $hd;
+ }
+ } else {
+ die "unknown zfs mode '$filesys'\n";
+ }
+
+ return ($devlist, $bootdevlist, $cmd);
+}
+
sub create_hdsel_view {
cleanup_view ();
my ($disk, $devname, $size, $model) = @{@$hds[0]};
$target_hd = $devname;
- $master_hd = find_master ($target_hd);
- my $label;
- $label = Gtk3::Label->new ("Target Harddisks: ");
- $hbox->pack_start ($label, 0, 0, 0);
+ $target_hd_label = Gtk3::Label->new ("Target Harddisk: ");
+ $hbox->pack_start ($target_hd_label, 0, 0, 0);
- my $combo = Gtk3::ComboBoxText->new_with_entry();
- my $e = $combo->get_child();
+ $target_hd_combo = Gtk3::ComboBoxText->new_with_entry();
+ my $e = $target_hd_combo->get_child();
$e->set_width_chars(40);
foreach my $hd (@$hds) {
($disk, $devname, $size, $model) = @$hd;
- $combo->append_text (get_device_desc ($devname, $size, $model));
+ $target_hd_combo->append_text (get_device_desc ($devname, $size, $model));
}
- $combo->set_active (0);
- $combo->signal_connect (changed => sub {
+ $target_hd_combo->set_active (0);
+ $target_hd_combo->signal_connect (changed => sub {
$a = shift->get_active;
my ($disk, $devname) = @{@$hds[$a]};
$target_hd = $devname;
- $master_hd = find_master ($target_hd);
});
-
- $hbox->pack_start ($combo, 0, 0, 10);
+
+ $hbox->pack_start ($target_hd_combo, 0, 0, 10);
my $options = Gtk3::Button->new ('_Options');
$options->signal_connect (clicked => \&create_hdoption_view);
$inbox->show_all;
display_html ("page1.htm");
- set_next (undef, \&create_country_view);
+
+ set_next (undef, sub {
+
+ if ($config_options->{filesys} =~ m/zfs/) {
+ eval { get_zfs_raid_setup(); };
+ if (my $err = $@) {
+ display_message ("Warning: $err\n" .
+ "Please fix ZFS setup first.");
+ } else {
+ create_country_view();
+ }
+ } else {
+ create_country_view();
+ }
+ });
}
sub create_extract_view {