aboutsummaryrefslogtreecommitdiffstats
path: root/testing/scripts
diff options
context:
space:
mode:
authorReto Buerki <reet@codelabs.ch>2012-12-07 17:54:19 +0100
committerTobias Brunner <tobias@strongswan.org>2013-01-17 16:54:54 +0100
commit8ed98c137321c3f92fb06b58e69aaecf4e531cdc (patch)
tree0dca4366a75f5b44dd55d9026a97312005fe3f8c /testing/scripts
parent7fa27191855eaf828ec3dcf90385e0782f74d2e2 (diff)
downloadstrongswan-8ed98c137321c3f92fb06b58e69aaecf4e531cdc.tar.bz2
strongswan-8ed98c137321c3f92fb06b58e69aaecf4e531cdc.tar.xz
Switch from raw images to qcow2 format
This allows to use minimal copy-on-write clones of the base image as guest images, which in turn saves a lot of disk space.
Diffstat (limited to 'testing/scripts')
-rwxr-xr-xtesting/scripts/build-baseimage41
-rwxr-xr-xtesting/scripts/build-umlhostfs15
-rwxr-xr-xtesting/scripts/build-umlrootfs16
-rwxr-xr-xtesting/scripts/function.sh31
4 files changed, 84 insertions, 19 deletions
diff --git a/testing/scripts/build-baseimage b/testing/scripts/build-baseimage
index b8f709216..c73c45430 100755
--- a/testing/scripts/build-baseimage
+++ b/testing/scripts/build-baseimage
@@ -10,6 +10,7 @@ echo "Building base image"
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
@@ -19,28 +20,45 @@ mkdir -p $CACHEDIR
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"
@@ -48,3 +66,6 @@ do
log_action "Disabling service $service"
execute_chroot "update-rc.d -f $service remove"
done
+
+log_action "Disabling root password"
+execute_chroot "passwd -d root"
diff --git a/testing/scripts/build-umlhostfs b/testing/scripts/build-umlhostfs
index 9c419ac9b..1028ef266 100755
--- a/testing/scripts/build-umlhostfs
+++ b/testing/scripts/build-umlhostfs
@@ -1,5 +1,5 @@
#!/bin/bash
-# create UML host file systems
+# create specific guest images
#
# Copyright (C) 2004 Eric Marchionni, Patrik Rayo
# Zuercher Hochschule Winterthur
@@ -20,12 +20,14 @@ echo "Creating guest images"
[ `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
@@ -41,8 +43,10 @@ do_on_exit umount $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" ]
@@ -58,6 +62,7 @@ do
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
diff --git a/testing/scripts/build-umlrootfs b/testing/scripts/build-umlrootfs
index cf11844ce..c67e4d557 100755
--- a/testing/scripts/build-umlrootfs
+++ b/testing/scripts/build-umlrootfs
@@ -1,5 +1,5 @@
#!/bin/bash
-# Create UML root filesystem
+# Create guest root image
#
# Copyright (C) 2004 Eric Marchionni, Patrik Rayo
# Zuercher Hochschule Winterthur
@@ -22,17 +22,24 @@ echo "Building root image"
[ -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"
@@ -43,6 +50,7 @@ execute "mount -o bind $ROOTFSCOMPILEDIR $LOOPDIR/root/compile"
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
diff --git a/testing/scripts/function.sh b/testing/scripts/function.sh
index 0d4ecb484..d72708246 100755
--- a/testing/scripts/function.sh
+++ b/testing/scripts/function.sh
@@ -117,6 +117,37 @@ do_on_exit()
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