Xen/Creating DomUs

DomUs are guest operating systems. This guide explains to you several ways to make these for Xen.

Using pre-built OS images
One of the easiest methods of creating domUs is to use a pre-built image - a single file that contains a filesystem and an already installed operating system.

With an existing image, you only need to create the Xen domU configuration file and supply a domU kernel (which can be re-used between several domUs).

http://stacklet.com/ provides pre-built Xen images for a range of common Linux distributions, including CentOS, Debian, Fedora Core, Slackware, and Gentoo.

Using app-emulation/domi
is a set of shell scripts from Gerd Knorr that can be used to build Suse, Fedora, Debian, Ubuntu and Gentoo domUs. domi creates a virtual disk on either a regular file or new LVM2 logical volume.

domi creates Fedora and CentOS domUs using, Debian and Ubuntu domUs using debootstrap, and Gentoo domUs using the regular chroot-style stage3 Gentoo install.

Unmask domi and its dependencies:

Example: File-backed Debian Sarge domU
Settings can be passed to domi as environment variables (ie. NAME=value domi) or through a file passed as the first argument to domi (ie. domi config-file). We'll use a config file:


 * 1) debian-test: initialization (i386)
 * 1) debian-test: initialization (i386)

1+0 records in 1+0 records out 1048576 bytes (1.0 MB) copied, 0.003593 seconds, 292 MB/s Disk geometry for /dev/loop/1: 0kB - 4295MB Disk label type: msdos Number Start   End     Size    Type      File system  Flags 1      1kB     4026MB  4026MB  primary                boot 2      4026MB  4294MB  268MB   primary add map 1-part1 : 0 7863281 linear /dev/loop/1 1 add map 1-part2 : 0 522648 linear /dev/loop/1 7863282
 * 1) debian-test: setup disk (sparse file /var/xen/debian-domU.img)
 * 1) debian-test: setup disk (sparse file /var/xen/debian-domU.img)

Label was truncated. Setting up swapspace version 1, size = 267591 kB LABEL=debian-test-swa, UUID=0328303e-2634-48b9-ace5-1cff6ff95cc2
 * 1) debian-test: setup root fs and swap
 * 1) debian-test: setup root fs and swap


 * 1) debian-test: copy cached debs [/var/cache/domi/debian-sarge]
 * 1) debian-test: copy cached debs [/var/cache/domi/debian-sarge]

15:23:05 URL: ftp://ftp.monash.edu.au/pub/linux/debian/pool/main/d/debootstrap/ [2107] -> ".listing" [1] 15:23:05 URL: ftp://ftp.monash.edu.au/pub/linux/debian/pool/main/d/debootstrap/debootstrap_0.1.17.7woody1_i386.deb [51554] -> "debootstrap_0.1.17.7woody1_i386.deb" [1] 15:23:05 URL: ftp://ftp.monash.edu.au/pub/linux/debian/pool/main/d/debootstrap/debootstrap_0.2.45-0.2_i386.deb [72236] -> "debootstrap_0.2.45-0.2_i386.deb" [1]
 * 1) debian-test: fetching debootstrap from ftp://ftp.monash.edu.au/pub/linux/debian
 * 1) debian-test: fetching debootstrap from ftp://ftp.monash.edu.au/pub/linux/debian

FINISHED --15:23:05-- Downloaded: 125,897 bytes in 3 files


 * 1) debian-test: unpack /var/cache/domi/debian-sarge/debootstrap_0.2.45-0.2_i386.deb
 * 1) debian-test: unpack /var/cache/domi/debian-sarge/debootstrap_0.2.45-0.2_i386.deb

I: Retrieving debootstrap.invalid_dists_sarge_Release I: Validating debootstrap.invalid_dists_sarge_Release I: Retrieving debootstrap.invalid_dists_sarge_main_binary-i386_Packages I: Validating debootstrap.invalid_dists_sarge_main_binary-i386_Packages I: Checking adduser... I: Checking apt... I: Checking apt-utils...
 * 1) debian-test: bootstrap debian sarge from ftp://ftp.monash.edu.au/pub/linux/debian
 * 1) debian-test: bootstrap debian sarge from ftp://ftp.monash.edu.au/pub/linux/debian

. ..

Filesystem          1K-blocks      Used Available Use% Mounted on /dev/mapper/1-part1    3869896    147060   3526256   5% /tmp/domi-6942/mnt
 * 1) debian-test: save downloaded debs [/var/cache/domi/debian-sarge]
 * 1) debian-test: save downloaded debs [/var/cache/domi/debian-sarge]

/dev/mapper/1-part1 umounted del devmap : 1-part1 del devmap : 1-part2
 * 1) debian-test: cleanup: virtual disk
 * 1) debian-test: cleanup: virtual disk


 * 1) debian-test: cleanup: remove tmp files
 * 1) debian-test: cleanup: remove tmp files

Now start the domU and attach to its console:

Linux version 2.6.16.18-xen (root@oak) (gcc version 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)) #12 Wed Jun 7 12:28:59 EST 2006 BIOS-provided physical RAM map: Xen: 0000000000000000 - 0000000008000000 (usable) 136MB LOWMEM available. IRQ lockup detection disabled Built 1 zonelists Kernel command line: ip=:1.2.3.4::::eth0:dhcp root=/dev/xvda1 ro Enabling fast FPU save and restore... done. Enabling unmasked SIMD FPU exception support... done. Initializing CPU#0 PID hash table entries: 1024 (order: 10, 16384 bytes) Xen reported: 1665.426 MHz processor. Dentry cache hash table entries: 32768 (order: 5, 131072 bytes) Inode-cache hash table entries: 16384 (order: 4, 65536 bytes) Software IO TLB disabled vmalloc area: c9000000-fbefa000, maxmem 33ffe000 Memory: 125364k/139264k available (2744k kernel code, 5556k reserved, 816k data, 164k init, 0k highmem) Checking if this processor honours the WP bit even in supervisor mode... Ok. Calibrating delay using timer specific routine.. 3330.63 BogoMIPS (lpj=16653169) Mount-cache hash table entries: 512 CPU: L1 I Cache: 64K (64 bytes/line), D cache 64K (64 bytes/line) CPU: L2 Cache: 256K (64 bytes/line) CPU: AMD Athlon(tm) stepping 01 Checking 'hlt' instruction... OK. Grant table initialized NET: Registered protocol family 16 PCI: setting up Xen PCI frontend stub Generic PHY: Registered new driver xen_mem: Initialising balloon driver. PCI: System does not support PCI PCI: System does not support PCI Initializing Cryptographic API

testing md5 test 1: d41d8cd98f00b204e9800998ecf8427e pass test 2: 0cc175b9c0f1b6a831c399e269772661 pass

. ..

Setting the System Clock using the Hardware Clock as reference... System Clock set. Local time: Wed Jun 14 06:52:44 UTC 2006

Initializing random number generator...done. Recovering nvi editor sessions... done. INIT: Entering runlevel: 2 Starting system log daemon: syslogd. Starting kernel log daemon: klogd. Starting MTA: exim4. Starting internet superserver: inetd. Starting deferred execution scheduler: atd. Starting periodic command scheduler: cron.

Debian GNU/Linux 3.1 (none) tty1

(none) login:

Gentoo domU using quickpkg
The dom0 is a Gentoo system compiled specifically for Xen (through CFLAGS="-mno-tls-direct-seg-refs" in ), and may even be built with your preferred CFLAGS and USE flags.

quickpkg allows you to create binary packages from an existing Gentoo system (such as your dom0), which can be combined with portage's support for alternate ROOTs to quickly create a Gentoo domU with the same CFLAGs as your dom0, without needing to recompile anything or perform a stage1 install.

If you don't already have it, install, as we'll be using equery to list all packages currently installed on the system:

If you're not already using the buildpkg feature in portage, you'll need to create binary packages from your dom0 install using the following script: Alternative

There is an [TIP_Filtering_Packages example] in the tips section of filtering out packages, using USE flags, categories and arbitrary name components.

Create storage for your domU, using your preferred method (eg. loopback file-based image, LVM2 logical volume, physical partition, or EVMS volume). Create a filesystem on this storage and mount it at.

Example: 4GB sparse loopback file-based image with reiserfs filesystem.

Next you need to create and initialize a swap space for use by domU. These instructions use a swap file, but you may want to consider using a seperate partition as a normal system would. For a discussion on the differences between the two, see The Linuxk-Kernel Mailing List: Swap partition vs swap file.

Download a stage3 tarball and unpack it into :

Mount the proc and dev filesystems so they are available from within the chroot environment:

Copy the existing portage tree from dom0. This will also copy the binary packages built earlier, as they are stored in :

Copy dom0's make.conf and to domU, so we're using the correct CFLAGS, CHOST, USE flags etc.

Copy resolv.conf into the chroot environment to ensure we can use internet access:

Make sure dom0 and domU are using the same profile, which is probably default-linux/x86/2008.0 (/desktop or /server)

Use binary packages to create a new Gentoo system in, overwriting config files from the stage3 tarball:

Chroot into the Gentoo domU and run the following. Don't worry about the ominous /usr/bin/python: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory when running gcc-config, as that's what we're fixing here. It seems doesn't play too well with portage's ROOT option, so after the above commands we have an invalid gcc profile selected.

Using the same method as you do for a normal install, set the domU's timezone and hostname.

Install, then use revdep-rebuild to remerge (from our binary packages) anything that still links against a package from the stage tarball.

Tip: You can use the --usepkg flag to emerge any package that was also installed on the dom0 system that the binary packages were created on as long as you want exactly the same USE flags.

Take care of any rebuilds or cleanups required by python and perl updates (using our binary packages, of course).

Install any non-system packages that will be required to boot the domU (eg. ):

Set a password for the domU's root user using:

Finally, exit the chroot environment with:

Create a Xen configuration file for our new domU. In this example, the loopback file will be exposed to the domU as.

Edit domU's to use the swapfile and Xen block device. domUs don't need a boot partition and don't have a CD-ROM or floppy drive, so remove those lines.

Umount the domU filesystem:

Start the domU and attach to its console: xm create gentoo -c

Once the domU running, check that all necessary users for various services as ssh are present in and.

Tip: You can now create a stage4 tarball to use for future Gentoo domUs on the same dom0. Autostart domU

If you want your domU to be started on system boot you have to create symlinks in to your domU configuration file.

Add the xendomains daemon to the default runlevel with:

By Hand
It is possible to create domUs by hand, you can do so as you would normally create any other linux install. Once finished, load it the same way as ttylinux or when it's on disk look at to see how to configure xen to use partitions instead of files.