- for dev in ${devs[@]}; do
- parted -s $dev mklabel gpt
- # gpt ubuntu cloud image uses ~4. fai uses 1 MiB.
- # I read something in the parted manual saying cheap flash media
- # likes to start at 4.
- # MiB because parted complains about alignment otherwise.
- pcmd="parted -a optimal -s -- $dev"
- $pcmd mkpart primary "ext3" 4MiB ${root_end}MiB
- $pcmd mkpart primary "linux-swap" ${root_end}MiB ${swap_end}MiB
- $pcmd mkpart primary "" ${swap_end}MiB ${disk_mib}MiB
- $pcmd mkpart primary "" 1MiB 4MiB
- $pcmd set $bios_grubn bios_grub on
- $pcmd set $bootn boot on # generally not needed on modern systems
- # the mkfs failed randomly on a vm, so I threw a sleep in here.
- sleep .1
-
- luks_dev=$dev$rootn
- yes YES | cryptsetup luksFormat $luks_dev $luks_dir/host-$HOSTNAME \
- -c aes-cbc-essiv:sha256 -s 256 || [[ $? == 141 ]]
- yes "$lukspw" | \
- cryptsetup luksAddKey --key-file $luks_dir/host-$HOSTNAME \
- $luks_dev || [[ $? == 141 ]]
- # background: Keyfile and password are treated just
- # like 2 ways to input a passphrase, so we don't actually need to have
- # different contents of keyfile and passphrase, but it makes some
- # security sense to a really big randomly generated passphrase
- # as much as possible, so we have both.
- #
- # This would remove the keyfile.
- # yes 'test' | cryptsetup luksRemoveKey /dev/... \
- # /key/file || [[ $? == 141 ]]
-
- cryptsetup luksOpen $luks_dev crypt_dev_${luks_dev##/dev/} \
- --key-file $luks_dir/host-$HOSTNAME
+ fi
+ ### end wipefs
+
+
+ # When we have 2 disks of at least 100g difference in size,
+ # make an extra partition on the end of the bigger one.
+ even_big_part=false
+ even_diff_min=100000
+ if $even_raid; then
+ smalli=0
+ bigi=1
+ if (( $(dev-mib ${devs[0]}) >= $(dev-mib ${devs[1]}) )); then
+ smalli=1
+ bigi=0
+ fi
+ disk_mib=$(dev-mib ${devs[smalli]})
+ even_big_dev=${devs[bigi]}
+ even_big_mib=$(dev-mib $even_big_dev)
+ if (( even_big_mib - disk_mib > even_diff_min )); then
+ even_big_part=true
+ fi
+ fi
+
+ for dev in ${devs[@]}; do
+ if [[ $SPECIAL_DISK ]]; then
+ dev=$(devbyid $SPECIAL_DISK)
+ fi
+
+ # parted will round up the disk size. Do -1 so we can have
+ # fully 1MiB unit partitions for easy resizing of the last partition.
+ # Otherwise we would pass in -0 for the end argument for the last partition.
+ #
+ # Note: parted print error output is expected. example:
+ # Error: /dev/vda: unrecognised disk label
+ if ! $even_raid; then
+ disk_mib=$(dev-mib)
+ fi
+
+ boot_part_mib=$(( boot_mib / ${#boot_devs[@]} ))
+ boot2_part_mib=$(( boot2_mib / ${#boot_devs[@]} ))
+ root2_part_mib=$(( root2_mib / ${#root_devs[@]} ))
+ build_part_mib=$(( build_mib / ${#root_devs[@]} ))
+ whonix_part_mib=$(( whonix_mib / ${#root_devs[@]} ))
+ browse_part_mib=$(( browse_mib / ${#root_devs[@]} ))
+ root_end=$(( disk_mib - boot_part_mib - boot2_part_mib ))
+ boot_end=$(( root_end + boot_part_mib ))
+
+ parted -s $dev mklabel gpt
+ # MiB because parted complains about alignment otherwise.
+ pcmd="parted -a optimal -s -- $dev"
+ # root partition, the main big one
+ $pcmd mkpart primary ext2 524MiB ${root_end}MiB
+ # without naming, systemd gives us misc errors like:
+ # dev-disk-by\x2dpartlabel-primary.device: Dev dev-disk-by\x2dpartlabel-primary.device appeared twice
+ $pcmd set $rootn lvm on
+ $pcmd name $rootn root
+ # boot partition
+ $pcmd mkpart primary "" ${root_end}MiB ${boot_end}MiB
+ $pcmd name $bootn boot
+ # boot2 partition
+ $pcmd mkpart primary "" ${boot_end}MiB ${disk_mib}MiB
+ $pcmd name $boot2n boot2
+ # uefi partition. efi sucks, half a gig, rediculous.
+ $pcmd mkpart primary "fat32" 12MiB 524MiB
+ $pcmd name $efin efi
+ $pcmd set $efin esp on
+ # note, this is shown here: https://support.system76.com/articles/bootloader/
+ # but not mentioned https://wiki.archlinux.org/index.php/EFI_system_partition
+ # probably not needed
+ $pcmd set $bootn boot on
+ $pcmd set $boot2n boot 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 $(bios_grubdev) ]] && (( secs < 10 )); do
+ sleep 1
+ secs=$((secs +1))