Xen is a powerful, popular open-source hypervisor that allows you to run numerous, isolated VPS’s on a single machine. While it sounds complicated to install, it’s actually rather easy.
You don’t actually need much to run Xen. For example, for this guide I’m using a Core i5 laptop. You can use any CPU that supports virtualization and obviously, the more powerful the server hardware (including hard drives, due to I/O), the better.
With the RAM, you need to make sure that Dom0 (the host server) has enough to run properly, so depending on your needs, consider reserving 1-2GB RAM minimum for it.
Don’t try and use SSD drives. Virtualization can be I/O intensive and given the current failure rates of SSDs and the fact that they have limited write life-times, you will be crying later on. If you really need fast I/O, consider something like SAS drives instead (or even a SAN setup).
This tutorial sets up Xen with bridging for networking (which is the easiest to work with) and will work perfectly in almost any home/office network. If you are thinking of getting a dedicated server at a ISP and want to use this guide, please check that the host supports VLANs and/or doesn’t do any MAC-address locking on the switches, or uses MAC addresses on the switches for IP assignment or similar - this will really mess around with the bridging and almost always make it unusable :( Unfortunately, a large number of hosts, especially budget ones like Hetzner, don’t use VLANs and assign IPs via MACs so it’s important to ask beforehand!
Install whatever packages you like, however don’t select Xen during install if you are installing Centos 5 - the default Xen package is really old, we’ll be installing a newer version later. Also, as LVM is superior to .img files for DomU disks, give yourself a small amount for the host system, say 20GB, and use the rest for LVM. A good example layout is:
- / - 20GB
- swap - 6GB
- LVM - rest of the space
Once the server is installed and up and running, do a yum upgrade:
Once this is complete, you’ll need to add the Gitco Repos to be able to install a newer version of Xen. First, edit /etc/yum.repos.d/CentOS-Base.repo and add the following:
[gitco-xen3.4.2] name=RHEL/CentOS-$releasever - GITCO XEN3.4.2 baseurl=http://www.gitco.de/repo/xen3.4.2 gpgcheck=0 enabled=1
You’ll notice that this is currently the latest version of the Xen 3 branch. I chose it because it is almost-new and has proven stability. If you would like to use the latest version (at time of writing), add the following instead:
[gitco-xen4.1.2] name=RHEL/CentOS-$releasever - GITCO XEN4.1.2 baseurl=http://www.gitco.de/repo/xen4.1.2 gpgcheck=0 enabled=1
yum install xen
And it will install Xen and any dependencies. Once this is done, make sure that Xen will start on boot:
chkconfig xend on
And edit the kernel settings to make sure that the Xen kernel gets selected - edit /boot/grub/menu.lst and change ‘default’ to the correct number - the new kernel is normally first, in which case change it to
Now, reboot the server, and when it comes back up, you can make sure that it is running Xen by typing in
If you see output similar to the below, then you have successfully installed Xen:
Name ID Mem VCPUs State Time(s) Domain-0 0 3770 4 r----- 23.7`
Now that Xen is up and running, let’s finish off the install.
Set up LVM
Now, let’s set up the LVM environment for the disks. Run the following commands:
pvcreate /dev/sda3 vgcreate XenGuests /dev/sda3
The pvcreate command sets up the physical volume on the third partition on the drive and the vgcreate command creates the volume group XenGuests. The actual name of the volume group isn’t that important so you can call it what you want. Check that it is working properly by running the following command:
You should see output like this:
VG #PV #LV #SN Attr VSize VFree XenGuests 1 0 0 wz--n- 574.17G 574.17G
Your Xen server is now ready to go! You may also want to turn off SELinux, it’ll make things easier when you start running VMs, but it’s up to you.
Install a Firewall on cPanel