From 1b695a5c30fd7fb8be45ce1eb9a98b7ca7492951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20L=2E=20Pati=C3=B1o?= Date: Wed, 28 Dec 2016 19:55:34 +0000 Subject: [PATCH] Customized `cleanup.sh` scripts for different Ubuntu versions. --- scripts/{cleanup.sh => cleanup-14.04.sh} | 0 scripts/cleanup-16.04.sh | 56 ++++++++++++++++++++++++ ubuntu-14.04-amd64.json | 2 +- ubuntu-16.04-amd64.json | 2 +- 4 files changed, 58 insertions(+), 2 deletions(-) rename scripts/{cleanup.sh => cleanup-14.04.sh} (100%) create mode 100755 scripts/cleanup-16.04.sh diff --git a/scripts/cleanup.sh b/scripts/cleanup-14.04.sh similarity index 100% rename from scripts/cleanup.sh rename to scripts/cleanup-14.04.sh diff --git a/scripts/cleanup-16.04.sh b/scripts/cleanup-16.04.sh new file mode 100755 index 0000000..69049a4 --- /dev/null +++ b/scripts/cleanup-16.04.sh @@ -0,0 +1,56 @@ +# Reducing the final size of the image to help Packer build a less big box. +# Credits to Vinicius Massuchetto and his helpful post in GitHub: +# http://vmassuchetto.github.io/2013/08/14/reducing-a-vagrant-box-size/ + +# Clean up APT packages +apt-get -y --purge remove linux-headers-$(uname -r) build-essential +apt-get -y autoremove +apt-get -y clean + +# Removing leftover leases and persistent rules +echo "Cleaning up dhcp leases" +rm /var/lib/dhcp/* + +# Make sure Udev doesn't block our network +echo "Cleaning up udev rules" +rm -rfv /dev/.udev/ +rm -v /lib/udev/rules.d/75-persistent-net-generator.rules + +# Remove Linux headers +rm -rfv /usr/src/linux-headers* + +# Remove Virtualbox specific files +rm -rfv /usr/src/vboxguest* /usr/src/virtualbox-ose-guest* + +# Clean any Python bytecode +find / -type f -name "*.pyc" -delete + +# Whiteout root +echo "Whiteouting /" +count=`df --sync -kP / | tail -n1 | awk -F ' ' '{print $4}'`; +count=$((count -= 1)) +dd if=/dev/zero of=/tmp/whitespace bs=1024 count=$count; +rm /tmp/whitespace; + +# Whiteout /boot +echo "Whiteouting /boot" +count=`df --sync -kP /boot | tail -n1 | awk -F ' ' '{print $4}'`; +count=$((count -= 1)) +dd if=/dev/zero of=/boot/whitespace bs=1024 count=$count; +rm /boot/whitespace; + +# Whiteout swap +echo "Whiteouting swap" +swappart=`cat /proc/swaps | tail -n1 | awk -F ' ' '{print $1}'` +swapoff $swappart; +dd if=/dev/zero of=$swappart; +mkswap $swappart; +swapon $swappart; + +# Zero out the rest of the free space using dd. +echo "Zero out the free space to aid VM compression" +dd if=/dev/zero of=/EMPTY bs=1M +rm -f /EMPTY + +echo "Adding a 2 sec delay to the interface up, to make the dhclient happy" +echo "pre-up sleep 2" >> /etc/network/interfaces diff --git a/ubuntu-14.04-amd64.json b/ubuntu-14.04-amd64.json index 3374163..df56db4 100644 --- a/ubuntu-14.04-amd64.json +++ b/ubuntu-14.04-amd64.json @@ -77,7 +77,7 @@ "scripts/python.sh", "scripts/virtualbox.sh", "scripts/docker-14.04.sh", - "scripts/cleanup.sh" + "scripts/cleanup-14.04.sh" ] } }, diff --git a/ubuntu-16.04-amd64.json b/ubuntu-16.04-amd64.json index 3ddb6b8..e40a3cc 100644 --- a/ubuntu-16.04-amd64.json +++ b/ubuntu-16.04-amd64.json @@ -73,7 +73,7 @@ "scripts/python.sh", "scripts/virtualbox.sh", "scripts/docker-16.04.sh", - "scripts/cleanup.sh" + "scripts/cleanup-16.04.sh" ] } },