-## create subvols ##
-cd /mnt
-btrfs subvolume create root_$DISTRO
-[[ -e q ]] || btrfs subvolume create q
-chown root:1000 q
-
-mkdir -p /mnt/root_$DISTRO/boot
-for x in q/a q/i; do
- mkdir -p $x
- chown 1000:1000 $x
- chmod 755 $x
-done
-# could set default like this, but no reason to.
-# btrfs subvolume set-default \
- # $(btrfs subvolume list . | grep "root_$DISTRO$" | awk '{print $2}') .
-chattr -Rf +C root_$DISTRO
-cd /
-umount /mnt
+if [[ $DISTRO != debianstable_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.
+ s=($(btrfs subvolume list --sort=-path /mnt |
+ sed -rn "s#^.*path\s*(root_$DISTRO/\S+)\s*\$#\1#p"))
+ for subvol in ${s[@]}; do btrfs subvolume delete /mnt/$subvol; done
+ btrfs subvolume set-default 0 /mnt
+ [[ ! -e /mnt/root_$DISTRO ]] || btrfs subvolume delete /mnt/root_$DISTRO
+
+ ## create subvols ##
+ cd /mnt
+
+ btrfs subvolume create root_$DISTRO
+
+ mkdir -p /mnt/root_$DISTRO/boot
+ # could set default subvol like this, but no reason to.
+ # btrfs subvolume set-default \
+ # $(btrfs subvolume list . | grep "root_$DISTRO$" | awk '{print $2}') .
+
+ # no cow on the root filesystem. it's setup is fully scripted,
+ # if it's messed up, we will just recreated it,
+ # and we can get better perf with this.
+ # I can't remember exactly why, but this is preferable to mounting with
+ # -o nodatacow, I think because subvolumes inherit that.
+ chattr -Rf +C root_$DISTRO
+ cd /
+ umount /mnt
+fi
+