github.com/hashicorp/packer@v1.14.3/examples/_common/minimize.sh (about) 1 #!/bin/sh -eux 2 3 case "$PACKER_BUILDER_TYPE" in 4 qemu) exit 0 ;; 5 esac 6 7 # Whiteout root 8 count=$(df --sync -kP / | tail -n1 | awk -F ' ' '{print $4}') 9 count=$(($count-1)) 10 dd if=/dev/zero of=/tmp/whitespace bs=1M count=$count || echo "dd exit code $? is suppressed"; 11 rm /tmp/whitespace 12 13 # Whiteout /boot 14 count=$(df --sync -kP /boot | tail -n1 | awk -F ' ' '{print $4}') 15 count=$(($count-1)) 16 dd if=/dev/zero of=/boot/whitespace bs=1M count=$count || echo "dd exit code $? is suppressed"; 17 rm /boot/whitespace 18 19 set +e 20 swapuuid="`/sbin/blkid -o value -l -s UUID -t TYPE=swap`"; 21 case "$?" in 22 2|0) ;; 23 *) exit 1 ;; 24 esac 25 set -e 26 27 if [ "x${swapuuid}" != "x" ]; then 28 # Whiteout the swap partition to reduce box size 29 # Swap is disabled till reboot 30 swappart="`readlink -f /dev/disk/by-uuid/$swapuuid`"; 31 /sbin/swapoff "$swappart"; 32 dd if=/dev/zero of="$swappart" bs=1M || echo "dd exit code $? is suppressed"; 33 /sbin/mkswap -U "$swapuuid" "$swappart"; 34 fi 35 36 sync;