changes for bullseye
[automated-distro-installer] / fai / config / hooks / partition.DEFAULT
index 0a0c2ad69946535a624c74d0ce3f7443ad69671c..3d024af5dbcc789939423f3afa2fc14089677d86 100755 (executable)
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
+PS4='+ $LINENO '
 set -eE -o pipefail
 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 
+if [[ $EUID != 0 ]]; then
+  echo "$0: error: need to run as root" >&2
+  exit 1
+fi
+
 # for calling outside of FAI:
 # # need to redep and set that location so that we get luks keys
 # export FAI=/srv/fai/config
@@ -147,18 +153,23 @@ else
   wipe=true
 fi
 
-## ignore disks that are mounted, eg when running from fai-cd
-declare -A disk_excludes
-while read -r l; do
-  eval "$l"
-  if [[ ! $PKNAME ]]; then
-    PKNAME="$KNAME"
-  fi
-  if [[ $MOUNTPOINT ]]; then
-    disk_excludes[$PKNAME]=true
-  fi
-done < <(lsblk -nP -o KNAME,MOUNTPOINT,PKNAME)
+if ((`nproc` > 2)); then
+  mopts=,compress=zstd
+fi
 
+declare -A disk_excludes
+if ! ifclass USE_MOUNTED; then
+  ## ignore disks that are mounted, eg when running from fai-cd
+  while read -r l; do
+    eval "$l"
+    if [[ ! $PKNAME ]]; then
+      PKNAME="$KNAME"
+    fi
+    if [[ $MOUNTPOINT ]]; then
+      disk_excludes[$PKNAME]=true
+    fi
+  done < <(lsblk -nP -o KNAME,MOUNTPOINT,PKNAME)
+fi
 
 hdds=()
 ssds=()
@@ -294,12 +305,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
@@ -308,8 +321,6 @@ 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
@@ -505,7 +516,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.
@@ -542,17 +553,17 @@ 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
 else
   boot_vol=boot_$DISTRO
 fi
-if $wipe; then
-  if [[ -e /mnt/$boot_vol ]]; then
-    btrfs subvolume delete /mnt/$boot_vol
-  fi
+if $wipe && [[ -e /mnt/$boot_vol ]]; then
+  btrfs subvolume delete /mnt/$boot_vol
+fi
+if [[ ! -e /mnt/$boot_vol ]]; then
   btrfs subvolume create $boot_vol
 fi
 cd /
@@ -565,7 +576,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
@@ -576,8 +587,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