Virtualization Company Logos Sun.com Intel.com AMD.com HP.com RedHat.com Apple.com SWSoft.com VMware.com Parallels.com Microsoft.com cj tracking image cj tracking image
Howto: Use Ubuntu-VM-Builder to quickly and easily build VMs
May 10th, 2008 under Xen, DIY Plans, Ubuntu, Open Source, x86 Virtualization, Desktop Computing, Virtualization, Intel, VMWare

This is the first in a series of posts outlining the feature, methods and ideas surrounding the tool: Ubuntu-VM-Builder.

Ubuntu-VM-Builder

Caution, security warning:
These are default settings for a new virtual machine, you will want to change them immediately or better idea would be to set them during build, for more information keep reading after the break.
Default fullname: Ubuntu
Default username: ubuntu
Default password: ubuntu

Here is some quick information on what Ubuntu-VM-builder is:

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. (source)

Step 1. To install Ubuntu-VM-Builder on your linux workstation, requires 8.04 or greater

sudo apt-get install ubuntu-vm-builder

ubuntu-vm-builder Depends on:
Depends: debootstrap
Depends: kpartx
Depends: parted
Depends: qemu

These will automatically be installed by apt-get during the installation, no other installation is required.

Step 2. To build a virtual machine, first move into the directory where you will want the vm folder to be created
mkdir ~/virtual-machines
cd ~/virtual-machines

Step 3. Run Ubuntu-vm-builder, with the required flags and options
sudo ubuntu-vm-builder kvm hardy

For more flags, options and some examples keep reading.

Examples:

Using a local apt-proxy mirror, for more information about apt-proxy read this post: Howto: Build your 1st Ubuntu JeOS Hardy VM, Apt-proxy
sudo ubuntu-vm-builder kvm hardy --mirror http://127.0.0.1:9999/ubuntu

Sets the hostname during VM creation.
sudo ubuntu-vm-builder kvm hardy --hostname hardy-server-vm

Installs ssh server and mysql server, imagine a database server virtual machine in under a minute!!
sudo ubuntu-vm-builder kvm hardy --addpkg openssh-server --addpkg mysql-server

To improve security it is highly recommended that you at least use a non default password for building virtual machines:
sudo ubuntu-vm-builder kvm hardy --name "Bradford M. Knowlton" --user bradmkjr --password d2vvfr94

The power of this tool is that you can also build 64bit images on a 32bit workstation, to be deployed on an 64bit capable Virtualization server, such as Amazon Elastic Computing Cloud or VMware ESX.
sudo ubuntu-vm-builder kvm hardy --arch amd64

Update: Vbox not yet working…
Bug #217771 in ubuntu-vm-builder (Ubuntu): “virtualbox image creation fails with errors”

Nick Barcet wrote on 5/08/2008: Looking at the code it looks like vbox has not been implemented yet for u-v-b. Feel free to do it if you have time to do so :)

This is the help information presented when ubuntu-vm-builder is run with either no flags or the incorrect flags:

usage: ubuntu-vm-builder <vm> <suite>
[–addpkg PKG]
[(-a|–arch) [i386,amd64]]
[(-d|–dest) <destination (directory)>]
[–domain DOMAIN]
[-h|–help]
[–hostname NAME]
[–mem num]
[–mirror URL]
[–removepkg PKG]
[(-t|–tmp) temp_dir]
[–user username]
[–name fullname]
[–pass password]
[–part partitionfile]
[–rootsize size]
[–optsize size]
[–swapsize size]
[–kernel-flavour <flavour>]
[–components <comma separated list of components>]
[–ssh-key <public key file>]
[–exec <script to execute>]
[–ip address [
[–mask value]
[–net value]
[–bcast value]
[–gw address]
[–dns address] ]

vm Generate image for the specified virtualisation software.
Valid choices are: vmw6 vmserver vbox qemu kvm
suite Use the specified Ubuntu suite.
Valid options: hardy, gutsy, feisty, edgy, dapper
–addpkg PKG Install PKG into the guest (can be specfied multiple times)
-a, –arch ARCH Specify the target architecture.
Valid options: i386 amd64 (defaults to host architecture)
-d, –dest Specify the destination directory.
Default: ubuntu-vm–
–domain DOMAIN Set DOMAIN as the domain name of the guest. Default:
The domain of the machine running this script.
-h, –help This help text.
-v, –verbose Show a lot of information as the vm is generated.
–hostname NAME Set NAME as the hostname of the guest. Default: ubuntu
Also uses this name as the VM name
–mem NN Assign NN megabytes of memory to the guest vm.
Default: 128
–mirror URL Use Ubuntu mirror at URL instead of the default, which
is: http://archive.ubuntu.com/ubuntu
–removepkg PKG Remove PKG from the guest (can be specfied multiple times)
-t, –tmp TMPDIR Use TMPDIR as temporary working area for the image
generation. Defaults to $TMPDIR if set, or /tmp if not.
–user username Set the name of the user to be added. Default: ubuntu.
–name fullname Set the full name of the user to be added. Default: Ubuntu.
–pass password Set the password for the user. Default: ubuntu.
–part partfile Allows to specify a partition table in partfile
each line of partfile should specify (root first):
mountpoint size
where size is in megabytes. You can have up to 4 virtual
disks, a new disk starts on a line with —
ie :
root 1000
/opt 1000
swap 256

/var 2000
/log 1500

The following three options are not used if –part is specified:
–rootsize size The size in MB of the root filesystem (default 4096)
–optsize size The size in MB of the /opt filesystem. If not set, no /opt
filesystem will be added.
–swapsize size The size in MB of the swap partition (default 1024)
–kernel-flavour The kernel image flavour to install (default: virtual for
>=gutsy on i386, server otherwise)
–components A comma seperaed list of distro components to include
(e.g. main,universe). This defaults to “main”
–ssh-key Add the given ssh public key file (absolute path)
to root’s authorized keys and install openssh-server
(WARNING: this has strong security implications)
–exec Run the given script file. You can use
‘chroot root <cmd>’ to execute code in the guest.
–ip address Ip address in dotted form
(defaults to dhcp if not specified)

Options below are discarded if –ip is not specified
–mask value IP mask in dotted form (default: 255.255.255.0)
–net value IP net address (default: X.X.X.0)
–bcast value IP broadcast (default: X.X.X.255)
–gw address Gateway address (default: X.X.X.1)
–dns address Name server address (default: X.X.X.1)

(’*’ denotes default option)

Options specific for vm type kvm:
–libvirt <uri> Add resulting VM to the libvirt hypervisor at <uri>.
–templates <dir> Look for libvirt VM XML templates in <dir> instead
of /usr/share/ubuntu-vm-builder/templates

Options specific for vm type qemu:
–libvirt <uri> Add resulting VM to the libvirt hypervisor at <uri>.
–templates <dir> Look for libvirt VM XML templates in <dir> instead
of /usr/share/ubuntu-vm-builder/templates

Options specific for vm type qemu-common:
–libvirt <uri> Add resulting VM to the libvirt hypervisor at <uri>.
–templates <dir> Look for libvirt VM XML templates in <dir> instead
of /usr/share/ubuntu-vm-builder/templates

Options specific for vm type vbox:
NONE

Options specific for vm type vmserver:
–templates <dir> Look for vmware vmx templates in <dir> instead
of /usr/share/ubuntu-vm-builder/templates

Options specific for vm type vmw6:
–templates <dir> Look for vmware vmx templates in <dir> instead
of /usr/share/ubuntu-vm-builder/templates

Options specific for vm type vmware-common:
–templates <dir> Look for vmware vmx templates in <dir> instead
of /usr/share/ubuntu-vm-builder/templates

ubuntu-vm-builder is Copyright (C) 2007-2008 Canonical Ltd. and
written by Soren Hansen <soren@canonical.com>.

References:
Ubuntu-VM-Builder



Leave a Reply