Fix partition issue
This commit is contained in:
1 parent
7c50d72f40
commit
7d3b01eae9
5 files changed
+424
-64
No files matched your search
@@ -24,6 +24,17 @@ if [[ ! -r $SETUP_FORM ]]; then
|
||||
fi
|
||||
source "$SETUP_FORM"
|
||||
|
||||
# Partition creation helpers, shared with test/partition-numbering-test.sh so
|
||||
# the numbering logic can be exercised without a real disk.
|
||||
DISK_PARTITIONING="${DISK_PARTITIONING:-/usr/share/omarchy-iso/disk-partitioning.sh}"
|
||||
[[ -r $DISK_PARTITIONING ]] ||
|
||||
DISK_PARTITIONING="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../usr/share/omarchy-iso/disk-partitioning.sh"
|
||||
if [[ ! -r $DISK_PARTITIONING ]]; then
|
||||
echo "ERROR: disk partitioning helpers not found at $DISK_PARTITIONING" >&2
|
||||
exit 1
|
||||
fi
|
||||
source "$DISK_PARTITIONING"
|
||||
|
||||
LOGO_WIDTH=$(awk '{ if (length > max) max = length } END { print max+0 }' "$LOGO_PATH")
|
||||
|
||||
export GUM_CONFIRM_PROMPT_FOREGROUND="6"
|
||||
@@ -361,15 +372,7 @@ get_root_disk() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Compute partition device path, handling NVMe/mmcblk's pN naming.
|
||||
partition_path() {
|
||||
local _disk="$1" _num="$2"
|
||||
if [[ "$_disk" == *nvme* || "$_disk" == *mmcblk* ]]; then
|
||||
echo "${_disk}p${_num}"
|
||||
else
|
||||
echo "${_disk}${_num}"
|
||||
fi
|
||||
}
|
||||
# partition_path lives in disk-partitioning.sh alongside the creation helpers.
|
||||
|
||||
# BitLocker writes the "-FVE-FS-" signature at offset 3 of the partition.
|
||||
detect_bitlocker() {
|
||||
@@ -416,13 +419,20 @@ detect_kernel() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Give udev a moment to create a device node after partitioning.
|
||||
wait_for_device() {
|
||||
local i
|
||||
for i in 1 2 3 4 5; do
|
||||
[[ -b "$1" ]] && return 0
|
||||
sleep 1
|
||||
done
|
||||
# wait_for_device lives in disk-partitioning.sh: it now reports failure, and
|
||||
# every caller here aborts on it.
|
||||
|
||||
# disk_step and create_partition fail through this rather than abort() so a
|
||||
# half-built layout is undone before the user is handed back their disk.
|
||||
disk_abort_hook() {
|
||||
# Release the target before reclaiming its partitions: a mounted filesystem
|
||||
# or an open LUKS mapping would keep parted from removing them.
|
||||
umount -R /mnt 2>/dev/null || true
|
||||
umount /mnt/btrfs-root 2>/dev/null || true
|
||||
rmdir /mnt/btrfs-root 2>/dev/null || true
|
||||
cryptsetup close omarchy_root 2>/dev/null || true
|
||||
rollback_created_parts "$disk"
|
||||
abort "$1"
|
||||
}
|
||||
|
||||
# Save the configurator answers the installer consumes: git identity and
|
||||
@@ -654,17 +664,17 @@ run_partition_decide() {
|
||||
|
||||
kernel_choice=$(detect_kernel)
|
||||
|
||||
local last_part
|
||||
last_part=$(lsblk -n -o PARTN "$disk" 2>/dev/null | grep -E '^[0-9]+$' | sort -n | tail -1)
|
||||
efi_part_num=$(( ${last_part:-0} + 1 ))
|
||||
root_part_num=$(( efi_part_num + 1 ))
|
||||
|
||||
efi_dev=$(partition_path "$disk" "$efi_part_num")
|
||||
root_partition_device=$(partition_path "$disk" "$root_part_num")
|
||||
# Partition numbers are not knowable until parted assigns them (it fills the
|
||||
# lowest free GPT slot, and freeing space by deleting a partition leaves one
|
||||
# below the highest). run_partition_execute reads them back after creation;
|
||||
# a dry run has nothing to read.
|
||||
efi_part_num=""
|
||||
root_part_num=""
|
||||
efi_dev="<assigned at creation>"
|
||||
root_partition_device="<assigned at creation>"
|
||||
root_mapper="<assigned at creation>"
|
||||
if [[ "$encrypt_installation" == "true" ]]; then
|
||||
root_mapper="/dev/mapper/omarchy_root"
|
||||
else
|
||||
root_mapper="$root_partition_device"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -672,64 +682,103 @@ run_partition_decide() {
|
||||
# the pre-mounted (protected) install configuration. Runs after the user step
|
||||
# so LUKS can be formatted with the user's password.
|
||||
run_partition_execute() {
|
||||
local dry=false
|
||||
local dry=false subvol
|
||||
[[ "${1:-}" == "dry" ]] && dry=true
|
||||
|
||||
if $dry; then
|
||||
$needs_mklabel && say "[dry] would initialize GPT on $disk"
|
||||
say "[dry] would create root partition at $root_partition_device"
|
||||
say "[dry] would create EFI partition at $efi_dev"
|
||||
say "[dry] would create an EFI partition and a root partition in the free region"
|
||||
say "[dry] partition numbers are assigned by parted at creation, then read back"
|
||||
say "[dry] encrypted=$encrypt_installation kernel=$kernel_choice"
|
||||
else
|
||||
step "Creating partitions on $disk"
|
||||
if $needs_mklabel; then
|
||||
parted --script "$disk" mklabel gpt
|
||||
disk_step "initializing GPT on $disk" parted --script "$disk" mklabel gpt
|
||||
partprobe "$disk" 2>/dev/null || true
|
||||
sleep 1
|
||||
fi
|
||||
parted --script "$disk" mkpart primary fat32 "${EFI_START_B}B" "${EFI_END_B}B"
|
||||
parted --script "$disk" set "$efi_part_num" esp on
|
||||
parted --script "$disk" name "$efi_part_num" "OMARCHY_EFI"
|
||||
parted --script "$disk" mkpart primary btrfs "${ROOT_START_B}B" "${ROOT_END_B}B"
|
||||
parted --script "$disk" name "$root_part_num" "OMARCHY_ROOT"
|
||||
|
||||
# create_partition reports the number parted actually used; nothing here
|
||||
# may assume it. It sets created_partition_number rather than printing so
|
||||
# the rollback bookkeeping survives (a $(...) would subshell it away).
|
||||
create_partition "$disk" "$EFI_START_B" "$EFI_END_B" fat32 OMARCHY_EFI ||
|
||||
disk_abort_hook "Could not create the EFI partition on $disk"
|
||||
efi_part_num="$created_partition_number"
|
||||
|
||||
create_partition "$disk" "$ROOT_START_B" "$ROOT_END_B" btrfs OMARCHY_ROOT ||
|
||||
disk_abort_hook "Could not create the root partition on $disk"
|
||||
root_part_num="$created_partition_number"
|
||||
|
||||
disk_step "flagging partition $efi_part_num as ESP" \
|
||||
parted --script "$disk" set "$efi_part_num" esp on
|
||||
|
||||
efi_dev=$(partition_path "$disk" "$efi_part_num")
|
||||
root_partition_device=$(partition_path "$disk" "$root_part_num")
|
||||
|
||||
partprobe "$disk"
|
||||
sync
|
||||
sleep 2
|
||||
|
||||
wait_for_device "$efi_dev"
|
||||
wait_for_device "$root_partition_device"
|
||||
wait_for_device "$efi_dev" || disk_abort_hook "EFI partition $efi_dev never appeared"
|
||||
wait_for_device "$root_partition_device" ||
|
||||
disk_abort_hook "Root partition $root_partition_device never appeared"
|
||||
|
||||
# Both partitions are ours and brand new, but the space they occupy may
|
||||
# carry signatures from whatever was deleted to free it.
|
||||
disk_step "clearing stale signatures on $efi_dev" wipefs -af "$efi_dev"
|
||||
disk_step "clearing stale signatures on $root_partition_device" wipefs -af "$root_partition_device"
|
||||
|
||||
if [[ "$encrypt_installation" == "true" ]]; then
|
||||
step "Setting up LUKS2 on $root_partition_device"
|
||||
printf "%s" "$password" | cryptsetup luksFormat --type luks2 --batch-mode "$root_partition_device" -
|
||||
printf "%s" "$password" | cryptsetup open "$root_partition_device" omarchy_root -
|
||||
# Kept as pipes rather than routed through disk_step: the passphrase must
|
||||
# not become an argv the process table can show. Folding stderr into
|
||||
# stdout still lands any error in the install log.
|
||||
if ! printf "%s" "$password" |
|
||||
cryptsetup luksFormat --type luks2 --batch-mode "$root_partition_device" - 2>&1; then
|
||||
disk_abort_hook "Formatting LUKS2 on $root_partition_device failed"
|
||||
fi
|
||||
if ! printf "%s" "$password" |
|
||||
cryptsetup open "$root_partition_device" omarchy_root - 2>&1; then
|
||||
disk_abort_hook "Opening the encrypted root on $root_partition_device failed"
|
||||
fi
|
||||
root_mapper="/dev/mapper/omarchy_root"
|
||||
else
|
||||
wipefs -af "$root_partition_device"
|
||||
root_mapper="$root_partition_device"
|
||||
fi
|
||||
|
||||
step "Creating Btrfs filesystem and subvolumes"
|
||||
mkfs.btrfs -f -L OMARCHY "$root_mapper"
|
||||
wait_for_device "$root_mapper"
|
||||
disk_step "creating the Btrfs filesystem on $root_mapper" \
|
||||
mkfs.btrfs -f -L OMARCHY "$root_mapper"
|
||||
wait_for_device "$root_mapper" || disk_abort_hook "Root device $root_mapper never appeared"
|
||||
|
||||
mkdir -p /mnt/btrfs-root
|
||||
mount "$root_mapper" /mnt/btrfs-root
|
||||
btrfs subvolume create /mnt/btrfs-root/@
|
||||
btrfs subvolume create /mnt/btrfs-root/@home
|
||||
btrfs subvolume create /mnt/btrfs-root/@log
|
||||
btrfs subvolume create /mnt/btrfs-root/@pkg
|
||||
disk_step "mounting $root_mapper" mount "$root_mapper" /mnt/btrfs-root
|
||||
for subvol in @ @home @log @pkg; do
|
||||
disk_step "creating subvolume $subvol" btrfs subvolume create "/mnt/btrfs-root/$subvol"
|
||||
done
|
||||
umount /mnt/btrfs-root
|
||||
rmdir /mnt/btrfs-root
|
||||
|
||||
mount -o noatime,compress=zstd,subvol=@ "$root_mapper" /mnt
|
||||
disk_step "mounting the target root" \
|
||||
mount -o noatime,compress=zstd,subvol=@ "$root_mapper" /mnt
|
||||
mkdir -p /mnt/home /mnt/var/log /mnt/var/cache/pacman/pkg /mnt"$esp_mount_in_target"
|
||||
mount -o noatime,compress=zstd,subvol=@home "$root_mapper" /mnt/home
|
||||
mount -o noatime,compress=zstd,subvol=@log "$root_mapper" /mnt/var/log
|
||||
mount -o noatime,compress=zstd,subvol=@pkg "$root_mapper" /mnt/var/cache/pacman/pkg
|
||||
disk_step "mounting /home" \
|
||||
mount -o noatime,compress=zstd,subvol=@home "$root_mapper" /mnt/home
|
||||
disk_step "mounting /var/log" \
|
||||
mount -o noatime,compress=zstd,subvol=@log "$root_mapper" /mnt/var/log
|
||||
disk_step "mounting the package cache" \
|
||||
mount -o noatime,compress=zstd,subvol=@pkg "$root_mapper" /mnt/var/cache/pacman/pkg
|
||||
|
||||
mkfs.fat -F32 -n OMARCHY_EFI "$efi_dev"
|
||||
mount "$efi_dev" /mnt"$esp_mount_in_target"
|
||||
disk_step "creating the ESP filesystem on $efi_dev" mkfs.fat -F32 -n OMARCHY_EFI "$efi_dev"
|
||||
disk_step "mounting the ESP" mount "$efi_dev" /mnt"$esp_mount_in_target"
|
||||
|
||||
# The orchestrator's first act is to verify this handoff. Check it here so
|
||||
# a failure names the step that broke rather than surfacing later as
|
||||
# "protected mode: /mnt is not a mountpoint".
|
||||
mountpoint -q /mnt ||
|
||||
disk_abort_hook "Target /mnt is not mounted; not starting the installer"
|
||||
mountpoint -q "/mnt$esp_mount_in_target" ||
|
||||
disk_abort_hook "ESP is not mounted at /mnt$esp_mount_in_target"
|
||||
fi
|
||||
|
||||
local luks_uuid_json="null" luks_uuid
|
||||
|
||||
Reference in new issue
Block a user