Skip to content

Instantly share code, notes, and snippets.

@infamousjoeg
Forked from srijanshetty/package-vagrant-box.md
Last active January 28, 2022 17:31
Show Gist options
  • Save infamousjoeg/067c405d7753900bbc32fba2345b2d47 to your computer and use it in GitHub Desktop.
Save infamousjoeg/067c405d7753900bbc32fba2345b2d47 to your computer and use it in GitHub Desktop.
Clean up a vagrant box before packaging
#!/bin/bash
# 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