<os>
<type arch='x86_64' machine='pc-1.1'>hvm</type>
<kernel>/var/run/kvm-swan-kernel</kernel>
- <cmdline>root=/dev/vda loglevel=1</cmdline>
+ <cmdline>root=/dev/vda1 loglevel=1</cmdline>
<boot dev='hd'/>
</os>
<features>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='file' device='disk'>
- <driver name='qemu' type='raw' cache='writethrough'/>
- <source file='/var/lib/libvirt/images/alice.img'/>
+ <driver name='qemu' type='qcow2' cache='writethrough'/>
+ <source file='/var/lib/libvirt/images/alice.qcow2'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</disk>
<os>
<type arch='x86_64' machine='pc-1.1'>hvm</type>
<kernel>/var/run/kvm-swan-kernel</kernel>
- <cmdline>root=/dev/vda loglevel=1</cmdline>
+ <cmdline>root=/dev/vda1 loglevel=1</cmdline>
<boot dev='hd'/>
</os>
<features>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='file' device='disk'>
- <driver name='qemu' type='raw' cache='writethrough'/>
- <source file='/var/lib/libvirt/images/bob.img'/>
+ <driver name='qemu' type='qcow2' cache='writethrough'/>
+ <source file='/var/lib/libvirt/images/bob.qcow2'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</disk>
<os>
<type arch='x86_64' machine='pc-1.1'>hvm</type>
<kernel>/var/run/kvm-swan-kernel</kernel>
- <cmdline>root=/dev/vda loglevel=1</cmdline>
+ <cmdline>root=/dev/vda1 loglevel=1</cmdline>
<boot dev='hd'/>
</os>
<features>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='file' device='disk'>
- <driver name='qemu' type='raw' cache='writethrough'/>
- <source file='/var/lib/libvirt/images/carol.img'/>
+ <driver name='qemu' type='qcow2' cache='writethrough'/>
+ <source file='/var/lib/libvirt/images/carol.qcow2'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</disk>
<os>
<type arch='x86_64' machine='pc-1.1'>hvm</type>
<kernel>/var/run/kvm-swan-kernel</kernel>
- <cmdline>root=/dev/vda loglevel=1</cmdline>
+ <cmdline>root=/dev/vda1 loglevel=1</cmdline>
<boot dev='hd'/>
</os>
<features>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='file' device='disk'>
- <driver name='qemu' type='raw' cache='writethrough'/>
- <source file='/var/lib/libvirt/images/dave.img'/>
+ <driver name='qemu' type='qcow2' cache='writethrough'/>
+ <source file='/var/lib/libvirt/images/dave.qcow2'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</disk>
<os>
<type arch='x86_64' machine='pc-1.1'>hvm</type>
<kernel>/var/run/kvm-swan-kernel</kernel>
- <cmdline>root=/dev/vda loglevel=1</cmdline>
+ <cmdline>root=/dev/vda1 loglevel=1</cmdline>
<boot dev='hd'/>
</os>
<features>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='file' device='disk'>
- <driver name='qemu' type='raw' cache='writethrough'/>
- <source file='/var/lib/libvirt/images/moon.img'/>
+ <driver name='qemu' type='qcow2' cache='writethrough'/>
+ <source file='/var/lib/libvirt/images/moon.qcow2'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
</disk>
<os>
<type arch='x86_64' machine='pc-1.1'>hvm</type>
<kernel>/var/run/kvm-swan-kernel</kernel>
- <cmdline>root=/dev/vda loglevel=1</cmdline>
+ <cmdline>root=/dev/vda1 loglevel=1</cmdline>
<boot dev='hd'/>
</os>
<features>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='file' device='disk'>
- <driver name='qemu' type='raw' cache='writethrough'/>
- <source file='/var/lib/libvirt/images/sun.img'/>
+ <driver name='qemu' type='qcow2' cache='writethrough'/>
+ <source file='/var/lib/libvirt/images/sun.qcow2'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
</disk>
<os>
<type arch='x86_64' machine='pc-1.1'>hvm</type>
<kernel>/var/run/kvm-swan-kernel</kernel>
- <cmdline>root=/dev/vda loglevel=1</cmdline>
+ <cmdline>root=/dev/vda1 loglevel=1</cmdline>
<boot dev='hd'/>
</os>
<features>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='file' device='disk'>
- <driver name='qemu' type='raw' cache='writethrough'/>
- <source file='/var/lib/libvirt/images/venus.img'/>
+ <driver name='qemu' type='qcow2' cache='writethrough'/>
+ <source file='/var/lib/libvirt/images/venus.qcow2'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</disk>
<os>
<type arch='x86_64' machine='pc-1.1'>hvm</type>
<kernel>/var/run/kvm-swan-kernel</kernel>
- <cmdline>root=/dev/vda loglevel=1</cmdline>
+ <cmdline>root=/dev/vda1 loglevel=1</cmdline>
<boot dev='hd'/>
</os>
<features>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='file' device='disk'>
- <driver name='qemu' type='raw' cache='writethrough'/>
- <source file='/var/lib/libvirt/images/winnetou.img'/>
+ <driver name='qemu' type='qcow2' cache='writethrough'/>
+ <source file='/var/lib/libvirt/images/winnetou.qcow2'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</disk>
EXTRAS=build-essential,gperf,libgmp-dev,libldap2-dev,libcurl4-openssl-dev,libxml2-dev,libtspi-dev,libsqlite3-dev,openssh-server,tcpdump,psmisc,openssl,vim,sqlite3,conntrack,gdb,cmake,libxerces-c2-dev,libltdl-dev,liblog4cxx10-dev,libboost-thread-dev,libboost-system-dev,git-core
SERVICES="isc-dhcp-server apache2 slapd"
PACKAGES=$EXTRAS,${SERVICES// /,}
+
CACHEDIR=$BUILDDIR/cache
APTCACHE=$LOOPDIR/var/cache/apt/archives
rm -f $ROOTFS
echo "`date`, building $ROOTFS" >>$LOGFILE
+
+load_qemu_nbd
+
log_action "Creating image $ROOTFS"
-execute "dd if=/dev/null of=$ROOTFS bs=1M seek=$ROOTFSSIZE count=1"
+execute "qemu-img create -f qcow2 $ROOTFS ${ROOTFSSIZE}M"
+
+log_action "Connecting image to NBD device $NBDEV"
+execute "qemu-nbd -c $NBDEV $ROOTFS"
+sync
+
+log_action "Partitioning disk"
+sfdisk /dev/nbd0 -D -uM >>$LOGFILE 2>&1 << EOF
+;
+EOF
+if [ $? != 0 ]
+then
+ log_status 1
+ exit 1
+else
+ log_status 0
+fi
log_action "Creating ext3 filesystem"
-execute "mkfs.ext3 -F $ROOTFS"
+execute "mkfs.ext3 $NBDPARTITION"
-log_action "Mounting image to $LOOPDIR"
-execute "mount -o loop $ROOTFS $LOOPDIR"
+log_action "Mounting $NBDPARTITION to $LOOPDIR"
+execute "mount $NBDPARTITION $LOOPDIR"
-log_action "Mounting cache to $CACHEDIR"
+log_action "Using $CACHEDIR as archive for apt"
mkdir -p $APTCACHE
execute "mount -o bind $CACHEDIR $APTCACHE"
-do_on_exit umount -l $APTCACHE
-do_on_exit umount -l $LOOPDIR
+do_on_exit graceful_umount $APTCACHE
+do_on_exit graceful_umount $LOOPDIR
+do_on_exit qemu-nbd -d $NBDEV
log_action "Running debootstrap ($ROOTFSSUITE, $ROOTFSARCH)"
execute "debootstrap --arch=$ROOTFSARCH --include=$PACKAGES $ROOTFSSUITE $LOOPDIR $ROOTFSMIRROR"
-log_action "Disabling root password"
-execute_chroot "passwd -d root"
-
for service in $SERVICES
do
log_action "Stopping service $service"
log_action "Disabling service $service"
execute_chroot "update-rc.d -f $service remove"
done
+
+log_action "Disabling root password"
+execute_chroot "passwd -d root"
#!/bin/bash
-# create UML host file systems
+# create specific guest images
#
# Copyright (C) 2004 Eric Marchionni, Patrik Rayo
# Zuercher Hochschule Winterthur
[ `id -u` -eq 0 ] || die "You must be root to run $0"
-BASE=$BUILDDIR/base.img
+BASE=$BUILDDIR/base.qcow2
HOSTSDIR=$PWD/hosts
[ -f $BASE ] || die "Base image $BASE not found"
[ -f $HOSTDIR ] || die "Hosts directory $HOSTSDIR not found"
+load_qemu_nbd
+
mkdir -p $BUILDDIR
mkdir -p $LOOPDIR
for host in $HOSTS
do
log_action "Creating guest image for $host"
- execute "cp $BASE $ROOTFSDIR/$host.img" 0
- execute "mount -o loop $ROOTFSDIR/$host.img $LOOPDIR" 0
+ execute "qemu-img create -b $BASE -f qcow2 $ROOTFSDIR/$host.qcow2" 0
+ execute "qemu-nbd -c $NBDEV $ROOTFSDIR/$host.qcow2" 0
+ sync
+ execute "mount $NBDPARTITION $LOOPDIR" 0
execute "cp -rf $HOSTSDIR/${host}/etc $LOOPDIR" 0
execute "cp -rf $HOSTSDIR/default/etc $LOOPDIR" 0
if [ "$host" = "winnetou" ]
execute_chroot "chown -R openldap:openldap /var/lib/ldap" 0
fi
sync
+ execute "umount $LOOPDIR" 0
+ execute "qemu-nbd -d $NBDEV" 0
log_status 0
- umount $LOOPDIR
done
#!/bin/bash
-# Create UML root filesystem
+# Create guest root image
#
# Copyright (C) 2004 Eric Marchionni, Patrik Rayo
# Zuercher Hochschule Winterthur
[ -f "$ROOTFS" ] || die "Root image $ROOTFS not found"
+load_qemu_nbd
+
mkdir -p $ROOTFSDIR
mkdir -p $LOOPDIR
mkdir -p $ROOTFSCOMPILEDIR
cd $ROOTFSDIR
-BASE=$BUILDDIR/base.img
+BASE=$BUILDDIR/base.qcow2
log_action "Creating $BASE"
execute "cp $ROOTFS $BASE"
-log_action "Mounting base image $BASE"
-execute "mount -o loop $BASE $LOOPDIR"
+log_action "Connecting base image to NBD device $NBDEV"
+execute "qemu-nbd -c $NBDEV $BASE"
+sync
+
+log_action "Mounting $NBDPARTITION to $LOOPDIR"
+execute "mount $NBDPARTITION $LOOPDIR"
+
log_action "Mounting proc filesystem to $LOOPDIR/proc"
execute "mount -t proc none $LOOPDIR/proc"
do_on_exit umount $LOOPDIR/root/compile
do_on_exit umount $LOOPDIR/proc
do_on_exit umount $LOOPDIR
+do_on_exit qemu-nbd -d $NBDEV
echo "Installing software from source"
RECPDIR=$TESTDIR/testing/scripts/recipes
fi
}
+# wait for a mount to disappear
+# $1 - device/image to wait for
+# $2 - maximum time to wait in seconds, default is 5 seconds
+graceful_umount()
+{
+ secs=$2
+ [ ! $secs ] && secs=5
+
+ let steps=$secs*100
+ for i in `seq 1 $steps`
+ do
+ umount $1 >>$LOGFILE 2>&1
+ mount | grep $1 >/dev/null 2>&1
+ [ $? -eq 0 ] || return 0
+ sleep 0.01
+ done
+
+ return 1
+}
+
+# load qemu NBD kernel module, if not already loaded
+load_qemu_nbd()
+{
+ lsmod | grep ^nbd[[:space:]]* >/dev/null 2>&1
+ if [ $? != 0 ]
+ then
+ log_action "Loading NBD kernel module"
+ execute "modprobe nbd max_part=16"
+ fi
+}
+
#############################################
# search and replace strings throughout a
# whole directory
for host in $STRONGSWANHOSTS
do
- ln -fs $ROOTFSDIR/$host.img $VIRTIMGSTORE/$host.img
+ ln -fs $ROOTFSDIR/$host.qcow2 $VIRTIMGSTORE/$host.qcow2
log_action "Guest $host"
execute "virsh create $CONFDIR/$host.xml"
done
do
log_action "Guest $host"
execute "virsh destroy $host"
- rm -f $VIRTIMGSTORE/$host.img
+ rm -f $VIRTIMGSTORE/$host.qcow2
done
log_action "Removing kernel $KERNEL"
ROOTFSSIZE=1024
ROOTFSSUITE=wheezy
ROOTFSARCH=amd64
-ROOTFS=$BUILDDIR/debian-$ROOTFSSUITE-$ROOTFSARCH.img
+ROOTFS=$BUILDDIR/debian-$ROOTFSSUITE-$ROOTFSARCH.qcow2
ROOTFSMIRROR=http://cdn.debian.net/debian
ROOTFSCOMPILEDIR=$BUILDDIR/compile
ROOTFSDIR=$BUILDDIR/root-fs
# libvirt config
+NBDEV=/dev/nbd0
+NBDPARTITION=${NBDEV}p1
VIRTIMGSTORE=/var/lib/libvirt/images
# Directory where test results will be stored