minimize.sh 975 B

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