Skip to content

Install Xen and libvirt on Debian Lenny

This should be an easy to follow guide about how to install Xen on Debian 5. You should be able to copy/paste most parts of on your shell. Please run this only on a clean and up-to-date Debian system.

Alright let’s get to it quick ‘n dirty.

First of all make sure your Debian install actually is up-to-date:

# apt-get update; apt-get upgrade

Let’s see which Xen kernel images are available and pick the most recent one to install:

# apt-cache search xen | grep image | awk '{print $1}'
# apt-get install `apt-cache search xen-linux-system \
| sort | tail -1 | awk '{print $1}'`

Once this is done reboot your system, login again and run:

# uname -a
Linux elysium 2.6.26-2-xen-amd64 #1 SMP Thu Feb 11 02:57:18 UTC 2010 x86_64 GNU/Linux

As you can see, the system is running kernel 2.6.26-2 with the xen-amd64 patch set.
As of now we should have Dom-0 available:

# xm list
Name                   ID   Mem VCPUs      State   Time(s)
Domain-0               0  3885     2     r-----      8.5


Let’s move on to the network. By default there is no bridge available from the virtual machines towards the external network. It’s fairly easy to accomplish though:

# vim /etc/xen/xend-config.sxp

Look for the following line and uncomment it:

(network-script network-bridge)

And while we’re editing the xend-config.sxp file, change the following line:

(xend-unix-server no)


(xend-unix-server yes)

Be sure to reload the new settings:

# /etc/init.d/xend restart

If you don’t edit this line or if you don’t reload, you obviously won’t be able to install or manage your virtual machines. You’d get to see errors like this:

ERROR    internal error failed to connect to xend
Traceback (most recent call last):
  File "/usr/bin/virt-install", line 693, in
  File "/usr/bin/virt-install", line 508, in main
    conn = cli.getConnection(options.connect)
  File "/var/lib/python-support/python2.5/virtinst/", line 123, in getConnection
  File "/usr/lib/python2.5/site-packages/", line 140, in open
    if ret is None:raise libvirtError('virConnectOpen() failed')
libvirtError: internal error failed to connect to xend

There are more options available to connect to xend.: xend-http-server, xend-tcp-xmlrpc-server, xend-unix-xmlrpc-server, xend-relocation-server.

The reason why I chose xend-unix-server over anything else is pretty straight forward. It only listens on the Unix socket layer which doesn’t need any other networking protocol to operate. You could compare it to connecting to localhost, but without the need for a networking device (e.g. lo0).

If you want to be able to manage this Xen server from a central node, be sure to change the appropriate management protocol. It’s beyond the scope of this howto, but I might post an howto on this subject later on this blog.

On to installing a virtual machine!

I for one am a big fan of abstraction layers. It makes life for a SysAdmin or DevOp so much easier if you’re able to run the same commands on different operating systems, platforms or architectures in general. That’s why I use libvirt. It’s a collection of libraries and tools that can be used to deploy virtual machines on different types of virtualization systems. Including but not limited to Xen, KVM and Qemu.

It’s also available as a Debian package, so installing it is very straight forward:

# apt-get install libvirt-bin virtinst

Once this is done we can install our first virtual machine:

# virt-install \
--name=test-debian-install \
--ram=1024 \
--file-size=10 \
--nographics \
--paravirt \
--file=/var/lib/xen/images/test-debian-install.img \

It’s probably a good idea to store this as a shell script on your Xen host for future reference.
You should see a familiar installer within seconds after invoking the command.

Once the install has completed you should be greeted with your new virtual machine’s login prompt:

Debian GNU/Linux 5.0 test-debian-install hvc0

test-debian-install login:

To exit your virtual machine’s console, simply press Ctrl-]


Published inHowto'sLinuxVirtualization


  1. Thank you. Thanks to your guide I had it up and running in no time.

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.