-
-
Save a-r-m-i-n/b8c7c977c2b1545a10f1bada817f0d34 to your computer and use it in GitHub Desktop.
Script to reduce VM size before packaging for vagrant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Credits to: | |
# - http://vstone.eu/reducing-vagrant-box-size/ | |
# - https://github.com/mitchellh/vagrant/issues/343 | |
# rm -rf /var/www/html/* | |
# BE CAREFUL with synched folders!!! | |
rm -rf ~/.composer/vendor/* | |
composer clearcache | |
apt-get purge -y ri | |
apt-get purge -y installation-report landscape-common wireless-tools wpasupplicant ubuntu-serverguide | |
apt-get purge -y python-dbus libnl1 python-smartpm python-twisted-core libiw30 | |
apt-get purge -y python-twisted-bin libdbus-glib-1-2 python-pexpect python-pycurl python-serial python-gobject python-pam python-openssl libffi5 | |
apt-get purge -y linux-image-3.0.0-12-generic-pae | |
# Remove APT cache | |
apt-get clean -y | |
apt-get autoclean -y | |
# Zero free space to aid VM compression | |
dd if=/dev/zero of=/EMPTY bs=1M | |
rm -f /EMPTY | |
# Remove bash history | |
unset HISTFILE | |
rm -f /root/.bash_history | |
rm -f /home/vagrant/.bash_history | |
rm -Rf /home/vagrant/.nano | |
# Cleanup log files | |
find /var/log -type f | while read f; do echo -ne '' > $f; done; | |
# Whiteout root | |
count=`df --sync -kP / | tail -n1 | awk -F ' ' '{print $4}'`; | |
let count-- | |
dd if=/dev/zero of=/tmp/whitespace bs=1024 count=$count; | |
rm /tmp/whitespace; | |
# Whiteout /boot | |
count=`df --sync -kP /boot | tail -n1 | awk -F ' ' '{print $4}'`; | |
let count-- | |
dd if=/dev/zero of=/boot/whitespace bs=1024 count=$count; | |
rm /boot/whitespace; | |
swappart=`cat /proc/swaps | tail -n1 | awk -F ' ' '{print $1}'` | |
swapoff $swappart; | |
dd if=/dev/zero of=$swappart; | |
mkswap $swappart; | |
swapon $swappart; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment