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:
+10
-3
@@ -377,9 +377,16 @@ if [[ "$MODE" == "shrink" ]]; then
|
||||
fi
|
||||
|
||||
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
|
||||
printf 'Yes\n' | parted "$S_DISK" resizepart "$S_PNUM" "${NEW_END}MiB" \
|
||||
|| die "parted resizepart failed."
|
||||
SECTOR_SIZE=$(cat /sys/block/"${S_DISK##*/}"/queue/hw_sector_size 2>/dev/null || echo 512)
|
||||
NEW_END_SEC=$(( NEW_END * 1048576 / SECTOR_SIZE ))
|
||||
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
|
||||
|
||||
# ── Create OEMDRV partition ───────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user