The Perfect Xen 3.0.1 Setup For Debian

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Tue, 2006-03-21 18:24. :: Debian | Xen | Virtualization

This is a "copy & paste" HowTo! The easiest way to follow this tutorial is to use a command line client/SSH client (like PuTTY for Windows) and simply copy and paste the commands (except where you have to provide own information like IP addresses, hostnames, passwords,...). This helps to avoid typos.

The Perfect Xen 3.0.1 Setup For Debian

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 03/20/2006

This tutorial provides step-by-step instructions on how to install Xen (version 3.0.1) on a Debian Sarge (3.1) system.

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. This saves money, and what is even more important, it's more secure. If the virtual machine of your DNS server gets hacked, it has no effect on your other virtual machines. Plus, you can move virtual machines from one Xen server to the next one.

I will use Debian Sarge for both the host OS (dom0) and the guest OS (domU). In an additional section at the end I will also show how to create a virtual local network with virtual machines, with dom0 being the router.

This howto is meant as a practical guide; it does not cover the theoretical backgrounds. They are treated in a lot of other documents in the web.

This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

1 Install The Debian Host System (dom0)

You can overall follow these instructions, but with a few changes:

However, it's important that you type linux26 at the boot prompt to install a kernel 2.6 system. dom0's FQDN in this example will be server1.example.com, so I specify server1 as Hostname and example.com as Domain name. server1.example.com's IP address will be 192.168.0.100 in this tutorial.

When it comes to the partitioning, I select Manually edit partition table. I create the following partitions:

  • /boot 100 MB (Primary) (Location for the new partition: Beginning) (ext3) (Bootable flag: on <-- important, otherwise your system will not boot!)
  • swap 1GB (Logical) (Location for the new partition: Beginning)
  • / 2GB (Logical) (Location for the new partition: Beginning) (ext3)
  • /vserver the rest (Logical) (Location for the new partition: Beginning) (ext3)

(Side note: You can also install everything in one big partition (as described here: http://www.howtoforge.com/perfect_setup_debian_sarge), but then you have to keep in mind that the Grub stanzas I describe in this howto are slightly different. For example, when I write that I add

title        Xen 3.0.1 / XenLinux 2.6.12-xen0
root (hd0,0)
kernel /xen.gz dom0_mem=65536
module /vmlinuz-2.6-xen0 root=/dev/hda6 ro console=tty0

to /boot/grub/menu.lst then you should probably use

title        Xen 3.0.1 / XenLinux 2.6.12-xen0
root (hd0,0)
kernel /boot/xen.gz dom0_mem=65536
module /boot/vmlinuz-2.6-xen0 root=/dev/hda6 ro console=tty0

in that file instead...)

When the Debian installer prompts Choose software to install: I make no selection and go on (dom0 should run as few software as possible in order not to be vulnerable to attacks. To the outside world it will be accessible only over SSH.).

2 Configure dom0's Network

Because the Debian Sarge installer has configured our system to get its network settings via DHCP, we have to change that now because a server should have a static IP address. Edit /etc/network/interfaces and adjust it to your needs (in this example setup I will use the IP address 192.168.0.100):

vi /etc/network/interfaces

# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)

# The loopback interface
auto lo
iface lo inet loopback

# The first network card - this entry was created during the Debian installation
# (network, broadcast and gateway are optional)
auto eth0
iface eth0 inet static
address 192.168.0.100
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1

Then restart your network:

/etc/init.d/networking restart

Edit /etc/resolv.conf and add some nameservers:

vi /etc/resolv.conf

search server
nameserver 145.253.2.75
nameserver 193.174.32.18
nameserver 194.25.0.60

Then set dom0's hostname:

echo server1.example.com > /etc/hostname
/bin/hostname -F /etc/hostname

3 Install Xen

There are two ways to install Xen: install the binary package from the Xen website, or compile Xen and the Xen kernels from the sources.

The first way is easier, but it has the disadvantage that the domU kernel that comes with the binary package has no support for quota and iptables, both features that I need in my virtual machines (domU). Plus, the dom0 kernel has no support for the dummy network driver, which might come in handy for more advanced network setups.

In chapter 3.1 I describe how to install the Xen binary package which is recommended for beginners (skip chapter 3.2 and continue with chapter 4). If you need quota and iptables in your virtual machines, then skip chapter 3.1 and continue with chapter 3.2 where I show how to install Xen from the sources.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by andmalc (registered user) on Sat, 2007-04-14 21:11.

Maybe the title for this should be changed to be more specific.  Instead of "The Perfect Xen 3.0.1 Setup For Debian", how about "Install Xen from source on Debian Sarge".

In 2007 it's not normally necessary to download and compile Xen from source, although this might have been the way to go when this was written back in early 2006.

 

Submitted by Anonymous (not registered) on Fri, 2006-04-07 09:46.

Good tutorial - like most here; thanks.

But a few questions remain open, like

1. Partitioning

For a shared production host, do you really think that one /vserver Partition is enough? And only *one* (well two, counting the swap) file per virtual machine? How about logfiles, fragmentation & all that stuff? I'd rather have a setup with separate *real* /usr, /var, /home etc. partitions for each virtual machine; not only performance-wise.

2. Memory

Since Xen3.0, should you really define an absolute memory size per virtual machine? Wouldn't it be far better to let Xen decide about that and dynamically allocate memory, maybe with a max-mem parameter?

3. Installation

To make all this work with for instance shared hosting, where you usually rent a box which you will never see, you should maybe expand this Howto with a debootstrap variant (and the right fixed IP) right from the start - otherwise you won't be able to access that box anymore after the first reboot.

But, like I said in the beginning: a nice tutorial - thanks again!

cheers,

wjl

Submitted by Anonymous (not registered) on Thu, 2006-06-15 08:20.

apt-get install python-dev

because xen does not compile without it

libsdl1.2-dev is also required for a graphical output of something but I cannot tell now about it (I should test)...

Submitted by Anonymous (not registered) on Thu, 2006-06-15 09:42.
apt-get install libgpmg1-dev is required also, because qemu fails with the test for static SDL library.