Skip to content

Commit

Permalink
Fix optimize with parted
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Guyot <[email protected]>
  • Loading branch information
pguyot committed May 4, 2024
1 parent 7d172f0 commit 55e9f30
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cleanup_image.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -uo pipefail
set -euxo pipefail

loopdev=$1
mount=$2
Expand All @@ -20,10 +20,10 @@ if [[ -d "${mount}" ]]; then
if [[ "${optimize}x" == "x" || "${optimize}x" == "yesx" ]]; then
if [[ -d "${mount}/boot" ]]; then
echo "Zero-filling unused blocks on boot filesystem..."
cat /dev/zero >"${mount}/boot/zero.fill" 2>/dev/null; sync; rm -f "${mount}/boot/zero.fill"
(cat /dev/zero >"${mount}/boot/zero.fill" 2>/dev/null || true); sync; rm -f "${mount}/boot/zero.fill"
fi
echo "Zero-filling unused blocks on root filesystem..."
cat /dev/zero >"${mount}/zero.fill" 2>/dev/null; sync; rm -f "${mount}/zero.fill"
(cat /dev/zero >"${mount}/zero.fill" 2>/dev/null || true); sync; rm -f "${mount}/zero.fill"
fi

umount "${mount}/dev/pts" || true
Expand All @@ -44,6 +44,8 @@ if [[ -d "${mount}" ]]; then
rootfs_blockcount=$(tune2fs -l ${rootdev} | grep "^Block count" | awk '{print $NF}')

echo "Resizing rootfs partition."
echo "DEBUG parted print"
parted -m --script "${loopdev}" unit B print
rootfs_partstart=$(parted -m --script "${loopdev}" unit B print | grep "^${rootfs_partnum}:" | awk -F ":" '{print $2}' | tr -d 'B')
rootfs_partsize=$((${rootfs_blockcount} * ${rootfs_blocksize}))
rootfs_partend=$((${rootfs_partstart} + ${rootfs_partsize}))
Expand Down

0 comments on commit 55e9f30

Please sign in to comment.