Virtualization With Xen 3.3.1 On Debian Etch - Page 2

4 Creating Image-Based Virtual Machines

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
dist   = etch     # Default distribution to install.
gateway   =
netmask   =
broadcast =
passwd = 1
kernel      = /boot/vmlinuz-`uname -r`
initrd      = /boot/initrd.img-`uname -r`
mirror =
serial_device = hvc0 #default
disk_device = xvda #default

The dir line specifies where the virtual machine images will be stored. dist specifies the distribution to be installed in the virtual machines (Debian Etch) (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 (or serial_device = xvc0) because otherwise your virtual machines might not boot 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= --memory=128Mb --arch=i386 --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:

server1:~# xen-create-image --size=4Gb --swap=256Mb --ip= --memory=128Mb --arch=i386 --role=udev

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

Networking Information
IP Address 1   : [MAC: 00:16:3E:85:BC:FC]
Netmask        :
Broadcast      :
Gateway        :

Loopback module not loaded and you're using loopback images
Run the following to load the module:

modprobe loop loop_max=255

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:

There should now be a configuration file - /etc/xen/ Open it and add the line extra = 'xencons=hvc0 console=hvc0' (or extra = 'xencons=xvc0 console=xvc0' if you use serial_device = xvc0 in /etc/xen-tools/xen-tools.conf) at the end so that the file looks as follows:

vi /etc/xen/

# Configuration file for the Xen instance, created
# by xen-tools 4.1 on Sun Feb  8 21:42:15 2009.

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

memory      = '128'

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

#  Physical volumes

#  Hostname
name        = ''

#  Networking
vif         = [ 'ip=,mac=00:16:3E:85:BC:FC' ]

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

extra = 'xencons=hvc0 console=hvc0'

If you don't add that line and you go to the console of the vm using the xm console command, the boot process seems to hang forever (while in fact, the vm is running perfectly fine - you can connect to it using SSH).

(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.)

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 (

(If you see something like this during the boot process of the vm...

EXT3-fs: mounted filesystem with ordered data mode.

  ** WARNING: Currently emulating unsupported memory accesses  **
  **          in /lib/tls glibc libraries. The emulation is    **
  **          slow. To ensure full performance you should      **
  **          install a 'xen-friendly' (nosegneg) version of   **
  **          the library, or disable tls support by executing **
  **          the following as root:                           **
  **          mv /lib/tls /lib/tls.disabled                    **
  ** Offending process: modprobe (pid=1757)                    **


... run the following command in the vm:

mv /lib/tls /lib/tls.disabled


To get a list of running virtual machines, type

xm list

The output should look like this:

server1:~# xm list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0   874     1     r-----    714.2                             1   128     1     -b----     63.8

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


server1:~# xen-list-images
Memory: 128

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

Share this page:

0 Comment(s)

Add comment


From: falko