Blog tvlooy

Shrinking your Debian Vagrant box

Vagrant, Debian | March 04, 2013

My Vagrant box is just 228M, which I think is very nice. It has:

How did I get my box this small? I have to thank Dominique Broeglin (dominique.broeglin.fr) and Marius Ducea (ducea.com) for their Debian tips.

After installing the Guest Additions, you have gcc and kernel headers etc. Remove them all:

aptitude purge cpp-4.3 gcc-4.3-base aptitude purge cpp-4.4 gcc-4.4-base g++-4.4

Also remove python stuff:

aptitude purge python2.6 python2.6-minimal

Use the orphaner and debfoster and zap everything:

orphaner --purge debfoster apt-get clean

Remove things you won't need:

rm -rf /home/vagrant/.bash_history rm -rf /root/.bash_history rm -rf /usr/src/vboxguest* rm -rf /usr/share/doc find /var/cache -type f -exec rm -rf {} \; find /var/log -type f | while read f; do echo -ne '' > $f; done;

Also let the system clean up all leftovers of removed packages:

dpkg --list | grep '^rc\b' | awk '{ print $2 }' | xargs sudo dpkg -P

Then, tighten things up:

aptitude install zerofree init 1

You have to set the root password first, and boot with GUI mode on, because you will have to login in single user mode.

mount -o remount,ro /dev/sda1 zerofree /dev/sda1 halt

Then I just package the box:

vagrant package

And it's done.