Skip to content

Commit

Permalink
Customized cleanup.sh scripts for different Ubuntu versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jose-lpa committed Dec 28, 2016
1 parent 5fccdc9 commit 1b695a5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
File renamed without changes.
56 changes: 56 additions & 0 deletions scripts/cleanup-16.04.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion ubuntu-14.04-amd64.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"scripts/python.sh",
"scripts/virtualbox.sh",
"scripts/docker-14.04.sh",
"scripts/cleanup.sh"
"scripts/cleanup-14.04.sh"
]
}
},
Expand Down
2 changes: 1 addition & 1 deletion ubuntu-16.04-amd64.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"scripts/python.sh",
"scripts/virtualbox.sh",
"scripts/docker-16.04.sh",
"scripts/cleanup.sh"
"scripts/cleanup-16.04.sh"
]
}
},
Expand Down

0 comments on commit 1b695a5

Please sign in to comment.