Added zfs compression settings to the standard pool creation function. Closes #10.

This commit is contained in:
oddlama 2021-06-02 16:18:31 +02:00
parent 2aa37e519e
commit 264f811e9d
No known key found for this signature in database
GPG Key ID: 14EFE510775FE39A
4 changed files with 73 additions and 15 deletions

59
configure vendored
View File

@ -150,10 +150,18 @@ function define_swap() {
fi fi
} }
function define_zfs_compression() {
if [[ $PARTITIONING_ZFS_USE_COMPRESSION != "false" ]]; then
echo -n "${PARTITIONING_ZFS_COMPRESSION@Q}"
else
echo -n "false"
fi
}
function define_disk_layout() { function define_disk_layout() {
case "$PARTITIONING_SCHEME" in case "$PARTITIONING_SCHEME" in
"classic_single_disk") define_disk_configuration_function "create_classic_single_disk_layout swap=$(define_swap) type=${PARTITIONING_BOOT_TYPE@Q} luks=${PARTITIONING_USE_LUKS@Q} root_fs=${PARTITIONING_ROOT_FS@Q}" "${PARTITIONING_DEVICE@Q}" ;; "classic_single_disk") define_disk_configuration_function "create_classic_single_disk_layout swap=$(define_swap) type=${PARTITIONING_BOOT_TYPE@Q} luks=${PARTITIONING_USE_LUKS@Q} root_fs=${PARTITIONING_ROOT_FS@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_ENCRYPTION@Q} 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_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}" ;;
"custom") "custom")
@ -176,6 +184,7 @@ PARTITIONING_BOOT_TYPES=("efi" "bios")
PARTITIONING_ROOT_FS_TYPES=("ext4" "btrfs") PARTITIONING_ROOT_FS_TYPES=("ext4" "btrfs")
PARTITIONING_BTRFS_RAID_TYPES=("raid0" "raid1") PARTITIONING_BTRFS_RAID_TYPES=("raid0" "raid1")
PARTITIONING_ZFS_POOL_TYPES=("standard" "custom") PARTITIONING_ZFS_POOL_TYPES=("standard" "custom")
PARTITIONING_ZFS_COMPRESSIONS=("on" "gzip" "lz4" "lzjb" "zle" "zstd" "zstd-fast")
function create_single_disk_layout() { function create_single_disk_layout() {
create_classic_single_disk_layout "$@" create_classic_single_disk_layout "$@"
@ -191,6 +200,16 @@ function parse_swap() {
fi fi
} }
function parse_zfs_compression() {
if [[ $1 == "false" ]]; then
PARTITIONING_ZFS_USE_COMPRESSION=false
PARTITIONING_ZFS_COMPRESSION=zstd
else
PARTITIONING_ZFS_USE_COMPRESSION=true
PARTITIONING_ZFS_COMPRESSION="$1"
fi
}
function create_classic_single_disk_layout() { function create_classic_single_disk_layout() {
PARTITIONING_SCHEME="classic_single_disk" PARTITIONING_SCHEME="classic_single_disk"
@ -221,7 +240,7 @@ function create_raid0_luks_layout() {
function create_zfs_centric_layout() { function create_zfs_centric_layout() {
PARTITIONING_SCHEME="zfs_centric" PARTITIONING_SCHEME="zfs_centric"
local known_arguments=('+swap' '?type' '?pool_type' '?encrypt') local known_arguments=('+swap' '?type' '?pool_type' '?encrypt' '?compress')
local extra_arguments=() local extra_arguments=()
declare -A arguments; parse_arguments "$@" declare -A arguments; parse_arguments "$@"
@ -230,6 +249,7 @@ function create_zfs_centric_layout() {
PARTITIONING_BOOT_TYPE="${arguments[type]}" PARTITIONING_BOOT_TYPE="${arguments[type]}"
PARTITIONING_ZFS_POOL_TYPE="${arguments[pool_type]:-standard}" PARTITIONING_ZFS_POOL_TYPE="${arguments[pool_type]:-standard}"
PARTITIONING_ZFS_ENCRYPTION="${arguments[encrypt]:-false}" PARTITIONING_ZFS_ENCRYPTION="${arguments[encrypt]:-false}"
parse_zfs_compression "${arguments[compress]:-false}"
} }
function create_btrfs_raid_layout() { function create_btrfs_raid_layout() {
@ -327,7 +347,7 @@ function load_default_config() {
LOCALE="C.utf8" LOCALE="C.utf8"
function disk_configuration() { function disk_configuration() {
#create_zfs_centric_layout swap=8GiB type=efi encrypt=true pool_type=standard /dev/sdX #create_zfs_centric_layout swap=8GiB type=efi encrypt=true compress=zstd pool_type=standard /dev/sdX
create_classic_single_disk_layout swap=8GiB type=efi luks=true root_fs=ext4 /dev/sdX create_classic_single_disk_layout swap=8GiB type=efi luks=true root_fs=ext4 /dev/sdX
} }
@ -713,6 +733,8 @@ MENU_ITEMS=(
"PARTITIONING_USE_LUKS" "PARTITIONING_USE_LUKS"
"PARTITIONING_ZFS_POOL_TYPE" "PARTITIONING_ZFS_POOL_TYPE"
"PARTITIONING_ZFS_ENCRYPTION" "PARTITIONING_ZFS_ENCRYPTION"
"PARTITIONING_ZFS_USE_COMPRESSION"
"PARTITIONING_ZFS_COMPRESSION"
"PARTITIONING_BTRFS_RAID_TYPE" "PARTITIONING_BTRFS_RAID_TYPE"
"PARTITIONING_DEVICE" "PARTITIONING_DEVICE"
"PARTITIONING_DEVICES" "PARTITIONING_DEVICES"
@ -756,7 +778,7 @@ function PARTITIONING_SCHEME_menu() {
# Set disk scheme # Set disk scheme
case "$dialog_out" in case "$dialog_out" in
"classic_single_disk") create_classic_single_disk_layout swap=8GiB type=efi luks=false root_fs=ext4 /dev/sdX ;; "classic_single_disk") create_classic_single_disk_layout swap=8GiB type=efi luks=false root_fs=ext4 /dev/sdX ;;
"zfs_centric") create_zfs_centric_layout swap=8GiB type=efi encrypt=true pool_type=standard /dev/sdX ;; "zfs_centric") create_zfs_centric_layout swap=8GiB type=efi encrypt=true compress=zstd pool_type=standard /dev/sdX ;;
"btrfs_centric") create_btrfs_centric_layout swap=8GiB type=efi raid_type=raid0 luks=false /dev/sdX ;; "btrfs_centric") create_btrfs_centric_layout swap=8GiB type=efi raid_type=raid0 luks=false /dev/sdX ;;
"raid0_luks") create_raid0_luks_layout swap=8GiB type=efi root_fs=ext4 /dev/sdX /dev/sdY ;; "raid0_luks") create_raid0_luks_layout swap=8GiB type=efi root_fs=ext4 /dev/sdX /dev/sdY ;;
"custom") PARTITIONING_SCHEME="$dialog_out" ;; "custom") PARTITIONING_SCHEME="$dialog_out" ;;
@ -848,6 +870,35 @@ function PARTITIONING_ZFS_ENCRYPTION_menu() {
UNSAVED_CHANGES=true UNSAVED_CHANGES=true
} }
function PARTITIONING_ZFS_USE_COMPRESSION_tag() { echo " ├ Use ZFS Compression"; }
function PARTITIONING_ZFS_USE_COMPRESSION_label() { on_off_label "$PARTITIONING_ZFS_USE_COMPRESSION" " ├ "; }
function PARTITIONING_ZFS_USE_COMPRESSION_show() { [[ $PARTITIONING_SCHEME != "custom" ]] && one_of "$PARTITIONING_SCHEME" "zfs_centric" && one_of "$PARTITIONING_ZFS_POOL_TYPE" "standard"; }
function PARTITIONING_ZFS_USE_COMPRESSION_help() { echo "Determines if compression should be enabled on the ZFS datasets."; }
function PARTITIONING_ZFS_USE_COMPRESSION_menu() {
on_off_toggle "PARTITIONING_ZFS_USE_COMPRESSION"
UNSAVED_CHANGES=true
}
function PARTITIONING_ZFS_COMPRESSION_tag() { echo " │ └ Compression algorithm"; }
function PARTITIONING_ZFS_COMPRESSION_label() { echo " │ └ ($PARTITIONING_ZFS_COMPRESSION)"; }
function PARTITIONING_ZFS_COMPRESSION_show() { [[ $PARTITIONING_SCHEME != "custom" ]] && one_of "$PARTITIONING_SCHEME" "zfs_centric" && one_of "$PARTITIONING_ZFS_POOL_TYPE" "standard" && is_on "$PARTITIONING_ZFS_USE_COMPRESSION"; }
function PARTITIONING_ZFS_COMPRESSION_help() { echo "Determines the compression algorithm used on the ZFS datasets. 'on' means to use the default compression algorithm determined by ZFS. If you need more granular control over the specific levels such as gzip-N or zstd-N, please use a custom pool."; }
function PARTITIONING_ZFS_COMPRESSION_menu() {
if menu_radiolist \
"Select ZFS compression algorithm" \
"Determines the compression algorithm used on the ZFS datasets. The special value 'on' means to use the default compression algorithm as determined by ZFS." \
"$PARTITIONING_ZFS_COMPRESSION" \
"${PARTITIONING_ZFS_COMPRESSIONS[@]}"
then
# Set timezone
PARTITIONING_ZFS_COMPRESSION="$dialog_out"
UNSAVED_CHANGES=true
else
# Return to menu
true
fi
}
function PARTITIONING_ZFS_POOL_TYPE_tag() { echo " ├ Pool type"; } function PARTITIONING_ZFS_POOL_TYPE_tag() { echo " ├ Pool type"; }
function PARTITIONING_ZFS_POOL_TYPE_label() { echo " ├ ($PARTITIONING_ZFS_POOL_TYPE)"; } function PARTITIONING_ZFS_POOL_TYPE_label() { echo " ├ ($PARTITIONING_ZFS_POOL_TYPE)"; }
function PARTITIONING_ZFS_POOL_TYPE_show() { [[ $PARTITIONING_SCHEME != "custom" ]] && one_of "$PARTITIONING_SCHEME" "zfs_centric"; } function PARTITIONING_ZFS_POOL_TYPE_show() { [[ $PARTITIONING_SCHEME != "custom" ]] && one_of "$PARTITIONING_SCHEME" "zfs_centric"; }

View File

@ -17,8 +17,7 @@
# This function will be called when a custom zfs pool type has been chosen. # This function will be called when a custom zfs pool type has been chosen.
# You do not need to change this, unless you have chosen a custom zfs pool type. # You do not need to change this, unless you have chosen a custom zfs pool type.
# $1: either 'true' or 'false' determining if the pool should be encrypted # $1: a string describing all device paths (for error messages)
# $2: a string describing all device paths (for error messages)
# $@: device paths # $@: device paths
function format_zfs_custom() { function format_zfs_custom() {
# See format_zfs_standard() function in scripts/functions.sh for an example! # See format_zfs_standard() function in scripts/functions.sh for an example!

View File

@ -240,7 +240,7 @@ function format() {
function format_zfs() { function format_zfs() {
USED_ZFS=true USED_ZFS=true
local known_arguments=('+ids' '?pool_type' '?encrypt') local known_arguments=('+ids' '?pool_type' '?encrypt' '?compress')
local extra_arguments=() local extra_arguments=()
declare -A arguments; parse_arguments "$@" declare -A arguments; parse_arguments "$@"

View File

@ -409,18 +409,26 @@ function disk_format() {
} }
# This function will be called when a custom zfs pool type has been chosen. # This function will be called when a custom zfs pool type has been chosen.
# $1: either 'true' or 'false' determining if the pool should be encrypted # $1: either 'true' or 'false' determining if the datasets should be encrypted
# $2: a string describing all device paths (for error messages) # $2: either 'false' or a value determining the dataset compression algorithm
# $3: a string describing all device paths (for error messages)
# $@: device paths # $@: device paths
function format_zfs_standard() { function format_zfs_standard() {
local encrypt="$1" local encrypt="$1"
local device_desc="$2" local compress="$2"
shift 2 local device_desc="$3"
shift 3
local devices=("$@") local devices=("$@")
local extra_args=()
einfo "Creating zfs pool on $devices_desc" einfo "Creating zfs pool on $devices_desc"
local extra_args=() if [[ "$compress" != false ]]; then
extra_args+=(
"-O" "compression=$compress"
)
fi
if [[ "$encrypt" == true ]]; then if [[ "$encrypt" == true ]]; then
extra_args+=( extra_args+=(
"-O" "encryption=aes-256-gcm" "-O" "encryption=aes-256-gcm"
@ -440,7 +448,6 @@ function format_zfs_standard() {
-O mountpoint=none \ -O mountpoint=none \
-O canmount=noauto \ -O canmount=noauto \
-O devices=off \ -O devices=off \
-O compression=zstd \
"${extra_args[@]}" \ "${extra_args[@]}" \
rpool \ rpool \
"${devices[@]}" \ "${devices[@]}" \
@ -459,6 +466,7 @@ function disk_format_zfs() {
local ids="${arguments[ids]}" local ids="${arguments[ids]}"
local pool_type="${arguments[pool_type]}" local pool_type="${arguments[pool_type]}"
local encrypt="${arguments[encrypt]-false}" local encrypt="${arguments[encrypt]-false}"
local compress="${arguments[compress]-false}"
if [[ ${disk_action_summarize_only-false} == "true" ]]; then if [[ ${disk_action_summarize_only-false} == "true" ]]; then
local id local id
# Splitting is intentional here # Splitting is intentional here
@ -487,9 +495,9 @@ function disk_format_zfs() {
|| die "Could not erase previous file system signatures from $devices_desc" || die "Could not erase previous file system signatures from $devices_desc"
if [[ "$pool_type" == "custom" ]]; then if [[ "$pool_type" == "custom" ]]; then
format_zfs_custom "$encrypt" "$devices_desc" "${devices[@]}" format_zfs_custom "$devices_desc" "${devices[@]}"
else else
format_zfs_standard "$encrypt" "$devices_desc" "${devices[@]}" format_zfs_standard "$encrypt" "$compress" "$devices_desc" "${devices[@]}"
fi fi
} }