From 92b5e9c4a62cda81699f398cc35092b8f556236b Mon Sep 17 00:00:00 2001 From: Brot der Bot Date: Fri, 1 May 2026 13:56:34 +0200 Subject: [PATCH] install.sh: fix four bugs found during live testing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Free-space start alignment parted reports free space starting at 0,02 MiB (before the GPT alignment boundary). The collect_free_space awk now rounds the start up to the next whole MiB (ceiling) and enforces a minimum of 1 MiB, then recomputes the usable size from the adjusted start. This prevents parted from being asked to create a partition at 0 MiB, which it cannot do. Locale-independent partition creation The previous `printf 'Yes\n' | parted mkpart` relied on parted accepting an English answer to its alignment-confirmation prompt. On a German-locale system parted asks "Ist dies noch akzeptabel?" and ignores "Yes", causing mkpart to fail. Replaced with `parted -s` (script/non-interactive mode), consistent with every other parted call in the script. Correct new-partition detection on disks with gaps The old heuristic took the highest partition number after partprobe. On a disk where existing partitions are numbered 2/3/4, a new partition in the gap before them receives number 1 — making the old heuristic point at partition 4 (the existing btrfs volume) and subsequently run mkfs.btrfs on it. The new awk matches by start position (OEMDRV_START ± 1 MiB) instead, which is unambiguous regardless of how numbers are assigned. Infinite loop on EOF stdin When the selection while-loop's `read` hits EOF (e.g. stdin exhausted after sudo consumed a piped password), it returns exit code 1 with an empty INPUT, which falls through to "Invalid input." and spins forever. Added `|| { echo; echo "Aborted."; exit 0; }` to all three read calls in the loop. install.md: drop stale install_from_repo.sh reference from title; clarify that REPO_URL/REPO_BRANCH overrides are optional. Co-Authored-By: Claude Sonnet 4.6 --- install.md | 4 ++-- system_setup/install.sh | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/install.md b/install.md index d9c91ed..6a9a284 100644 --- a/install.md +++ b/install.md @@ -1,4 +1,4 @@ -# OEMDRV Bootstrap — install.sh + install_from_repo.sh +# OEMDRV Bootstrap — install.sh the script `./system_setup/install.sh` prepares a target machine for automated Fedora deployment. It shrinks an existing partition to carve out a dedicated **OEMDRV** partition, which Anaconda/Kickstart will detect automatically during installation. @@ -37,7 +37,7 @@ curl -fsSL ${REPO_URL%.git}/raw/branch/${REPO_BRANCH:-main}/system_setup/install sudo -E bash /tmp/install.sh ``` -That way, install.sh should know what to pull. +Both are optional. That way, install.sh should know what to pull. ## After the script completes diff --git a/system_setup/install.sh b/system_setup/install.sh index 5191cac..ee7293e 100755 --- a/system_setup/install.sh +++ b/system_setup/install.sh @@ -196,9 +196,12 @@ collect_free_space() { $1+0 > 0 { for (i = 1; i <= NF; i++) { if ($i == "free") { - start=$2; end=$3; size=$4; - gsub(/MiB/,"",start); gsub(/MiB/,"",end); gsub(/MiB/,"",size); - s=int(start+0); e=int(end+0); sz=int(size+0); + gsub(/MiB/,"",$2); gsub(/MiB/,"",$3); + e=int($3+0); + raw_s=$2+0; + s=int(raw_s)+(raw_s>int(raw_s)?1:0); + if (s < 1) s = 1; + sz=e-s; if (sz >= min) print s " " e " " sz; break } @@ -332,12 +335,12 @@ SEL=-1 while true; do echo if [[ $FS_IDX -gt 0 && $shrink_count -gt 0 ]]; then - read -r -p "Enter f to use free space, s to shrink a partition, or q to quit: " INPUT + read -r -p "Enter f to use free space, s to shrink a partition, or q to quit: " INPUT || { echo; echo "Aborted."; exit 0; } elif [[ $FS_IDX -gt 0 ]]; then - read -r -p "Enter number of free space region to use, or q to quit: " INPUT + read -r -p "Enter number of free space region to use, or q to quit: " INPUT || { echo; echo "Aborted."; exit 0; } [[ "$INPUT" =~ ^[0-9]+$ ]] && INPUT="f${INPUT}" else - read -r -p "Enter number of partition to shrink, or q to quit: " INPUT + read -r -p "Enter number of partition to shrink, or q to quit: " INPUT || { echo; echo "Aborted."; exit 0; } [[ "$INPUT" =~ ^[0-9]+$ ]] && INPUT="s${INPUT}" fi @@ -458,15 +461,16 @@ fi # ── Create OEMDRV partition ─────────────────────────────────────────────────── info "Creating new OEMDRV partition (${OEMDRV_START}–${OEMDRV_END} MiB) on $WORK_DISK..." -printf 'Yes\n' | parted "$WORK_DISK" mkpart anacondainstall btrfs "${OEMDRV_START}MiB" "${OEMDRV_END}MiB" \ +parted -s "$WORK_DISK" mkpart anacondainstall btrfs "${OEMDRV_START}MiB" "${OEMDRV_END}MiB" \ || die "parted mkpart failed. Check that the target area is free space on $WORK_DISK." partprobe "$WORK_DISK" sleep 1 -# Determine new partition number (highest on the disk after partprobe) +# Find the partition whose start matches OEMDRV_START (±1 MiB for alignment) NEW_PNUM=$(parted -s "$WORK_DISK" -m unit MiB print 2>/dev/null \ - | awk -F: '/^[0-9]/{n=$1} END{print n}') + | awk -F: -v s="$OEMDRV_START" ' + /^[0-9]/ { gsub(/MiB/,"",$2); if (int($2+0) >= s-1 && int($2+0) <= s+1) { print $1; exit } }') [[ -n "$NEW_PNUM" ]] || die "Could not determine new partition number on $WORK_DISK." OEMDRV_DEV=$(new_part_device "$WORK_DISK" "$NEW_PNUM")