feat: more flexible default layout

This commit is contained in:
thiblizz 2023-10-22 16:37:24 +02:00
parent f2f3e96211
commit 4309e3b17b
3 changed files with 49 additions and 31 deletions

14
configure vendored
View File

@ -168,8 +168,8 @@ function define_disk_layout() {
define_disk_configuration_function "create_existing_partitions_layout boot=${PARTITIONING_BOOT_DEVICE@Q} swap=${swapdev@Q} type=${PARTITIONING_BOOT_TYPE@Q}" "${PARTITIONING_DEVICE@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}" ;;
"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}" ;;
"raid0_luks") define_disk_configuration_function "create_raid0_luks_layout swap=$(define_swap) type=${PARTITIONING_BOOT_TYPE@Q} luks=${PARTITIONING_USE_LUKS@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} luks=${PARTITIONING_USE_LUKS@Q} root_fs=${PARTITIONING_ROOT_FS@Q}" "${PARTITIONING_DEVICES[@]@Q}" ;;
"custom")
# Show current function declaration, trim trailing whitespace
declare -f disk_configuration \
@ -284,26 +284,28 @@ function create_existing_partitions_layout() {
function create_raid0_luks_layout() {
PARTITIONING_SCHEME="raid0_luks"
local known_arguments=('+swap' '?type' '?root_fs')
local known_arguments=('+swap' '?type' '?luks' '?root_fs')
local extra_arguments=()
declare -A arguments; parse_arguments "$@"
PARTITIONING_DEVICES=("${extra_arguments[@]}")
parse_swap "${arguments[swap]}"
PARTITIONING_BOOT_TYPE="${arguments[type]}"
PARTITIONING_USE_LUKS="${arguments[luks]:-true}"
PARTITIONING_ROOT_FS="${arguments[root_fs]:-ext4}"
}
function create_raid1_luks_layout() {
PARTITIONING_SCHEME="raid1_luks"
local known_arguments=('+swap' '?type' '?root_fs')
local known_arguments=('+swap' '?type' '?luks' '?root_fs')
local extra_arguments=()
declare -A arguments; parse_arguments "$@"
PARTITIONING_DEVICES=("${extra_arguments[@]}")
parse_swap "${arguments[swap]}"
PARTITIONING_BOOT_TYPE="${arguments[type]}"
PARTITIONING_USE_LUKS="${arguments[luks]:-true}"
PARTITIONING_ROOT_FS="${arguments[root_fs]:-ext4}"
}
@ -919,8 +921,8 @@ function PARTITIONING_SCHEME_menu() {
"existing_partitions") create_existing_partitions_layout boot=/dev/sdA swap=false type="$DEFAULT_BOOT_TYPE" /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 ;;
"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 ;;
"raid0_luks") create_raid0_luks_layout swap=8GiB type="$DEFAULT_BOOT_TYPE" luks=true root_fs=ext4 /dev/sdX /dev/sdY ;;
"raid1_luks") create_raid1_luks_layout swap=8GiB type="$DEFAULT_BOOT_TYPE" luks=true root_fs=ext4 /dev/sdX /dev/sdY ;;
"custom") PARTITIONING_SCHEME="$dialog_out" ;;
esac
UNSAVED_CHANGES=true

View File

@ -35,10 +35,10 @@ function disk_configuration() {
#
# Parameters:
# swap=<size> Create a swap partition with given size, or no swap
# at all if set to false
# at all if set to false.
# type=[efi|bios] Selects the boot type. Defaults to efi if not given.
# luks=[true|false] Encrypt root partition. Defaults to false if not given.
# root_fs=[ext4|btrfs] Root filesystem
# root_fs=[ext4|btrfs] Root filesystem. Defaults to ext4 if not given.
#create_classic_single_disk_layout swap=8GiB type=efi luks=true root_fs=ext4 /dev/sdX
# 2. create_btrfs_centric_layout
@ -52,7 +52,7 @@ function disk_configuration() {
#
# Parameters:
# swap=<size> Create a swap partition with given size, or no swap
# at all if set to false
# at all if set to false.
# type=[efi|bios] Selects the boot type. Defaults to efi if not given.
# encrypt=[true|false] Encrypt the zfs datasets. Defaults to false if not given.
# compress=[false|<compression>] Compress the zfs datasets. For valid values visit man zfsprops. Defaults to false if not given.
@ -68,9 +68,10 @@ function disk_configuration() {
#
# Parameters:
# swap=<size> Create a swap partition with given size for each disk,
# or no swap at all if set to false
# 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
# luks=[true|false] Encrypt root partition. Defaults to true if not given.
# root_fs=[ext4|btrfs] Root filesystem. Defaults to ext4 if not given.
# 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}
@ -83,9 +84,10 @@ function disk_configuration() {
#
# Parameters:
# swap=<size> Create a swap partition with given size for each disk,
# or no swap at all if set to false
# 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
# luks=[true|false] Encrypt root partition. Defaults to true if not given.
# root_fs=[ext4|btrfs] Root filesystem. Defaults to ext4 if not given.
# 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}
@ -100,7 +102,7 @@ function disk_configuration() {
#
# Parameters:
# swap=<size> Create a swap partition with given size, or no swap
# at all if set to false
# at all if set to false.
# type=[efi|bios] Selects the boot type. Defaults to efi if not given.
# luks=[true|false] Encrypt root partition and btrfs devices. Defaults
# to false if not given.

View File

@ -293,10 +293,10 @@ function expand_ids() {
# Single disk, 3 partitions (efi, swap, root)
# Parameters:
# swap=<size> Create a swap partition with given size, or no swap at all if set to false
# swap=<size> Create a swap partition with given size, or no swap at all if set to false.
# type=[efi|bios] Selects the boot type. Defaults to efi if not given.
# luks=[true|false] Encrypt root partition. Defaults to false if not given.
# root_fs=[ext4|btrfs] Root filesystem
# root_fs=[ext4|btrfs] Root filesystem. Defaults to ext4 if not given.
function create_classic_single_disk_layout() {
local known_arguments=('+swap' '?type' '?luks' '?root_fs')
local extra_arguments=()
@ -353,7 +353,7 @@ function create_single_disk_layout() {
# Skip partitioning, and use existing pre-formatted partitions. These must be trivially mountable.
# Parameters:
# swap=<device|false> Use the given device as swap, or no swap at all if set to false
# swap=<device|false> Use the given device as swap, or no swap at all if set to false.
# boot=<device> Use the given device as the bios/efi partition.
# type=[efi|bios] Selects the boot type. Defaults to efi if not given.
function create_existing_partitions_layout() {
@ -389,7 +389,7 @@ function create_existing_partitions_layout() {
# Multiple disks, up to 3 partitions on first disk (efi, optional swap, root with zfs).
# Additional devices will be added to the zfs pool.
# Parameters:
# swap=<size> Create a swap partition with given size, or no swap at all if set to false
# swap=<size> Create a swap partition with given size, or no swap at all if set to false.
# type=[efi|bios] Selects the boot type. Defaults to efi if not given.
# encrypt=[true|false] Encrypt zfs pool. Defaults to false if not given.
# pool_type=[stripe|mirror] Select raid type. Defaults to stripe.
@ -444,11 +444,12 @@ function create_zfs_centric_layout() {
# - swap: raid 0 → fs
# - root: raid 0 → luks → fs
# Parameters:
# swap=<size> Create a swap partition with given size for each disk, or no swap at all if set to false
# 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
# luks=[true|false] Encrypt root partition. Defaults to true if not given.
# root_fs=[ext4|btrfs] Root filesystem. Defaults to ext4 if not given.
function create_raid0_luks_layout() {
local known_arguments=('+swap' '?type' '?root_fs')
local known_arguments=('+swap' '?type' '?luks' '?root_fs')
local extra_arguments=()
declare -A arguments; parse_arguments "$@"
@ -456,6 +457,7 @@ function create_raid0_luks_layout() {
|| die_trace 1 "Expected at least one positional argument (the devices)"
local size_swap="${arguments[swap]}"
local type="${arguments[type]:-efi}"
local use_luks="${arguments[luks]:-true}"
local root_fs="${arguments[root_fs]:-ext4}"
for i in "${!extra_arguments[@]}"; do
@ -469,12 +471,17 @@ function create_raid0_luks_layout() {
[[ $size_swap != "false" ]] \
&& create_raid new_id=part_raid_swap name="swap" level=0 ids="$(expand_ids '^part_swap_dev[[:digit:]]$')"
create_raid new_id=part_raid_root name="root" level=0 ids="$(expand_ids '^part_root_dev[[:digit:]]$')"
local root_id="part_root"
if [[ "$use_luks" == "true" ]]; then
create_luks new_id=part_luks_root name="root" id=part_raid_root
root_id="part_luks_root"
fi
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
format id="$root_id" type="$root_fs" label=root
if [[ $type == "efi" ]]; then
DISK_ID_EFI="part_${type}_dev0"
@ -483,7 +490,7 @@ function create_raid0_luks_layout() {
fi
[[ $size_swap != "false" ]] \
&& DISK_ID_SWAP=part_raid_swap
DISK_ID_ROOT=part_luks_root
DISK_ID_ROOT="$root_id"
if [[ $root_fs == "btrfs" ]]; then
DISK_ID_ROOT_TYPE="btrfs"
@ -501,11 +508,12 @@ function create_raid0_luks_layout() {
# - 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
# 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
# luks=[true|false] Encrypt root partition. Defaults to true if not given.
# root_fs=[ext4|btrfs] Root filesystem. Defaults to ext4 if not given.
function create_raid1_luks_layout() {
local known_arguments=('+swap' '?type' '?root_fs')
local known_arguments=('+swap' '?type' '?luks' '?root_fs')
local extra_arguments=()
declare -A arguments; parse_arguments "$@"
@ -513,6 +521,7 @@ function create_raid1_luks_layout() {
|| die_trace 1 "Expected at least one positional argument (the devices)"
local size_swap="${arguments[swap]}"
local type="${arguments[type]:-efi}"
local use_luks="${arguments[luks]:-true}"
local root_fs="${arguments[root_fs]:-ext4}"
for i in "${!extra_arguments[@]}"; do
@ -526,12 +535,17 @@ function create_raid1_luks_layout() {
[[ $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:]]$')"
local root_id="part_root"
if [[ "$use_luks" == "true" ]]; then
create_luks new_id=part_luks_root name="root" id=part_raid_root
root_id="part_luks_root"
fi
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
format id="$root_id" type="$root_fs" label=root
if [[ $type == "efi" ]]; then
DISK_ID_EFI="part_${type}_dev0"
@ -540,7 +554,7 @@ function create_raid1_luks_layout() {
fi
[[ $size_swap != "false" ]] \
&& DISK_ID_SWAP=part_raid_swap
DISK_ID_ROOT=part_luks_root
DISK_ID_ROOT="$root_id"
if [[ $root_fs == "btrfs" ]]; then
DISK_ID_ROOT_TYPE="btrfs"
@ -556,7 +570,7 @@ function create_raid1_luks_layout() {
# 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:
# swap=<size> Create a swap partition with given size, or no swap at all if set to false
# swap=<size> Create a swap partition with given size, or no swap at all if set to false.
# type=[efi|bios] Selects the boot type. Defaults to efi if not given.
# luks=[true|false] Encrypt root partition and btrfs devices. Defaults to false if not given.
# raid_type=[raid0|raid1] Select raid type. Defaults to raid0.