This commit is contained in:
Marc Beninca 2024-11-12 09:35:29 +01:00
parent 305968a9e6
commit 4e81f18817
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -1,18 +1,18 @@
rescue_wipe_0_init_hetzner_8_8() { rescue_wipe_0_init_hetzner_8_8() {
local device local device
local devices=( local devices=(
'/dev/sda' "/dev/sda"
'/dev/sdb' "/dev/sdb"
) )
local members local members
local number local number
local passphrase local passphrase
local unit='mib' local unit="mib"
# read passphrase # read passphrase
passphrase="$(read_passphrase)" passphrase="$(read_passphrase)"
# #
lsblk lsblk
echo -n 'WIPE' "${devices[@]}" '/?\ OR CANCEL /!\' echo -n "WIPE" "${devices[@]}" "/?\\ OR CANCEL /!\\"
read read
# #
number=0 number=0
@ -53,7 +53,7 @@ rescue_wipe_0_init_hetzner_8_8() {
echo "#${number}: ${device}4" echo "#${number}: ${device}4"
# wipe bios # wipe bios
dd \ dd \
if='/dev/zero' of="${device}4" if="/dev/zero" of="${device}4"
done done
# #
number=0 number=0
@ -63,7 +63,7 @@ rescue_wipe_0_init_hetzner_8_8() {
echo "#${number}: ${device}3" echo "#${number}: ${device}3"
# format esp # format esp
dd \ dd \
if='/dev/zero' of="${device}3" bs='1M' if="/dev/zero" of="${device}3" bs="1M"
mkfs.vfat \ mkfs.vfat \
-F 32 \ -F 32 \
-S 4096 \ -S 4096 \
@ -81,8 +81,8 @@ rescue_wipe_0_init_hetzner_8_8() {
echo echo
echo "#${number}: ${device}2" echo "#${number}: ${device}2"
# wipe boot # wipe boot
dd status='progress' \ dd status="progress" \
if='/dev/zero' of="${device}2" bs='1G' count=1 if="/dev/zero" of="${device}2" bs="1G" count=1
done done
# #
members=() members=()
@ -90,24 +90,24 @@ rescue_wipe_0_init_hetzner_8_8() {
members+=("${device}2") members+=("${device}2")
done done
mdadm \ mdadm \
--create '/dev/md/boot' \ --create "/dev/md/boot" \
--level 0 \ --level 0 \
--metadata 1 \ --metadata 1 \
--name 'md:boot' \ --name "md:boot" \
--raid-devices ${#devices[@]} \ --raid-devices ${#devices[@]} \
--uuid '00000000:00000000:00000000:00000002' \ --uuid "00000000:00000000:00000000:00000002" \
"${members[@]}" "${members[@]}"
# #
mkfs.btrfs --force \ mkfs.btrfs --force \
--checksum 'sha256' \ --checksum "sha256" \
--label 'boot' \ --label "boot" \
--uuid '00000000-0000-0000-0000-00000000000b' \ --uuid "00000000-0000-0000-0000-00000000000b" \
'/dev/md/boot' "/dev/md/boot"
# mount boot # mount boot
mkdir --parents '/media/boot' mkdir --parents "/media/boot"
mount \ mount \
--options 'autodefrag,compress-force=zstd' \ --options "autodefrag,compress-force=zstd" \
'/dev/md/boot' '/media/boot' "/dev/md/boot" "/media/boot"
# #
number=0 number=0
for device in "${devices[@]}"; do for device in "${devices[@]}"; do
@ -115,8 +115,8 @@ rescue_wipe_0_init_hetzner_8_8() {
echo echo
echo "#${number}: ${device}1" echo "#${number}: ${device}1"
# wipe crypt head # wipe crypt head
dd status='progress' \ dd status="progress" \
if='/dev/zero' of="${device}1" bs='1G' count=1 if="/dev/zero" of="${device}1" bs="1G" count=1
done done
# #
members=() members=()
@ -124,30 +124,30 @@ rescue_wipe_0_init_hetzner_8_8() {
members+=("${device}1") members+=("${device}1")
done done
mdadm \ mdadm \
--create '/dev/md/crypt' \ --create "/dev/md/crypt" \
--level 0 \ --level 0 \
--metadata 1 \ --metadata 1 \
--name 'md:crypt' \ --name "md:crypt" \
--raid-devices ${#devices[@]} \ --raid-devices ${#devices[@]} \
--uuid '00000000:00000000:00000000:00000001' \ --uuid "00000000:00000000:00000000:00000001" \
"${members[@]}" "${members[@]}"
# encrypt # encrypt
echo "${passphrase}" | echo "${passphrase}" |
cryptsetup \ cryptsetup \
--verbose \ --verbose \
--batch-mode \ --batch-mode \
--type 'luks2' \ --type "luks2" \
--pbkdf 'argon2id' \ --pbkdf "argon2id" \
--cipher 'aes-xts-plain64' \ --cipher "aes-xts-plain64" \
--iter-time 8192 \ --iter-time 8192 \
--key-size 512 \ --key-size 512 \
--hash 'sha512' \ --hash "sha512" \
--use-random \ --use-random \
luksFormat \ luksFormat \
'/dev/md/crypt' "/dev/md/crypt"
# open # open
echo "${passphrase}" | echo "${passphrase}" |
cryptsetup luksOpen '/dev/md/crypt' 'crypt' cryptsetup luksOpen "/dev/md/crypt" "crypt"
# passphrase # passphrase
unset passphrase unset passphrase
} }
@ -155,7 +155,7 @@ rescue_wipe_0_init_hetzner_8_8() {
rescue_wipe_2_make_hetzner_8_8() { rescue_wipe_2_make_hetzner_8_8() {
local passphrase local passphrase
# close # close
cryptsetup luksClose 'crypt' cryptsetup luksClose "crypt"
# read passphrase # read passphrase
passphrase="$(read_passphrase)" passphrase="$(read_passphrase)"
# encrypt # encrypt
@ -163,34 +163,34 @@ rescue_wipe_2_make_hetzner_8_8() {
cryptsetup \ cryptsetup \
--verbose \ --verbose \
--batch-mode \ --batch-mode \
--type 'luks2' \ --type "luks2" \
--pbkdf 'argon2id' \ --pbkdf "argon2id" \
--cipher 'aes-xts-plain64' \ --cipher "aes-xts-plain64" \
--iter-time 8192 \ --iter-time 8192 \
--key-size 512 \ --key-size 512 \
--hash 'sha512' \ --hash "sha512" \
--use-random \ --use-random \
luksFormat \ luksFormat \
'/dev/md/crypt' "/dev/md/crypt"
# open # open
echo "${passphrase}" | echo "${passphrase}" |
cryptsetup luksOpen '/dev/md/crypt' 'crypt' cryptsetup luksOpen "/dev/md/crypt" "crypt"
# passphrase # passphrase
unset passphrase unset passphrase
# format crypt # format crypt
mkfs.btrfs --force \ mkfs.btrfs --force \
--checksum 'sha256' \ --checksum "sha256" \
--label 'crypt' \ --label "crypt" \
--uuid '00000000-0000-0000-0000-00000000000c' \ --uuid "00000000-0000-0000-0000-00000000000c" \
'/dev/mapper/crypt' "/dev/mapper/crypt"
# mount crypt # mount crypt
mkdir --parents '/media/crypt' mkdir --parents "/media/crypt"
mount \ mount \
--options 'autodefrag,compress-force=zstd' \ --options "autodefrag,compress-force=zstd" \
'/dev/mapper/crypt' '/media/crypt' "/dev/mapper/crypt" "/media/crypt"
# make swap file # make swap file
btrfs filesystem mkswapfile \ btrfs filesystem mkswapfile \
--size '64g' \ --size "64g" \
--uuid '00000000-0000-0000-0000-000000000005' \ --uuid "00000000-0000-0000-0000-000000000005" \
'/media/crypt/swap' "/media/crypt/swap"
} }