Skip to content

Instantly share code, notes, and snippets.

@DiegoPino
Forked from srijanshetty/package-vagrant-box.md
Created March 15, 2017 14:40
Show Gist options
  • Save DiegoPino/fcf92e09231954c81eeea0cf5a3d6396 to your computer and use it in GitHub Desktop.
Save DiegoPino/fcf92e09231954c81eeea0cf5a3d6396 to your computer and use it in GitHub Desktop.
Clean up a vagrant box before packaging

We’re now going to clean up disk space on the VM so when we package it into a new Vagrant box, it’s as clean as possible. First, remove APT cache

$ sudo apt-get clean

Then, “zero out” the drive (this is for Ubuntu):

$ sudo dd if=/dev/zero of=/EMPTY bs=1M
$ sudo rm -f /EMPTY

Lastly, let’s clear the Bash History and exit the VM:

$ cat /dev/null > ~/.bash_history && history -c && exit

We’re now going to repackage the server we just created into a new Vagrant Base Box. It’s very easy with Vagrant:

$ vagrant package --output mynew.box
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment