Copy vagrant box locally

27

21

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

xiankai

Posted 2013-08-22T12:12:17.393

Reputation: 478

Answers

41

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 default

  • run 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 atlas
Vagrant package will create a .box file automatically.

For more information, type in vagrant --help

spuder

Posted 2013-08-22T12:12:17.393

Reputation: 8 755

Seems like a great way, but unfortunately I am using a different version of vagrant, while your commands seem to be for 1.0.x – xiankai – 2013-08-23T03:47:47.717

@xiankai I am running 1.2.2 and I have verified that these steps work for me. I made a few tweaks to my answer for clarity, give it another try and let me know what errors you get. – spuder – 2013-08-23T04:59:14.147

Ah, after looking at the link you posted, I tried vagrant package instead of vagrant box package and it seems like I'm on the right track now! – xiankai – 2013-08-23T08:36:20.997

vagrant package is correct. That was a typo on my part. – spuder – 2013-08-23T13:37:26.897