Skip to content

Instantly share code, notes, and snippets.

@tonejito
Forked from gecbla/vagrant
Last active March 7, 2016 19:21
Show Gist options
  • Save tonejito/75f767583cc65d056343 to your computer and use it in GitHub Desktop.
Save tonejito/75f767583cc65d056343 to your computer and use it in GitHub Desktop.
Clone vagrant box locally
#!/bin/bash -vx
# Vagrant Documentation
# @see http://docs.vagrantup.com/v2/cli/package.html
# @see http://stackoverflow.com/questions/19094024/is-there-any-way-to-clone-a-vagrant-box-that-is-already-installed
#
# @fork https://gist.github.com/suplo/9758118
# @fork https://gist.github.com/gecbla/9525c33af29e962555aa
VAGRANT=/usr/bin/vagrant
CLONE_NAME=clone-`date '+%s'`
VAGRANT_DIR=~/vagrant
VAGRANT_BOX_DIR=~/.vagrant.d/boxes
VAGRANT_BOX_FILE=$VAGRANT_BOX_DIR/$CLONE_NAME.box
# Export the current state into a BOX_FILE
$VAGRANT package --output $VAGRANT_BOX_FILE
# Add the BOX_FILE to the available boxes
$VAGRANT box add --name $CLONE_NAME --provider virtualbox $VAGRANT_BOX_FILE
# Chech if the box has been added
$VAGRANT box list
# Prepare clone directory for VagrantFile
cd $VAGRANT_DIR
mkdir $CLONE_NAME
cd $CLONE_NAME
# Initialize clone
$VAGRANT init $CLONE_NAME
# Get the clone up
$VAGRANT up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment