Made mdadm uuids discoverable

This commit is contained in:
oddlama 2020-04-21 23:41:27 +02:00
parent cfcefae1ec
commit d203dfc6c3
No known key found for this signature in database
GPG Key ID: 88EA325D51D53908
3 changed files with 18 additions and 9 deletions

View File

@ -132,9 +132,10 @@ resolve_id_to_device() {
local arg="${disk_id_to_resolvable[$id]#*:}"
case "$type" in
'partuuid') get_device_by_partuuid "$arg" ;;
'ptuuid') get_device_by_ptuuid "$arg" ;;
'uuid') get_device_by_uuid "$arg" ;;
'partuuid') get_device_by_partuuid "$arg" ;;
'ptuuid') get_device_by_ptuuid "$arg" ;;
'uuid') get_device_by_uuid "$arg" ;;
'mdadm') get_device_by_mdadm_uuid "$arg" ;;
*) die "Cannot resolve '$type:$arg' to device (unkown type)"
esac
}
@ -237,12 +238,14 @@ disk_create_raid() {
done
devices_desc="${devices_desc:0:-2}"
local mddevice="/dev/md/$name"
local uuid="${DISK_ID_TO_UUID[$new_id]}"
disk_id_to_resolvable[$new_id]="uuid:$uuid"
DISK_MDADM_UUID_TO_DEVICE[${uuid,,}]="$mddevice"
disk_id_to_resolvable[$new_id]="mdadm:$uuid"
einfo "Creating raid$level ($new_id) on $devices_desc"
mdadm \
--create "/dev/md/$name" \
--create "$mddevice" \
--verbose \
--homehost="$HOSTNAME" \
--metadata=1.2 \

View File

@ -29,6 +29,8 @@ declare -A DISK_ID_TO_UUID
declare -A DISK_GPT_HAD_SIZE_REMAINING
# An associative from PTUUID to device
declare -A DISK_PTUUID_TO_DEVICE
# An associative from MDADM uuid to device
declare -A DISK_MDADM_UUID_TO_DEVICE
only_one_of() {
local previous=""
@ -229,8 +231,8 @@ create_default_disk_layout() {
else
DISK_ID_BIOS="part_$type"
fi
DISK_ID_SWAP=part_raid
DISK_ID_ROOT=part_luks
DISK_ID_SWAP=part_swap
DISK_ID_ROOT=part_root
}
# Example 2: Multiple disks, with raid 0 and luks

View File

@ -134,12 +134,16 @@ get_device_by_partuuid() {
get_device_by_blkid_field 'PARTUUID' "$1"
}
get_device_by_uuid() {
get_device_by_blkid_field 'UUID' "$1"
}
get_device_by_ptuuid() {
echo -n "${DISK_PTUUID_TO_DEVICE[${1,,}]}"
}
get_device_by_uuid() {
get_device_by_blkid_field 'UUID' "$1"
get_device_by_mdadm_uuid() {
echo -n "${DISK_MDADM_UUID_TO_DEVICE[${1,,}]}"
}
load_or_generate_uuid() {