From 87d58de9c6f3a0801ad6dffa17dbca103c4764a3 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 26 Sep 2006 18:06:21 +0100 Subject: [PATCH] wip Xen support - files from adt-play on samual8 --- debian/changelog | 6 +++ xen/cleanup | 12 +++++ xen/config | 51 ++++++++++++++++++ xen/fixups | 53 +++++++++++++++++++ xen/fixups-inside | 61 +++++++++++++++++++++ xen/on-testbed | 4 ++ xen/pbuilderrc | 65 +++++++++++++++++++++++ xen/setup | 76 +++++++++++++++++++++++++++ xen/vif-common.sh | 1 + xen/vif-script | 62 ++++++++++++++++++++++ xen/with-testbed | 34 ++++++++++++ xen/xen-divert-tls-libc | 45 ++++++++++++++++ xen/xen-divert-tls-libc.before-expand | 45 ++++++++++++++++ xen/xmdomain | 9 ++++ 14 files changed, 524 insertions(+) create mode 100755 xen/cleanup create mode 100644 xen/config create mode 100755 xen/fixups create mode 100755 xen/fixups-inside create mode 100755 xen/on-testbed create mode 100644 xen/pbuilderrc create mode 100755 xen/setup create mode 120000 xen/vif-common.sh create mode 100755 xen/vif-script create mode 100755 xen/with-testbed create mode 100755 xen/xen-divert-tls-libc create mode 100755 xen/xen-divert-tls-libc.before-expand create mode 100644 xen/xmdomain diff --git a/debian/changelog b/debian/changelog index c8baa51..25aac38 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +autopkgtest (0.6.0~0iwj-wip0) edgy; urgency=low + + * Work-in-progress for Xen support. + + -- Ian Jackson Tue, 26 Sep 2006 18:05:50 +0100 + autopkgtest (0.5.3) dapper; urgency=low * Rename package autodebtest => autopkgtest. diff --git a/xen/cleanup b/xen/cleanup new file mode 100755 index 0000000..1b87b3a --- /dev/null +++ b/xen/cleanup @@ -0,0 +1,12 @@ +#!/bin/bash +set -e +. ./config + +mkdir -p $play $snap + +try () { "$@" >/dev/null 2>&1 ||:; } + +try xm destroy $xmname +try umount $lvbase +try dmsetup remove $nsnap +rm -f $lvfsptr diff --git a/xen/config b/xen/config new file mode 100644 index 0000000..61f000a --- /dev/null +++ b/xen/config @@ -0,0 +1,51 @@ +#---------- +# must install +# autopkgtest pbuilder libadns1-bin chiark-utils-bin +# +# /etc/xen/scripts/vif-route-adt +# /etc/default/adt-xen +# /etc/init.d/adt-xen and links +#---------- + +#kernel=/boot/boot/vmlinuz-2.6-xen +kernel=/boot/xen0-linux-2.6.16-1-686 +ramdisk=/boot/xen-initrd + +tbmem=256 +frzmem=32 +fssize=1G +snapsize=100M +cowchunk=8 + +vg=glalonde +#distro=dapper +distro=edgy +pbuilderopts='--mirror http://mirror.relativity.greenend.org.uk/mirror/ubuntu.early' +domain=adt.relativity.greenend.org.uk +sshkey=/root/.ssh/id_dsa_adt + +pfx=adt +guesthname=$distro.$domain +playbase=/var/lib/autopkgtest/xenlvm-play +#hosthname=`hostname -f` +hosthname=samual.relativity.greenend.org.uk +xmname=${pfx}_${distro} + +play=${playbase}/${distro} + +nbase=${pfx}_${distro}_base +lvbaserhs=$vg/$nbase +lvbase=/dev/$lvbaserhs + +nsnap=${pfx}_${distro}_snap +lvsnap=/dev/mapper/$nsnap + +ncowdata=${pfx}_${distro}_cowdata +lvcowdatarhs=$vg/$ncowdata +lvcowdata=/dev/$lvcowdatarhs + +lvfsptrrhs=${pfx}_fs/${distro} +lvfsptr=/dev/$lvfsptrrhs +xmdomain=$play/xmdomain + +guestaddr=`adnshost -t a +Do +Dt +Dc $guesthname` diff --git a/xen/fixups b/xen/fixups new file mode 100755 index 0000000..55cb069 --- /dev/null +++ b/xen/fixups @@ -0,0 +1,53 @@ +#!/bin/sh +set -ex + +dest=$1 +hosthname=$2 +guesthname=$3; shift + +hostaddr=`adnshost -t a +Do +Dt +Dc $hosthname` +guestaddr=`adnshost -t a +Do +Dt +Dc $guesthname` + +echo '---fixups:' + +cp xen-divert-tls-libc \ + fixups-inside \ + $dest/root/ + +mkdir -p $dest/lib/modules +cp -a /lib/modules/`uname -r`/ $dest/lib/modules/. + +mkdir -p /root/.ssh +id_dsa=/root/.ssh/id_dsa_adt +test -f $id_dsa || ssh-keygen -t dsa -N '' -f $id_dsa +mkdir -m 02700 -p $dest/root/.ssh +cp $id_dsa.pub $dest/root/.ssh/authorized_keys + +cat <$dest/etc/init.d/xenethtoolk +#!/bin/sh +case "$1" in +start) + ethtool -K eth0 tx off + ethtool -K eth0 rx off + ;; +esac +END +chmod +x $dest/etc/init.d/xenethtoolk +ln -s ../init.d/xenethtoolk $dest/etc/rc2.d/S21xenethtoolk + +chroot $dest root/fixups-inside "$@" "$hostaddr" "$guestaddr" + +kh=/etc/ssh/ssh_known_hosts +test ! -f $kh || cp $kh $kh.new +exec 3>$kh.new +pfx="$guesthname,$guestaddr" +test ! -f $kh || perl -pe '$_="" if m/^(\S+)\s/ && $1 eq "'$pfx'";' $kh >&3 +for f in $dest/etc/ssh/ssh_host_*_key.pub; do + perl -pe '$_= "'$pfx' ".$_;' $f >&3 +done +exec 3>&- +mv $kh.new $kh + +echo ' +=== adt xen fixups done. +' diff --git a/xen/fixups-inside b/xen/fixups-inside new file mode 100755 index 0000000..a4d4bf4 --- /dev/null +++ b/xen/fixups-inside @@ -0,0 +1,61 @@ +#!/bin/sh +set -ex + +hosthname=$1 +guesthname=$2 +hostaddr=$3 +guestaddr=$4 + +echo '(---' + +cd /root + +perl -i~ -pe 's/ main$/ main universe/ if m/^deb http/' /etc/apt/sources.list +apt-get update + +apt-get -y --force-yes install libc6-xen || ./xen-divert-tls-libc do + +ldconfig + +cat >/etc/fstab </etc/network/interfaces </etc/hostname + +apt-get -y --force-yes install \ + openssh-server ed build-essential + +perl -i~ -wne ' + BEGIN { + $pep= PermitEmptyPasswords; + $want= "$pep no\n"; + $done= 0; + } + if (m/^\s*$pep/oi) { + $_= $want; + $done= 1; + } + $o .= $_; + END { + print $want or die $! unless $done; + print $o or die $!; + } +' /etc/ssh/sshd_config + +echo '---)' diff --git a/xen/on-testbed b/xen/on-testbed new file mode 100755 index 0000000..7a34c8f --- /dev/null +++ b/xen/on-testbed @@ -0,0 +1,4 @@ +#!/bin/sh +set -e +. ./config +ssh -i $sshkey $guestaddr "$@" diff --git a/xen/pbuilderrc b/xen/pbuilderrc new file mode 100644 index 0000000..671a35e --- /dev/null +++ b/xen/pbuilderrc @@ -0,0 +1,65 @@ +# this is your configuration file for pbuilder. +# the file in /usr/share/pbuilder/pbuilderrc is the default template. +# /etc/pbuilderrc is the one meant for editing. +# +# read pbuilderrc.5 document for notes on specific options. + +BASETGZ=/var/cache/pbuilder/base.tgz +#EXTRAPACKAGES=gcc3.0-athlon-builder +#export DEBIAN_BUILDARCH=athlon +BUILDPLACE=/var/cache/pbuilder/build/ +MIRRORSITE=http://ftp.jp.debian.org/debian +#NONUSMIRRORSITE="http://ftp.jp.debian.org/debian-non-US" +#OTHERMIRROR="deb http://www.home.com/updates/ ./" +#export http_proxy=http://your-proxy:8080/ +USEPROC=yes +USEDEVPTS=yes +USEDEVFS=no +BUILDRESULT=/var/cache/pbuilder/result/ + +# specifying the distribution forces the distribution on "pbuilder update" +#DISTRIBUTION=sarge +#specify the cache for APT +APTCACHE="/var/cache/pbuilder/aptcache/" +APTCACHEHARDLINK="no" +REMOVEPACKAGES="lilo" +#HOOKDIR="/usr/lib/pbuilder/hooks" +HOOKDIR="" + +# make debconf not interact with user +export DEBIAN_FRONTEND="noninteractive" + +DEBEMAIL="" + +#for pbuilder debuild +BUILDSOURCEROOTCMD="fakeroot" +PBUILDERROOTCMD="sudo" + +#default is to build everything. Passed on to dpkg-buildpackage +#DEBBUILDOPTS="-b" +DEBBUILDOPTS="" + +#APT configuration files directory +APTCONFDIR="" + +# the username and ID used by pbuilder, inside chroot. Needs fakeroot, really +BUILDUSERID=1234 +BUILDUSERNAME=pbuilder + +# BINDMOUNTS is a space separated list of things to mount +# inside the chroot. +BINDMOUNTS="" + +# Set the debootstrap variant to 'buildd' type. +# DEBOOTSTRAPOPTS[0]='--variant=buildd' +# or work around bug in debootstrap 3.0.0 (314858) +unset DEBOOTSTRAPOPTS + +# Set the PATH I am going to use inside pbuilder: default is "/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin" +export PATH="/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin" + +# SHELL variable is used inside pbuilder by commands like 'su'; and they need sane values +export SHELL=/bin/bash + +# The name of debootstrap command. +DEBOOTSTRAP="debootstrap" diff --git a/xen/setup b/xen/setup new file mode 100755 index 0000000..64c5403 --- /dev/null +++ b/xen/setup @@ -0,0 +1,76 @@ +#!/bin/bash +set -e +. ./config +./cleanup +lvchange -a n $lvcowdata ||: +lvremove $lvbase ||: +lvremove $lvcowdata ||: + +lvcreate -L $fssize -n $lvbase $vg +lvcreate -L $snapsize -n $ncowdata $vg +#dd if=/dev/zero of=$lvbase +mkfs -t ext3 $lvbase + +mkdir -p $play/base +mount $lvbase $play/base + +#--basetgz $play/base.tgz --buildplace + +pbuilder create --configfile ./pbuilderrc --distribution $distro \ + --no-targz --buildplace $play/base \ + $pbuilderopts --debootstrapopts --variant='' + +./fixups $play/base $hosthname $guesthname + +echo " +--- writing $xmdomain --- +" + +hostaddr=`adnshost -t a +Do +Dt +Dc $hosthname` + +cat <$xmdomain +kernel = "$kernel" +memory = $tbmem +root = "/dev/hda1" +extra = "ro console=tty0" +disk = [ "phy:$lvfsptrrhs,hda1,w" ] +vif = [ "bridge=none,mac=00:16:3e:7c:aa:7f,ip=$guestaddr,script=/etc/xen/scripts/vif-route-adt" ] +on_crash = "preserve" +on_reboot = "preserve" +on_shutdown = "preserve" +END + +if [ "x$ramdisk" != x ]; then +cat <>$xmdomain +ramdisk = "$ramdisk" +END +fi + +umount $lvbase + +mkdir -p /dev/${pfx}_fs +ln -sf ../$lvbaserhs $lvfsptr +xm create $xmdomain name=$xmname +retries=10 + +while true; do + if ping -c 1 $guestaddr && ./on-testbed id; then break; fi + if [ $retries -le 0 ]; then + echo >&2 'no response from guest' + xm console $xmname + exit 1 + fi + retries=$(($retries-1)) + sleep 2 +done + +xm mem-set $xmname $frzmem +retries=10 +while sleep 1; do + if xm mem-max $xmname $frzmem; then break; fi + if [ $retries -le 0 ]; then echo >&2 'cannot reduce memory'; exit 1; fi + retries=$(($retries-1)) +done + +xm save $xmname $play/xen-save +rm $lvfsptr diff --git a/xen/vif-common.sh b/xen/vif-common.sh new file mode 120000 index 0000000..044e402 --- /dev/null +++ b/xen/vif-common.sh @@ -0,0 +1 @@ +/etc/xen/scripts/vif-common.sh \ No newline at end of file diff --git a/xen/vif-script b/xen/vif-script new file mode 100755 index 0000000..b94f5fb --- /dev/null +++ b/xen/vif-script @@ -0,0 +1,62 @@ +#!/bin/sh +#============================================================================ +# /etc/xen/vif-route +# +# Script for configuring a vif in routed mode. +# The hotplugging system will call this script if it is specified either in +# the device configuration given to Xend, or the default Xend configuration +# in /etc/xen/xend-config.sxp. If the script is specified in neither of those +# places, then vif-bridge is the default. +# +# Usage: +# vif-route (add|remove|online|offline) +# +# Environment vars: +# vif vif interface name (required). +# XENBUS_PATH path to this device's details in the XenStore (required). +# +# Read from the store: +# ip list of IP networks for the vif, space-separated (default given in +# this script). +#============================================================================ + +exec >/root/u 2>&1 +set -x +date + +dir=$(dirname "$0") +. "$dir/vif-common.sh" + +main_ip=$(dom0_ip) + +case "$command" in + online) + ifconfig ${vif} ${main_ip} netmask 255.255.255.255 \ + broadcast ${main_ip} up + ipcmd='a' + ;; + offline) + ifdown ${vif} + ipcmd='d' + ;; +esac + +if [ "${ip}" ] ; then + # If we've been given a list of IP addresses, then add routes from dom0 to + # the guest using those addresses. + for addr in ${ip} ; do + ip r ${ipcmd} ${addr} dev ${vif} src ${main_ip} + done +fi + +handle_iptable + +date >/root/t + +iptable + +log debug "Successful vif-route $command for $vif." +if [ "$command" == "online" ] +then + success +fi diff --git a/xen/with-testbed b/xen/with-testbed new file mode 100755 index 0000000..b98289b --- /dev/null +++ b/xen/with-testbed @@ -0,0 +1,34 @@ +#!/bin/bash +set -e + +trap 'exit 127' 0 + +. ./config +./cleanup + +modprobe dm-snapshot ||: + +#dd if=/dev/zero of=/dev/$lvcowdata bs=512 count=$cowchunk status=noxfer + +bdsize=$(blockdev --getsize $lvbase) +dmsetup create $nsnap <&1 "usage: $0 do|undo" +esac + +exit 0 diff --git a/xen/xen-divert-tls-libc.before-expand b/xen/xen-divert-tls-libc.before-expand new file mode 100755 index 0000000..f05ffc9 --- /dev/null +++ b/xen/xen-divert-tls-libc.before-expand @@ -0,0 +1,45 @@ +#!/bin/sh + +set -e + +cd /lib + +eachfile () { + find -type f | sh -ec "while read f; do + $1 + done" +} + +case "$#.$1" in +1.'do') + mkdir -p tls-aside + cd tls + find -type d -exec sh -c 'mkdir -p /lib/tls-aside/$1' x '{}' \; + eachfile 'dpkg-divert --add --divert "/lib/tls-aside/$f" "/lib/tls/$f"' + eachfile 'mv "/lib/tls/$f" "/lib/tls-aside/$f"' + chattr +i . + echo 'xen libc workaround enabled, diversions installed: + tls disabled, libc upgrade may be troubled' + ;; +1.'undo') + chattr -i tls + if test -d tls-aside; then + cd tls-aside + eachfile 'mv "/lib/tls-aside/$f" "/lib/tls/$f"' + cd .. + rmdir tls-aside + fi + dpkg-divert --list | perl -ne ' + next unless + s,^local diversion of (/lib/tls/),dpkg-divert --remove $1,; + next unless s, to /lib/tls-aside/\S+$,,; + print or die $!; + ' | sh -e + echo 'xen libc workaround disabled, normal status restored: + tls enabled, libc upgrade definitely possible' + ;; +*) + echo >&1 "usage: $0 do|undo" +esac + +exit 0 diff --git a/xen/xmdomain b/xen/xmdomain new file mode 100644 index 0000000..788aefe --- /dev/null +++ b/xen/xmdomain @@ -0,0 +1,9 @@ +kernel = "/boot/boot/vmlinuz-2.6-xen" +memory = 128 +root = "/dev/hda1" +extra = "ro console=tty0" +disk = [ "phy:glalonde/adt_dapper_base,hda1,w" ] +vif = [ "bridge=none,mac=00:16:3e:7c:aa:7f,ip=172.18.45.65,script=/etc/xen/scripts/vif-route-adt" ] +on_crash = "preserve" +on_reboot = "preserve" +on_shutdown = "preserve" -- 2.30.2