Manually save and restore mapped ids and devices

This commit is contained in:
oddlama 2020-04-23 17:42:23 +02:00
parent 2274c3f7c2
commit f40334f9be
No known key found for this signature in database
GPG Key ID: 88EA325D51D53908
3 changed files with 28 additions and 13 deletions

View File

@ -411,6 +411,11 @@ print_summary_tree() {
} }
apply_disk_actions() { apply_disk_actions() {
# Clean old resolved ids
rm -rf "$RESOLVABLE_MAP_DIR" &>/dev/null
unset DISK_ID_TO_RESOLVABLE; declare -A -g DISK_ID_TO_RESOLVABLE
unset DISK_UUID_TO_DEVICE; declare -A -g DISK_UUID_TO_DEVICE
local param local param
local current_params=() local current_params=()
for param in "${DISK_ACTIONS[@]}"; do for param in "${DISK_ACTIONS[@]}"; do

View File

@ -27,14 +27,14 @@ USED_LUKS=false
DISK_ACTIONS=() DISK_ACTIONS=()
# An associative array from disk id to a resolvable string # An associative array from disk id to a resolvable string
declare -A DISK_ID_TO_RESOLVABLE declare -A DISK_ID_TO_RESOLVABLE
# An associative from uuid to device
declare -A DISK_UUID_TO_DEVICE
# An associative array from disk id to parent gpt disk id (only for partitions) # An associative array from disk id to parent gpt disk id (only for partitions)
declare -A DISK_ID_PART_TO_GPT_ID declare -A DISK_ID_PART_TO_GPT_ID
# An associative array to check for existing ids (maps to uuids) # An associative array to check for existing ids (maps to uuids)
declare -A DISK_ID_TO_UUID declare -A DISK_ID_TO_UUID
# An associative set to check for correct usage of size=remaining in gpt tables # An associative set to check for correct usage of size=remaining in gpt tables
declare -A DISK_GPT_HAD_SIZE_REMAINING declare -A DISK_GPT_HAD_SIZE_REMAINING
# An associative from uuid to device
declare -A DISK_UUID_TO_DEVICE
only_one_of() { only_one_of() {
local previous="" local previous=""

View File

@ -158,29 +158,39 @@ create_resolve_entry() {
case "$type" in case "$type" in
'partuuid') ;; 'partuuid') ;;
'ptuuid') DISK_UUID_TO_DEVICE[$arg]="$device" ;;
'uuid') ;; 'uuid') ;;
'mdadm') DISK_UUID_TO_DEVICE[$arg]="$device" ;;
'luks') ;; 'luks') ;;
'ptuuid') ;& # fallthrough
'mdadm')
DISK_UUID_TO_DEVICE[$arg]="$device"
mkdir -p "$RESOLVABLE_MAP_DIR/DISK_UUID_TO_DEVICE" \
|| die "Could not create resolveable map dir '$RESOLVABLE_MAP_DIR'"
echo -n "$device" > "$RESOLVABLE_MAP_DIR/DISK_UUID_TO_DEVICE/$(base64 -w 0 <<< "$id")"
;;
*) die "Cannot add resolvable entry for '$type:$arg' (unknown type)" *) die "Cannot add resolvable entry for '$type:$arg' (unknown type)"
esac esac
DISK_ID_TO_RESOLVABLE[$id]="$type:$arg" DISK_ID_TO_RESOLVABLE[$id]="$type:$arg"
mkdir -p "$RESOLVABLE_MAP_DIR" \ mkdir -p "$RESOLVABLE_MAP_DIR/DISK_ID_TO_RESOLVABLE" \
|| die "Could not create resolveable map dir '$RESOLVABLE_MAP_DIR'" || die "Could not create resolveable map dir '$RESOLVABLE_MAP_DIR'"
echo -n "$type:$arg" > "$RESOLVABLE_MAP_DIR/$(base64 -w 0 <<< "$id")" echo -n "$type:$arg" > "$RESOLVABLE_MAP_DIR/DISK_ID_TO_RESOLVABLE/$(base64 -w 0 <<< "$id")"
} }
load_resolvable_entries() { load_resolvable_entries() {
[[ -d $RESOLVABLE_MAP_DIR ]] \ [[ -d $RESOLVABLE_MAP_DIR ]] \
|| return 0 || return 0
local base_id local base64_key
local id local key
local saved local value
for base_id in "$RESOLVABLE_MAP_DIR/"*; do for base64_key in "$RESOLVABLE_MAP_DIR/DISK_ID_TO_RESOLVABLE/"*; do
id="$(base64 -d <<< "$(basename "$base_id")")" key="$(base64 -d <<< "$(basename "$base64_key")")"
saved="$(cat "$base_id")" value="$(cat "$base64_key")"
DISK_ID_TO_RESOLVABLE[$id]="$saved" DISK_ID_TO_RESOLVABLE[$key]="$value"
done
for base64_key in "$RESOLVABLE_MAP_DIR/DISK_UUID_TO_DEVICE/"*; do
key="$(base64 -d <<< "$(basename "$base64_key")")"
value="$(cat "$base64_key")"
DISK_UUID_TO_DEVICE[$key]="$value"
done done
} }