Copy vagrant box locally
I have a vagrant box running on VirtualBox, and I need to make a copy (with all its existing config and data), so that I can make changes on it without affecting the original.
The problem is that my original box came as a file package - the internet connection where I'm working with is extremely slow so someone else copied their vagrant and virtualbox folders to my machine. Thus there is no
config.vm.box_url
to use.
How can I accomplish this?
Edit: I am using Vagrant 1.2.2
Create a new box from your existing vm:
cd into the directory with your Vagrant file
run
vagrant package
This will export a box file called package.box by defaultrun
vagrant box add foo package.box
to add package.box to your existing boxes. (Assuming you are using VirtualBox and not VMWare)run
vagrant box list
to verify it was added.
Now you can just create a new folder, run vagrant init
as normal and set your box to the following:
config.vm.box = "foo"
The new VM will spin up with the exact data that was present in the previous VM.
Vagrant Documentation
Additionally checkout a new product from the creators of Vagrant called Packer. It will do this same thing, but allow you to copy your vm's to other providers (Amazon, VirtualBox ect..)
Update
Newer versions of Vagrant have two commands that make the above steps unnecessary.
vagrant share
vagrant package
Vagrant share
will upload your box to atlasVagrant package
will create a .box file automatically.
For more information, type in vagrant --help