X-Git-Url: https://iankelling.org/git/?p=automated-distro-installer;a=blobdiff_plain;f=fai%2Fconfig%2Fhooks%2Fpartition.DEFAULT;h=80f0d7c4a70afd9dfb86f616c7830089bb06bcc3;hp=09020d27b30fbf55e864b4e30abfbc5f99f686f7;hb=bfd6bbd3a188aac6871f8b5e1116a0979682d52b;hpb=739efea3642e2f8a7a672c4600da152a27bedf1a diff --git a/fai/config/hooks/partition.DEFAULT b/fai/config/hooks/partition.DEFAULT index 09020d2..80f0d7c 100755 --- a/fai/config/hooks/partition.DEFAULT +++ b/fai/config/hooks/partition.DEFAULT @@ -26,16 +26,17 @@ fi # for calling outside of FAI: # 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. -# - Set a VOL_DISTROVER, eg: +# - Set a VOL_DISTROVER (if not doing mkroot2) eg: # fai-setclass VOL_NABIA -# - export luks_dir=/q/root/luks # # OPTIONS: # +# mkroot2: for running outside of fai and setting up the root2/boot2 luks and btrfs +# # environment variables: # # HOSTNAME: if frodo, we exclude 2 devices from the /boot array, which @@ -63,6 +64,20 @@ fi # raid10. # RAID1: forces raid1 filesystem. +mkroot2=false +if [[ $1 ]]; then + case $1 in + mkroot2) + mkroot2=true + ;; + *) + echo "$0: error: unsupported arg: $1" >&2 + exit 1 + ;; + esac +fi + + if [[ $SPECIAL_DISK ]]; then export CLASS_REPARTITION=true fi @@ -104,18 +119,20 @@ fi # boot rootn=1 -swapn=2 -bootn=3 -efin=4 +root2n=2 +swapn=3 +bootn=4 +boot2n=5 +efin=6 # ext partition so grub can write persistent variables, # so it can do a one time boot. grub can't write to # btrfs or any cow fs because it's more # more complicated to do and they don't want to. -grub_extn=5 +grub_extn=7 # bios boot partition, # https://wiki.archlinux.org/index.php/GRUB -bios_grubn=6 -even_bign=7 +bios_grubn=8 +even_bign=9 lastn=$bios_grubn @@ -135,9 +152,11 @@ add-part() { # add partition suffix to $dev echo $d-part$part } -bootdev() { add-part $@ $bootn; } rootdev() { add-part $@ $rootn; } +root2dev() { add-part $@ $root2n; } swapdev() { add-part $@ $swapn; } +bootdev() { add-part $@ $bootn; } +boot2dev() { add-part $@ $boot2n; } efidev() { add-part $@ $efin; } grub_extdev() { add-part $@ $grub_extn; } bios_grubdev() { add-part $@ $bios_grubn; } @@ -146,8 +165,10 @@ even_bigdev() { add-part $@ $even_bign; } crypt-dev() { echo /dev/mapper/crypt_dev_${1##*/}; } crypt-name() { echo crypt_dev_${1##*/}; } root-cryptdev() { crypt-dev $(rootdev $@); } +root2-cryptdev() { crypt-dev $(root2dev $@); } swap-cryptdev() { crypt-dev $(swapdev $@); } root-cryptname() { crypt-name $(rootdev $@); } +root2-cryptname() { crypt-name $(root2dev $@); } swap-cryptname() { crypt-name $(swapdev $@); } dev-mib() { @@ -165,8 +186,7 @@ luks-setup() { # cryptsetup luksAddKey --pbkdf pbkdf2 # then remove the new format keys with cryptsetup luksRemoveKey # then cryptsetup convert DEV --type luks1, then readd old keys and remove temp. - yes YES | cryptsetup luksFormat $luksdev $luks_file \ - --type luks1 -c aes-cbc-essiv:sha256 -s 256 || [[ $? == 141 ]] + yes YES | cryptsetup luksFormat $luksdev $luks_file || [[ $? == 141 ]] yes "$lukspw" | \ cryptsetup luksAddKey --key-file $luks_file \ $luksdev || [[ $? == 141 ]] @@ -200,7 +220,7 @@ if (($(nproc) > 2)); then fi declare -A disk_excludes -if ! ifclass USE_MOUNTED; then +if ! $mkroot2 && ! ifclass USE_MOUNTED; then ## ignore disks that are mounted, eg when running from fai-cd while read -r l; do eval "$l" @@ -274,6 +294,7 @@ fi boot_space=0 first=true boot_devs=() +boot2_devs=() for dev in ${devs[@]}; do if ifclass frodo; then # I ran into a machine where the bios doesn't know about some disks, @@ -299,11 +320,15 @@ for dev in ${devs[@]}; do break fi done - $bad_disk || boot_devs+=($(bootdev)) + if ! $bad_disk; then + boot_devs+=($(bootdev)) + boot2_devs+=($(boot2dev)) + fi else boot_space=$(( boot_space + $(parted -m $dev unit MiB print | \ sed -nr "s#^/dev/[^:]+:([0-9]+).*#\1#p") - 1)) boot_devs+=($(bootdev)) + boot2_devs+=($(boot2dev)) fi if $first && [[ $boot_devs ]]; then first_efi=$(efidev) @@ -335,31 +360,42 @@ if (( boot_space > 60000 )); then # becuase I keep a minimal debian install on it for # recovery needs and for doing pxe-kexec. boot_mib=10000 -elif (( boot_space > 30000 )); then + root2_mib=200000 + boot2_mib=2000 +elif (( boot_spa_ce > 30000 )); then boot_mib=$(( 5000 + (boot_space - 30000) / 2 )) + root2_mib=100 + boot2_mib=100 else # Small vms don't have room for /boot recovery. With 3 kernels # installed, i'm using 132M on t8, so this seems like plenty of # room. note: rhel 8 recomments 1g for /boot. boot_mib=500 - # + root2_mib=100 + boot2_mib=100 fi case $raid_level in - 1*) boot_mib=$(( boot_mib * 2 )) ;; + 1*) + boot_mib=$(( boot_mib * 2 )) + boot2_mib=$(( boot2_mib * 2 )) + root2_mib=$(( root2_mib * 2 )) + ;; esac ### end calculate boot partition space if [[ ! $DISTRO ]]; then - if ifclass VOL_BUSTER_BOOTSTRAP; then - DISTRO=debianbuster_bootstrap + if ifclass VOL_BULLSEYE_BOOTSTRAP; then + DISTRO=debianbullseye_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_BOOKWORM; then + DISTRO=debianbookworm elif ifclass VOL_TESTING; then DISTRO=debiantesting elif ifclass VOL_XENIAL; then @@ -374,6 +410,8 @@ if [[ ! $DISTRO ]]; then DISTRO=trisqueletiona elif ifclass VOL_NABIA; then DISTRO=trisquelnabia + elif $mkroot2; then + : else echo "PARTITIONER ERROR: no distro class/var set" >&2 exit 1 @@ -393,6 +431,13 @@ bpart() { # btrfs a partition if [[ ! $luks_dir ]]; then # see README for docs about how to create these luks_dir=$FAI/distro-install-common/luks + if [[ ! -d $luks_dir ]]; then + luks_dir=/q/root/luks + fi + if [[ ! -d $luks_dir ]]; then + echo "$0: error: no luks_dir found" >&2 + exit 1 + fi fi luks_file=$luks_dir/host-$HOSTNAME @@ -430,8 +475,36 @@ for dev in ${devs[@]}; do root_devs+=($(rootdev)) done shopt -s nullglob -if $partition; then +# We write to these files instead of just /etc/fstab, /etc/crypttab, +# because these are filesystems created after our current root, and so +# this allows us to update other root filesystems too. +rm -f /mnt/root/root2-{fs,crypt}tab +if $mkroot2; then + if $partition; then + echo $0: error: found partition=true but have mkroot2 arg + exit 1 + fi + for dev in ${devs[@]}; do + luks_file=$luks_dir/host-amy + lukspw=$(cat $luks_dir/amy) + luks-setup $(root2dev) + cat >>/mnt/root/root2-crypttab <>/mnt/root/root2-fstab < /tmp/fai/fstab </tmp/fai/disk_var.sh < /tmp/fai/fstab <> /tmp/fai/fstab <>/tmp/fai/crypttab <> /tmp/fai/fstab <