The Perfect Xen 3.0.1 Setup For Debian - Page 4

4 Create A Virtual Machine (domU)

Next we create an image of a virtual machine. It will be a basic Debian system. This image will be the template for all our virtual machines. Whenever we want to create a new virtual machine, we just copy this image, create a new Xen configuration file and boot the copy, and then we can go on and configure the copy to our needs (e.g install a mail server, web server, DNS server, etc. on it). All our images will be on the /vserver partition which should be the largest one we have.

mkdir /vserver/vm_base
mkdir /vserver/images

Now we create a 1 GB image file and a 500 MB swap image. In the end the virtual machines will have 1 GB space and 500 MB swap. These are just example values, in the real world you might want to have more space for your virtual machines (e.g. between 5 and 30 GB), so just increase the value of count to create larger images.

dd if=/dev/zero of=/vserver/images/vm_base.img bs=1024k count=1000
dd if=/dev/zero of=/vserver/images/vm_base-swap.img bs=1024k count=500

Then we format /vserver/images/vm_base.img with ext3 and vm_base-swap.img with swap:

mkfs.ext3 /vserver/images/vm_base.img

When you see the following, answer with y:

/vserver/images/mail.img is not a block special device.
Proceed anyway? (y,n) <-- y

mkswap /vserver/images/vm_base-swap.img

4.1 Install A Basic Debian In The Image

In order to install a basic Debian system in our image, we mount the image, run debootstrap and a few other commands:

mount -o loop /vserver/images/vm_base.img /vserver/vm_base
debootstrap --arch i386 sarge /vserver/vm_base/

chroot /vserver/vm_base

You are asked the following question:

Archive access method for apt: <-- http

Then select a mirror close to you.

Afterwards, edit /etc/apt/sources.list and replace testing with stable. That's how my /etc/apt/sources.list looks:

vi /etc/apt/sources.list

deb stable main
deb-src stable main

deb stable/updates main

Then run

apt-get update

Now we set up our locales. If we do not do this now, we will see some ugly warnings during base-config like these:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = "en_DE:en_US:en_GB:en",
LC_ALL = (unset),
LANG = "en_US"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory

They are not serious, but ugly... So we run

apt-get install localeconf

Select locales to install (e.g. en_US ISO-8859-1) and select the standard locale (e.g. en_US).

You will be asked a few questions:

Manage locale configuration files with debconf? <-- Yes
Environment settings that should override the default locale: <-- do not select anything
Replace existing locale configuration files? <-- Yes
Default system locale: <-- e.g. en_US ISO-8859-1

Next run


You will see a menu with installation options. This is what we do:

  1. Configure timezone
  2. Set up users and passwords
  3. Select and install packages (when it comes to Choose software to install:, you can choose whatever you like; I, however, choose nothing because I want to install a basic system.)
  4. Finish configuring the base system

Don't deal with the other menu items, you don't need them. Then we remove nfs-common and delete /etc/hostname:

apt-get remove nfs-common
rm -f /etc/hostname

Then edit /etc/fstab. It should look like this:

vi /etc/fstab

/dev/hda1               /               ext3    defaults        1       2
/dev/hda2 none swap sw 0 0
/dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0

Change /etc/network/interfaces to look like this:

vi /etc/network/interfaces

auto lo
iface lo inet loopback

Then create /etc/hosts:

vi /etc/hosts       localhost.localdomain   localhost

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Now we leave the chroot environment:


Then we copy over the kernel modules to our virtual machine image and unmount the image:

cp -dpR /lib/modules/ /vserver/vm_base/lib/modules/
mv /vserver/vm_base/lib/tls /vserver/vm_base/lib/tls.disabled
umount /vserver/vm_base

If you get a warning like this: umount: /vserver/vm_base: device is busy don't worry about it, it's not important.

Now our virtual machine image template is ready!

Share this page:

13 Comment(s)

Add comment


From: Anonymous at: 2006-04-07 08:46:05

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!



From: Anonymous at: 2006-06-15 07:20:56

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

From: Anonymous at: 2006-06-15 08:42:24

apt-get install libgpmg1-dev is required also, because qemu fails with the test for static SDL library.

From: at: 2007-04-14 20:11:25

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.


From: Anonymous at: 2006-07-31 18:47:40

I just installed the lastest version of Xen and there are a couple additional steps necessary (in at least some configurations).

Specifically, I needed to create an initrd that didn't use devfs.

How I did it; After step 3.1.1:

Install yaird from

     see for how to use

      and for specifics of yaird


depmod 2.6.16-xen


yaird -o /boot/initrd.img-2.6.16-xen 2.6.16-xen


Then the /boot/grub/menu.lst should look like

title Xen 3.0 / XenLinux 2.6.12

kernel /xen.gz dom0_mem=64000

module /vmlinuz-2.6.12-xen0 root=/dev/hda6 ro console=tty0

module /initrd.img-2.6.16-xen



From: spetersons at: 2008-12-11 20:34:19

I was just using your tutorial and just though one small adjustment needs to be made just to update to xen-3.02. Here is the link I found everything else so far seems to be the same except needing to change the 1 to a 2 on each step that has xen-3.01.

From: Anonymous at: 2006-04-17 03:31:19

I got this tip from the how to at:

That howto is a little less detailed than yours but is the only one I found that allows large memory systems which I figure are common in the Xen world.

Alternatively, if your box has 4GB or more RAM, you will want to
enable PAE so the Xen kernel can see the extra memory. So replace the make world with

 make XEN_TARGET_X86_PAE=y world
and the make install with
 make XEN_TARGET_X86_PAE=y install

From: Anonymous at: 2006-06-06 19:24:49

dont forget install latex package to install xen docs.

bruno taranto

From: Anonymous at: 2006-04-03 19:07:10

If you get a warning like this: umount: /vserver/vm_base: device is busy don't worry about it, it's not important.

Are you sure? It at least means it hasn't been umounted. At least try
umount -l /vservrer/vm_base


umount -fl /vservrer/vm_base

but -f could be dangerous depending why it failed

If you want to know why the umount failed:

fuser -m /vserver/vm_base

to see which processes are using files on that mount point.

From: Anonymous at: 2006-04-26 10:51:50

it is because of the atd daemon. Maybe it is launched by base-config. You have to kill this daemon and then umount the filesystem. Then you can restart the daemon.

From: Anonymous at: 2006-05-02 16:58:36

When I run base-config I get the error:


I resolved executing these commands:

mount -t proc proc /proc
cd /dev
./MAKEDEV generic

From: Anonymous at: 2006-06-08 23:27:18

Also need:

mount -t devpts none /dev/pts

From: Anonymous at: 2006-03-22 13:35:27

I prefer to use LVM2 for domU partitions, how about the others?