Creating a new Vagrant base box from an existing VM

Typically my Vagrant workflow starts with a official base box provided by Ubuntu. With help of a Vagrant providervagrant up will create a virtual machine (VM) using specified base box.

Then using either Puppet provisioner or apt-get I normally install/update required packages and libraries in my VM.

Once install/update is finished, sometime I prefer to repackage updated virtual machine as a new base box to avoid repeating the install and update process. Also repackaging allows me to work offline as no provisioning is required.

First step is to get id or specific name of VM from your Vagrant provider. If you are using VirtualBox as provider you can see a list of virtual machine with their specific machine. For example following image illustrate two VM running under VirtualBox Node_default_1387087098 and Blogs_default_1386384681

Get VM List from VirtualBox

Once you have specific name for VM which you want to repackage, you can run

vagrant package --base SPECIFIC_NAME_FOR_VM --output /yourfolder/

So for instance, if I am interested to repackage VM Node_default_1387087098 then I will run,

vagrant package --base Node_default_1387087098 --output /myfolder/

Packaging VM as new base box

Please note I named output box as precise64Node as original base box is precise64 and I repackaged for Node specific uses. It is just a personal convention.

Now you can use this new base box like any other Vagrant box.

Using new base box