feat: add raid1 support

This commit is contained in:
thiblizz 2023-10-20 23:39:49 +02:00 committed by GitHub
parent dfabf41185
commit e5b0fe6313
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 117 additions and 15 deletions

22
configure vendored
View File

@ -169,6 +169,7 @@ function define_disk_layout() {
"zfs_centric") define_disk_configuration_function "create_zfs_centric_layout swap=$(define_swap) type=${PARTITIONING_BOOT_TYPE@Q} encrypt=${PARTITIONING_ZFS_USE_ENCRYPTION@Q} compress=$(define_zfs_compression) pool_type=${PARTITIONING_ZFS_POOL_TYPE@Q}" "${PARTITIONING_DEVICES[@]@Q}" ;; "zfs_centric") define_disk_configuration_function "create_zfs_centric_layout swap=$(define_swap) type=${PARTITIONING_BOOT_TYPE@Q} encrypt=${PARTITIONING_ZFS_USE_ENCRYPTION@Q} compress=$(define_zfs_compression) pool_type=${PARTITIONING_ZFS_POOL_TYPE@Q}" "${PARTITIONING_DEVICES[@]@Q}" ;;
"btrfs_centric") define_disk_configuration_function "create_btrfs_centric_layout swap=$(define_swap) type=${PARTITIONING_BOOT_TYPE@Q} raid_type=${PARTITIONING_BTRFS_RAID_TYPE@Q} luks=${PARTITIONING_USE_LUKS@Q}" "${PARTITIONING_DEVICES[@]@Q}" ;; "btrfs_centric") define_disk_configuration_function "create_btrfs_centric_layout swap=$(define_swap) type=${PARTITIONING_BOOT_TYPE@Q} raid_type=${PARTITIONING_BTRFS_RAID_TYPE@Q} luks=${PARTITIONING_USE_LUKS@Q}" "${PARTITIONING_DEVICES[@]@Q}" ;;
"raid0_luks") define_disk_configuration_function "create_raid0_luks_layout swap=$(define_swap) type=${PARTITIONING_BOOT_TYPE@Q} root_fs=${PARTITIONING_ROOT_FS@Q}" "${PARTITIONING_DEVICES[@]@Q}" ;; "raid0_luks") define_disk_configuration_function "create_raid0_luks_layout swap=$(define_swap) type=${PARTITIONING_BOOT_TYPE@Q} root_fs=${PARTITIONING_ROOT_FS@Q}" "${PARTITIONING_DEVICES[@]@Q}" ;;
"raid1_luks") define_disk_configuration_function "create_raid1_luks_layout swap=$(define_swap) type=${PARTITIONING_BOOT_TYPE@Q} root_fs=${PARTITIONING_ROOT_FS@Q}" "${PARTITIONING_DEVICES[@]@Q}" ;;
"custom") "custom")
# Show current function declaration, trim trailing whitespace # Show current function declaration, trim trailing whitespace
declare -f disk_configuration \ declare -f disk_configuration \
@ -208,6 +209,7 @@ ALL_PARTITIONING_SCHEMES=(
"zfs_centric" "ZFS centric (optional ZFS compression and encryption)" "zfs_centric" "ZFS centric (optional ZFS compression and encryption)"
"btrfs_centric" "Btrfs centric (optional raid0/1 via btrfs)" "btrfs_centric" "Btrfs centric (optional raid0/1 via btrfs)"
"raid0_luks" "Raid0 (N>=2 disks) and luks for root" "raid0_luks" "Raid0 (N>=2 disks) and luks for root"
"raid1_luks" "Raid1 (N>=2 disks) and luks for root"
"custom" "Custom (expert option; edit the config manually later)" "custom" "Custom (expert option; edit the config manually later)"
) )
@ -292,6 +294,19 @@ function create_raid0_luks_layout() {
PARTITIONING_ROOT_FS="${arguments[root_fs]:-ext4}" PARTITIONING_ROOT_FS="${arguments[root_fs]:-ext4}"
} }
function create_raid1_luks_layout() {
PARTITIONING_SCHEME="raid1_luks"
local known_arguments=('+swap' '?type' '?root_fs')
local extra_arguments=()
declare -A arguments; parse_arguments "$@"
PARTITIONING_DEVICES=("${extra_arguments[@]}")
parse_swap "${arguments[swap]}"
PARTITIONING_BOOT_TYPE="${arguments[type]}"
PARTITIONING_ROOT_FS="${arguments[root_fs]:-ext4}"
}
function create_zfs_centric_layout() { function create_zfs_centric_layout() {
PARTITIONING_SCHEME="zfs_centric" PARTITIONING_SCHEME="zfs_centric"
@ -905,6 +920,7 @@ function PARTITIONING_SCHEME_menu() {
"zfs_centric") create_zfs_centric_layout swap=8GiB type="$DEFAULT_BOOT_TYPE" encrypt=true compress=zstd pool_type=standard /dev/sdX ;; "zfs_centric") create_zfs_centric_layout swap=8GiB type="$DEFAULT_BOOT_TYPE" encrypt=true compress=zstd pool_type=standard /dev/sdX ;;
"btrfs_centric") create_btrfs_centric_layout swap=8GiB type="$DEFAULT_BOOT_TYPE" raid_type=raid0 luks=false /dev/sdX ;; "btrfs_centric") create_btrfs_centric_layout swap=8GiB type="$DEFAULT_BOOT_TYPE" raid_type=raid0 luks=false /dev/sdX ;;
"raid0_luks") create_raid0_luks_layout swap=8GiB type="$DEFAULT_BOOT_TYPE" root_fs=ext4 /dev/sdX /dev/sdY ;; "raid0_luks") create_raid0_luks_layout swap=8GiB type="$DEFAULT_BOOT_TYPE" root_fs=ext4 /dev/sdX /dev/sdY ;;
"raid1_luks") create_raid1_luks_layout swap=8GiB type="$DEFAULT_BOOT_TYPE" root_fs=ext4 /dev/sdX /dev/sdY ;;
"custom") PARTITIONING_SCHEME="$dialog_out" ;; "custom") PARTITIONING_SCHEME="$dialog_out" ;;
esac esac
UNSAVED_CHANGES=true UNSAVED_CHANGES=true
@ -1012,7 +1028,7 @@ function PARTITIONING_SWAP_DEVICE_menu() {
function PARTITIONING_ROOT_FS_tag() { echo " ├ Root filesystem"; } function PARTITIONING_ROOT_FS_tag() { echo " ├ Root filesystem"; }
function PARTITIONING_ROOT_FS_label() { echo " ├ ($PARTITIONING_ROOT_FS)"; } function PARTITIONING_ROOT_FS_label() { echo " ├ ($PARTITIONING_ROOT_FS)"; }
function PARTITIONING_ROOT_FS_show() { [[ $PARTITIONING_SCHEME != "custom" ]] && one_of "$PARTITIONING_SCHEME" "classic_single_disk" "raid0_luks"; } function PARTITIONING_ROOT_FS_show() { [[ $PARTITIONING_SCHEME != "custom" ]] && one_of "$PARTITIONING_SCHEME" "classic_single_disk" "raid0_luks" "raid1_luks"; }
function PARTITIONING_ROOT_FS_help() { echo "Select the amount of swap to use."; } function PARTITIONING_ROOT_FS_help() { echo "Select the amount of swap to use."; }
function PARTITIONING_ROOT_FS_menu() { function PARTITIONING_ROOT_FS_menu() {
if menu_radiolist \ if menu_radiolist \
@ -1152,7 +1168,7 @@ function PARTITIONING_DEVICES_label() {
if [[ "$invalid" -gt 0 ]]; then if [[ "$invalid" -gt 0 ]]; then
echo " └ (${#PARTITIONING_DEVICES[@]} devices, \Z1$invalid invalid\Zn)" echo " └ (${#PARTITIONING_DEVICES[@]} devices, \Z1$invalid invalid\Zn)"
elif [[ "${#PARTITIONING_DEVICES[@]}" -eq 1 && "$PARTITIONING_SCHEME" == "raid0_luks" ]]; then elif [[ "${#PARTITIONING_DEVICES[@]}" -eq 1 && "$PARTITIONING_SCHEME" == "raid0_luks" || "$PARTITIONING_SCHEME" == "raid1_luks" ]]; then
echo " └ (${#PARTITIONING_DEVICES[@]} devices, \Z1need at least 2\Zn)" echo " └ (${#PARTITIONING_DEVICES[@]} devices, \Z1need at least 2\Zn)"
elif [[ "${#PARTITIONING_DEVICES[@]}" -eq 0 ]]; then elif [[ "${#PARTITIONING_DEVICES[@]}" -eq 0 ]]; then
echo " └ (${#PARTITIONING_DEVICES[@]} devices, \Z1need at least 1\Zn)" echo " └ (${#PARTITIONING_DEVICES[@]} devices, \Z1need at least 1\Zn)"
@ -1160,7 +1176,7 @@ function PARTITIONING_DEVICES_label() {
echo " └ (${#PARTITIONING_DEVICES[@]} devices)" echo " └ (${#PARTITIONING_DEVICES[@]} devices)"
fi fi
} }
function PARTITIONING_DEVICES_show() { [[ $PARTITIONING_SCHEME != "custom" ]] && one_of "$PARTITIONING_SCHEME" "raid0_luks" "zfs_centric" "btrfs_centric"; } function PARTITIONING_DEVICES_show() { [[ $PARTITIONING_SCHEME != "custom" ]] && one_of "$PARTITIONING_SCHEME" "raid0_luks" "raid1_luks" "zfs_centric" "btrfs_centric"; }
function PARTITIONING_DEVICES_help() { echo "The block devices to which the layout will be applied."; } function PARTITIONING_DEVICES_help() { echo "The block devices to which the layout will be applied."; }
function PARTITIONING_DEVICES_menu() { function PARTITIONING_DEVICES_menu() {
local invalid=() local invalid=()

View File

@ -74,7 +74,22 @@ function disk_configuration() {
# Careful: You will get N times the swap amount, so be sure to divide beforehand. # Careful: You will get N times the swap amount, so be sure to divide beforehand.
#create_raid0_luks_layout swap=4GiB type=efi root_fs=ext4 /dev/sd{X,Y} #create_raid0_luks_layout swap=4GiB type=efi root_fs=ext4 /dev/sd{X,Y}
# 4. create_btrfs_centric_layout # 4. create_raid1_luks_layout
#
# This layout creates the single disk layout on multiple disks and combines
# the swap and root partitions in separate raid1 arrays. Useful if you e.g. have
# several nvme drives and want data redundancy. Only one boot partition will actually
# be used though.
#
# Parameters:
# swap=<size> Create a swap partition with given size for each disk,
# or no swap at all if set to false
# type=[efi|bios] Selects the boot type. Defaults to efi if not given.
# root_fs=[ext4|btrfs] Root filesystem
# Careful: You will get N times the swap amount, so be sure to divide beforehand.
#create_raid1_luks_layout swap=4GiB type=efi root_fs=ext4 /dev/sd{X,Y}
# 5. create_btrfs_centric_layout
# #
# This layout is the same as the single_disk_layout, but uses btrfs as the root # This layout is the same as the single_disk_layout, but uses btrfs as the root
# filesystem and allows you to put additional disks into the btrfs device pool. # filesystem and allows you to put additional disks into the btrfs device pool.

View File

@ -496,6 +496,63 @@ function create_raid0_luks_layout() {
fi fi
} }
# Multiple disks, with raid 1 and luks
# - efi: partition on all disks, but only first disk used
# - swap: raid 1 → fs
# - root: raid 1 → luks → fs
# Parameters:
# swap=<size> Create a swap partition with given size for each disk, or no swap at all if set to false
# type=[efi|bios] Selects the boot type. Defaults to efi if not given.
# root_fs=[ext4|btrfs] Root filesystem
function create_raid1_luks_layout() {
local known_arguments=('+swap' '?type' '?root_fs')
local extra_arguments=()
declare -A arguments; parse_arguments "$@"
[[ ${#extra_arguments[@]} -gt 0 ]] \
|| die_trace 1 "Expected at least one positional argument (the devices)"
local size_swap="${arguments[swap]}"
local type="${arguments[type]:-efi}"
local root_fs="${arguments[root_fs]:-ext4}"
for i in "${!extra_arguments[@]}"; do
create_gpt new_id="gpt_dev${i}" device="${extra_arguments[$i]}"
create_partition new_id="part_${type}_dev${i}" id="gpt_dev${i}" size=512MiB type="$type"
[[ $size_swap != "false" ]] \
&& create_partition new_id="part_swap_dev${i}" id="gpt_dev${i}" size="$size_swap" type=raid
create_partition new_id="part_root_dev${i}" id="gpt_dev${i}" size=remaining type=raid
done
[[ $size_swap != "false" ]] \
&& create_raid new_id=part_raid_swap name="swap" level=1 ids="$(expand_ids '^part_swap_dev[[:digit:]]$')"
create_raid new_id=part_raid_root name="root" level=1 ids="$(expand_ids '^part_root_dev[[:digit:]]$')"
create_luks new_id=part_luks_root name="root" id=part_raid_root
format id="part_${type}_dev0" type="$type" label="$type"
[[ $size_swap != "false" ]] \
&& format id=part_raid_swap type=swap label=swap
format id=part_luks_root type="$root_fs" label=root
if [[ $type == "efi" ]]; then
DISK_ID_EFI="part_${type}_dev0"
else
DISK_ID_BIOS="part_${type}_dev0"
fi
[[ $size_swap != "false" ]] \
&& DISK_ID_SWAP=part_raid_swap
DISK_ID_ROOT=part_luks_root
if [[ $root_fs == "btrfs" ]]; then
DISK_ID_ROOT_TYPE="btrfs"
DISK_ID_ROOT_MOUNT_OPTS="defaults,noatime,compress=zstd,subvol=/root"
elif [[ $root_fs == "ext4" ]]; then
DISK_ID_ROOT_TYPE="ext4"
DISK_ID_ROOT_MOUNT_OPTS="defaults,noatime,errors=remount-ro,discard"
else
die "Unsupported root filesystem type"
fi
}
# Multiple disks, up to 3 partitions on first disk (efi, optional swap, root with btrfs). # Multiple disks, up to 3 partitions on first disk (efi, optional swap, root with btrfs).
# Additional devices will be first encrypted and then put directly into btrfs array. # Additional devices will be first encrypted and then put directly into btrfs array.
# Parameters: # Parameters:

View File

@ -291,6 +291,19 @@ function disk_create_raid() {
local mddevice="/dev/md/$name" local mddevice="/dev/md/$name"
local uuid="${DISK_ID_TO_UUID[$new_id]}" local uuid="${DISK_ID_TO_UUID[$new_id]}"
if [[ ${level} == 1 ]]; then
einfo "Creating raid$level ($new_id) on $devices_desc"
mdadm \
--create "$mddevice" \
--verbose \
--homehost="$HOSTNAME" \
--metadata=1.0 \
--raid-devices="${#devices[@]}" \
--uuid="$uuid" \
--level="$level" \
"${devices[@]}" \
|| die "Could not create raid$level array '$mddevice' ($new_id) on $devices_desc"
else
einfo "Creating raid$level ($new_id) on $devices_desc" einfo "Creating raid$level ($new_id) on $devices_desc"
mdadm \ mdadm \
--create "$mddevice" \ --create "$mddevice" \
@ -302,6 +315,7 @@ function disk_create_raid() {
--level="$level" \ --level="$level" \
"${devices[@]}" \ "${devices[@]}" \
|| die "Could not create raid$level array '$mddevice' ($new_id) on $devices_desc" || die "Could not create raid$level array '$mddevice' ($new_id) on $devices_desc"
fi
} }
function disk_create_luks() { function disk_create_luks() {