This tutorial provides step-by-step instructions on how to install Xen on an Ubuntu Hardy Heron (Ubuntu 8.04.1) server system (i386). You can find all the software used here in the Ubuntu repositories, so no external files or compilation are needed.
Xen lets you create guest operating systems (*nix operating systems like Linux and FreeBSD), so called "virtual machines" or domUs, under a host operating system (dom0). Using Xen you can separate your applications into different virtual machines that are totally independent from each other (e.g. a virtual machine for a mail server, a virtual machine for a high-traffic web site, another virtual machine that serves your customers' web sites, a virtual machine for DNS, etc.), but still use the same hardware.
Make sure that you are logged in as root
sudo su -
Install vim and make sure to turn on the "syntax on" in /etc/vim/vimrc
aptitude install vim
To install Xen and all needed dependencies, all we have to do is run the following command:
apt-get install ubuntu-xen-server
This will also install the xen-tools package which we use later on to create virtual machines.
Next do this:
mv /lib/tls /lib/tls.disabled
We also need to add the loop module to the kernel every time we boot our system, so we edit /etc/modules. If you already have a loop line in there, make it look like this, otherwise add it:
Now take a look at the /boot directory to see which kernels and ramdisks are installed:
ls -l /boot/
You can now also take a look at the /usr/lib/xen-tools directory because it reveals which distributions can be installed in a virtual machine with xen-tools:
ls -l /usr/lib/xen-tools
I want to store my virtual machines in the /home/xen directory, therefore I create it now:
mkdir -p /home/xen
We will use xen-tools to create virtual machines. xen-tools make it very easy to create virtual machines - please read this tutorial to learn more: http://www.howtoforge.com/xen_tools_xen_shell_argo. As mentioned before, the xen-tools package got installed together with the ubuntu-xen-server package.
Now we edit /etc/xen-tools/xen-tools.conf. This file contains the default values that are used by the xen-create-image script unless you specify other values on the command line. I changed the following values and left the rest untouched:
The dist line holds the default distribution that you want to install in a virtual machine. The contents of the /usr/lib/xen-tools directory reveals which distributions are available (see above).
The kernel line must contain our Xen kernel, and the initrd line its ramdisk. The default /etc/xen-tools/xen-tools.conf file has the values kernel = /boot/vmlinuz-uname -r and initrd = /boot/initrd.img-uname -r which automatically translate to the correct kernel and ramdisk, so we don't have to modify these lines.
The passwd = 1 line makes that you can specify a root password when you create a new guest domain. In the mirror line specify an Ubuntu mirror close to you.
Make sure you specify a gateway and netmask. If you don't, and you don't specify a gateway and netmask on the command line when using xen-create-image, your guest domains won't have networking even if you specified an IP address!
Now reboot the system:
If your system reboots without problems, then everything is fine! Run:
and your new Xen kernel should show up
Now let's create our first guest domain, rtplxap01, running Hardy Heron (hardy) with the IP address 172.16.110.230:
xen-create-image --hostname=rtplxap01 --size=10Gb --swap=1024Mb --ide \
A lot of switches are unnecessary here because we specified the same details in /etc/xen-tools/xen-tools.conf but it shows that you can specify the desired settings either on the command line or in /etc/xen-tools/xen-tools.conf. Please make sure that you specify --ide, otherwise your virtual machine might not boot!
To learn more about the available options, take a look at the xen-create-image man page:
There should now be a rtplxap01 configuration file - /etc/xen/rtplxap01.cfg. Take a look at it to become familiar with virtual machine configuration files:
The file: parameter is now deprecated in Xen 3.2, therefore we must edit /etc/xen/rtplxap01.cfg now and replace file: with tap:aio: (otherwise you'll get an error similar to this one:
Error: Device 769 (vbd) could not be connected. losetup /dev/loop0 /home/xen/domains/xen1.example.com/swap.img failed
Please note: if you have a dual-core CPU and want the virtual machine to use both CPU cores, please add the line vcpus = '2' to the configuration file, like this:
# Configuration file for the Xen instance rtplxap01, created
To start the virtual machine, run:
xm create /etc/xen/rtplxap01.cfg
To log in on that virtual machine, run:
xm console rtplxap01
Type CTRL+] if you are at the console, or CTRL+5 if you're using PuTTY to go back to dom0
In the virtual machine (when you use it for the first time), run:
mv /lib/tls /lib/tls.disabled
Now back to the host system (dom0). To get a list of running virtual machines, type:
To shut down rtplxap01, run:
xm shutdown rtplxap01
If you want rtplxap01 to start automatically at the next boot of the system, run:
ln -s /etc/xen/rtplxap01.cfg /etc/xen/auto
Here are the most important Xen commands: