From e5516e835d0508b9d3bac110936c3e9b90d43d53 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Wed, 11 Sep 2024 17:12:14 -0400 Subject: [PATCH] fixies for fsf special_disk partitioning --- fai/config/hooks/partition.DEFAULT | 70 +++++++++++++++--------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/fai/config/hooks/partition.DEFAULT b/fai/config/hooks/partition.DEFAULT index 5d13b99..47f103e 100755 --- a/fai/config/hooks/partition.DEFAULT +++ b/fai/config/hooks/partition.DEFAULT @@ -429,29 +429,20 @@ EOF exit 0 } -d() { - if $dry_run; then - printf "%s\n" "$*" +maybe-prompt() { + if [[ $SPECIAL_DISK ]]; then + cmd_prompt+=("$*") else "$@" fi } -# usage: lvmwipe [-n] SHORT_DEV_NAME... -# -n dry run. +# usage: lvmwipe SHORT_DEV_NAME... # example: lvmwipe /dev/sda /dev/sdb lvmwipe() { - local dry_run pv_dev short_dev vg lvs lv pv vgs_of_pv + local pv_dev short_dev vg lvs lv pv vgs_of_pv local -a wipe_short_devs pv_wipes vg_wipes pv_devs local -A vg_map - dry_run=false - case $1 in - -n) - dry_run=true - shift - ;; - esac - would_wipe=false wipe_short_devs=("$@") for short_dev in "${wipe_short_devs[@]}"; do if [[ $short_dev != /dev/* ]]; then @@ -475,7 +466,7 @@ lvmwipe() { vg_wipes+=($vg) lvs=$(vgs --noheadings -o lv_path $vg) for lv in $lvs; do - d wipefs --backup -a $lv + maybe-prompt wipefs --backup -a $lv done done fi @@ -483,13 +474,12 @@ lvmwipe() { done for vg in ${vg_wipes[@]}; do - d vgchange -an $vg - d vgremove -ff $vg + maybe-prompt vgchange -an $vg + maybe-prompt vgremove -ff $vg done for pv in ${pv_wipes[@]}; do - would_wipe=true - d pvremove -ff $pv + maybe-prompt pvremove -ff $pv done } @@ -597,12 +587,6 @@ pvn=1 bootn=2 -# rootn=1 -# root2n=2 -# swapn=3 -# bootn=4 -# boot2n=5 - efin=3 # ext partition so grub can write persistent variables, # so it can do a one time boot. grub can't write to @@ -785,7 +769,14 @@ else root2_mib=100 boot2_mib=100 fi -boot_part_mib=$(( boot_mib * raid_duplication / ${#boot_devs[@]} )) + +if [[ $SPECIAL_DISK ]]; then + # In this case, the number of detected boot_devs may not be what we + # actually end up using if and when we use this disk's boot partition. + boot_part_mib=$boot_mib +else + boot_part_mib=$(( boot_mib * raid_duplication / ${#boot_devs[@]} )) +fi if zilap; then boot2_part_mib=$(( boot2_mib * raid_duplication / ${#boot_devs[@]} )) @@ -850,7 +841,7 @@ fi # -# for servers, 4gb min based on https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/managing_storage_devices/getting-started-with-swap_managing-storage-devices#recommended-system-swap-space_getting-started-with-swap +# for servers, a bit randomly picking 6gb per disk based on https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/managing_storage_devices/getting-started-with-swap_managing-storage-devices#recommended-system-swap-space_getting-started-with-swap # meh, i'll just do that * drives for machines with lots of ram. mem_kb=$(awk '$1 == "MemTotal:" {print $2}' /proc/meminfo) mem_gb=$(( mem_kb / 1024 / 1024 )) @@ -858,7 +849,7 @@ if (( mem_gb < 64 )); then # enable hibernate with 1.5x of ram, split per disk swap_mib=$(( mem_gb * 3 / ${#devs[@]} )) else - swap_mib=4096 + swap_mib=6144 fi shopt -s nullglob @@ -884,13 +875,22 @@ fi if $partition; then ### begin wipefs if [[ $SPECIAL_DISK ]]; then - lvmwipe -n $SPECIAL_DISK - if $would_wipe; then - echo wipefs --backup -a $SPECIAL_DISK* - echo "$0: exiting. review and execute above wipefs commands manually" + lvmwipe $SPECIAL_DISK + maybe-prompt sleep 10 + maybe-prompt wipefs --backup -a $SPECIAL_DISK* + echo "$0: execute the following?" + for cmd in "${cmd_prompt[@]}"; do + echo "$cmd" + done + read -r -t 1000 -p 'Y/n ' -n 1 prompt_input + if [[ ! $prompt_input || $prompt_input == [Yy] ]]; then + for cmd in "${cmd_prompt[@]}"; do + $cmd + done + else + echo "$0: got negative response: $prompt_input. exiting" exit 0 fi - devwipe $SPECIAL_DISK else # we do lvm removals just for the disks we are using lvmwipe "${short_devs[@]}" @@ -979,7 +979,7 @@ if $partition; then fi fi - if [[ $SPECIAL_DISK ]] && ! $fsf; then + if [[ $SPECIAL_DISK ]] && ! fsf; then lvcreate -y -L $root_mib $vg -n data else # -L unit default mebibyte @@ -1042,7 +1042,7 @@ if $partition; then done sleep 3 - if ! $fsf; then + if ! fsf; then mkfs.fat -F32 $dev$efisuf fi -- 2.30.2