Initial public import of the proven Bash installer (installer/) and the production Rust workspace (installer-rs/). The reference ISO, build output and local agent transcripts are gitignored. Verified: installer/tests/run_tests.sh and cargo test --workspace both pass.
69 lines
2.4 KiB
Bash
69 lines
2.4 KiB
Bash
#!/usr/bin/env bash
|
|
# shellcheck shell=bash
|
|
#
|
|
# GPT partition creation for the installation target.
|
|
#
|
|
# Every function here is destructive and must be invoked through
|
|
# run_destructive, which enforces prior authorization.
|
|
|
|
# partitions_require_tools
|
|
partitions_require_tools() {
|
|
require_cmd sgdisk partprobe blkid wipefs || return 1
|
|
}
|
|
|
|
# partitions_wipe DISK - zap all existing partition signatures
|
|
partitions_wipe() {
|
|
local disk="$1"
|
|
run_destructive "wipe partition signatures on $disk" wipefs -a "$disk" || return 1
|
|
run_destructive "zap GPT/MBR on $disk" sgdisk --zap-all "$disk"
|
|
}
|
|
|
|
# partitions_create_gpt DISK - EFI + root (LUKS or plain btrfs)
|
|
partitions_create_gpt() {
|
|
local disk="$1"
|
|
local efi_mib root_type=8309
|
|
efi_mib="$(config_get EFI_SIZE_MIB)"
|
|
[[ "$efi_mib" =~ ^[0-9]+$ ]] || efi_mib=1024
|
|
if [[ "$(config_get ENCRYPTION)" == "none" ]]; then
|
|
root_type=8300
|
|
fi
|
|
|
|
run_destructive "create GPT on $disk" sgdisk --set-alignment=2048 \
|
|
--new=1:0:+${efi_mib}M --typecode=1:ef00 --change-name=1:EFI \
|
|
--new=2:0:0 --typecode=2:${root_type} --change-name=2:phoebus-root \
|
|
"$disk" || return 1
|
|
run_destructive "re-read partition table on $disk" partprobe "$disk"
|
|
command -v udevadm >/dev/null 2>&1 && run_cmd "settle udev" udevadm settle
|
|
}
|
|
|
|
# partitions_named DISK - first EFI and root partition paths via blkid
|
|
partitions_named() {
|
|
local disk="$1"
|
|
EFI_PART="" ROOT_PART=""
|
|
# Prefer explicit GPT names when available.
|
|
if command -v blkid >/dev/null 2>&1; then
|
|
local dev label
|
|
while IFS= read -r dev; do
|
|
label="$(blkid -s PARTLABEL -o value "$dev" 2>/dev/null)"
|
|
case "$label" in
|
|
EFI) EFI_PART="$dev" ;;
|
|
phoebus-root) ROOT_PART="$dev" ;;
|
|
esac
|
|
done < <(disk_partitions "$disk")
|
|
fi
|
|
# Fallback by order.
|
|
local -a parts=()
|
|
mapfile -t parts < <(disk_partitions "$disk")
|
|
[[ -z "$EFI_PART" && ${#parts[@]} -ge 1 ]] && EFI_PART="${parts[0]}"
|
|
[[ -z "$ROOT_PART" && ${#parts[@]} -ge 2 ]] && ROOT_PART="${parts[1]}"
|
|
[[ -n "$EFI_PART" && -n "$ROOT_PART" ]]
|
|
}
|
|
|
|
# partitions_verify DISK - sanity check after creation
|
|
partitions_verify() {
|
|
local disk="$1"
|
|
partitions_named "$disk" || { log_error "could not identify created partitions on $disk"; return 1; }
|
|
[[ -b "$EFI_PART" && -b "$ROOT_PART" ]] || { log_error "partition devices missing"; return 1; }
|
|
log_info "partitions: EFI=$EFI_PART root=$ROOT_PART"
|
|
return 0
|
|
}
|