Skip to content

Instantly share code, notes, and snippets.

@hollodotme
Last active July 22, 2017 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hollodotme/dfa35f2342e63ac953282fa2e9f5f9b1 to your computer and use it in GitHub Desktop.
Save hollodotme/dfa35f2342e63ac953282fa2e9f5f9b1 to your computer and use it in GitHub Desktop.

Re-package a vagrant box after modification

  • SSH into existing box and make changes

Update software

apt-get update && apt-get dist-upgrade -y && apt-get autoremove --purge -y
  • exit and vagrant reload

Update VirtualBox Guest additions

See here

  • exit and vagrant reload

Remove all MySQL databases

mysql -uroot -p  -e "SHOW DATABASES;" | grep -v Database | grep -v mysql| grep -v sys | grep -v performance_schema | grep -v information_schema | gawk '{print "drop database " $1 ";select sleep(0.1);"}' | mysql -uroot -proot

Reduce size of the box:

sudo apt-get autoclean
sudo rm -rf /var/log/vboxadd-install* /var/log/VBoxGuestAdditions*
# run as root, clears all log files
for logfile in `find /var/log -name '*.log' -type f`; do echo '' > $logfile; done
rm -rf /tmp/*
sudo dd if=/dev/zero of=/EMPTY bs=1M
sudo rm -f /EMPTY
cat /dev/null > ~/.bash_history && history -c && exit
  • Halt the box and re-package:
vagrant halt
vagrant package --output /path/to/mynew.box
  • Get checksum:
openssl sha1 /path/to/mynew.box
  • Add new version to the json catalog incl. checksum
  • Upload new version to server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment