From e5b0fe63133a67be6eb76ddbe73bab3061c71011 Mon Sep 17 00:00:00 2001 From: thiblizz <101073848+thiblizz@users.noreply.github.com> Date: Fri, 20 Oct 2023 23:39:49 +0200 Subject: [PATCH 1/5] feat: add raid1 support --- configure | 22 ++++++++++++++--- gentoo.conf.example | 17 ++++++++++++- scripts/config.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++ scripts/functions.sh | 36 +++++++++++++++++++--------- 4 files changed, 117 insertions(+), 15 deletions(-) diff --git a/configure b/configure index 4124d5a..8034c6f 100755 --- a/configure +++ b/configure @@ -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}" ;; "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}" ;; + "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") # Show current function declaration, trim trailing whitespace declare -f disk_configuration \ @@ -208,6 +209,7 @@ ALL_PARTITIONING_SCHEMES=( "zfs_centric" "ZFS centric (optional ZFS compression and encryption)" "btrfs_centric" "Btrfs centric (optional raid0/1 via btrfs)" "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)" ) @@ -292,6 +294,19 @@ function create_raid0_luks_layout() { 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() { 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 ;; "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 ;; + "raid1_luks") create_raid1_luks_layout swap=8GiB type="$DEFAULT_BOOT_TYPE" root_fs=ext4 /dev/sdX /dev/sdY ;; "custom") PARTITIONING_SCHEME="$dialog_out" ;; esac UNSAVED_CHANGES=true @@ -1012,7 +1028,7 @@ function PARTITIONING_SWAP_DEVICE_menu() { function PARTITIONING_ROOT_FS_tag() { echo " ├ Root filesystem"; } 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_menu() { if menu_radiolist \ @@ -1152,7 +1168,7 @@ function PARTITIONING_DEVICES_label() { if [[ "$invalid" -gt 0 ]]; then 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)" elif [[ "${#PARTITIONING_DEVICES[@]}" -eq 0 ]]; then echo " └ (${#PARTITIONING_DEVICES[@]} devices, \Z1need at least 1\Zn)" @@ -1160,7 +1176,7 @@ function PARTITIONING_DEVICES_label() { echo " └ (${#PARTITIONING_DEVICES[@]} devices)" 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_menu() { local invalid=() diff --git a/gentoo.conf.example b/gentoo.conf.example index cb6b864..fb69f03 100644 --- a/gentoo.conf.example +++ b/gentoo.conf.example @@ -74,7 +74,22 @@ function disk_configuration() { # 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} - # 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= 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 # filesystem and allows you to put additional disks into the btrfs device pool. diff --git a/scripts/config.sh b/scripts/config.sh index c1a4e22..5c9f49a 100644 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -496,6 +496,63 @@ function create_raid0_luks_layout() { 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= 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). # Additional devices will be first encrypted and then put directly into btrfs array. # Parameters: diff --git a/scripts/functions.sh b/scripts/functions.sh index 28898e1..51614cf 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -291,17 +291,31 @@ function disk_create_raid() { local mddevice="/dev/md/$name" local uuid="${DISK_ID_TO_UUID[$new_id]}" - einfo "Creating raid$level ($new_id) on $devices_desc" - mdadm \ - --create "$mddevice" \ - --verbose \ - --homehost="$HOSTNAME" \ - --metadata=1.2 \ - --raid-devices="${#devices[@]}" \ - --uuid="$uuid" \ - --level="$level" \ - "${devices[@]}" \ - || die "Could not create raid$level array '$mddevice' ($new_id) on $devices_desc" + 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" + mdadm \ + --create "$mddevice" \ + --verbose \ + --homehost="$HOSTNAME" \ + --metadata=1.2 \ + --raid-devices="${#devices[@]}" \ + --uuid="$uuid" \ + --level="$level" \ + "${devices[@]}" \ + || die "Could not create raid$level array '$mddevice' ($new_id) on $devices_desc" + fi } function disk_create_luks() { From 647da12b431f1bc1d3153616dd0e5b376717737c Mon Sep 17 00:00:00 2001 From: thiblizz <101073848+thiblizz@users.noreply.github.com> Date: Sat, 21 Oct 2023 16:36:28 +0200 Subject: [PATCH 2/5] fix: address review comments --- configure | 2 +- scripts/functions.sh | 38 ++++++++++++++++---------------------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/configure b/configure index 8034c6f..78d14a0 100755 --- a/configure +++ b/configure @@ -1168,7 +1168,7 @@ function PARTITIONING_DEVICES_label() { if [[ "$invalid" -gt 0 ]]; then echo " └ (${#PARTITIONING_DEVICES[@]} devices, \Z1$invalid invalid\Zn)" - elif [[ "${#PARTITIONING_DEVICES[@]}" -eq 1 && "$PARTITIONING_SCHEME" == "raid0_luks" || "$PARTITIONING_SCHEME" == "raid1_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)" elif [[ "${#PARTITIONING_DEVICES[@]}" -eq 0 ]]; then echo " └ (${#PARTITIONING_DEVICES[@]} devices, \Z1need at least 1\Zn)" diff --git a/scripts/functions.sh b/scripts/functions.sh index 51614cf..a760b40 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -276,6 +276,7 @@ function disk_create_raid() { local devices_desc="" local devices=() + local extra_args=() local id local dev # Splitting is intentional here @@ -291,31 +292,24 @@ function disk_create_raid() { local mddevice="/dev/md/$name" local uuid="${DISK_ID_TO_UUID[$new_id]}" + extra_args=() 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" + extra_args+=("--metadata=1.0") else - einfo "Creating raid$level ($new_id) on $devices_desc" - mdadm \ - --create "$mddevice" \ - --verbose \ - --homehost="$HOSTNAME" \ - --metadata=1.2 \ - --raid-devices="${#devices[@]}" \ - --uuid="$uuid" \ - --level="$level" \ - "${devices[@]}" \ - || die "Could not create raid$level array '$mddevice' ($new_id) on $devices_desc" + extra_args+=("--metadata=1.2") fi + + einfo "Creating raid$level ($new_id) on $devices_desc" + mdadm \ + --create "$mddevice" \ + --verbose \ + --homehost="$HOSTNAME" \ + "${extra_args[@]}" \ + --raid-devices="${#devices[@]}" \ + --uuid="$uuid" \ + --level="$level" \ + "${devices[@]}" \ + || die "Could not create raid$level array '$mddevice' ($new_id) on $devices_desc" } function disk_create_luks() { From fa7d0df6098982046330be76500dcbb034e464f9 Mon Sep 17 00:00:00 2001 From: thiblizz <101073848+thiblizz@users.noreply.github.com> Date: Sat, 21 Oct 2023 16:45:24 +0200 Subject: [PATCH 3/5] fix: unused variable --- scripts/functions.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index a760b40..dbb5373 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -276,7 +276,6 @@ function disk_create_raid() { local devices_desc="" local devices=() - local extra_args=() local id local dev # Splitting is intentional here From 0c790740f3f77072833a452265ff7bf69d9dc916 Mon Sep 17 00:00:00 2001 From: thiblizz <101073848+thiblizz@users.noreply.github.com> Date: Sat, 21 Oct 2023 16:54:52 +0200 Subject: [PATCH 4/5] feat: increase the boot/EFI partition to 1GiB (closes #98) --- scripts/config.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/config.sh b/scripts/config.sh index 5c9f49a..5cebf88 100644 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -311,7 +311,7 @@ function create_classic_single_disk_layout() { local root_fs="${arguments[root_fs]:-ext4}" create_gpt new_id=gpt device="$device" - create_partition new_id="part_$type" id=gpt size=512MiB type="$type" + create_partition new_id="part_$type" id=gpt size=1GiB type="$type" [[ $size_swap != "false" ]] \ && create_partition new_id=part_swap id=gpt size="$size_swap" type=swap create_partition new_id=part_root id=gpt size=remaining type=linux @@ -408,7 +408,7 @@ function create_zfs_centric_layout() { # Create layout on first disk create_gpt new_id="gpt_dev0" device="${extra_arguments[0]}" - create_partition new_id="part_${type}_dev0" id="gpt_dev0" size=512MiB type="$type" + create_partition new_id="part_${type}_dev0" id="gpt_dev0" size=1GiB type="$type" [[ $size_swap != "false" ]] \ && create_partition new_id="part_swap_dev0" id="gpt_dev0" size="$size_swap" type=swap create_partition new_id="part_root_dev0" id="gpt_dev0" size=remaining type=linux @@ -460,7 +460,7 @@ function create_raid0_luks_layout() { 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" + create_partition new_id="part_${type}_dev${i}" id="gpt_dev${i}" size=1GiB 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 @@ -517,7 +517,7 @@ function create_raid1_luks_layout() { 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" + create_partition new_id="part_${type}_dev${i}" id="gpt_dev${i}" size=1GiB 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 @@ -575,7 +575,7 @@ function create_btrfs_centric_layout() { # Create layout on first disk create_gpt new_id="gpt_dev0" device="${extra_arguments[0]}" - create_partition new_id="part_${type}_dev0" id="gpt_dev0" size=512MiB type="$type" + create_partition new_id="part_${type}_dev0" id="gpt_dev0" size=1GiB type="$type" [[ $size_swap != "false" ]] \ && create_partition new_id="part_swap_dev0" id="gpt_dev0" size="$size_swap" type=swap create_partition new_id="part_root_dev0" id="gpt_dev0" size=remaining type=linux From d8c8096b8552e55a120b1c2b9ab24c205c6ebaa5 Mon Sep 17 00:00:00 2001 From: thiblizz <101073848+thiblizz@users.noreply.github.com> Date: Sat, 21 Oct 2023 17:02:59 +0200 Subject: [PATCH 5/5] Revert "feat: increase the boot/EFI partition to 1GiB (closes #98)" This reverts commit 0c790740f3f77072833a452265ff7bf69d9dc916. --- scripts/config.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/config.sh b/scripts/config.sh index 5cebf88..5c9f49a 100644 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -311,7 +311,7 @@ function create_classic_single_disk_layout() { local root_fs="${arguments[root_fs]:-ext4}" create_gpt new_id=gpt device="$device" - create_partition new_id="part_$type" id=gpt size=1GiB type="$type" + create_partition new_id="part_$type" id=gpt size=512MiB type="$type" [[ $size_swap != "false" ]] \ && create_partition new_id=part_swap id=gpt size="$size_swap" type=swap create_partition new_id=part_root id=gpt size=remaining type=linux @@ -408,7 +408,7 @@ function create_zfs_centric_layout() { # Create layout on first disk create_gpt new_id="gpt_dev0" device="${extra_arguments[0]}" - create_partition new_id="part_${type}_dev0" id="gpt_dev0" size=1GiB type="$type" + create_partition new_id="part_${type}_dev0" id="gpt_dev0" size=512MiB type="$type" [[ $size_swap != "false" ]] \ && create_partition new_id="part_swap_dev0" id="gpt_dev0" size="$size_swap" type=swap create_partition new_id="part_root_dev0" id="gpt_dev0" size=remaining type=linux @@ -460,7 +460,7 @@ function create_raid0_luks_layout() { 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=1GiB type="$type" + 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 @@ -517,7 +517,7 @@ function create_raid1_luks_layout() { 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=1GiB type="$type" + 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 @@ -575,7 +575,7 @@ function create_btrfs_centric_layout() { # Create layout on first disk create_gpt new_id="gpt_dev0" device="${extra_arguments[0]}" - create_partition new_id="part_${type}_dev0" id="gpt_dev0" size=1GiB type="$type" + create_partition new_id="part_${type}_dev0" id="gpt_dev0" size=512MiB type="$type" [[ $size_swap != "false" ]] \ && create_partition new_id="part_swap_dev0" id="gpt_dev0" size="$size_swap" type=swap create_partition new_id="part_root_dev0" id="gpt_dev0" size=remaining type=linux