forked from obel1x/fedora-OEMDRV
install.sh: fix four bugs found during live testing
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 <noreply@anthropic.com>
This commit is contained in:
+13
-9
@@ -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<n> to use free space, s<n> to shrink a partition, or q to quit: " INPUT
|
||||
read -r -p "Enter f<n> to use free space, s<n> 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")
|
||||
|
||||
Reference in New Issue
Block a user