Creating Virtual Machines For Xen, KVM, VMware Workstation 6, and VMware Server With vmbuilder On Ubuntu 8.10

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Sun, 2008-12-14 18:53. :: KVM | Ubuntu | VMware | Xen | Virtualization

Creating Virtual Machines For Xen, KVM, VMware Workstation 6, and VMware Server With vmbuilder On Ubuntu 8.10

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 12/11/2008

vmbuilder is a tool (introduced on Ubuntu 8.10) that allows you to build virtual machines (with Ubuntu as the OS) for multiple virtualization techniques. Currently it supports Xen, KVM, VMware Workstation 6, and VMware Server. You can afterwards copy the virtual machines to another system (a Xen, KVM, VMware Workstation 6, or VMware Server host) and run them there.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

I'm using a machine with the hostname server1.example.com and the IP address 192.168.0.100 here as my host system.

Because we will run all the steps from this tutorial with root privileges, we can either prepend all commands in this tutorial with the string sudo, or we become root right now by typing

sudo su

 

2 Installing vmbuilder

vmbuilder can be installed as follows:

apt-get install python-vm-builder

 

3 Installing apt-proxy

Whenever vmbuilder builds a new VM, it has to download all packages from an Ubuntu mirror which can take quite some time. To speed this up, we install apt-proxy...

apt-get install apt-proxy

... to cache the downloaded packages so that subsequent VM installations will be a lot faster.

Now open /etc/apt-proxy/apt-proxy-v2.conf...

vi /etc/apt-proxy/apt-proxy-v2.conf

... and replace the default Ubuntu mirror with a mirror close to you (e.g. http://de.archive.ubuntu.com/ubuntu if you are in Germany):

[...]
[ubuntu]
;; Ubuntu archive
backends = http://de.archive.ubuntu.com/ubuntu
min_refresh_delay = 15m
[...]

Then we restart apt-proxy:

/etc/init.d/apt-proxy restart

apt-proxy listens on port 9999, so we can pass our local apt-proxy "mirror" as an argument to the vmbuilder script.

 

4 Using vmbuilder

Take a look at the following commands to learn how to use vmbuilder:

vmbuilder xen ubuntu --help

vmbuilder kvm ubuntu --help

vmbuilder vmw6 ubuntu --help

vmbuilder vmserver ubuntu --help

I will now create four virtual machines with the name vm7, one for Xen, one for KVM, one for VMware Workstation 6, and one for VMware Server. I'm assuming that you are using bridging for your virtual machines.

vmbuilder uses a template to create virtual machines - this template is located in the /etc/vmbuilder/libvirt/ directory. Because we must modify the template, we create a copy and modify that one:

mkdir -p ~/vm7/mytemplates/libvirt
cp /etc/vmbuilder/libvirt/* ~/vm7/mytemplates/libvirt/

Now we open ~/vm7/mytemplates/libvirt/libvirtxml.tmpl...

vi ~/vm7/mytemplates/libvirt/libvirtxml.tmpl

... and change the network section from

[...]
    <interface type='network'>
      <source network='default'/>
    </interface>
[...]

to

[...]
    <interface type='bridge'>
      <source bridge='br0'/>
    </interface>
[...]

because we want the VMs to use bridging (if you use NAT instead of bridging, then don't modify the template!).

Now we come to the partitioning of our VM. We create a file called vmbuilder.partition...

vi ~/vm7/vmbuilder.partition

... and define the desired partitions as follows:

root 8000
swap 4000
/var 20000

This defines a root partition (/) with a size of 8000MB, a swap partition of 4000MB, and a /var partition of 20000MB. Of course, you are free to define whatever partitions you like (as long as you also define root and swap).

I want to install openssh-server in the VM. To make sure that each VM gets a unique OpenSSH key, we cannot install openssh-server when we create the VM. Therefore we create a script called boot.sh that will be executed when the VM is booted for the first time. It will install openssh-server (with a unique key) and also force the user (I will use the default username administrator for my VMs together with the default password howtoforge) to change the password when he logs in for the first time:

vi ~/vm7/boot.sh

# This script will run the first time the virtual machine boots
# It is ran as root.

# Expire the user account
passwd -e administrator

# Install openssh-server
apt-get update
apt-get install -qqy --force-yes openssh-server

Make sure you replace the username administrator with your default login name.

(You can find more about this here: https://help.ubuntu.com/community/JeOSVMBuilder#First%20boot)

(You can also define a "first login" script as described here: https://help.ubuntu.com/community/JeOSVMBuilder#First%20login)


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.