V8.00.000.2025.06.17

Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
2025-07-29 12:54:50 +02:00
parent e9f3297cd1
commit f4fb74f689
16 changed files with 994 additions and 341 deletions

View File

@@ -20,9 +20,14 @@ guard_sourcing
#######################################
#######################################
# Function that generates each partition on each device according to the chosen recipe string.
# Function that generates each partition on each device according to the chosen recipe string and collects information about:
# - the mount path and whether to mount or not and in which order mounting must be done.
# - LUKS encryption enabled.
# - Specific device partition data for each mount path.
# Globals:
# ARY_FSTAB_MOUNT_PATHS
# DIR_LOG
# HMP_FSTAB_MOUNT_FTYPE
# HMP_PATH_PARTUUID
# VAR_RECIPE_FIRMWARE
# VAR_RECIPE_STRING
@@ -39,10 +44,22 @@ guard_sourcing
# 0: on success
#######################################
partitioning() {
### Declare Arrays and Variables.
declare -Ag HMP_PATH_PARTUUID
declare var_dev var_part var_end_arg var_begin var_end var_fs var_boot var_pri var_uuid var_mount_path var_label var_end_mib
declare -a ary_devs ary_parts
### Declare Arrays, HashMaps, and Variables.
declare -Ag HMP_PATH_PARTUUID # Used in: 3290() - [Mount Path:Partition UUID].
declare -Ag HMP_FSTAB_MOUNT_FTYPE # Used in: 4040() - [Mount Path:Filesystem type].
declare -Ag HMP_PATH_DEV_PART # Used in: 3220() - [Mount Path:DEV.PARTITION].
# Used in: 3240() - [Mount Path:DEV.PARTITION].
declare -ag ARY_CRYPT_MOUNT_PATHS=() # Used in: 3220() - Only entries [/paths] for encryption.
declare -ag ARY_FORMT_MOUNT_PATHS=() # Used in: 3240() - Only entries [/paths] for filesystem generation.
declare -ag ARY_FSTAB_MOUNT_PATHS=() # Used in: 4040() - Only entries [/paths] for '/etc/fstab' generation.
declare -ag ARY_PATHS_SORTED=() # Used in: - All entries [/paths] in a mount ordering scheme.
declare var_dev="" var_part="" \
var_begin="" var_boot="" var_encryption="" var_end="" var_end_arg="" var_end_mib="" var_format="" var_fs="" var_label="" \
var_mount_path="" var_mount_true="" var_pri="" var_uuid=""
declare -a ary_devs=() ary_parts=() ary_paths_unsorted=()
declare -i i=0 var_dev_size=0 var_dev_end=0
### Iterate over all devices in the recipe.
@@ -57,10 +74,12 @@ partitioning() {
if command -v sgdisk >/dev/null && sgdisk --zap-all "/dev/${var_dev}"; then
do_log "debug" "file_only" "3200() [command -v sgdisk >/dev/null && sgdisk --zap-all]."
do_log "info" "file_only" "3200() Partition table: '/dev/${var_dev}' wiped with 'sgdisk --zap-all'."
elif dd if=/dev/zero of="/dev/${var_dev}" bs=1M count=8 status=none; then
do_log "debug" "file_only" "3200() [dd if=/dev/zero of=/dev/${var_dev} bs=1M count=8 status=none]."
do_log "info" "file_only" "3200() Partition table: '/dev/${var_dev}' overwritten with zeros."
else
@@ -72,7 +91,7 @@ partitioning() {
else
do_log "info" "file_only" "3200() Partition table: '/dev/${var_dev}' discarded (blkdiscard)."
do_log "info" "file_only" "3200() Partition table: '/dev/${var_dev}' discarded [blkdiscard -f /dev/${var_dev}]."
fi
@@ -103,12 +122,15 @@ partitioning() {
for var_part in "${ary_parts[@]}"; do
### Extract parameters from YAML.
var_begin=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.begin" "${VAR_SETUP_PART}")
var_end=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.end" "${VAR_SETUP_PART}")
var_fs=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.version" "${VAR_SETUP_PART}")
var_boot=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.bootable" "${VAR_SETUP_PART}")
var_pri=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.primary" "${VAR_SETUP_PART}")
var_mount_path=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.mount.path" "${VAR_SETUP_PART}")
var_begin=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.begin" "${VAR_SETUP_PART}")
var_end=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.end" "${VAR_SETUP_PART}")
var_fs=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.version" "${VAR_SETUP_PART}")
var_format=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.format" "${VAR_SETUP_PART}")
var_boot=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.bootable" "${VAR_SETUP_PART}")
var_pri=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.primary" "${VAR_SETUP_PART}")
var_mount_path=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.mount.path" "${VAR_SETUP_PART}")
var_mount_true=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.mount.enable" "${VAR_SETUP_PART}")
var_encryption=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.encryption.enable" "${VAR_SETUP_PART}")
### Assign the start zone of the first partition and skip the first 2 MiB as best practice.
if [[ "${var_begin,,}" == "min" ]]; then
@@ -215,9 +237,33 @@ partitioning() {
do_log "fatal" "file_only" "3200() Partition: '/dev/${var_dev}${var_part}' could not read PARTUUID."
return "${ERR_PART_READ}"
else
HMP_PATH_PARTUUID["PARTUUID_${var_mount_path}"]="${var_uuid}"
HMP_PATH_PARTUUID["${var_mount_path}"]="${var_uuid}"
do_log "debug" "file_only" "3200() Stored in HashMap [HMP_PATH_PARTUUID] : '${var_mount_path}' -> '${HMP_PATH_PARTUUID["${var_mount_path}"]}'."
fi
### Gathering information for encryption module 3220().
if [[ "${var_encryption}" == "true" ]]; then
ARY_CRYPT_MOUNT_PATHS+=("${var_mount_path}")
fi
### Gathering information for filesystem module 3240().
if [[ "${var_format}" == "true" ]]; then
ARY_FORMT_MOUNT_PATHS+=("${var_mount_path}")
fi
### Gathering information for mounting module 3280().
HMP_PATH_DEV_PART["${var_mount_path}"]="${var_dev}.${var_part}"
ary_paths_unsorted+=("${var_mount_path}")
### Gathering information for '/etc/fstab'-generation in 4040().
if [[ "${var_mount_true}" == "true" ]]; then
ARY_FSTAB_MOUNT_PATHS+=("${var_mount_path}")
do_log "debug" "file_only" "3200() Stored in Array [ARY_FSTAB_MOUNT_PATHS] : '${var_mount_path}'."
HMP_FSTAB_MOUNT_FTYPE["${var_mount_path}"]="${var_fs}"
do_log "debug" "file_only" "3200() Stored in HashMap [HMP_FSTAB_MOUNT_FTYPE] : '${var_mount_path}' -> '${HMP_FSTAB_MOUNT_FTYPE["${var_mount_path}"]}'."
fi
done
lsblk -o NAME,START,SIZE,PHY-SEC,LOG-SEC,ALIGNMENT "/dev/${var_dev}" >| "${DIR_LOG}/${var_dev}_alignment.log"
@@ -225,6 +271,13 @@ partitioning() {
done
### Prepare mount ordering scheme.
# shellcheck disable=SC2312
IFS=$'\n' read -r -d '' -a ARY_PATHS_SORTED < <(printf "%s\n" "${ary_paths_unsorted[@]}" | sort -u | awk 'BEGIN{FS="/"}{print NF, $0}' | sort -n | cut -d' ' -f2- && printf '\0')
printf "%s\n" "${ary_paths_unsorted[@]}" >| "${DIR_LOG}/mount_paths_unsorted.log"
printf "%s\n" "${ARY_PATHS_SORTED[@]}" >| "${DIR_LOG}/mount_paths_sorted.log"
return 0
}
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh