+ sleep 3
+ pvcreate -y -ff $dev$pvsuf
+ vgcreate -y -ff $vg $dev$pvsuf
+
+ if fsf; then
+ root_mib=40000
+ else
+ # This would maximize it, but we are going for a separate filesystem in /o,
+ # so use fixed sizes to allow both to grow
+ # 600 = uefi 512 + grubext 8 + bios grub 3 + some extra cuz this is lvm
+ #root_mib=$(( disk_mib - root2_part_mib - swap_mib - boot_part_mib - boot2_part_mib - 600 ))
+ o_mib=$(( 120 * 1000 ))
+ # max minus o, minus a gig just for some extra space
+ max_root_mib=$(( disk_mib - root2_part_mib - swap_mib - boot_part_mib - boot2_part_mib - 600 - o_mib - 1000 ))
+ root_mib=$(( 1000 * 1000 )) # * 1000 to make it in gb.
+ if (( max_root_mib < root_mib )); then
+ root_mib=$max_root_mib
+ fi
+ fi
+
+ if [[ $SPECIAL_DISK ]]; then
+ lvcreate -y -L $max_root_mib $vg -n data
+ else
+ # -L unit default mebibyte
+ lvcreate -y -L $root_mib $vg -n root
+ if ! fsf; then
+ lvcreate -y -L $o_mib $vg -n o
+ fi
+ lvcreate -y -L $swap_mib $vg -n swap
+ # unencrypted swap needs mkswap
+ if fsf; then
+ mkswap /dev/$vg/swap
+ fi
+ fi
+
+ $pcmd mkpart primary "" ${pv_end}MiB ${disk_mib}MiB
+ $pcmd name $bootn boot
+ $pcmd set $bootn boot on
+
+ # uefi partition, for normal bios systems, its just in case.
+ $pcmd mkpart primary "fat32" 12MiB 524MiB
+ $pcmd name $efin efi
+ # note, this is shown here: https://support.system76.com/articles/bootloader/
+ # but not mentioned https://wiki.archlinux.org/index.php/EFI_system_partition
+ # might not be needed
+ $pcmd set $efin esp on
+
+ # i only need a few k, but googling min size,
+ # I found someone saying that gparted required
+ # required at least 8 because of their hard drive cylinder size.
+ # And 8 is still very tiny.
+ # grub_ext partition
+ $pcmd mkpart primary "ext2" 4MiB 12MiB
+ $pcmd name $grub_extn grubext
+ # gpt ubuntu cloud image uses ~4 mb for this partition. fai uses 1 MiB.
+ # so, I use 3, whatever.
+ # note: parted manual saying cheap flash media
+ # should to start at 4.
+ # biols grub partition
+ $pcmd mkpart primary "" 1MiB 4MiB
+ $pcmd name $bios_grubn biosgrub
+ $pcmd set $bios_grubn bios_grub on
+ if $even_big_part && [[ $dev == "$even_big_dev" ]]; then
+ $pcmd mkpart primary ext3 ${disk_mib}MiB ${even_big_mib}MiB
+ $pcmd name $even_bign even_big
+ fi
+
+ # the mkfs failed before on a vm, which prompted me to add
+ # sleep .1
+ # then it failed again on a physical machine
+ # with:
+ # Device /dev/disk/by-id/foo doesn't exist or access denied,
+ # so I added a wait until it existed.
+ # Then I added the mkfs.ext2, which claimed to succeed,
+ # but then couldn't be found upon reboot. In that case we didn't
+ # wait at all. So I've added a 3 second minimum wait.
+ secs=0
+ while [[ ! -e $dev$efisuf ]] && (( secs < 40 )); do
+ sleep 1
+ secs=$((secs +1))
+ done
+ sleep 3
+
+ mkfs.fat -F32 $dev$efisuf
+
+ if ! fsf && $even_big_part && [[ $dev == "$even_big_dev" ]]; then
+ luks-setup $even_big_dev$even_bigsuf ${even_big_dev##*/}$even_bigsuf
+ mkfs.btrfs -f /dev/mapper/${even_big_dev##*/}$even_bigsuf
+ fi
+
+ # Holds just a single file, rarely written, so
+ # use ext2, like was often used for the /boot partition.
+ # This exists because grub can only persist data to a non-cow fs.
+ # And we use persisting a var in grub to do a one time boot.
+ # We could pass the data on the kernel command line and persist it
+ # to grubenv after booting, but that relies on the boot always succeeding.
+ # 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 $dev$grub_extsuf
+
+ if [[ $SPECIAL_DISK ]]; then
+ luks-setup /dev/$vg/data crypt-$vg-data
+ exit 0
+ fi
+
+ # for fsf, no encryption of root because root will not contain any
+ # sensitive data.
+ if ! fsf; then
+ luks-setup /dev/$vg/root crypt-$vg-root
+ luks-setup /dev/$vg/o crypt-$vg-o
+ fi
+
+ done
+ ls -la /dev/btrfs-control # this was probably for debugging...
+ sleep 1
+
+ bpart ${root_devs[@]}
+ if ! fsf; then
+ bpart ${o_devs[@]}
+ fi
+ bpart ${boot_devs[@]}
+
+else ## end if $partition ##
+
+ if ! fsf; then
+ for vg in ${vgs[@]}; do
+ if [[ -e /dev/mapper/crypt-$vg-root ]]; then
+ continue
+ fi
+ if $rerootfs; then
+ luks-setup /dev/$vg/root crypt-$vg-root
+ else
+ cryptsetup luksOpen /dev/$vg/root crypt-$vg-root \
+ --key-file $luks_file
+ cryptsetup luksOpen /dev/$vg/o crypt-$vg-o \
+ --key-file $luks_file
+ fi
+ done
+ fi
+
+ if $rerootfs; then