Skip to content

Commit d898718

Browse files
committed
Make expand script executable, break up processing parted output, use qemu-img resize command rather than dd to grow image
1 parent 0713657 commit d898718

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

expand.sh

100644100755
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,20 @@ echo "SOURCE_IMAGE: $SOURCE_IMAGE"
1212
echo "EXPAND: $EXPAND"
1313

1414
# Determine the current size of the partition.
15-
SIZE_BEFORE=$(parted -s "${SOURCE_IMAGE}" unit MiB print | grep -e '^ 2' \
16-
| xargs echo -n | cut -d" " -f 4 | tr -d MiB)
15+
PARTED_OUT=$(parted -s "${SOURCE_IMAGE}" unit MiB print)
16+
SIZE_BEFORE=$(echo -e "${PARTED_OUT}" | grep -e '^ 2' | xargs echo -n \
17+
| cut -d" " -f 4 | tr -d MiB)
1718

1819
# Find the end of the root partition. This assumes there are two partitions.
19-
ROOT_END=$(parted -s "${SOURCE_IMAGE}" unit MiB print | grep -e '^ 2' \
20-
| xargs echo -n | cut -d" " -f 3 | tr -d MiB)
20+
ROOT_END=$(echo -e "${PARTED_OUT}" | grep -e '^ 2' | xargs echo -n \
21+
| cut -d" " -f 3 | tr -d MiB)
2122

2223
ROOT_END_NEW=$(($ROOT_END + $EXPAND))
2324

2425
parted -s "${SOURCE_IMAGE}" unit MiB print free
2526

2627
# Expand the image slightly more than required for the new partition.
27-
dd bs=1M if=/dev/zero count=$(($EXPAND + 1)) >> $SOURCE_IMAGE
28+
qemu-img resize -f raw $SOURCE_IMAGE "+$((EXPAND + 1))M"
2829

2930
parted -s "${SOURCE_IMAGE}" unit MiB print free
3031

0 commit comments

Comments
 (0)