Installing Xen 3.3 With Kernel 2.6.27 On Ubuntu 8.10 (x86_64) - Page 2

3 Creating Image-Based Virtual Machines

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: The xen-tools package got installed as a dependency when we installed the ubuntu-xen-server package, so we don't need to install it anymore.

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:

vi /etc/xen-tools/xen-tools.conf
dir = /home/xen
memory = 256Mb
dist   = lenny     # Default distribution to install.
gateway   =
netmask   =
broadcast =
passwd = 1
kernel      = /boot/vmlinuz-2.6.27-11-server
initrd      = /boot/initrd.img-2.6.27-11-server
mirror =
serial_device = hvc0
disk_device = xvda #default

In the kernel and initrd lines, we don't use our dom0 kernel that we built in the last chapter ( because this kernel does not work in a domU. Please use one of the default Ubuntu kernels (take a look at the output of

ls -l /boot

), e.g. 2.6.27-11-server! The default Ubuntu kernels are built to work in Xen guests, so there's no need to build a special domU kernel.

The dir line specifies where the virtual machine images will be stored. dist specifies the distribution to be installed in the virtual machines (Debian Lenny) (there's a comment in the file that explains what distributions are currently supported).

The passwd = 1 line makes that you can specify a root password when you create a new guest domain. In the mirror line specify a Debian mirror close to you.

Make sure you specify a gateway, netmask, and broadcast address. 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!

It is very important that you add the line serial_device = hvc0 (not xvc0 or tty1!) because otherwise the console of your virtual machines might not work properly!

Before we go on, we must create the directory where the virtual machine images should be stored:

mkdir /home/xen 

Now let's create our first guest domain,, with the IP address

xen-create-image --size=4Gb --swap=256Mb --ip= --arch=amd64 --role=udev

Options that you specify on the command line override the settings in /etc/xen-tools/xen-tools.conf. Options that are not specified on the command line are taken from /etc/xen-tools/xen-tools.conf. Please make sure that you add --role=udev, or your virtual machine might not boot properly!

(To learn more about the available options, take a look at the xen-create-image man page:

man xen-create-image


The xen-create-image command will now create the virtual machine for us. This can take a few minutes. The output should be similar to this one:

[email protected]:~# xen-create-image --size=4Gb --swap=256Mb --ip= --arch=amd64 --role=udev

General Information
Hostname       :
Distribution   :  lenny
Partitions     :  swap            256Mb (swap)
                  /               4Gb   (ext3)
Image type     :  sparse
Memory size    :  256Mb
Kernel path    :  /boot/vmlinuz-2.6.27-11-server
Initrd path    :  /boot/initrd.img-2.6.27-11-server

Networking Information
IP Address 1   : [MAC: 00:16:3E:1E:C4:E1]
Netmask        :
Broadcast      :
Gateway        :

Creating partition image: /home/xen/domains/

Creating swap on /home/xen/domains/

Creating partition image: /home/xen/domains/

Creating ext3 filesystem on /home/xen/domains/
Installation method: debootstrap

Running hooks

Role: udev
        File: /etc/xen-tools/role.d/udev
Role script completed.

Creating Xen configuration file
Setting up root password
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
All done

Logfile produced at:
[email protected]:~#

There should now be a configuration file - /etc/xen/ Take a look at it to become familiar with virtual machine configuration files:

vi /etc/xen/
# Configuration file for the Xen instance, created
# by xen-tools 3.9 on Fri Feb 13 00:28:34 2009.

#  Kernel + memory size
kernel      = '/boot/vmlinuz-2.6.27-11-server'
ramdisk     = '/boot/initrd.img-2.6.27-11-server'
memory      = '256'

#  Disk device(s).
root        = '/dev/xvda2 ro'
disk        = [

#  Hostname
name        = ''

#  Networking
vif         = [ 'ip=,mac=00:16:3E:1E:C4:E1' ]

#  Behaviour
on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'

(Please note: if you have a dual-core or quad-core CPU and want the virtual machine to use all CPU cores, please add the line vcpus = '2' or vcpus = '4' to the configuration file.)

Before we start the virtual machine for the first time, we must first mount its storage device and copy the domU kernel to it (the xen-create-image command copies the dom0 kernel to the guest, but as I mentioned before, our domU kernel is different from the dom0 kernel (2.6.27-11-server in this example)):

mount -o loop /home/xen/domains/ /mnt
cd /mnt/lib/modules/
cp -pfr /lib/modules/2.6.27-11-server/ .
umount /mnt

To start the virtual machine, run

xm create /etc/xen/


xm console

to log in on that virtual machine (type CTRL+] if you are at the console, or CTRL+5 if you're using PuTTY to go back to dom0), or use an SSH client to connect to it (

To get a list of running virtual machines, type

xm list 

The output should look like this:

[email protected]:~# xm list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  3499     2     r-----   2826.0                            22   256     1     -b----      5.8
[email protected]:~#

To shut down, do this:

xm shutdown 

If you want to start automatically at the next boot of the system, then do this:

ln -s /etc/xen/ /etc/xen/auto

Here are the most important Xen commands:

xm create -c /path/to/config - Start a virtual machine.
xm shutdown <name> - Stop a virtual machine.
xm destroy <name> - Stop a virtual machine immediately without shutting it down. It's as if you switch off the power button.
xm list - List all running systems.
xm console <name> - Log in on a virtual machine.
xm help - List of all commands.

A list of all virtual machines that were created with the xen-create-image command is available under


[email protected]:~# xen-list-images
Memory: 256
[email protected]:~#

To learn more about what you can do with xen-tools, take a look at this tutorial:

Share this page:

Suggested articles

7 Comment(s)

Add comment



I would like to thank you for your posting    “Installing Xen 3.3 With Kernel 2.6.27 On Ubuntu 8.10 (x86_64)”

I followed the steps mentioned in this, and was able to create the Xen server successfully. Thanks a lot for the nice Installation guide.

I have few questions after I did create the VM or domU on Xen

1 Can we create Windows domU on Xen-ubuntu server ?  How do we create it? If not is there any work around for this?

2 How do we duplicate or clone and existing VM( domU ) with and without it running?

It would be really great if you could answer this question or if you can direct to any place Where I can find information on this.


Have you Compiled your kernel with Xen sources and installed all the modules?

I got this error as I didnot do install of the new xen modules. Please check that




Thanks for the Wonderful effort in bring the Xen installation guide to the whole world making it simple and easy. Thanks Falko Timme for this good effort.

By: chintalvaady

Hi friends,

i have used this HOW TO and it has been very useful .however..i get the following error when i type "xm create /etc/xen/"..


Can anyone here try to solve it

[email protected]:~# xm create /etc/xen/
ERROR Internal error: Could not obtain handle on privileged command interface (2 = No such file or directory)
Traceback (most recent call last):
  File "/usr/sbin/xm", line 8, in <module>
    from xen.xm import main
  File "/usr/lib/python2.5/site-packages/xen/xm/", line 61, in <module>
    xc = xen.lowlevel.xc.xc()
xen.lowlevel.xc.Error: (1, 'Internal error', 'Could not obtain handle on privileged command interface (2 = No such file or directory)')
[email protected]:~#


By: Anonymous

i've the same problems. it seems, that you didn't boot the xen kernel...


Hello and thanks for the detailed instructions.

I am not sure why from the time I run update-grub nothing gets updates (mainly menu.lst) and I reboot, I have the same kernel as before!?

The files are there under /boot/

But again when I type any xm command or xm by itself I get:

ERROR Internal error: Could not obtain handle on privileged command interface (2 = No such file or directory)
Traceback (most recent call last):
  File "/usr/sbin/xm", line 8, in <module>
    from xen.xm import main
  File "/usr/lib/python2.5/site-packages/xen/xm/", line 61, in <module>
    xc = xen.lowlevel.xc.xc()
xen.lowlevel.xc.Error: (1, 'Internal error', 'Could not obtain handle on privileged command interface (2 = No such file or directory)')

When I edit the menu.lst manually and insert any xen kernels available I either get a reboot/kernel panic, or freezes or once I was able to boot up in xen but No NIC (except for lo) so I had no network at all?!

For some reason eth0/1 and 2 all disappeared?!

Can you post a sample of a working menu.lst please?!

my server only loads  vmlinuz-2.6.27-7-server


Thank You!



By: Mick T.

Good article, I've been something like this to help me get Xen running on Intrepid. If you do a revision of this article you might want to consider building images as DEB packages.