diff --git a/src/partitioning.sh b/src/partitioning.sh index c1a70f9..63751fc 100644 --- a/src/partitioning.sh +++ b/src/partitioning.sh @@ -48,6 +48,20 @@ partition_path() { 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() { : "${DISK:?Target disk 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" set 1 esp on parted -s "$DISK" mkpart ROOT "$ESP_SIZE" "$ROOT_END" - partprobe "$DISK" + refresh_partition_table "$DISK" ESP_PART="$(partition_path "$DISK" 1)" ROOT_PART="$(partition_path "$DISK" 2)" diff --git a/src/sanity.sh b/src/sanity.sh index 7d45a2b..6f422bd 100644 --- a/src/sanity.sh +++ b/src/sanity.sh @@ -41,6 +41,22 @@ require_command() { 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() { if [[ "$(id -u)" -ne 0 ]]; then die "Run this script as root." @@ -57,7 +73,7 @@ sanity_check_base() { sanity_check_commands() { require_command lsblk - require_command partprobe + require_any_command partprobe partx udevadm require_command parted require_command cryptsetup require_command mkfs.vfat