Creating a Xen Virtual Machine

First you need to create the lvm volume for the VM. Create a volume for swap also.

# lvcreate -L1024M -n vm01data bendervg
# lvcreate -L256M -n vm01swap bendervg

Create a filesystem on this volume.

# mkfs.ext3 /dev/bendervg/vm01data
# mkswap /dev/bendervg/vm01swap

Bootstrap the filesystem. You may need to set http_proxy to allow stuff to download.

# mount /dev/bendervg/vm01 /mnt/vm01
# <del>debootstrap --verbose sarge /mnt/vm01</del>
# debootstrap squeeze /mnt2

The vm is not ready to be booted. Create a xen config file like the example below. Create it in /etc/xen/domains and symlink it in /etc/xen/auto if you want the domain to start automatically when the machine starts. Important directives are name, memory, kernel and vbd. You can then start the domU.

# xm create -c /etc/xen/domains/vm01

Press Ctrl-] to detach this console.

TTY problems

Sometimes(i.e. recently) debootstrap doesn't create the /dev/tty* devices properly. A world of arse insues. The solution is to manually create these devices.

flexo:/mnt/vm09/dev# for i in `seq 1 9`; do mknod tty$i c 4 $i; done
flexo:/mnt/vm09/dev# chgrp tty tty*

Configuring the VM

The install created with debootstrap is very bare. You have a bit of configuration before the machine is usable. First you should set a root password. The default is to have no root password set at all.

Then edit /etc/hostname and set the hostname. Hostnames should be the name of the real machine and the vm number. e.g.


Edit /etc/fstab so it knows where the root and swap are.

# /etc/fstab: static file system information.
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
/dev/hda1       /               ext3    defaults,errors=remount-ro 0       1
/dev/hda2       none            swap    sw              0       0

Edit /etc/network/interfaces and set the correct parameters.

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
        iface eth0 inet static
        # dns-* options are implemented by the resolvconf package, if installed

Setup apt. In all likelyhood when you setup a domain you wont have access to the real internet, so use http mirrors and use as your proxy.

# apt-setup

Install some nescessary packages.

# apt-get install ssh vim resolvconf

Move the tls library(it conflicts with xen).

# mv /lib/tls /lib/tls.disabled

Edit the /root/AuthorisedRoot file and put whoever is allowed have root on the machine as root. Encrypt with the root password you created above. -x will enable vim's encryption facility.

# vim -x /root/AuthorisedRoot

Email root to global admins. And put intelligence's key(below) in /root/.ssh/authorized_keys.

# cd root/.ssh/
# scp root@intelligence:~/.ssh/ authorized_keys

Example Xen config file

#  -*- mode: python; -*-
# Python configuration setup for 'xm create'.
# This script sets the parameters used when a domain is created using 'xm create'.
# You use a separate script for each domain you want to create, or 
# you can set the parameters for the domain on the xm command line.

# Kernel image file.
kernel = "/boot/vmlinuz-"

# Optional ramdisk.
#ramdisk = "/boot/initrd.gz"

# The domain build function. Default is 'linux'.

# Initial memory allocation (in megabytes) for the new domain.
memory = 128

# A name for your domain. All domains must have different names.
name = "bender-vm01"

# Which CPU to start domain on? 
#cpu = -1   # leave to Xen to pick

# Define network interfaces.

# Number of network interfaces. Default is 1.

# Optionally define mac and/or bridge for the network interfaces.
# Random MACs are assigned if not given.
#vif = [ 'mac=aa:00:00:00:00:11, bridge=xen-br0' ]

# Define the disk devices you want the domain to have access to, and
# what you want them accessible as.
# Each disk entry is of the form phy:UNAME,DEV,MODE
# where UNAME is the device, DEV is the device name the domain will see,
# and MODE is r for read-only, w for read-write.

disk = [ 'phy:bendervg/vm01,hda1,w', 'phy:bendervg/vm01swap,hda2,w' ]

# Set the kernel command line for the new domain.
# You only need to define the IP parameters and hostname if the domain's
# IP config doesn't, e.g. in ifcfg-eth0 or via DHCP.
# You can use 'extra' to set the runlevel and custom environment
# variables used by custom rc scripts (e.g. VMID=, usr= ).

# Set if you want dhcp to allocate the IP address.
# Set netmask.
# Set default gateway.
# Set the hostname.
#hostname= "vm%d" % vmid

# Set root device.
root = "/dev/hda1 ro"

# Root device for nfs.
#root = "/dev/nfs"
# The nfs server.
#nfs_server = ''  
# Root directory on the nfs server.
#nfs_root   = '/full/path/to/root/directory'

# Sets runlevel 4.
extra = "4"

# Set according to whether you want the domain restarted when it exits.
# The default is 'onreboot', which restarts the domain when it shuts down
# with exit code reboot.
# Other values are 'always', and 'never'.

#restart = 'onreboot'


last edited 2011-04-21 23:25:09 by 089-101-244184