125 lines
2.7 KiB
Bash
125 lines
2.7 KiB
Bash
rwx_rescue_wipe_0_init_hetzner_8_8() {
|
|
local device
|
|
set \
|
|
"/dev/sda" \
|
|
"/dev/sdb"
|
|
local members
|
|
local number
|
|
local passphrase
|
|
# read passphrase
|
|
passphrase="$(rwx_read_passphrase)"
|
|
# warn
|
|
rwx_warn_wipe "${@}"
|
|
#
|
|
number=0
|
|
for device in "${@}"; do
|
|
number=$((number + 1))
|
|
echo
|
|
echo "#${number}: ${device}"
|
|
#
|
|
parted --script "${device}" \
|
|
mktable gpt \
|
|
unit "mib" \
|
|
mkpart "crypt-${number}" 33282 7630885 \
|
|
mkpart "boot-${number}" 514 33282 \
|
|
mkpart "esp-${number}" 2 514 \
|
|
set 3 esp on \
|
|
mkpart "bios-${number}" 1 2 \
|
|
set 4 bios_grub on
|
|
done
|
|
#
|
|
number=0
|
|
for device in "${@}"; do
|
|
number=$((number + 1))
|
|
echo
|
|
echo "#${number}: ${device}4"
|
|
# wipe bios
|
|
rwx_fs_wipe "${device}4"
|
|
done
|
|
#
|
|
number=0
|
|
for device in "${@}"; do
|
|
number=$((number + 1))
|
|
echo
|
|
echo "#${number}: ${device}3"
|
|
# format esp
|
|
rwx_fs_wipe "${device}3" "1M"
|
|
rwx_fs_make_fat "${device}3" "esp-${number}" "0000000${number}"
|
|
# mount esp
|
|
mkdir --parents "/media/esp/${number}"
|
|
mount "${device}3" "/media/esp/${number}"
|
|
done
|
|
#
|
|
number=0
|
|
for device in "${@}"; do
|
|
number=$((number + 1))
|
|
echo
|
|
echo "#${number}: ${device}2"
|
|
# wipe boot
|
|
rwx_fs_wipe "${device}2" "1G" 1
|
|
done
|
|
#
|
|
members=""
|
|
for device in "${@}"; do
|
|
members="${members} ${device}2"
|
|
done
|
|
rwx_fs_raid_create \
|
|
"boot" "00000000:00000000:00000000:00000002" ${members}
|
|
#
|
|
rwx_fs_make_btrfs "/dev/md/boot" "boot" \
|
|
"00000000-0000-0000-0000-00000000000b"
|
|
# mount boot
|
|
mkdir --parents "/media/boot"
|
|
mount \
|
|
--options "autodefrag,compress-force=zstd" \
|
|
"/dev/md/boot" "/media/boot"
|
|
#
|
|
number=0
|
|
for device in "${@}"; do
|
|
number=$((number + 1))
|
|
echo
|
|
echo "#${number}: ${device}1"
|
|
# wipe crypt head
|
|
rwx_fs_wipe "${device}1" "1G" 1
|
|
done
|
|
#
|
|
members=""
|
|
for device in "${@}"; do
|
|
members="${members} ${device}1"
|
|
done
|
|
rwx_fs_raid_create \
|
|
"crypt" "00000000:00000000:00000000:00000001" ${members}
|
|
# encrypt
|
|
rwx_fs_luks_format "${passphrase}" "/dev/md/crypt"
|
|
# open
|
|
echo "${passphrase}" |
|
|
cryptsetup luksOpen "/dev/md/crypt" "crypt"
|
|
# passphrase
|
|
unset passphrase
|
|
}
|
|
|
|
rwx_rescue_wipe_2_make_hetzner_8_8() {
|
|
local passphrase
|
|
# close
|
|
cryptsetup luksClose "crypt"
|
|
# read passphrase
|
|
passphrase="$(rwx_read_passphrase)"
|
|
# encrypt
|
|
rwx_fs_luks_format "${passphrase}" "/dev/md/crypt"
|
|
# open
|
|
echo "${passphrase}" |
|
|
cryptsetup luksOpen "/dev/md/crypt" "crypt"
|
|
# passphrase
|
|
unset passphrase
|
|
# format crypt
|
|
rwx_fs_make_btrfs "/dev/mapper/crypt" "crypt" \
|
|
"00000000-0000-0000-0000-00000000000c"
|
|
# mount crypt
|
|
mkdir --parents "/media/crypt"
|
|
mount \
|
|
--options "autodefrag,compress-force=zstd" \
|
|
"/dev/mapper/crypt" "/media/crypt"
|
|
# make swap file
|
|
rwx_fs_make_btrfs_swap "/media/crypt/swap" "64g" \
|
|
"00000000-0000-0000-0000-000000000005"
|
|
}
|