sh/bash/rescue-ovh.sh

106 lines
2.3 KiB
Bash
Raw Normal View History

2024-11-11 17:06:27 +00:00
rescue_wipe_0_init_ovh_vle2() {
2024-11-11 14:40:04 +00:00
local device="/dev/sdb"
local passphrase
# read passphrase
2024-11-12 08:28:08 +00:00
passphrase="$(read_passphrase)"
2024-11-11 15:37:27 +00:00
# warn
2024-11-11 11:32:13 +00:00
lsblk
printf "%s" "WIPE ${device} /?\\ OR CANCEL /!\\"
read -r
#
2024-11-12 18:45:47 +00:00
parted --script "${device}" \
mktable gpt \
unit "mib" \
mkpart "crypt" 4610 40959 \
mkpart "boot" 514 4610 \
mkpart "esp" 2 514 \
set 3 esp on \
mkpart bios 1 2 \
2024-11-11 16:21:21 +00:00
set 4 bios_grub on
2024-11-11 15:37:27 +00:00
# bios / wipe
2024-11-12 19:22:58 +00:00
fs_wipe "${device}4"
2024-11-11 15:37:27 +00:00
# esp / wipe
2024-11-12 19:22:58 +00:00
fs_wipe "${device}3" "1M"
2024-11-11 15:37:27 +00:00
# esp / format
2024-11-12 19:03:47 +00:00
fs_make_fat "${device}3" "esp" "00000001"
2024-11-11 15:37:27 +00:00
# esp / mount
mkdir --parents "/media/esp"
mount "${device}3" "/media/esp"
# boot / wipe
2024-11-12 19:22:58 +00:00
fs_wipe "${device}2" "1G" 1
2024-11-11 15:37:27 +00:00
# boot / format
mkfs.btrfs --force \
2024-11-11 15:38:48 +00:00
--checksum "sha256" \
--label "boot" \
--uuid "00000000-0000-0000-0000-00000000000b" \
"${device}2"
2024-11-11 15:37:27 +00:00
# boot / mount
mkdir --parents "/media/boot"
mount --options "autodefrag,compress-force=zstd" \
"${device}2" "/media/boot"
# crypt / wipe
2024-11-12 19:22:58 +00:00
fs_wipe "${device}1" "1G" 1
2024-11-11 15:37:27 +00:00
# crypt / encrypt
2024-11-11 11:37:07 +00:00
echo "${passphrase}" |
cryptsetup \
--verbose \
--batch-mode \
--type "luks2" \
--pbkdf "argon2id" \
--cipher "aes-xts-plain64" \
2024-11-11 15:37:27 +00:00
--iter-time 4096 \
2024-11-11 11:37:07 +00:00
--key-size 512 \
--hash "sha512" \
--use-random \
luksFormat \
2024-11-11 14:40:04 +00:00
"${device}1"
2024-11-11 15:37:27 +00:00
# crypt / open
2024-11-11 11:37:07 +00:00
echo "${passphrase}" |
2024-11-11 14:40:04 +00:00
cryptsetup luksOpen "${device}1" "crypt"
2024-11-12 08:28:08 +00:00
# passphrase
unset passphrase
2024-11-11 15:37:27 +00:00
}
2024-11-11 17:06:27 +00:00
rescue_wipe_2_make_ovh_vle2() {
2024-11-11 21:16:37 +00:00
local device="/dev/sdb"
2024-11-11 15:37:27 +00:00
local passphrase
# crypt / close
2024-11-11 11:32:13 +00:00
cryptsetup luksClose "crypt"
2024-11-11 15:37:27 +00:00
# read passphrase
2024-11-12 08:28:08 +00:00
passphrase="$(read_passphrase)"
2024-11-11 15:37:27 +00:00
# crypt / encrypt
echo "${passphrase}" |
cryptsetup \
--verbose \
--batch-mode \
--type "luks2" \
--pbkdf "argon2id" \
--cipher "aes-xts-plain64" \
--iter-time 4096 \
--key-size 512 \
--hash "sha512" \
--use-random \
luksFormat \
"${device}1"
# crypt / open
echo "${passphrase}" |
cryptsetup luksOpen "${device}1" "crypt"
2024-11-12 08:28:08 +00:00
# passphrase
unset passphrase
2024-11-11 15:37:27 +00:00
# crypt / format
mkfs.btrfs --force \
2024-11-11 15:38:48 +00:00
--checksum "sha256" \
--label "crypt" \
--uuid "00000000-0000-0000-0000-00000000000c" \
2024-11-11 21:21:17 +00:00
"/dev/mapper/crypt"
2024-11-11 15:37:27 +00:00
# crypt / mount
mkdir --parents "/media/crypt"
mount --options "autodefrag,compress-force=zstd" \
2024-11-11 21:21:17 +00:00
"/dev/mapper/crypt" "/media/crypt"
2024-11-11 15:37:27 +00:00
# crypt / swap
btrfs filesystem mkswapfile \
2024-11-11 15:38:48 +00:00
--size "4g" \
--uuid "00000000-0000-0000-0000-000000000005" \
"/media/crypt/swap"
2024-11-11 15:37:27 +00:00
}