FreeBSD minimize: let dd(1) automatically exit on disk full
Don't need to periodically check the space left, dd(1) will
automatically exit after it cannot write to the disk anymore.
This mitigate the issue that fs may reserve some space so the
available space size will never get to 0.
MODIFY
packer_templates/freebsd/scripts/minimize.sh
packer_templates/freebsd/scripts/minimize.sh
@@ -8,17 +8,8 @@ ZROOT="zroot/ROOT/default"
COMPRESSION=$(zfs get -H compression $ZROOT | cut -f3);
zfs set compression=off $ZROOT;
-dd if=/dev/zero of=/EMPTY bs=1m &
-PID=$!;
-
-avail=$(zfs get -pH avail $ZROOT | cut -f3);
-while [ "$avail" -ne 0 ]; do
- sleep 15;
- avail=$(zfs get -pH avail $ZROOT | cut -f3);
-done
-
-kill $PID || echo "dd already exited";
-
+dd if=/dev/zero of=/EMPTY bs=1m || echo "dd(1) exits after taking over all the space"
+sync
rm -f /EMPTY;
# Block until the empty file has been removed, otherwise, Packer
# will try to kill the box while the disk is still full and that's bad

FreeBSD minimize: let dd(1) automatically exit on disk full

Don't need to periodically check the space left, dd(1) will
automatically exit after it cannot write to the disk anymore.
This mitigate the issue that fs may reserve some space so the
available space size will never get to 0.

Signed-off-by: Li-Wen Hsu <lwhsu@lwhsu.org>