This particular way of installing and configuring Xen is just the path of least resistance for me. There are
many other possible ways of configuring the system.
1. Install a clean base server system.
Setup Ubuntu like you normally would. I have created 3 partitions on hda, but you can do it any way you like.
Just keep your differences in mind when you edit the config files.
hda1 is swap
hda2 is 2 GB and mounted as /
hda3 is the rest of the disk and mounted as /xen-images
2. Update the system and install Xen
2.1. Install Xen and configure it
Open a root shell so you don't have to type sudo for every command.
Update the system and install nessecary packages.
Download and extract the Xen 3.0 tarball from http://www.xensource.com/xen/downloads/
apt-get install iproute python python-twisted bridge-utils debootstrap
Check for error messages - it should say OK to all.
tar xvf xen-3.0.1-install-x86_32.tgz
Next we create modules.dep and map files for the new kernel. (see /lib/modules for the correct kernel version)
Edit /etc/mkinitramfs/modules and append the following line:
/sbin/depmod -a 2.6.16-xen
If you run out of loop devices later just increase max_loop and rebuild the initrd.
Create an initrd image. Use the same version number as before.
Edit /boot/grub/menu.lst placing the following lines before the Automagic section
mkinitramfs -o initrd.img-2.6.16-xen 2.6.16-xen
Make Xen start up and autostart selected guests when the system starts up. xend must start before,
title Xen 3.0 / XenLinux 2.6
module /boot/vmlinuz-2.6-xen root=/dev/hda2 ro
and must be stopped after xendomains.
Disable Thread-Local Storage (remember to check this after every update)
update-rc.d xend start 30 2 3 4 5 . stop 31 0 1 6 .
update-rc.d xendomains start 31 2 3 4 5 . stop 30 0 1 6 .
2.2. The following workarounds may not be required later, but I had to do them.
mv /lib/tls /lib/tls.disabled
To make sure that /var/run/xenstored and /var/run/xend exist.
mv /etc/udev/rules.d/xen-backend.rules /etc/udev/rules.d/92-xen-backend.rules
Edit /etc/init.d/xend and insert the following lines after the check for /proc/xen/capabilities
Edit /etc/init.d/xendomains and change the LOCKFILE line to read
if [ ! -d /var/run/xend ] ; then
mkdir -p /var/run/xend
if [ ! -d /var/run/xenstored ] ; then
mkdir -p /var/run/xenstored
2.3. All done for this part so reboot.
When the system is back up try the following command to verify that everything is ok.
You should see something similar to this:
3. Configuring the guest domains
Name ID Mem(MiB) VCPUs State Time(s)
Domain-0 0 463 1 r----- 42.3
3.1. Create disk images and bootstrap them
Create a mountpoint for the images.
Create a 1 GB image file and 500 MB swap file, for larger images increase count.
Change permissions for the image files. No one should have access to your Domain-0 computer since that
dd if=/dev/zero of=/xen-images/guest_base.img bs=1024k count=1000<br/>
dd if=/dev/zero of=/xen-images/guest_base-swap.img bs=1024k count=500
would compromise security for all of the guest domains, but this is a good idea anyway and doesn't affect Xen.
Format guest_base.img as ext3 and then format guest_base-swap.img as swap.
chmod 640 /xen-images/guest_base*
When it says "/xen-images/guest_base.img is not a block special device." answer yes to proceed anyway.
Mount the guest image and bootstrap it.
You should replace http://archive.ubuntu.com/ubuntu/ with a mirror that is closer to you.
Copy your /etc/apt/sources.list to the new image.
mount -o loop /xen-images/guest_base.img /xen-images/mnt<br/>
debootstrap --arch i386 dapper /xen-images/mnt http://archive.ubuntu.com/ubuntu/
Copy the kernel modules.
cp /etc/apt/sources.list /xen-images/mnt/etc/apt/
Disable Thread-Local Storage.
cp -dpR /lib/modules/2.6.16-xen /xen-images/mnt/lib/modules/
Configure networking for the guest /xen-images/mnt/etc/network/interfaces
mv /xen-images/mnt/lib/tls /xen-images/mnt/lib/tls.disabled
Create /xen-images/mnt/etc/hosts and make it look like this.
# The loopback network interface
iface lo inet loopback
# The primary network interface
# Uncomment this and configure after the system has booted for the first time
#iface eth0 inet static
# address 192.168.0.101
# netmask 255.255.255.0
# broadcast 192.168.0.255
# gateway 192.168.0.1
# dns-nameservers 192.168.0.1
127.0.0.1 localhost localhost.localdomain
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
Edit /xen-images/mnt/etc/fstab so it looks like this.
echo guest > /xen-images/mnt/etc/hostname
Unmount the image.
proc /proc proc defaults 0 0
/dev/hda1 / ext3 defaults,errors=remount-ro 0 1
/dev/hda2 none swap sw 0 0
If you get this warning "umount: /xen-images/mnt: device is busy" don't worry, it's not important.
3.2. Boot up the base image to finalize the configuration
Create a config file for the guest /etc/xen/baseimage
Start the guest.
# -*- mode: python; -*-
kernel = "/boot/vmlinuz-2.6.16-xen"
ramdisk = "/boot/initrd.img-2.6.16-xen"
memory = 128
name = "baseimage"
vif = ['bridge=xenbr0']
disk = ['file:/xen-images/guest_base.img,hda1,w','file:/xen-images/guest_base-swap.img,hda2,w']
ip = "192.168.0.101"
netmask = "255.255.255.0"
gateway = "192.168.0.1"
hostname = "baseimage"
root = "/dev/hda1 ro"
extra = "4"
Login as root and set the root password.
xm create baseimage -c
Enable shadow passwords.
Create a backup of /etc/network/interfaces
Edit /etc/network/interfaces and put in correct values so you can access the Internet.
cp /etc/network/interfaces /etc/network/interfaces.bak
Install packages (add ubuntu-desktop and more if you want).
Disable Thread-Local Storage if it has been updated.
apt-get install ubuntu-base configure-debian openssh-server
Configure the system any way you like, I recommend that you try every menu item.
mv /lib/tls /lib/tls.disabled
You should do utils->console-data before utils->console-common.
Make /etc/sudoers writable.
Add the new user you created to /etc/sudoers
chmod 660 /etc/sudoers
Fix permissions for /etc/sudoers
chmod 440 /etc/sudoers
Replace /etc/network/interfaces with the backup copy.
You are now done setting up the base image so shut it down.
mv /etc/network/interfaces.bak /etc/network/interfaces
4. Creating your first guest domain
Make a copy of the base guest images.
cp /xen-images/guest_base.img /xen-images/guestdom1.img
cp /xen-images/guest_base-swap.img /xen-images/guestdom1-swap.img
Edit /etc/xen/guestdom1 and change name, disk and hostname to the following values.
mv /etc/xen/baseimage /etc/xen/guestdom1
You will want to change the following files for each new guest you create.
name = "guestdom1"
disk = ['file:/xen-images/guestdom1.img,hda1,w','file:/xen-images/guestdom1-swap.img,hda2,w']
hostname = "guestdom1"
To make the guest start up automatically and make Domain 0 wait for it before shutting down.
Or if you want to start and stop the guest manually.
ln -s /etc/xen/guestdom1 /etc/xen/auto/
For further information check the Xen Documentation
xm create guestdom1
Other points of interest: