diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-26 18:31:35 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-26 18:31:35 -0500 |
| commit | f02ba03c12599bdd61b5208c9a65f458ae05aa15 (patch) | |
| tree | 249a2e5eed52aaaa5cc2c9ca57d549a21560c8c6 /installer/lib/disk.sh | |
| parent | 6de9f378cf52b9e9b0e89b396a12b978700241ff (diff) | |
| download | archangel-f02ba03c12599bdd61b5208c9a65f458ae05aa15.tar.gz archangel-f02ba03c12599bdd61b5208c9a65f458ae05aa15.zip | |
refactor: unify partition_disks across ZFS and Btrfs install paths
The monolith's partition_disks() at installer/archangel was ZFS-only and silently shadowed lib/disk.sh:partition_disks(), which had been dead code since the Btrfs install path was added. install_btrfs was assembling partitioning manually via partition_disk (singular) plus a separate format_efi_partitions call. Two parallel implementations meant fixes had to land in two places and the lib version drifted with no visible warning.
The unified partition_disks now lives in lib/disk.sh. It reads SELECTED_DISKS, dispatches the per-disk layout on FILESYSTEM (BF00 for ZFS, 8300 for Btrfs), populates EFI_PARTS + ROOT_PARTS, and formats each EFI partition with EFI0, EFI1, ... labels.
Folded in two pre-existing divergences while consolidating. wipefs -af now runs on every disk, not just the ZFS path. The Btrfs path was missing this defense against non-GPT signatures (LVM, mdadm, ext) that sgdisk --zap-all alone won't touch. EFI labels standardized on EFI0, EFI1, ... across both paths. The lib version was producing asymmetric EFI / EFI2 labels. No consumer in the repo references the labels after format, so that change is cosmetic.
ZFS_PARTS renamed to ROOT_PARTS for symmetry with get_root_partition. Deleted four orphaned helpers: format_efi, format_efi_partitions (only caller was the collapsed install_btrfs section), get_efi_partitions, get_root_partitions (test-only callers after install_btrfs simplified).
Verified end to end: bats 134/134, make test-install passing 12/12 configs across both install paths.
Diffstat (limited to 'installer/lib/disk.sh')
| -rw-r--r-- | installer/lib/disk.sh | 108 |
1 files changed, 39 insertions, 69 deletions
diff --git a/installer/lib/disk.sh b/installer/lib/disk.sh index f40d828..b548b4f 100644 --- a/installer/lib/disk.sh +++ b/installer/lib/disk.sh @@ -6,46 +6,66 @@ # Partition Disks ############################# -# Partition a single disk for ZFS/Btrfs installation -# Creates: EFI partition (512M) + root partition (rest) -# Uses global FILESYSTEM variable to determine partition type +# Partition a single disk for ZFS or Btrfs installation. Wipes +# non-GPT signatures (LVM, mdadm, ext) with wipefs, zaps the GPT +# with sgdisk, then lays down a 512M EFI partition plus a root +# partition that fills the rest. Root partition type code is +# selected from FILESYSTEM (BF00 for ZFS, 8300 for Btrfs). partition_disk() { local disk="$1" local efi_size="${2:-512M}" - # Determine root partition type based on filesystem - local root_type="BF00" # ZFS (Solaris root) + local root_type="BF00" if [[ "$FILESYSTEM" == "btrfs" ]]; then - root_type="8300" # Linux filesystem + root_type="8300" fi info "Partitioning $disk..." - # Wipe existing partition table - sgdisk --zap-all "$disk" || error "Failed to wipe $disk" - - # Create EFI partition (512M, type EF00) + wipefs -af "$disk" || error "Failed to wipe signatures on $disk" + sgdisk --zap-all "$disk" || error "Failed to zap GPT on $disk" sgdisk -n 1:0:+${efi_size} -t 1:EF00 -c 1:"EFI" "$disk" || error "Failed to create EFI partition on $disk" - - # Create root partition (rest of disk) sgdisk -n 2:0:0 -t 2:$root_type -c 2:"ROOT" "$disk" || error "Failed to create root partition on $disk" - # Notify kernel of partition changes partprobe "$disk" 2>/dev/null || true sleep 1 info "Partitioned $disk: EFI=${efi_size}, ROOT=remainder" } -# Partition multiple disks (for RAID configurations) +# Partition every disk in SELECTED_DISKS, format each EFI partition, +# and populate the EFI_PARTS + ROOT_PARTS arrays for downstream +# callers (create_zfs_pool, btrfs_open_encryption, +# sync_efi_partitions, fstab generation). +# +# EFI labels are EFI0, EFI1, ... in selection order so multi-disk +# layouts get a stable, distinguishable scheme that lsblk -f can +# show. Errors out if SELECTED_DISKS is empty so a misconfigured +# install can't silently skip partitioning. partition_disks() { - local efi_size="${1:-512M}" - shift - local disks=("$@") + if [[ ${#SELECTED_DISKS[@]} -eq 0 ]]; then + error "partition_disks: SELECTED_DISKS is empty" + fi + + step "Partitioning ${#SELECTED_DISKS[@]} disk(s)" + + EFI_PARTS=() + ROOT_PARTS=() + + for disk in "${SELECTED_DISKS[@]}"; do + partition_disk "$disk" + EFI_PARTS+=("$(get_efi_partition "$disk")") + ROOT_PARTS+=("$(get_root_partition "$disk")") + done + + sleep 2 - for disk in "${disks[@]}"; do - partition_disk "$disk" "$efi_size" + for i in "${!EFI_PARTS[@]}"; do + info "Formatting EFI partition ${EFI_PARTS[$i]}..." + mkfs.fat -F32 -n "EFI$i" "${EFI_PARTS[$i]}" || error "Failed to format ${EFI_PARTS[$i]}" done + + info "Partitioning complete. Created ${#EFI_PARTS[@]} EFI and ${#ROOT_PARTS[@]} ROOT partitions." } ############################# @@ -72,56 +92,6 @@ get_root_partition() { fi } -# Get all root partitions from disk array -get_root_partitions() { - local disks=("$@") - local parts=() - for disk in "${disks[@]}"; do - parts+=("$(get_root_partition "$disk")") - done - printf '%s\n' "${parts[@]}" -} - -# Get all EFI partitions from disk array -get_efi_partitions() { - local disks=("$@") - local parts=() - for disk in "${disks[@]}"; do - parts+=("$(get_efi_partition "$disk")") - done - printf '%s\n' "${parts[@]}" -} - -############################# -# EFI Partition Management -############################# - -# Format EFI partition -format_efi() { - local partition="$1" - local label="${2:-EFI}" - - info "Formatting EFI partition: $partition" - mkfs.fat -F32 -n "$label" "$partition" || error "Failed to format EFI: $partition" -} - -# Format all EFI partitions -format_efi_partitions() { - local disks=("$@") - local first=true - - for disk in "${disks[@]}"; do - local efi - efi=$(get_efi_partition "$disk") - if $first; then - format_efi "$efi" "EFI" - first=false - else - format_efi "$efi" "EFI2" - fi - done -} - ############################# # Disk Selection (Interactive) ############################# |
