[pve-devel] [RFC/PATCH v2 installer 1/3] Add minfree handling for ZFS

Stoiko Ivanov s.ivanov at proxmox.com
Thu Nov 15 18:02:01 CET 2018


Change partitioning scheme for zfs bootable disks to align with the
wiki-entries by zol-upstream [0]:

* Still create a bios_boot partition in the beginning
* Add 512M for future use as /boot/efi
* Optionally leave `minfree` GB unpartitioned (e.g. for swap)
* The actual ZFS partition
* Leave 8M at the end, accounting for slight differences in disk size
* change sgdisk command-order to get partitions aligned to 1MiB

[0] https://github.com/zfsonlinux/zfs/wiki/Debian-Stretch-Root-on-ZFS

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 proxinstall | 41 +++++++++++++++++++++++++++--------------
 1 file changed, 27 insertions(+), 14 deletions(-)

diff --git a/proxinstall b/proxinstall
index fac87ee..18679c6 100755
--- a/proxinstall
+++ b/proxinstall
@@ -937,34 +937,47 @@ sub partition_bootable_zfs_disk {
     syscmd("sgdisk -Z ${target_dev}");
     my $hdsize = hd_size($target_dev); # size in blocks (1024 bytes)
 
-    my $hdgb = int($hdsize/(1024*1024));
-    die "hardisk '$target_dev' too small (${hdsize}GB)\n" if $hdgb < 8;
+    my $minfree = defined($config_options->{minfree}) ? int($config_options->{minfree} * 1024*1024) : 0;
+    my $remaining_hdsize = $hdsize - $minfree;
 
-    # 1 - GRUB boot partition: 1M
-    # 2 - OS/Data partition
-    # 9 - ZFS reserved partition
+    my $hdgb = int($remaining_hdsize/(1024*1024));
+    die "hardisk '$target_dev' too small (${hdgb}GB)\n" if $hdgb < 8;
 
-    my $grubbootdev = get_partition_dev($target_dev, 1);
-    my $osdev = get_partition_dev ($target_dev, 2);
+    # 3 - GRUB boot partition: 1M
+    # 2 - EFI partition: 512M
+    # 1 - OS/Data partition
+    # optional minfree unpartitioned space
+    # 9 - ZFS reserved partition 8M
 
-    my $pcmd = ['sgdisk', '-a1'];
+    my $os_size = $remaining_hdsize - 1024*522; #512M efi + 1M bios_boot +1M alignment + 8M ZFS-reserve
 
-    my $pnum = 1;
-    push @$pcmd, "-n$pnum:34:2047", "-t$pnum:EF02";
+    my $grubbootdev = get_partition_dev($target_dev, 2);
+    my $osdev = get_partition_dev ($target_dev, 1);
+
+    my $pcmd = ['sgdisk'];
+
+    my $pnum = 3;
+    push @$pcmd, "-n$pnum:1M:+512M", "-t$pnum:EF00";
 
     $pnum = 9;
     push @$pcmd, "-n$pnum:-8M:0", "-t$pnum:BF07";
 
-    $pnum = 2;
-    push @$pcmd, "-n$pnum:2048:0", "-t$pnum:BF01", '-c', "$pnum:zfs";
+    $pnum = 1;
+    push @$pcmd, "-n$pnum:513M:+${os_size}K", "-t$pnum:BF01", '-c', "$pnum:zfs";
 
     push @$pcmd, $target_dev;
 
-    my $os_size = $hdsize - 1024 - 1024*8;
-
     syscmd($pcmd) == 0 ||
 	die "unable to partition harddisk '${target_dev}'\n";
 
+    $pcmd = ['sgdisk', '-a1'];
+
+    $pnum = 2;
+    push @$pcmd, "-n$pnum:34:2047", "-t$pnum:EF02" , $target_dev;
+
+    syscmd($pcmd) == 0 ||
+	die "unable to create bios_boot partition '${target_dev}'\n";
+
     &$udevadm_trigger_block();
 
     syscmd("dd if=/dev/zero of=$osdev bs=1M count=16") if -b $osdev;
-- 
2.11.0





More information about the pve-devel mailing list