I have a vagrant box up and running (configured with a LAMP stack). I need to transfer it to another PC. How can I export it? I guess that I can get a file (or files) that can be copied to another PC, so there I can run some command to import the vagrant box.
You have two ways to do this, I'll call it dirty way and clean way:
1. The dirty way
Create a box from your current virtual environment, using vagrant package
command:
http://docs.vagrantup.com/v2/cli/package.html
Then copy the box to the other pc, add it using vagrant box add
and run it using vagrant up
as usual.
Keep in mind that files in your working directory (the one with the Vagrantfile
) are shared when the virtual machine boots, so you need to copy it to the other pc as well.
2. The clean way
Theoretically it should never be necessary to do export/import with Vagrant. If you have the foresight to use provisioning for configuring the virtual environment (chef, puppet, ansible), and a version control system like git for your working directory, copying an environment would be at this point simple as running:
git clone <your_repo>
vagrant up
package
command is the proper way to do it. –
Fiend My hard drive in my Mac was making beeping noises in the middle of a project so I decided to install a SSD. I needed to move my project from one disk to another. A few things to consider:
- I'm vagrant w/ virtualbox on a Mac
- I'm using git
This is what worked for me:
1.) Copy your ~/.vagrant.d directory to your new machine.
2.) Copy your ~/VirtualBox\ VMs directory to your new machine.
3.) In VirtualBox add the machines one by one using **Machine** >> **Add**
4.) Run `vagrant box list` to see if vagrant acknowledges your machines.
5.) `git clone my_project`
6.) `vagrant up`
I had a few problems with VB Guest additions.
I fixed them with this solution.
vagrant box list
: 0bin.net/paste/iCiaqNhU-i3bbfY2#-KDiXYcRFni1RNgNJhOBrIs/… –
Pals This is actually pretty simple
- Install virtual box and vagrant on the remote machine
Wrap up your vagrant machine
vagrant package --base [machine name as it shows in virtual box] --output /Users/myuser/Documents/Workspace/my.box
copy the box to your remote
init the box on your remote machine by running
vagrant init [machine name as it shows in virtual box] /Users/myuser/Documents/Workspace/my.box
Run
vagrant up
VBoxManage list vms
. After you can just copy and do what is told in @Phil 2nd and 4th steps. :) Yey. –
Pangermanism scotch/box (virtualbox, 3.0)
). My command - virtual machines with identifier, e.g.: "Win10 - SandBox" {bc251c06-501f-4c0f-bgfa-21f2815ba2cd}
–
Pangermanism The easiest way would be to package the Vagrant box and then copy (e.g. scp
or rsync
) it over to the other PC, add it and vagrant up
;-)
For detailed steps, check this out =>
Is there any way to clone a vagrant box that is already installed
None of the above answers worked for me. I have been 2 days working out the way to migrate a Vagrant + VirtualBox Machine from a computer to another... It's possible!
First, you need to understand that the virtual machine is separated from your sync / shared folder. So when you pack your machine you're packing it without your files, but with the databases.
What you need to do:
1- Open the CMD of your computer 1 host machine (Command line. Open it as Adminitrator with the right button -> "Run as administrator") and go to your vagrant installed files. On my case: C:/VVV You will see your Vagrantfile an also these folders:
/config/
/database/
/log/
/provision/
/www/
Vagrantfile
...
The /www/ folder is where I have my Sync Folder with my development domains. You may have your sync folder in other place, just be sure to understand what you are doing. Also /config and /database are sync folders.
2- run this command: vagrant package --vagrantfile Vagrantfile
(This command does a package of your virtual machine using you Vagrantfile configuration.)
Here's what you can read on the Vagrant documentation about the command:
A common misconception is that the --vagrantfile option will package a Vagrantfile that is used when vagrant init is used with this box. This is not the case. Instead, a Vagrantfile is loaded and read as part of the Vagrant load process when the box is used. For more information, read about the Vagrantfile load order.
https://www.vagrantup.com/docs/cli/package.html
When finnished, you will have a package.box file.
3- Copy all these files (/config, /database, Vagrantfile, package.box, etc.) and paste them on your Computer 2 just where you want to install your virtual machine (on my case D:/VVV).
Now you have a copy of everything you need on your computer 2 host.
4- run this: vagrant box add package.box --name VVV
(The --name is used to name your virtual machine. On my case it's named VVV) (You can use --force if you already have a virtual machine with this name and want to overwrite it. (Use carefully !))
This will unpack your new vagrant Virtual machine.
5- When finnished, run:
vagrant up
The machine will install and you should see it on the "Oracle virtual machine box manager". If you cannot see the virtual machine, try running the Oracle VM box as administrator (right click -> Run as administrator)
You now may have everything ok but remember to see if your hosts are as you expected:
c:/windows/system32/hosts
6- Maybe it's a good idea to copy your host file from your Computer 1 to your Computer 2. Or copy the lines you need. In my case these are the hosts I need:
192.168.50.4 test.dev
192.168.50.4 vvv.dev
...
Where the 192.168.50.4 is the IP of my Virtual machine and test.dev and vvv.dev are developing hosts.
I hope this can help you :) I'll be happy if you feedback your go.
Some particularities of my case that you may find:
When I ran vagrant up, there was a problem with mysql, it wasn't working. I had to run on the Virtual server (right click on the oracle virtual machine -> Show console): apt-get install mysql-server
After this, I ran again vagrant up and everything was working but without data on the databases. So I did a mysqldump all-tables from the Computer 1 and upload them to Computer 2.
OTHER NOTES:
My virtual machine is not exactly on Computer 1 and Computer 2. For example, I made some time ago internal configuration to use NFS (to speed up the server sync folders) and I needed to run again this command on the Computer 2 host: vagrant plugin install vagrant-winnfsd
I had to migrate my Vagrant boxes to a new machine and found this dirty but simple method to work well (it's for VirtualBox-based machines, I assume it can be adapted to other providers):
- copy over the VirtualBox box, e.g. by using the "Export/Import Appliance" functionality in the VirtualBox GUI
- copy over the Vagrant directory
- edit
.vagrant/machines/default/virtualbox/id
in the Vagrant directory to the new VirtualBox ID (which you get viaVBoxManage list vms
).
vagrant up
still created a new VM. However I was able to attach the old machine's disk to the new one using the VirtualBox GUI and this now works as desired. –
Instate As stated in
How can I change where Vagrant looks for its virtual hard drive?
the virtual-machine state is stored in a predefined VirtualBox folder. Copying the corresponding machine (folder) besides your vagrant-project to your other host should preserve your virtual machine state.
I also had to copy the private_key file from .vagrant/machines/default/virtualbox folder in order for vagrant ssh to work
As of 2019 there is a subcommand: vagrant box repackage
vagrant box repackage --help
Usage: vagrant box repackage <name> <provider> <version>
-h, --help Print this help
You can find name
provider
and version
by running vagrant box list
vagrant box list
macinbox (virtualbox, 10.14.5)
The ouput of vagrant box repackage
is a file called package.box
which is basically a tgz file which the content can be listed as below:
tar tzf package.box
./metadata.json
./box.ovf
./Vagrantfile
./box-disk001.vmdk
© 2022 - 2024 — McMap. All rights reserved.