Replace parted resizepart with sfdisk --force

parted fails to resize a mounted partition non-interactively.
sfdisk --no-reread --force writes the updated partition table
directly without TTY/confirmation issues, and partprobe
re-reads it afterwards.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-27 16:40:18 +02:00
parent 5c2182a1c9
commit 5ef48c84e5
+10 -3
View File
@@ -377,9 +377,16 @@ if [[ "$MODE" == "shrink" ]]; then
fi fi
info "Shrinking partition $S_PNUM to ${NEW_END} MiB in partition table..." info "Shrinking partition $S_PNUM to ${NEW_END} MiB in partition table..."
# Use printf instead of -s so parted's "partition is busy" confirmation is answered Yes SECTOR_SIZE=$(cat /sys/block/"${S_DISK##*/}"/queue/hw_sector_size 2>/dev/null || echo 512)
printf 'Yes\n' | parted "$S_DISK" resizepart "$S_PNUM" "${NEW_END}MiB" \ NEW_END_SEC=$(( NEW_END * 1048576 / SECTOR_SIZE ))
|| die "parted resizepart failed." sfdisk -d "$S_DISK" | awk -v dev="$S_DEV" -v new_end="$NEW_END_SEC" '
$0 ~ "^" dev " : " {
match($0, /start= *([0-9]+)/, a)
sub(/size= *[0-9]+/, "size= " (new_end - a[1]+0))
}
{ print }
' | sfdisk --no-reread --force "$S_DISK" \
|| die "sfdisk partition resize failed."
fi fi
# ── Create OEMDRV partition ─────────────────────────────────────────────────── # ── Create OEMDRV partition ───────────────────────────────────────────────────