ubuntu-vm-builder

Originally developed to create the JeOS variant of Ubuntu Server Edition, ubuntu-vm-builder can be used to create customized virtual machines.

ubuntu-vm-builder provides a method to quickly create a clean testing environment, a way to automate the virtual machine installation process, and for software developers, the ability to integrate the creation of a virtual machine into the build process of an application. If using a local mirror the virtual machine creation process can take less than two minutes from start to finish.

To create a custom virtual machine, enter the following:

sudo ubuntu-vm-builder kvm hardy --addpkg vim

The above command will create a KVM image adding the vim package to the virtual machine. The default virtual machine image is KVM, but vmw6, vmserver, vbox, and qemu image options are also available.

By adding additional --addpkg options any number of applications can be included in the image. For example:

sudo ubuntu-vm-builder kvm hardy --addpkg vim --addpkg screen --mem 256

Also notice that the --mem 256 option increases the virtual machines memory from the default 128M.

At the end of the image creation you will be prompted to confirm the additional package installation. After the image creation process has finished a directory named ubuntu-vm-hardy-i386 or ubuntu-vm-hardy-amd64 is created, and inside is the virtual machine image file named root.qcow2 and a shell script, used to start the virtual machine, named according to the image type.

Refer to the ubuntu-vm-builder man page for more customization options.

Using ubuntu-vm-builder with libvirt

Combining ubuntu-vm-builder with libvirt provides a great environment for virtual machine creation and management.

Use the --libvirt <uri> option to automatically add the newly created virtual machine to a libvirt domain. For example:

sudo ubuntu-vm-builder kvm hardy --addpkg vim --mem 256 --libvirt qemu:///system

Once the process has finished use virsh to start the virtual machine:

virsh -c qemu:///system start ubuntu

The default virtual machine name is ubuntu use the --hostname option to change it. See the section called “virsh” for more details.