Creating a new Vagrant base box from an existing VM

Table of Contents

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
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/OUTPUT_BOX_NAME.box

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/precise64Node.box
Packaging VM as new base box
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
Using new base box

Related Posts

Decoupling Deployment and Release- Feature Toggles

Decoupling Deployment and Release- Feature Toggles

There are key differences between deployment and release. Deployment means putting the latest stable …

Jekyll, Amazon S3, Vagrant And Puppet

Jekyll, Amazon S3, Vagrant And Puppet

Recently I moved my blog from Scriptogram to static site generated by Jekyll and hosted on Amazon …

Visual Regression

Visual Regression

A new breed of tools have started appearing on our radar supporting the very idea of automated …