Copy vagrant box locally

25,363

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

Share:
25,363

Related videos on Youtube

xiankai
Author by

xiankai

Updated on September 18, 2022

Comments

  • xiankai
    xiankai over 1 year

    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
    xiankai over 10 years
    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
  • spuder
    spuder over 10 years
    @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.
  • xiankai
    xiankai over 10 years
    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!
  • spuder
    spuder over 10 years
    vagrant package is correct. That was a typo on my part.