Relax partition refresh dependency

This commit is contained in:
Stefan Strobl 2025-12-24 14:57:05 +01:00
parent a6e5399572
commit 051485cede
2 changed files with 32 additions and 2 deletions

View File

@ -48,6 +48,20 @@ partition_path() {
fi fi
} }
refresh_partition_table() {
local disk="$1"
if command -v partprobe >/dev/null 2>&1; then
partprobe "$disk"
elif command -v partx >/dev/null 2>&1; then
partx -u "$disk"
elif command -v udevadm >/dev/null 2>&1; then
udevadm settle
else
log_warn "No partition refresh tool available; proceeding without refresh."
fi
}
partition_disk() { partition_disk() {
: "${DISK:?Target disk is required}" : "${DISK:?Target disk is required}"
: "${ESP_SIZE:?ESP size is required}" : "${ESP_SIZE:?ESP size is required}"
@ -65,7 +79,7 @@ partition_disk() {
parted -s "$DISK" mkpart ESP fat32 1MiB "$ESP_SIZE" parted -s "$DISK" mkpart ESP fat32 1MiB "$ESP_SIZE"
parted -s "$DISK" set 1 esp on parted -s "$DISK" set 1 esp on
parted -s "$DISK" mkpart ROOT "$ESP_SIZE" "$ROOT_END" parted -s "$DISK" mkpart ROOT "$ESP_SIZE" "$ROOT_END"
partprobe "$DISK" refresh_partition_table "$DISK"
ESP_PART="$(partition_path "$DISK" 1)" ESP_PART="$(partition_path "$DISK" 1)"
ROOT_PART="$(partition_path "$DISK" 2)" ROOT_PART="$(partition_path "$DISK" 2)"

View File

@ -41,6 +41,22 @@ require_command() {
fi fi
} }
require_any_command() {
local found=""
local cmd
for cmd in "$@"; do
if command -v "$cmd" >/dev/null 2>&1; then
found="yes"
break
fi
done
if [[ -z "$found" ]]; then
die "Missing required command: one of $*"
fi
}
sanity_check_base() { sanity_check_base() {
if [[ "$(id -u)" -ne 0 ]]; then if [[ "$(id -u)" -ne 0 ]]; then
die "Run this script as root." die "Run this script as root."
@ -57,7 +73,7 @@ sanity_check_base() {
sanity_check_commands() { sanity_check_commands() {
require_command lsblk require_command lsblk
require_command partprobe require_any_command partprobe partx udevadm
require_command parted require_command parted
require_command cryptsetup require_command cryptsetup
require_command mkfs.vfat require_command mkfs.vfat