I tested the following script on a vagrant box.
The box was 850MB without the script, and 450 MB with the script.
The script was taken from chef/bento with just one modification.
I tested the following script on a vagrant box.
The box was 850MB without the script, and 450 MB with the script.
The script was taken from chef/bento with just one modification.
#!/bin/bash -eux | |
# source is: https://github.com/chef/bento/blob/master/packer/scripts/ubuntu/cleanup.sh | |
# only modification is the "try catch" (air quotes) for dd - since that snipped was taken from another context | |
# delete all linux headers | |
dpkg --list | awk '{ print $2 }' | grep linux-headers | xargs apt-get -y purge | |
# this removes specific linux kernels, such as | |
# linux-image-3.11.0-15-generic but | |
# * keeps the current kernel | |
# * does not touch the virtual packages, e.g.'linux-image-generic', etc. | |
# | |
dpkg --list | awk '{ print $2 }' | grep 'linux-image-3.*-generic' | grep -v `uname -r` | xargs apt-get -y purge | |
# delete linux source | |
dpkg --list | awk '{ print $2 }' | grep linux-source | xargs apt-get -y purge | |
# delete development packages | |
dpkg --list | awk '{ print $2 }' | grep -- '-dev$' | xargs apt-get -y purge | |
# delete compilers and other development tools | |
apt-get -y purge cpp gcc g++ | |
# delete X11 libraries | |
apt-get -y purge libx11-data xauth libxmuu1 libxcb1 libx11-6 libxext6 | |
# delete obsolete networking | |
apt-get -y purge ppp pppconfig pppoeconf | |
# delete oddities | |
apt-get -y purge popularity-contest | |
apt-get -y autoremove | |
apt-get -y clean | |
rm -rf VBoxGuestAdditions_*.iso VBoxGuestAdditions_*.iso.? | |
rm -f /tmp/chef*deb | |
# with the e flag set, we have to "catch" the error dd is gonna trigger when it fills up the disk | |
{ | |
dd if=/dev/zero of=/EMPTY bs=1M | |
} || { | |
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 | |
sync |