mostly nabia and update bootstrap to buster
[automated-distro-installer] / fai / config / hooks / partition.DEFAULT
index ebd38667c418824240cd7bb96bebb24d2a54949d..e9cce5009a04fb20311611299064982c7cd51353 100755 (executable)
@@ -25,12 +25,12 @@ if [[ $EUID != 0 ]]; then
 fi
 
 # for calling outside of FAI:
-# # need to redep and set that location so that we get luks keys
-# export FAI=/srv/fai/config
 # fai-redep
+# s
 # source /b/fai/fai-wrapper
 # - set any appropriate classes with: fai-setclass OPT1... which sets CLASS_OPT1=true...
 #   or run eval-fai-classfile FILE
+# export luks_dir=/q/root/luks
 #
 # OPTIONS:
 #
@@ -74,7 +74,7 @@ skiptask partition || ! type skiptask
 
 if ! type -p devbyid; then
   for d in $FAI/distro-install-common \
-             /a/bin/fai/fai/config/distro-install-common $FAI $PWD; do
+               /a/bin/fai/fai/config/distro-install-common $FAI $PWD; do
     [[ -d $d ]] || continue
     if [[ -e $d/devbyid ]]; then
       devbyid=$d/devbyid
@@ -153,6 +153,9 @@ else
   wipe=true
 fi
 
+if ((`nproc` > 2)); then
+  mopts=,compress=zstd
+fi
 
 declare -A disk_excludes
 if ! ifclass USE_MOUNTED; then
@@ -267,9 +270,13 @@ for dev in ${devs[@]}; do
   fi
 done
 
+even_raid=false
 if ifclass RAID0 || (( ${#boot_devs[@]} == 1 )); then
   raid_level=0
 elif ifclass RAID1 || (( ${#boot_devs[@]} <= 3 )); then
+  if (( ${#boot_devs[@]} == 2 )); then
+    even_raid=true
+  fi
   raid_level=1
 else
   raid_level=10
@@ -302,12 +309,14 @@ esac
 
 
 if [[ ! $DISTRO ]]; then
-  if ifclass VOL_STRETCH_BOOTSTRAP; then
-    DISTRO=debianstretch_bootstrap
+  if ifclass VOL_BUSTER_BOOTSTRAP; then
+    DISTRO=debianbuster_bootstrap
   elif ifclass VOL_STRETCH; then
     DISTRO=debianstretch
   elif ifclass VOL_BUSTER; then
     DISTRO=debianbuster
+  elif ifclass VOL_BULLSEYE; then
+    DISTRO=debianbullseye
   elif ifclass VOL_TESTING; then
     DISTRO=debiantesting
   elif ifclass VOL_XENIAL; then
@@ -316,12 +325,12 @@ if [[ ! $DISTRO ]]; then
     DISTRO=ubuntubionic
   elif ifclass VOL_FOCAL; then
     DISTRO=ubuntufocal
-  elif ifclass VOL_BELENOS; then
-    DISTRO=trisquelbelenos
   elif ifclass VOL_FLIDAS; then
     DISTRO=trisquelflidas
   elif ifclass VOL_ETIONA; then
     DISTRO=trisqueletiona
+  elif ifclass VOL_NABIA; then
+    DISTRO=trisquelnabia
   else
     echo "PARTITIONER ERROR: no distro class/var set" >&2
     exit 1
@@ -339,33 +348,33 @@ bpart() { # btrfs a partition
 }
 
 
-if [[ ! -e /a/bin/fai/fai-wrapper ]]; then
+if [[ ! $luks_dir ]]; then
   # see README for docs about how to create these
   luks_dir=$FAI/distro-install-common/luks
+fi
 
-  luks_file=$luks_dir/host-$HOSTNAME
-  if [[ ! -e $luks_file ]]; then
-    hostkeys=($luks_dir/host-*)
-    # if there is only one key, we might be deploying somewhere
-    # where dhcp doesnt give us a proper hostname, so use that.
-    if [[ ${#hostkeys[@]} == 1 && -e ${hostkeys[0]} ]]; then
-      luks_file=${hostkeys[0]}
-    else
-      echo "$0: error: no key for hostname at $luks_file" >&2
-      exit 1
-    fi
-  fi
-
-  # # note, corresponding changes in /b/ds/keyscript-{on,off}
-  if ifclass demohost; then
-    lukspw=x
-  elif [[ -e $luks_dir/$HOSTNAME ]]; then
-    lukspw=$(cat $luks_dir/$HOSTNAME)
+luks_file=$luks_dir/host-$HOSTNAME
+if [[ ! -e $luks_file ]]; then
+  hostkeys=($luks_dir/host-*)
+  # if there is only one key, we might be deploying somewhere
+  # where dhcp doesnt give us a proper hostname, so use that.
+  if [[ ${#hostkeys[@]} == 1 && -e ${hostkeys[0]} ]]; then
+    luks_file=${hostkeys[0]}
   else
-    lukspw=$(cat $luks_dir/iank)
+    echo "$0: error: no key for hostname at $luks_file" >&2
+    exit 1
   fi
 fi
 
+# # note, corresponding changes in /b/ds/keyscript-{on,off}
+if ifclass demohost; then
+  lukspw=x
+elif [[ -e $luks_dir/$HOSTNAME ]]; then
+  lukspw=$(cat $luks_dir/$HOSTNAME)
+else
+  lukspw=$(cat $luks_dir/iank)
+fi
+
 
 first_root_crypt=$(root-cryptdev ${devs[0]})
 
@@ -401,6 +410,17 @@ if $partition; then
   fi
   ### end wipefs
 
+
+  if $even_raid; then
+    for dev in ${devs[@]}; do
+      disk_mib=$(( $(parted -m $dev unit MiB print | \
+                       sed -nr "s#^/dev/[^:]+:([0-9]+).*#\1#p") - 1))
+      if [[ ! min_disk_mib ]] || (( disk_mib < min_disk_mib )); then
+        min_disk_mib=$disk_mib
+      fi
+    done
+  fi
+
   for dev in ${devs[@]}; do
     if [[ $SPECIAL_DISK ]]; then
       dev=$(devbyid $SPECIAL_DISK)
@@ -412,8 +432,12 @@ if $partition; then
     #
     # Note: parted print error output is expected. example:
     # Error: /dev/vda: unrecognised disk label
-    disk_mib=$(( $(parted -m $dev unit MiB print | \
-                     sed -nr "s#^/dev/[^:]+:([0-9]+).*#\1#p") - 1))
+    if $even_raid; then
+      disk_mib=$min_disk_mib
+    else
+      disk_mib=$(( $(parted -m $dev unit MiB print | \
+                       sed -nr "s#^/dev/[^:]+:([0-9]+).*#\1#p") - 1))
+    fi
     root_end=$(( disk_mib - swap_mib - boot_mib /  ${#boot_devs[@]} ))
     swap_end=$(( root_end + swap_mib))
 
@@ -468,7 +492,7 @@ if $partition; then
     # This is just a bit more robust, and it could work for booting
     # into ipxe which can't persist data, if we ever got that working.
     mkfs.ext2 $(grub_extdev)
-    # when we move to newer than trisquel 8, we can remove
+    # when we move to newer than trisquel 9, we can remove
     # --type luks1. We can also check on cryptsetup --help | less /compil
     # to see about the other settings. Default in debian 9 is luks2.
     # You can convert from luks2 to luks 1 by adding a temporary key:
@@ -513,7 +537,7 @@ else
 fi
 
 
-if $wipe && [[ $DISTRO != debianstretch_bootstrap ]]; then
+if $wipe && [[ $DISTRO != debianbuster_bootstrap ]]; then
   # bootstrap distro doesn't use separate encrypted root.
   mount -o subvolid=0 $first_root_crypt /mnt
   # systemd creates subvolumes we want to delete.
@@ -550,7 +574,7 @@ btrfs subvolume set-default 0 /mnt # already default, just ensuring it.
 mkdir -p /mnt/grub2
 cp $FAI/distro-install-common/libreboot_grub.cfg /mnt/grub2
 
-if [[ $DISTRO == debianstretch_bootstrap ]]; then
+if [[ $DISTRO == debianbuster_bootstrap ]]; then
   # this is just convenience for the libreboot_grub config
   # so we can glob the other ones easier.
   boot_vol=$DISTRO
@@ -573,7 +597,7 @@ grub-editenv /mnt/grubenv set did_fai_check=true
 grub-editenv /mnt/grubenv set last_boot=/$boot_vol
 umount /mnt
 
-if [[ $DISTRO == debianstretch_bootstrap ]]; then
+if [[ $DISTRO == debianbuster_bootstrap ]]; then
   cat > /tmp/fai/fstab <<EOF
 $first_boot_dev  /  btrfs  noatime,subvol=$boot_vol  0 0
 EOF
@@ -584,8 +608,8 @@ EOF
 else
   # note, fai creates the mountpoints listed here
   cat > /tmp/fai/fstab <<EOF
-$first_root_crypt  /  btrfs          noatime,subvol=root_$DISTRO  0 0
-$first_root_crypt  /mnt/root  btrfs  nofail,noatime,subvolid=0  0 0
+$first_root_crypt  /  btrfs          noatime,subvol=root_$DISTRO$mopts  0 0
+$first_root_crypt  /mnt/root  btrfs  nofail,noatime,subvolid=0$mopts  0 0
 $first_boot_dev  /boot  btrfs        nofail,noatime,subvol=$boot_vol  0 0
 $first_boot_dev  /mnt/boot  btrfs    nofail,noatime,subvolid=0  0 0
 EOF