This is a tutorial about how to use Ubuntu Server 8.04 as dom0 (host) for Xen, i.e. how to install Xen on Ubuntu Server. In a later post I’ll show how to install domUs (guests). The whole setup is done with a rather complex disk configuration using both raid 1 (mirroring) and LVM. It requires some knowledge about Xen (e.g. I’ll not try to convince you to use Xen – I assume it’s already your plan and you had read of all the advantages it gives you
).
Disk-layout considerations
In order to use Windows with Xen you also need to have Intel VT or AMD-V – and have it enabled, too. My “metal” is a AMD-V enabled CPU, 4 GB RAM, 2 x 400 GB SATA II disks, and a 1 GBit NIC (network interface card) – a DS5000 at Hetzner. I’ve chosen to have a rather complex disk setup based on a lot of reading different places at the web (and for fun, too), e.g. [1], [2], [3], and [4]. First of all I want protection (raid 1 – mirroring) because I’m going to use the system in a production environment, but I don’t want to pay the money for a real hardware RAID controller, hence I’ve decided to use software raid, i.e. mdadm. I know it’s expensive in CPU-time, but I’m willing to “pay” for the protection this way. I want LVM for the domUs because it among other things enables me to take snapshots and easily grow/shrink the size of the disk.
The only thing I don’t want mirrored, is the swap-partitions. I know it might cause the system to crash if a disk fails, but only data in memory can be lost this way. If a swap-partition crashes it’s likely because the disk is dead, and as a back-up I want extra swap-partitions on the other disk so that I can use those until a new disk is installed. I don’t want the swap-partitions to be LVM – only normal partitions that can be mapped directly to domUs through Xen. Because of my metal, it’s not likely that I’m going to have more than 5 domUs running, hence I need 12 swap-partitions in total (the 5 plus 1 for dom0 and doubleing it to encounter the extra ones if a disk crashes). Because I don’t know if the memory of dom0 or a domU is going to be ballooned (resized – and yes, among many other things Xen i capable of that), I’ve decided to go with a size of 4GB of all the swap-partitions. It may be a little oversized, but better safe than sorry and I have plenty of disk space for my needs.
Of course the root file system of dom0 needs to be mirrored, but I don’t want to use LVM with this, because I’m not going to use any of the advantages with dom0. So this is going to be an ordinary raid 1 xfs partition. The rest of the disk space is used to make a VG (volume group) in LVM, and this pool can then be used to make LV (logical volumes) to disks for the domUs.
At this point please be aware that I’m going to map a LV to a domU to its root file system and a “normal” partition to its swap. Xen gives other possibilities, e.g. map a file on dom0 to the root file system of a domU or simply use a “normal” partition. All three choices have advantages and disadvantages; I’ve made my mind up and chosen to use the LVM-approach. I’ve also chosen to use xfs instead of ext3, but this choice really makes no difference in this tutorial: if you like ext3 better, then please use it.
Disk layout
If the two psysical 400GB disks are called /dev/sda and /dev/sdb, the disk-layout can be depicted as follows:
disk partition size usage/mount pri/log --------------------------------------------------------------- /dev/sda /dev/sda1 1GB /dev/md0 (bootable) primary /dev/sda2 20GB /dev/md1 (dom0 -> /) primary /dev/sda5 4GB swap dom0 logical /dev/sda6 4GB dnu* (swap domU1) logical /dev/sda7 4GB dnu* (swap domU2) logical /dev/sda8 4GB dnu* (extra swap domU3) logical /dev/sda9 4GB dnu* (extra swap domU4) logical /dev/sda10 4GB dnu* (extra swap domU5) logical /dev/sda11 rest /dev/md2 (LVM) logical /dev/sdb /dev/sdb1 1GB /dev/md0 (bootable) primary /dev/sdb2 20GB /dev/md1 (dom0 -> /) primary /dev/sdb5 4GB dnu* (extra swap dom0) logical /dev/sdb6 4GB dnu* (extra swap domU1) logical /dev/sdb7 4GB dnu* (extra swap domU2) logical /dev/sdb8 4GB dnu* (swap domU3) logical /dev/sdb9 4GB dnu* (swap domU4) logical /dev/sdb10 4GB dnu* (swap domU5) logical /dev/sdb11 rest /dev/md2 (LVM) logical *dnu = DO NOT USE (is going to be mounted by the domUs) /dev/md0 (bootable) /boot 1GB raid 1 (dom0 -> /boot) /dev/md1 / 20GB raid 1 (dom0 -> /) /dev/md2 /dev/lvmstore/lv1 15GB / (dom1) /dev/lvmstore/lv2 15GB / (dom2) /dev/lvmstore/lv3 15GB / (dom3) /dev/lvmstore/lv4 20GB / (dom4) ... ... ...
Installation
The task of making this configuration in Ubuntu can be a bit confusing. How to make this configuration depends on the way you’re installing Ubuntu. I’ve had quite some troubles with LILO, so I recommend that you use GRUB instead! That’s also what [6] recommends.
As earlier mentioned, my server is hosted at Hetzner. Here you can only manipulate the installation through a configuration file. This means that the disk configuration has to be performed a bit different. You could of course also make this disk layout with the ordinary Ubuntu installer, but I’ll not get into details how to do that in this tutorial. First reboot into rescue mode and execute
installimage
Now choose to edit the configuration file. First you need to enable software raid (thanks, [5]) and choose GRUB:
SWRAID 1
BOOTLOADER grubFurthermore I configured the hostname. I made the initial partitioning scheme like this:
PART 1 /boot ext3 1G PART 2 / xfs 20G PART 3 swap swap 4G
And then I installed the system. After this was done, the disk layout needed to be modified heavily to get what we wanted.
Because we are going to modify the harddisk layout on a running system, be aware that you might delete data! Please make sure you have a backup of all important data. Also do not do this if you’re not able to restore the server somehow (boot it to rescue mode or similar if something should fail)!
First launch
cfdisk /dev/sda
And perform these steps:
- Select sda3 and delete it
- Create a new locigal partition of 4301.83 MB at the beginning and change type to 82 (Linux swap)
- Create five new locigal partition of 4301.83 MB at the beginning and don’t change the type
- Create a partition on the rest of space of type FD (Linux raid autodetect) – it’s going to be used for a mirrored LVM
- Write (don’t mind about the warning “No primary partitions are marked as bootable” – cfdisk doesn’t know the /dev/md0 is bootable)
- Quit
Now do almost the same with /dev/sdb by
cfdisk /dev/sdb
And perform these steps:
- Select sdb3 and delete it
- Create six new locigal partition of 4301.83 MB at the beginning and don’t change the type
- Create a partition on the rest of space of type FD (Linux raid autodetect) – it’s going to be used for a mirrored LVM
- Write (again, don’t mind about the warning – cfdisk doesn’t know the /dev/md0 is bootable)
- Quit
After this, my disk layout was like this:

Use your favorite text editor (vim, nano or whatever) and:
vim /etc/fstab
Change
/dev/md2 none swap sw 0 0
to
/dev/sda5 none swap sw 0 0
We also need to get /dev/md2 removed from mdadm:
vim /etc/mdadm/mdadm.conf
Comment the line with /dev/md2 out.
Now
umount /dev/md2 mdadm --manage --remove /dev/md2
Again: be sure that if something fails, you’re able to enter some kind of rescue mode! If you are sure, please reboot to activate the new partiotions etc.
And now we check that /dev/md2 is gone:
cat /proc/mdstat mdadm --detail /dev/md2 dmesg | grep md2
Now please verify that the new swap is used be using
freeto see how much free swap space is available (if it says 0 the system doesn’t use the swap). If there’s no swap space, try to initialize the new swap by
mkswap /dev/sda5
and then reboot.
To create the mirroring of the LVM-storage, we perform:
mdadm --create --verbose /dev/md2 --level=1 --raid-devices=2 /dev/sda11 /dev/sdb11
In order to get the array started on system start-up, execute this:
mdadm --brief --examine /dev/sda11 >> /etc/mdadm/mdadm.conf
Now we need to create the LVM (the lvmstore is the name, and LVs – logical volumes – will be located at /dev/lvmstore/name-of-lv):
pvcreate /dev/md2 vgcreate lvmstore /dev/md2
The output should be something like:
root@host:~# pvcreate /dev/md2 Physical volume "/dev/md2" successfully created root@host:~# vgcreate lvmstore /dev/md2 Volume group "lvmstore" successfully created
Now you’re ready to create LVs. In my case I’m going to create three of 15 GB and one on 20 GB:
root@host:~# lvcreate -n lv1 -L 15G lvmstore Logical volume "lv1" created root@host:~# lvcreate -n lv2 -L 15G lvmstore Logical volume "lv2" created root@host:~# lvcreate -n lv3 -L 15G lvmstore Logical volume "lv3" created root@host:~# lvcreate -n lv4 -L 20G lvmstore Logical volume "lv4" created root@host:~# ls -l /dev/lvmstore total 0 lrwxrwxrwx 1 root root 24 2008-08-02 13:55 lv1 -> /dev/mapper/lvmstore-lv1 lrwxrwxrwx 1 root root 24 2008-08-02 13:55 lv2 -> /dev/mapper/lvmstore-lv2 lrwxrwxrwx 1 root root 24 2008-08-02 13:55 lv3 -> /dev/mapper/lvmstore-lv3 lrwxrwxrwx 1 root root 24 2008-08-02 13:55 lv4 -> /dev/mapper/lvmstore-lv4
Please reboot to be sure that everything’s alright.
Post install
First we’ll upgrade the system:
apt-get update apt-get upgrade apt-get dist-upgrade reboot
This will reboot the machine in order to use a new kernel.
After the reboot, install Xen and tools for:
apt-get install ubuntu-xen-server xen-tools xfsprogs
Add this to /etc/modules:
loop max_loop=64
Now you need to deactivate a startup-script (by moving it), that makes it impossible for the machine to boot properly – at least everywhere I’ve tried (thanks to [7] for the solution!):
mv /etc/init.d/loadcpufreq /etc/init.d/loadcpufreq.backup
If you don’t do this, the machine probably will not boot. At my server with Hetzner I was able to ping it though, but when I tried to SSH, I got a “Connection Resufed”.
Now reboot and verify running the Xen-kernel:
uname -r xm list
Sources
[1]: http://forums.novell.com/novell-product-support-forums/suse-linux-enterprise-server-sles/sles-virtualization/331444-suggest-swap-size-dom0.html
[2]: http://www.gagme.com/greg/linux/raid-lvm.php
[3]: http://video.dkuug.dk/2007-10-16-xen/mr-xen.pdf
[4]: http://www.howtoforge.com/high-performance-xen-on-ubuntu-8.04-amd64
[5]: http://www.afterschool.dk/documents/hetzner/raid_hetzner_server/
[6]: http://wiki.debian.org/Xen
[7]: http://ubuntuforums.org/showthread.php?t=819404


September 22nd, 2008 at 16:30 (UTC)
Geat howoto! can i put this on heztner wiki and delete the outdated rubbish there?
btw: /dev/sdv ? hetzer aint’t having clusters =)
it’s not complex ! it is pratical !
Have you ever compared the cpu times against their wiki?
still doing things like this… ?
i thought about redundant dynamic allocated storing space with high i/o whithout putting that into virtu…
any ideas?
ve sees (or however that is spelled) =))
September 22nd, 2008 at 20:11 (UTC)
Hi!
Thanks a lot.
Yes, you’re welcome, but I’d like you to refer to this page (in order for the visitors to be able to view comments, corrections etc.).
And the typing errors has been corrected – thank
.
Regards!
September 26th, 2008 at 19:20 (UTC)
Hi there!
This really is a great article.
I haven’t tried anything right now, simply because my server isn’t online yet.
But in a few hours my server (Hetzner DS7000) will be online.
So pretty much: thanks in advance
September 28th, 2008 at 05:22 (UTC)
Hi did you changed something? i tried to repeat this howto today.
Unforuatley i can create :
mdadm –create –verbose /dev/md2 –level=1 –raid-devices=2 /dev/sda11 /dev/sdb11
i always get mdadm: /dev/sdb11 appears to be part of a raid array:
level=raid1 devices=2
help ! =-)
September 29th, 2008 at 07:13 (UTC)
Hi jake.
Sorry about your trouble.
Are you on a “clean” system? Are you sure that /etc/mdadm/mdadm.conf doesn’t already contain information about /dev/sdb11?
Regards
.
September 29th, 2008 at 16:05 (UTC)
Hi Mikkel!
my trouble is not yours =) ! approximately 26,5 rescue sytems later, i thought so.
i talked to the hetzer guys,too.
/dev/sdb/ ain’t showing on installimage. i spended some quality hours with the unbutu mdadm bugtraq =). As i said, i tryed it before and it worked great! Hetzer is changing the hdd’s now. Update soon. =-)
September 29th, 2008 at 16:25 (UTC)
Oh, I didn’t realize that you’ve tried it before.
Thanks for noting me, and please let me know how everything goes!
September 29th, 2008 at 18:06 (UTC)
Hi Mikkel,
first of all congrats to those howto’s, they are absolutely well done and gave me some ideas
…
i do have the ds3000 atm(had the ds7000 before), i am running Ubuntu Server 8.04 on it with some web projects and game servers running…
now, i would like to host a newer game server that is only aviable as a windows version, so i would like to run a virtual sys with winxp pro on it.
till now i did try vmware server, witch unfortunately had some very bad network lags(not an option for gaming) and i tried virtualbox, with what i am quite happy as it uses only very little on system resources, BUT: the vbox has the problem that it does not allow me to ping from host->guest and without that i cant administrate the game server our call statistical scripts etc. ….(i did search the web, tried allot of different howto’s and nothing fixed that small leftover problem since 4 days so far)
now my question:
Would it be possible to use your solution on a “running and setted up” server and use only the second hard drive(as its not used atm)?
If yes, would you be so kind and give me some pointers what i maybe consider to not screw up the running server?
your articles are somehow the last resource for me atm to fix my problem, as i already go insane on that
Thanks a million
Mario
September 30th, 2008 at 06:25 (UTC)
Hi Mario.
Thanks for your comment!
Yes, you are able to set up Xen on a running system, although I would strongly recommend you not to! Normally it’s advised that you don’t use dom0 (the host running Xen) for any other things than being dom0.
Instead I would recommend you to start over, so to speak, and instead make your current software setup on a virtual machine, too. This of course requires you to be able to have some down time while configuring this net setup.
Regards,
Mikkel.
October 23rd, 2008 at 10:40 (UTC)
Hello,
Thank you for taking the time to write all of this down
I am trying to use 8.04.1 server to make this happen and found a few problems.
It seems lvm2 needs to be installed to get the pvcreate vgcreate lvmstore commands.
which I found out was:
(apt-get install lvm2)
The problem I am having is:
lvcreate -n lv1 -L 20G lvmstore
# lvcreate -n lv1 -L 20G lvmstore
/proc/misc: No entry for device-mapper found
Is device-mapper driver missing from kernel?
Failure to communicate with kernel device-mapper driver.
/proc/misc: No entry for device-mapper found
Is device-mapper driver missing from kernel?
Failure to communicate with kernel device-mapper driver.
Incompatible libdevmapper 1.02.20 (2007-06-15)(compat) and kernel driver
striped: Required device-mapper target(s) not detected in your kernel
lvcreate: Create a logical volume
# uname -a
Linux ubuntu 2.6.24-19-generic #1 SMP Wed Jun 18 14:43:41 UTC 2008 i686 GNU/Linux
I found the answer here:
http://ubuntuforums.org/showthread.php?t=689342
modprobe dm_mod
modprobe dm_mirror
modprobe dm_snapshot
Then:
# lvcreate -n lv1 -L 20G lvmstore
Logical volume “lv1″ created
October 24th, 2008 at 12:14 (UTC)
Hi Brian! I didn’t run into that specific problem, but others might do it, too, so thanks a lot for your contribution!
October 24th, 2008 at 16:16 (UTC)
when will you show us how to install guests ?
Very nice tutorial …
October 27th, 2008 at 07:31 (UTC)
Hi Karel.
If you look at http://www.scienco.org/tag/xen/ you’ll find two guides for installing guests: one for FreeBSD and one for Ubuntu. And the one for FreeBSD can also be used if you want to install Windows.