V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m30s
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m30s
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
@@ -79,7 +79,7 @@ recipe:
|
||||
mount:
|
||||
enable: true
|
||||
options: "defaults,nodev,nosuid,noexec,umask=0077"
|
||||
options_snap: ""
|
||||
optsnap: ""
|
||||
path: "/boot/efi"
|
||||
primary: primary
|
||||
2:
|
||||
@@ -118,7 +118,7 @@ recipe:
|
||||
### MUST be "true" for "/boot":
|
||||
enable: true
|
||||
options: "defaults,nodev,nosuid,noexec,noatime,compress=no,discard=async,subvol=@boot"
|
||||
options_snap: ""
|
||||
optsnap: ""
|
||||
path: "/boot"
|
||||
primary: primary
|
||||
3:
|
||||
@@ -153,7 +153,7 @@ recipe:
|
||||
mount:
|
||||
enable: true
|
||||
options: "defaults,nodev"
|
||||
options_snap: ""
|
||||
optsnap: ""
|
||||
path: "/recovery"
|
||||
primary: primary
|
||||
4:
|
||||
@@ -194,7 +194,7 @@ recipe:
|
||||
mount:
|
||||
enable: true
|
||||
options: "defaults,discard"
|
||||
options_snap: ""
|
||||
optsnap: ""
|
||||
path: "SWAP"
|
||||
primary: primary
|
||||
5:
|
||||
@@ -235,7 +235,7 @@ recipe:
|
||||
mount:
|
||||
enable: true
|
||||
options: "defaults,rw,nodev,nosuid,noatime,discard,mode=1777"
|
||||
options_snap: ""
|
||||
optsnap: ""
|
||||
path: "/tmp"
|
||||
primary: primary
|
||||
6:
|
||||
@@ -261,7 +261,7 @@ recipe:
|
||||
compress: "zstd"
|
||||
level: "7"
|
||||
dedup: true
|
||||
subvolume: "@"
|
||||
subvolume: "@root"
|
||||
snapshot: "@root_snap"
|
||||
format: true
|
||||
label: "btrfs_root"
|
||||
@@ -270,7 +270,7 @@ recipe:
|
||||
mount:
|
||||
enable: true
|
||||
options: "defaults,errors=remount-ro,noatime,compress=zstd:7,discard=async,autodefrag,subvol=@"
|
||||
options_snap: "ro,nodev,nosuid,noexec,nodatacow,subvol=@root_snap"
|
||||
optsnap: "ro,nodev,nosuid,noexec,nodatacow,subvol=@root_snap"
|
||||
path: "/"
|
||||
primary: primary
|
||||
7:
|
||||
@@ -305,7 +305,7 @@ recipe:
|
||||
mount:
|
||||
enable: true
|
||||
options: "defaults,nodev,nosuid,relatime,compress=zstd:7,discard=async,autodefrag,subvol=@home"
|
||||
options_snap: "ro,nodev,nosuid,noexec,nodatacow,subvol=@home_snap"
|
||||
optsnap: "ro,nodev,nosuid,noexec,nodatacow,subvol=@home_snap"
|
||||
path: "/home"
|
||||
primary: primary
|
||||
8:
|
||||
@@ -340,7 +340,7 @@ recipe:
|
||||
mount:
|
||||
enable: true
|
||||
options: "defaults,nodev,relatime,compress=zstd:7,discard=async,subvol=@usr"
|
||||
options_snap: ""
|
||||
optsnap: ""
|
||||
path: "/usr"
|
||||
primary: primary
|
||||
9:
|
||||
@@ -375,7 +375,7 @@ recipe:
|
||||
mount:
|
||||
enable: true
|
||||
options: "defaults,nodev,nosuid,relatime,compress=zstd:7,discard=async,subvol=@var"
|
||||
options_snap: "ro,nodev,nosuid,noexec,nodatacow,subvol=@var_snap"
|
||||
optsnap: "ro,nodev,nosuid,noexec,nodatacow,subvol=@var_snap"
|
||||
path: "/var"
|
||||
primary: primary
|
||||
10:
|
||||
@@ -410,7 +410,7 @@ recipe:
|
||||
mount:
|
||||
enable: true
|
||||
options: "defaults,nodev,nosuid,noexec,noatime,nodatacow,compress=zstd:7,discard=async,subvol=@var_log"
|
||||
options_snap: ""
|
||||
optsnap: ""
|
||||
path: "/var/log"
|
||||
primary: primary
|
||||
11:
|
||||
@@ -445,7 +445,7 @@ recipe:
|
||||
mount:
|
||||
enable: true
|
||||
options: "defaults,nodev,nosuid,noexec,noatime,nodatacow,compress=zstd:7,discard=async,subvol=@var_log_audit"
|
||||
options_snap: ""
|
||||
optsnap: ""
|
||||
path: "/var/log/audit"
|
||||
primary: primary
|
||||
12:
|
||||
@@ -480,7 +480,7 @@ recipe:
|
||||
mount:
|
||||
enable: true
|
||||
options: "defaults,nodev,nosuid,noatime,compress=zstd:7,nodatacow,discard=async,subvol=@var_tmp"
|
||||
options_snap: ""
|
||||
optsnap: ""
|
||||
path: "/var/tmp"
|
||||
primary: primary
|
||||
13:
|
||||
@@ -515,7 +515,7 @@ recipe:
|
||||
mount:
|
||||
enable: true
|
||||
options: "defaults,nodev,nosuid,relatime,compress=zstd:7,discard=async,subvol=@opt"
|
||||
options_snap: ""
|
||||
optsnap: ""
|
||||
path: "/opt"
|
||||
primary: primary
|
||||
|
||||
|
||||
@@ -30,27 +30,6 @@ skip_path() {
|
||||
return 1
|
||||
}
|
||||
|
||||
#######################################
|
||||
# Function to generate btrfs-subvolumes.
|
||||
# Globals:
|
||||
# ERR_BTRFS_SUBVOL
|
||||
# TARGET
|
||||
# Arguments:
|
||||
# $1: MOUNT_PATH
|
||||
# $2: SUBVOLUME
|
||||
#######################################
|
||||
create_btrfs_subvolume() {
|
||||
declare var_mount_path="$1"
|
||||
declare var_subvolume="$2"
|
||||
|
||||
if ! btrfs subvolume create "${TARGET}${var_mount_path}/${var_subvolume}"; then
|
||||
do_log "error" "false" "Error occurred at creation of subvolume: '${var_subvolume}' in: '${TARGET}${var_mount_path}'."
|
||||
return "${ERR_BTRFS_SUBVOL}"
|
||||
fi
|
||||
|
||||
do_log "info" "false" "Created: '${var_subvolume}' at: '${TARGET}${var_mount_path}'."
|
||||
}
|
||||
|
||||
#######################################
|
||||
# Function to create the mount path and mount the respective device on it.
|
||||
# Globals:
|
||||
@@ -166,8 +145,10 @@ mount_partition() {
|
||||
|
||||
done
|
||||
|
||||
declare var_dev var_part var_fs_btrfs_compress var_fs_btrfs_level var_encryption_enable var_encryption_label \
|
||||
var_fs_label var_fs_options var_fs_version var_mount_path var_mount_options var_mount_subvolume
|
||||
declare var_dev var_part \
|
||||
var_fs_btrfs_compress var_fs_btrfs_level var_fs_btrfs_subvolume var_fs_btrfs_snapshot \
|
||||
var_encryption_enable var_encryption_label \
|
||||
var_fs_label var_fs_options var_fs_version var_mount_path var_mount_options var_mount_optsnap
|
||||
declare -a ary_devs ary_parts
|
||||
|
||||
### Iterate over all devices in the recipe.
|
||||
@@ -181,6 +162,8 @@ mount_partition() {
|
||||
### Extract parameters from YAML.
|
||||
var_fs_btrfs_compress=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.btrfs.compress" "${VAR_SETUP_PART}")
|
||||
var_fs_btrfs_level=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.btrfs.level" "${VAR_SETUP_PART}")
|
||||
var_fs_btrfs_subvolume=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.btrfs.subvolume" "${VAR_SETUP_PART}")
|
||||
var_fs_btrfs_snapshot=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.btrfs.snapshot" "${VAR_SETUP_PART}")
|
||||
var_encryption_enable=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.encryption.enable" "${VAR_SETUP_PART}")
|
||||
var_encryption_label=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.encryption.label" "${VAR_SETUP_PART}")
|
||||
var_fs_label=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.label" "${VAR_SETUP_PART}")
|
||||
@@ -188,7 +171,7 @@ mount_partition() {
|
||||
var_fs_version=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.version" "${VAR_SETUP_PART}")
|
||||
var_mount_path=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.mount.path" "${VAR_SETUP_PART}")
|
||||
var_mount_options=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.mount.options" "${VAR_SETUP_PART}")
|
||||
var_mount_subvolume=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.mount.subvolume" "${VAR_SETUP_PART}")
|
||||
var_mount_optsnap=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.mount.optsnap" "${VAR_SETUP_PART}")
|
||||
|
||||
### Skip already mounted paths ("/", "/boot", "/boot/efi") and skip ("/recovery")
|
||||
skip_path "${var_mount_path}" && continue
|
||||
@@ -231,19 +214,38 @@ mount_partition() {
|
||||
|
||||
fi
|
||||
|
||||
declare device
|
||||
device=$(resolve_device "${var_dev}" "${var_part}" "${var_encryption_enable}" "${var_encryption_label}")
|
||||
declare var_resolved_dev
|
||||
var_resolved_dev=$(resolve_device "${var_dev}" "${var_part}" "${var_encryption_enable}" "${var_encryption_label}")
|
||||
|
||||
if [[ "${var_fs_version,,}" == btrfs ]]; then
|
||||
|
||||
### Mount toplevel (subvolid=0) *without* extra options
|
||||
declare -a ary_cmd_mount=(mount -o "subvolid=0" "${var_resolved_dev}" "${VAR_SAFE_MNT_BASE}")
|
||||
safe_exec "${ary_cmd_mount[@]}" "${ERR_BTRFS_INITPH}" || return "${ERR_BTRFS_INITPH}"
|
||||
|
||||
btrfs subvolume create "${VAR_SAFE_MNT_BASE}"/"${var_fs_btrfs_subvolume}"
|
||||
|
||||
if [[ -n "${var_fs_btrfs_snapshot}" ]]; then
|
||||
btrfs subvolume create "${VAR_SAFE_MNT_BASE}"/"${var_fs_btrfs_snapshot}" || return "${ERR_BTRFS_SUBVOL}"
|
||||
fi
|
||||
|
||||
umount "${VAR_SAFE_MNT_BASE}"
|
||||
|
||||
fi
|
||||
|
||||
case "${var_fs_version,,}:${var_encryption_enable,,}" in
|
||||
btrfs:*)
|
||||
validate_btrfs_compression "${var_fs_btrfs_compress}" "${var_fs_btrfs_level}" || return "${ERR_BTRFS_OPTION}"
|
||||
declare var_btrfs_compression_options="compress=${var_fs_btrfs_compress}:${var_fs_btrfs_level}"
|
||||
[[ -n "${var_mount_options}" ]] && var_btrfs_compression_options+=",${var_mount_options}"
|
||||
mount_with_dir "${var_mount_path}" "${device}" "${var_btrfs_compression_options}" || return "${ERR_MOUNTING_DEV}"
|
||||
[[ -n ${var_mount_subvolume} ]] && create_btrfs_subvolume "${var_mount_path}" "${var_mount_subvolume}"
|
||||
mount_with_dir "${var_mount_path}" "${var_resolved_dev}" "${var_btrfs_compression_options}" || return "${ERR_MOUNTING_DEV}"
|
||||
if [[ -n "${var_fs_btrfs_snapshot}" ]]; then
|
||||
mkdir -p "${TARGET}${var_mount_path}/.snapshots"
|
||||
mount -o "${var_mount_optsnap}" "${var_resolved_dev}" "${TARGET}${var_mount_path}/.snapshots"
|
||||
fi
|
||||
;;
|
||||
ext4:*)
|
||||
mount_with_dir "${var_mount_path}" "${device}" "${var_mount_options}" || return "${ERR_MOUNTING_DEV}"
|
||||
mount_with_dir "${var_mount_path}" "${var_resolved_dev}" "${var_mount_options}" || return "${ERR_MOUNTING_DEV}"
|
||||
;;
|
||||
*) do_log "error" "false" "Unsupported fs/encryption combination."
|
||||
return "${ERR_MOUNTING_DEV}" ;;
|
||||
|
||||
@@ -27,12 +27,13 @@ declare -girx ERR_INVALID_PORT=243 # Port validation failure.
|
||||
declare -girx ERR_ARG_MISMATCH=242 # The wrong number of optional arguments has been provided.
|
||||
declare -girx ERR_PARTITIONTBL=241 # The partition table is not allowed.
|
||||
declare -girx ERR_READ_PARTTBL=240 # The partition could not be deleted, created, or the UUID of the partition could not be read.
|
||||
declare -girx ERR_BTRFS_SUBVOL=239 # The btrfs subvolume could not be created.
|
||||
declare -girx ERR_BTRFS_OPTION=238 # Compression options algo:level not valid btrfs pairs.
|
||||
declare -girx ERR_MOUNTING_DEV=237 # The Device could not be mounted.
|
||||
declare -girx ERR_MOUNTING_ROOT=236 # The / Volume could not be mounted.
|
||||
declare -girx ERR_MOUNTING_LUKS=235 # The LUKS Volume could not be mounted.
|
||||
declare -girx ERR_UNKNOWN_DEV=234 # Unknown Device Path.
|
||||
declare -girx ERR_BTRFS_INITPH=239 # The btrfs subvolume could not be initialized.
|
||||
declare -girx ERR_BTRFS_SUBVOL=238 # The btrfs subvolume could not be created.
|
||||
declare -girx ERR_BTRFS_OPTION=237 # Compression options algo:level not valid btrfs pairs.
|
||||
declare -girx ERR_MOUNTING_DEV=236 # The Device could not be mounted.
|
||||
declare -girx ERR_MOUNTING_ROOT=235 # The / Volume could not be mounted.
|
||||
declare -girx ERR_MOUNTING_LUKS=234 # The LUKS Volume could not be mounted.
|
||||
declare -girx ERR_UNKNOWN_DEV=233 # Unknown Device Path.
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user