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
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
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
}
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
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[@]} ))
#
-# 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 ))
# 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
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[@]}"
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
done
sleep 3
- if ! $fsf; then
+ if ! fsf; then
mkfs.fat -F32 $dev$efisuf
fi