43

I installed a VirtualBox and then installed a Ubuntu 12.10 Server Base OS in it. I have installed all kinds of php packages and other packages in it. My friends recommended me to use Vagrant so I can share my setup with my team mates easily.

Because my current VirtualBox VM was not created using vagrant up, I am not sure how to package it. The documentation over at Vagrant talks about packaging but starts by saying:

Before working through the rest of this page, make sure the virtual environment is built by running vagrant up.

In my case, my existing VM was NOT created initially using vagrant up.

How do I package my existing VM?

Steffen Opel
  • 63,899
  • 11
  • 192
  • 211
Kim Stacks
  • 10,202
  • 35
  • 151
  • 282

9 Answers9

26

The important thing to realize (and the vagrant docs are not overly clear on that) is that there are two "flavors" of packaging:

  1. The packaging guide in "getting started" you are referring to assumes you have started from a vagrant base box and initialized it with vagrant up, which you have not. This allows you to package any customizations you have made to a vagrant base box.
  2. If you start from scratch or from a "plain" VirtualBox VM, as you do, you need to create a vagrant base box. You should be fine following the guide, which is based on Ubuntu.

There's a detailed guide for creating vagrant boxes from scratch using Oracle Enterprise Linux, which might be helpful. You could also try VeeWee.

Alternatively, you could start with a Ubuntu 12.10 base box and port your customizations, in which case you could use the simpler first way of packaging.

Update

The above refers to Vagrant 1.0. Things have changed slightly in 1.1 and in particular the docs have been rewritten:

  1. The vagrant package command allows you to package any customizations you have made to an existing vagrant base box in the same way as in 1.0.
  2. The documentation for creating base boxes with VirtualBox has been removed in 1.1, but the docs suggest the process has stayed the same, but now an additional metadata.json file is required as Vagrant 1.1 supports multiple providers.
kynan
  • 13,235
  • 6
  • 79
  • 81
  • 1.1 is out, and the docs have been re-written. Any chance for an update? – odigity Nov 27 '13 at 19:53
  • Nice. BTW-I just finished reading the "Vagrant: Up and Running" book by the creator of Vagrant, and it goes into more detail in the docs -- especially on box creation, which gets a whole chapter. It is up-to-date with v1.1.x (even though they're now up to 1.3.x, I don't think the book has anything broken or outdated). – odigity Nov 30 '13 at 22:13
  • Noticed a change since the book was published: the args to config.vm.network in the book were 'hostonly' and 'bridged'; they've since been renamed to 'public_network" and 'private_network'. – odigity Nov 30 '13 at 23:35
  • @odigity Feel free to edit the answer and add more information from the book if you think that's helpful. – kynan Dec 01 '13 at 00:33
  • I just begin to study vagrant, this was very usefull for me. If someone has any idea where can i find the free book **vagrant up and running** by Mitchell, i will very grateful – Robert Jan 20 '14 at 17:34
  • @Rob3 You can buy it [from O'Reilly](http://shop.oreilly.com/product/0636920026358.do). – kynan Jan 21 '14 at 12:48
10

vagrant package --output box_name.box --base "vm machine name" --vagrantfile Vagrantfile

Make sure that port forwarding and SSH keys are setup properly.

This may be a good example: https://github.com/okfn/ckan/wiki/How-to-Create-a-CentOS-Vagrant-Base-Box

aminalid
  • 1,156
  • 10
  • 7
8

Any VirtualBox can be packaged to Vagrant Base Boxes (basically OVA with a Vagrantfile).

Problems are: the VM is not build as per the vagrant base boxes, if you are not sharing it on vagrantbox.es then it'll be fine.

Just install vagrant (via gem or the installer), run the following command in the VM folder to package it to .box

NOTE: For Vagrant 1.2.x, the recommended install method is using the OS specific package. Ruby Gem is NOT available for 1.2.x.

vagrant package --base ubuntu --output /path/to/ubuntu.box

Remember, if you want to share the vagrant base box with others, better to read the docs and follow those rules to make it easier for others.

Terry Wang
  • 13,840
  • 3
  • 50
  • 43
5

While not a complete answer, I think you can get what you need from the documentation, which is quite extensive. I believe that vagrant up is merely a convenient means to setting up a Vagrant "box". There are a number of requirements for a box to be Vagrant compliant. They are described here...

Documentation: Vagrant - Base Boxes

The bare bones needed for a box are as follows...

  • VirtualBox Guest Additions for shared folders, port forwarding, etc.
  • SSH with key-based auth support for the vagrant user
  • Ruby & RubyGems to install Chef and Puppet
  • Chef and Puppet for provisioning support

Once a box is compliant with these requirements, it should simply be a matter of using the vagrant package command to create a portable installation...

More documentation: Vagrant - Boxes

So, while I don't have a complete answer, having never done it this way, I think it's possible to get your installation into a state that will allow you to package and distribute it.

Ian Atkin
  • 6,302
  • 2
  • 17
  • 24
  • Thank you for your answer. Let me try to understand what you are saying. You are suggesting that I re-create the same setup I currently have but using vagrant, so that I can get the package done. Yes? – Kim Stacks Jan 24 '13 at 15:02
  • No, I think it's possible to inject the dependencies after the fact. There was a time before `vagrant up` when boxes were created manually, one step at a time. It may still be possible to get your instance in a state that will make it compliant and package-able. – Ian Atkin Jan 24 '13 at 15:04
  • I apologize, but I think I am going to need more hand-holding in this case. I still do not quite wrap my mind round the documentation itself. Could you give me a more complete answer? Thank you. – Kim Stacks Jan 24 '13 at 15:08
3

Use the 'VBoxManage list vms' command!I used it with sudo only to see there were no VMS listed.So use the command with the right authenticated user.The answers above also helped with making the box.

1

Personally, the illusive aspect of the packaging process was the --base switch. I suspect that might be the case with a lot of people. Check out vagrant package --help for the description. The documentation does not seem to make mention of it either.

I found these two great, in-depth, step-by-step guides to create Vagrant boxes from machines that were originally VirtualBox machines:

  1. How to Create a CentOS Vagrant Base Box
  2. Creating base box from scratch for Vagrant
Batandwa
  • 530
  • 4
  • 7
  • 18
1

As mentioned here - http://sysadm.pp.ua/linux/sistemy-virtualizacii/vagrant-box-creation.html You need three things for box to be imported and packaged:

  • Install Guest additions
  • Passwordless sudo
  • SSH access So you just need to login to your Ubuntu 12.10, install Vbox Guest additions, add user "vagrant" with passwordless sudo access.
david
  • 641
  • 6
  • 2
0

Look at the updated documentation to find all the caracteristics your box should have if you want it to work seamlessly with vagrant :

http://docs.vagrantup.com/v2/virtualbox/boxes.html

You should also take a look at a great project called veewee, wich permits you to script the generation of vagrant box from scractch. It means veewee will actually download the ISO from your distribution and install it on a virgin virtualbox machine and then configure and install all dependencies.

It comes with a lot of recipes for all different kind of linux distribution :

https://github.com/jedi4ever/veewee

Here comes even more boxes. They say they are puppet boxes but they work with all providers (chef, puppet and shell script) :

https://github.com/puppetlabs/puppet-vagrant-boxes

fe_lix_
  • 938
  • 11
  • 18
0

The packaging guide in "Getting Started" you are referring to assumes you have started from a vagrant base box and initialized it with vagrant up, which you have not. This allows you to package any customizations you have made to a vagrant base box.

If you start from scratch or from a "plain" VirtualBox VM, as you do, you need to create a vagrant base box. You should be fine following the guide, which is based on Ubuntu.

Simon Martin
  • 4,203
  • 7
  • 56
  • 93
kumae
  • 1