49

I must have the same VM in other computers but I don't want to download the whole box, php mysql, etc...

I have a box already configured the way it should be and I want to run this VM in others computers.

When the user run "vagrant up" the machine should start without downloading nothing.

Does anybody have a solution for that?

Mateusgf
  • 889
  • 1
  • 8
  • 14
  • I wrote some scripts for automating the transfer of vagrant boxes. See [soniah/transfer_vagrant_boxes](https://github.com/soniah/transfer_vagrant_boxes) – Sonia Hamilton Nov 10 '15 at 08:38

2 Answers2

95

The easiest thing to do would be to package the pre-configured vagrant box and transfer the .box file to the other machine, add the box and run vagrant up.

So the steps look like below:

  1. Package the pre-configured box => vagrant package --base preconfigured_vm --output /path/to/mybox.box. Note that as per the docs, the --base option should be the UUID of the machine, or the name VirtualBox gives the machine (found when opening the VirtualBox application).
  2. transfer the box to the computer by using scp, rsync or whatever... (you also start a web server quickly by using python -m http.server PORT or ruby -run -e httpd /path/to -p PORT)
  3. Init and start vagrant init preconfigured_vm /path/to/mybox.box
  4. Done
Terry Wang
  • 13,840
  • 3
  • 50
  • 43
  • 6
    To pass in the UUID of the preconfigured_vm to the --base parameter in Vagrant 1.1+, I followed the [tip](http://stackoverflow.com/questions/9434313/how-do-i-associate-a-vagrant-project-directory-with-an-existing-virtualbox-vm#comment23660947_9437813): "For Vagrant 1.1, the UUIDs are stored in a machine-specific file at .vagrant/machines/{name}/{provider}/id. In fact, the only thing that file contains is the UUID." – Raymond Yee Nov 10 '13 at 16:35
  • 5
    If you're using VirtualBox, you can also get the UUID/name from the command `VBoxManage list vms`. – Chris Schmitz Feb 02 '15 at 20:44
  • 2
    Also, to add the box you can run the command `vagrant box add --name="boxname" mybox.box` where the `name` is the value from your Vagrant file's `config.vm.box` property and `mybox.box` is the box created from step 1 in Terry's answer. – Chris Schmitz Feb 02 '15 at 20:56
  • Also, send the other user your Vagrantfile too, as this stores important details for vagrant to use when spinning up a new box. – Felipe Alvarez Jul 27 '15 at 00:03
  • Good instructions, but results in a large file. Try using `dd` to wipe any blank space, as suggested here: https://scotch.io/tutorials/how-to-create-a-vagrant-base-box-from-an-existing-one The difference for me was 3.1GB vs 2.2GB. – Paul Suart Nov 02 '15 at 02:00
6

You just have to download the VM box only one time and make the all changes and configurations that you need and then re-package this one on a new box called "myVM.box".

Then you comment in the Vagrantfile the following line

#config.vm.box_url = "https://site_of_boxes..."

and used

config.vm.box = "myVM"

It starts up without download any VM.

Robert
  • 10,403
  • 14
  • 67
  • 117