Skip to content

Instantly share code, notes, and snippets.

@srijanshetty
Last active June 20, 2023 08:49
Show Gist options
  • Save srijanshetty/86aa6540d27736c1c11b to your computer and use it in GitHub Desktop.
Save srijanshetty/86aa6540d27736c1c11b 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