Personal tools
shadowfax.org.uk logo
Views

Setting up Xen on Ubuntu

From Shadowfax

Jump to: navigation, search

Contents

Background

Xen is an opensource virtualisation platform which is available for linux (as well as other OSs). It allows numerous guest OSs to be run on the hosting server as Virtual Machines (VMs).

Resources

Installing guest OS's on Ubuntu

The link (Virtualising Ubunto on Ubunto) provides a very useful baseline install. However, if you want a different guest OS there are a number of bits which need changing.

The first of these is the dist identifier in the xen-tools.conf file. This should be the name of the distribution. You can find the supported distributions by listing the contents of /usr/lib/xen-tools. All the files ending in .d are distributions (eg centos-5.d). In this example to install centos 5 I would set dist=centos-5

The second change that you need to make is the mirror. This should point to a mirror appropriate for the distribution. For centos this is mirror=http://mirror.centos.org/centos/5/os/i386/images/xen/.

The third change is the install-method (in the xen-create-image command). The article shows install-method=debootstrap. This did not work for centos. After a bit of googling I changed the install-method to rinse. (Note the size and memory values in the example are quite small - these determine the disk space and memory allocated to the virtual machine)

xen-create-image --hostname=hostname.domainnaime --size=2Gb --swap=256Mb --ide \
--ip=192.168.0.101 --netmask=255.255.255.0 --gateway=192.168.0.1 --force \
--dir=/home/xen --memory=64Mb --arch=i386 --kernel=/boot/vmlinuz-2.6.24-16-xen \
--initrd=/boot/initrd.img-2.6.24-16-xen --install-method=rinse --dist=centos-5 \
--mirror=http://mirror.centos.org/centos/5/os/i386/images/xen/ --passwd

The fourth change is to add a line to the domain configuration file to tell it what type of console to run. The domain config file is in /etc/xen and is called domainname.cfg where domainnaim is the name you gave the domain (eg hostname.domainname.org). The following example shows the line you would add to allow a text console

extra       = 'console=tty xencons=tty'

Increasing VM Memory & Disk Space

If a VM has been created with too little memory it can easily be altered by changing the following line in the config file and restarting the VM

memory    = '64'

Increasing disk space is a bit harder (but not too much). The VM must not be running whilst doing this - so stop it using xm destroy.

First locate the disk image for the virtual machine - the location can be found in the config file and it will be something line /home/xen/domains/domain-name/disk.img. It is advisable to back this file up before proceeding (eg cp disk.img disk-bck.img). Once this is done we can extend the image by appending formatted blocks to it as follows:

dd if=/dev/zero bs=1024 count=1000000 >> disk.img
resize2fs -f disk.img

The first of these commands adds 1GB of storage in 1024 byte blocks to the image. The second command expands the internal file system to the limits of the image. To add more than 1GB change the count value.

Once this is done, restart the VM and test to ensure that it has worked.

VM Management

  • To delete a VM xen-delete-image domainname
  • To copy a VM xen-duplicate-image --from=old vm name --hostname=new domain name
  • To start a VM xm create config file name (eg xm create /etc/xen/hostname.domainname.cfg)
  • To list VMs xm list (NB this gives the VM Id which may be used in place of domain name)
  • To stop a VM xm shutdown domain name or virtual machine id (eg xm shutdown 1).
  • xm shutdown may restart the VM immediately. To stop and kill the VM use xm destroy domain name or VM Id
  • To log on to a VM xm console domain name or virtual machine id


Leave your comment

Menu