Veewee, for Creating VMs
If you want to play around with virtualization software like Vagrant, Virtualbox, or VMWare Fusion, you'll need to create a virtual machine image (henceforth referred to as a "VM"). The most common way to do this is to download an Ubuntu or CentOS ISO and install it through the virtualization GUI. However this is a time-consuming process, and if you discover that you made a mistake or you want to tweak the way you installed the operating system, you have to start the process over.
Veewee to the rescue! Veewee is a tool for automatically building VMs from ISOs, in a variety of formats. Veewee describes the exact process used to create the VM, so it's easy to share with other people (team members or contributors for example). Also, you can check the procedure into version control and easily reproduce the original VM later, so you don't need to keep different versions of a 700 megabyte VM sitting around on your hard drive.
Questions Before We Begin
Can't I just use a kickstart or preseed file to do this?
Yes. But wait, there's more! Veewee will use your kickstart / preseed file in addition to managing the VM (attaching the ISO and powering it on, for example), so you can kick back and let the autopilot do the rest.
What about tools like chef and puppet?
Chef and puppet are great for provisioning software packages and system configuration, but you need to have a base operating system installed first. Once Veewee has installed the base OS for you, you're free to have chef or puppet take over. In fact, using Veewee to create a Vagrant box is a prerequisite to that workflow.
In order to run Veewee, you'll need
bundler installed on your system. If you don't have ruby these, refer to Installing Ruby the Correct Way and you'll be on your way in no time. The Veewee docs ask for ruby 1.9.2 but I had great success with ruby 1.9.3-p392. YMMV.
$ git clone https://github.com/jedi4ever/veewee.git $ cd veewee $ bundle install
At this point you should be able to run
bundle exec veewee and see the following output:
Commands: veewee fusion # Subcommand for Vmware fusion veewee help [COMMAND] # Describe available commands or one specific command veewee kvm # Subcommand for KVM veewee parallels # Subcommand for Parallels veewee vbox # Subcommand for VirtualBox veewee version # Prints the Veewee version information
bundle exec veewee is a bit tedious, I'm going to create an alias for it via:
$ alias veewee="bundle exec veewee"
This enables us to simply type
veewee as long as we're in the veewee folder. You can make this alias persistant by adding it to
~/.bash_profile or its equivalent on your system (
~/.profile on Ubuntu or
~/.zshrc for z-shell).
Creating a VM
When you ran
veewee earlier you should have seen a list of commands. Most of these (aside from the obvious
version commands) actually correspond to the virtualization software you're using. You'll need to invoke one to see the other commands. For example:
$ veewee vbox Commands: veewee vbox build [BOX_NAME] # Build box veewee vbox define [BOX_NAME] [TEMPLATE] # Define a new basebox starting from a template ...
Building a VM involves two steps. First, we need to create the definition (called a "box") used to describe the installation procedure. Then we need to build it. We do this using the
Defining a VM
Veewee includes a selection of templates to create your first box. I selected an Ubuntu template, but you can choose from anything in the
$ veewee vbox define awesome-ubuntu-server ubuntu-12.04.2-server-amd64 ^ ^ | | Box name Which template to use to create the box definition
Somewhere in the console spew you should have noticed that your definition has been created under
definitions/. You can see it like so:
$ ls definitions awesome-ubuntu-server
Veewee also mentions that you can customize the definition, so let's take a moment to tweak it. Since I'm using VirtualBox for this one, with Chef, I'm going to make changes to
:postinstall_files => [ "base.sh", "vagrant.sh", "virtualbox.sh", #"vmfusion.sh", # I commented these three lines #"ruby.sh", #"puppet.sh", "chef.sh", "cleanup.sh", "zerodisk.sh" ],
Feel free to make whatever changes are most relevant for you before continuing on to the next section. The
vmfusion.sh line barfed on my first run-through, so comment that one out unless you're planning to use it.
Building the VM
Now that we have a definition for our box, the next step is to build it. Since this is our first box, veewee will download a handful of dependencies, including VirtualBox guest additions and the ISO for the operating system we selected.
Since I already had the Ubuntu server ISO downloaded, I moved it into
iso/ and saved some time, but if you don't have your chosen OS ISO, veewee will download it for you when you run:
$ veewee vbox build awesome-ubuntu-server -n
From here, Veewee runs through the installation process (downloading files as necessary). You can watch Veewee's progress in the terminal, or (and this is the whole point, really) you can put it in the background and go do other things while Veewee takes care of everything for you.
Note: If you want to watch Veewee work, you can omit the
-n flag from the
-n suppresses the GUI.
This is by far the easiest part of the entire process, but it takes some time. So go watch an episode of your favorite TV show or play a game or pretend to work for awhile, and come back later. On my computer this process took about 15 minutes.
If everything works, you'll eventually see:
The box awesome-ubuntu-server was built successfully!
If you go looking, you'll find the new VM conveniently located inside the
~/VirtualBox VMs/ folder on your computer.
Export the VM for Vagrant Use
Since I plan to use this box with Vagrant, the final step for me is to export it into the Vagrant box format.
$ veewee vbox export awesome-ubuntu-server
Veewee is nice enough to export the box into the location where Vagrant is going to look for it, and spews a message indicating this:
To import it into vagrant type: vagrant box add 'awesome-ubuntu-server' '/Users/cbednarski/code/veewee/awesome-ubuntu-server.box' To use it: vagrant init 'awesome-ubuntu-server' vagrant up vagrant ssh
That's it! If you want to get fancy, you can upload the image to a server and share it with your team, or show them how to run through the Veewee process themselves.