Creating a virtual machine on a Xen hypervisor turns out to be pretty easy. The hardest part is dealing with LVM so that you have disk space available for the new machine.


There is a little bit of pre-work we have to do in order to get a working virtual machine. We need a bootable kernel, the configuration file, and disk space.


The kernel is pretty easy. We need to download two files.

sudo mkdir -p /var/lib/xen/images/ubuntu-netboot
pushd /var/lib/xen/images/ubuntu-netboot
sudo wget
sudo wget

This will give us the files we need to boot and install our new virtual machine.

Drive Space

I’m not a huge fan of how the command line for LVM works. Arcane, commands don’t follow normal conventions and to many of the commands are to similar. But it works.

Run sudo pvs to see what volume groups have available free space. I’ll assume that you have free space on vg-guests.

In order to build the actual volume:

sudo lvcreate -L 6G -n guest1 /dev/vg-guests

The Configuration File

The configuration file combines the above sections into something that we can use.

sudo vi /etc/xen/guest1.cfg

The file should look something like:

name = "guest1"
memory = 512
disk = ['phy:/dev/vg-guests/guest1,xvda,w']
vif = [ 'mac=5F:03:97:55:7C:5F,bridge=xenbr0' ]
# bootloader = "pygrub"
kernel = "/var/lib/xen/images/ubuntu-netboot/vmlinuz"
ramdisk = "/var/lib/xen/images/ubuntu-netboot/initrd.gz"
extra = "debian-installer/exit/always_halt=true -- console=hvc0"

You’ll need to adjust the disk portion to reflect the correct volume group and logical volume that you created. I highly recommend adding the mac option. If you don’t, everytime you reboot you will get a different MAC address and therefore a different IP address.

Boot and Install

The hard work is done, lets boot this thing up.

sudo xl create /etc/xen/guest1.cfg -c

This will connect you to the console of the new virtual machine and allow you to run through a text based installation. Install as per normal with your preferences.


When the installation is complete and you tell it to reboot, it will dump you pack to the Xen host machine. From there, you need to change the configuration file to be similar to:

name = "guest1"
memory = 512
disk = ['phy:/dev/vg-guests/guest1,xvda,w']
vif = [ 'mac=5F:03:97:55:7C:5F,bridge=xenbr0' ]
bootloader = "pygrub"
# kernel = "/var/lib/xen/images/ubuntu-netboot/vmlinuz"
# ramdisk = "/var/lib/xen/images/ubuntu-netboot/initrd.gz"
# extra = "debian-installer/exit/always_halt=true -- console=hvc0"

All you are doing is uncommenting the bootloader option and commenting the kernel, ramdisk and extra options so that it doesn’t attempt to boot and install again.

You will need to setup pygrub with sudo ln -s /usr/lib/xen-4.1/bin/pygrub /usr/bin/pygrub.

You can turn the virtual machine back on with.

sudo xl create /etc/xen/guest1.cfg -c

From there you can log in as normal. If you have install an SSH server, you can find the IP address and log in over the wire. Most of the updates should already be done for you ( or at least they where for me ).


23 October 2014