xen snippets

Quick step by step on creating a xen environment in Debian Etch

Tagged xen, debian, etch, stable, virtualisointi, virtualisering  Languages bash

Jumpstart with Xen out-of-the-box in Debian Etch stable.

sudo apt-get install xen-tools xen-hypervisor linux-image-xen-amd64 bridge-utils iproute sysfsutils
# [reboot into xen kernel now]
sudo xen-create-image --hostname=db2.aktagon.com \
--size=10Gb --swap=256Mb --ip= \
--netmask= --gateway= \
--force --dir=/work/vserver --memory=512Mb \
--arch=i386 --kernel=/boot/vmlinuz-2.6.18-5-xen-amd64 \
--debootstrap --dist=etch \
--mirror=http://ftp.funet.fi/pub/linux/mirrors/debian/ \
sudo xm create /etc/xen/db1.aktagon.com.cfg

Creating a local Debian mirror for your Xen servers

Tagged xen, debian, etch, local mirror, amd64, anonftpsync, nginx  Languages bash

Once you've bought a dual or quad Xeon and started to experiment with virtualization you will soon want to create your local mirror to make installs lightning fast. This is a step-by-step how i did it.

First create the Xen that will be our mirror server. The size requirements can be found here: Debian mirror sizes The combined size of amd64 architecture and architecture independent files was 39Gb on 1.9.2007. So I made the image 50Gb big. Remember to change this mirror to a location near you.

xen-create-image --hostname=mirrors.aktagon.com \
--size=50Gb --swap=256Mb --ip= \
--netmask= --gateway= \
--force --dir=/work/vserver --memory=256Mb \
--arch=amd64 \
--kernel=/boot/vmlinuz-2.6.18-5-xen-amd64 \
--debootstrap --dist=etch \
--mirror= http://ftp.fi.debian.org/debian/\

Then ssh into your new Xen as root.

ssh -l root mirrors.aktagon.com

Make base configurations for a fresh Xen.

apt-get update && apt-get install locales console-data && dpkg-reconfigure locales

Then get the mirror synchronization script from Debian.

wget "http://www.debian.org/mirror/anonftpsync"
chmod a+x anonftpsync

Then install dependencies for anonftpsync script. Otherwise the script will fail with a -bash: lockfile: command not found error.

apt-get install procmail

Install nginx.

apt-get install nginx

Configure anonftpsync with your favorite editor and change the lines below. These settings will setup a mirror only for amd64 files. You could remove i386 from the excluded architectures, but then a 50Gb image won't fit all the files.

ARCH_EXCLUDE="alpha arm hppa hurd-i386 i386 ia64 m68k mipsel mips powerpc s390 sh sparc source"

Make the log directory.

mkdir -p /var/log/mirroring

Configure nginx by modifying /etc/nginx/nginx.conf with your favorite editor. Just add the autoindex line into server { location / { context

# abbreviated start of file for clarity...
    server {
        listen       80;
        server_name  localhost;

        access_log  /var/log/nginx/localhost.access.log;

        location / {
            root   /var/www;
            # add the line below to allow directory listing
            autoindex  on;
            index  index.html index.htm;
   # abbreviated end of file for clarity...

Do the synchronizing. And wait... for a long while. On a 8/1Mbit cable the first synchronize took roughly 20 hours.


Now modify your /etc/apt/sources.list on existing Xen images to use your local mirror. And remember to create new Xen images using your new mirror :) In the above case the URL is http://mirrors.aktagon.com/debian

NB: there is no public mirrors.aktagon.com available... sorry.

Fix for "Failed to find an unused loop device" when using xen

Tagged xen, debian, xen source, loop devices  Languages bash

If you use Xen and get an error "Failed to find an unused loop device" when you try to create a guest then you are probably using disk images and have run out of loop devices. Each guest uses at least two loop devices. Modify (or create) a file called /etc/modprobe.d/local-loop and add this line:

options loop max_loop=64

Use a number suitable for your needs. With 64 loop devices you can run up to 32 guests on your host, assuming you aren't using loop devices for any other purposes.

Multiple IP addresses on a Xen VM

Tagged xen, multiple ip's  Languages bash

Xen VM's support up to three IP addresses. Just give them as parameters when you create the image. There will be one interface within the Xen and the other IP's are mapped to interface aliases.

xen-create-image ... --ip= --ip= ...

Xen DomU maintenance from Dom0

Tagged xen, domu, dom0, maintenance  Languages bash
xm shutdown xyz
mount -o loop disk.img /mnt/os-image/
chroot /mnt/os-image/

# Do your stuff

umount /mnt/os-image

Resizing a Xen disk image partition

Tagged xen, disk, image, resize  Languages bash
# Stop & backup
xm shutdown sandbox
cp -a sandbox/ sandbox.bk

# Verify MD5 sum
md5sum sandbox/disk.img 
4976347006df34843d29c939b5fc3742  sandbox/disk.img
md5sum sandbox.bk/disk.img 
4976347006df34843d29c939b5fc3742  sandbox.bk/disk.img

# Create a 5Gb temp file
dd if=/dev/zero of=Tempfile bs=1024 count=5000000

# Append it to the existing image
cat Tempfile >> disk.img
rm Tempfile

# Resize the partition
resize2fs -f disk.img

# Check partition & start domU
fsck.ext3 disk.img
xm create -c sandbox.cfg

Xen templates

Tagged xen, template  Languages bash

Description here...

# Docs

# 20 Gb disk image
dd if=/dev/zero of=/srv/xen/mailserver.img oflag=direct bs=1M seek=20470 count=1

# Copy template
cp template.cfg domu.cfg

# Edit template

# Start domU
xm create -c domu.cfg