Commit 820ce6fb authored by Antonio Terceiro's avatar Antonio Terceiro

autopkgtest-build-qemu: build VM images with vmdb2

Ubuntu images can't be created ATM due to a bug in Ubuntu's grub2 package:
https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1786699

However, if I locally hack vmdb2 to not pass the command line option
removed by Ubuntu, Ubuntu images can be created just fine.

Both Debian and Ubuntu images created have been tested with autopkgtest.

Thanks to Simon McVittie for the Debian kernel selection snippet.

Closes: #904972
parent 300ece79
......@@ -46,6 +46,7 @@ virts = chroot \
programs = tools/autopkgtest-buildvm-ubuntu-cloud \
tools/autopkgtest-build-lxc \
tools/autopkgtest-build-lxd \
tools/autopkgtest-build-qemu \
runner/autopkgtest \
$(NULL)
......
......@@ -33,6 +33,7 @@ Suggests:
qemu-system,
qemu-utils,
schroot,
vmdb2,
Breaks: debci (<< 1.7~)
Description: automatic as-installed testing for Debian packages
autopkgtest runs tests on binary packages. The tests are run on the
......
#!/bin/sh
# autopkgtest-build-qemu is part of autopkgtest
# autopkgtest is a tool for testing Debian binary packages
#
# Copyright (C) Antonio Terceiro <terceiro@debian.org>.
#
# Build a QEMU image for using with autopkgtest
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# See the file CREDITS for a full list of credits information (often
# installed as /usr/share/doc/autopkgtest/CREDITS).
set -eu
if [ $# -lt 2 -o $# -gt 5 ]; then
echo "usage: $0 <release> <image> [<mirror>] [<architecture>] [<script>]"
exit 1
fi
if ! which vmdb2 > /dev/null; then
echo "E: vmdb2 not found. This script requires vmdb2 to be installed"
exit 2
fi
release="$1"
image="$2"
mirror="${3:-http://deb.debian.org/debian}"
architecture="${4:-}"
if [ -z "$architecture" ]; then
architecture=$(dpkg --print-architecture)
fi
user_script="${5:-/dev/null}"
# detect apt proxy
# support backwards compatible env var too
AUTOPKGTEST_APT_PROXY=${AUTOPKGTEST_APT_PROXY:-${ADT_APT_PROXY:-}}
if [ -z "$AUTOPKGTEST_APT_PROXY" ]; then
RES=`apt-config shell proxy Acquire::http::Proxy`
if [ -n "$RES" ]; then
eval $RES
else
RES=`apt-config shell proxy_cmd Acquire::http::Proxy-Auto-Detect`
eval $RES
if [ -n "$proxy_cmd" ]; then
proxy=`$proxy_cmd`
fi
fi
if echo "${proxy:-}" | egrep -q '(localhost|127\.0\.0\.[0-9]*)'; then
# set http_proxy for the initial debootstrap
export http_proxy="$proxy"
# translate proxy address to one that can be accessed from the
# running VM
AUTOPKGTEST_APT_PROXY=$(echo "$proxy" | sed -r "s#localhost|127\.0\.0\.[0-9]*#10.0.2.2#")
if [ -n "$AUTOPKGTEST_APT_PROXY" ]; then
echo "Detected local apt proxy, using $AUTOPKGTEST_APT_PROXY as virtual machine proxy"
fi
elif [ -n "${proxy:-}" ]; then
AUTOPKGTEST_APT_PROXY="$proxy"
echo "Using $AUTOPKGTEST_APT_PROXY as container proxy"
# set http_proxy for the initial debootstrap
export http_proxy="$proxy"
fi
fi
script=/bin/true
for s in $(dirname $(dirname "$0"))/setup-commands/setup-testbed \
/usr/share/autopkgtest/setup-commands/setup-testbed; do
if [ -r "$s" ]; then
script="$s"
echo "Using customization script $script ..."
break
fi
done
case "$mirror" in
*ubuntu*)
kernel=linux-image-virtual
;;
*)
case "$architecture" in
(armhf)
kernel=linux-image-armmp
;;
(hppa)
kernel=linux-image-parisc
;;
(i386)
case "$release" in
(jessie)
kernel=linux-image-586
;;
(*)
kernel=linux-image-686
;;
esac
;;
(ppc64)
kernel=linux-image-powerpc64
;;
(*)
kernel="linux-image-$architecture"
;;
esac
;;
esac
vmdb2_config=$(mktemp)
trap "rm -rf $vmdb2_config" INT TERM EXIT
cat > "$vmdb2_config" <<EOF
steps:
- mkimg: "{{ image }}"
size: 20G
- mklabel: msdos
device: "{{ image }}"
- mkpart: primary
device: "{{ image }}"
start: 0%
end: 100%
part-tag: root-part
- mkfs: ext4
partition: root-part
- mount: root-part
fs-tag: root-fs
- debootstrap: $release
mirror: $mirror
target: root-fs
- apt: install
packages:
- $kernel
- ifupdown
fs-tag: root-fs
- chroot: root-fs
shell: |
passwd --delete root
useradd --home-dir /home/user --create-home user
passwd --delete user
echo host > /etc/hostname
- grub: bios
root-fs: root-fs
root-part: root-part
device: "{{ image }}"
console: serial
- mount-virtual-filesystems: root-fs
- shell: '$script \$ROOT'
root-fs: root-fs
- shell: 'chroot \$ROOT sh < $user_script'
root-fs: root-fs
EOF
vmdb2 \
--verbose \
--image="$image".raw \
"$vmdb2_config"
qemu-img convert -O qcow2 "$image".raw "$image".new
rm -f "$image".raw
# replace a potentially existing image as atomically as possible
mv "$image".new "$image"
.TH autopkgtest-build-qemu 1 2014 "Linux Programmer's Manual"
.SH NAME
autopkgtest-build-qemu \- Create autopkgtest virtual machine images for autopkgtest-virt-qemu
.SH SYNOPSIS
.B autopkgtest-build-qemu
.I RELEASE
.I IMAGE
.RI [ MIRROR ]
.RI [ ARCHITECTURE ]
.RI [ SCRIPT ]
.SH DESCRIPTION
.B autopkgtest-build-qemu
creates virtual machine images suitable for use with autopkgtest's QEMU runner
\fBautopkgtest-virt-qemu\fR(1).
Under the hood, it uses \fBvmdb2\fR(1) to create the images.
The \fBMIRROR\fR parameter can be used to control which distrition to install.
It defaults to \fIhttp://deb.debian.org/debian\fR (i.e. Debian), but you can
pass a mirror of any Debian derivative.
It defaults to the native architecture, but you can specify a different one as
fourth parameter.
The path to a script to be executed inside the virtual machine root filesystem
can be passed as the fifth parameter. The script must be a POSIX shell script,
and should not depend on bash-specific features. This script will be executed
inside a \fBchroot\fR(1) call in the virtual machine root filesystem.
Note that you need to call this as root.
You can specify an apt proxy to use in the virtual machine in the
.B $AUTOPKGTEST_APT_PROXY
environment variable. If you have an apt proxy configured on the host, the
virtual machine will automatically use this, otherwise there is no default.
.SH EXAMPLES
# autopkgtest-build-qemu unstable /path/to/debian-unstable.img
.PP
$ sudo autopkgtest-build-qemu stable /path/to/debian-stable-i386.img i386
.PP
$ sudo autopkgtest-build-qemu bionic /path/to/ubuntu-bionic.img http://archive.ubuntu.com/ubuntu
.SH SEE ALSO
\fBautopkgtest-virt-qemu\fR(1),
\fBvmdb2\fR(1),
\fBautopkgtest\fR(1),
\fB/usr/share/doc/autopkgtest/\fR.
.SH AUTHORS AND COPYRIGHT
.B autopkgtest-build-qemu
was written by Antonio Terceiro <terceirio@debian.org>
This manpage is part of autopkgtest, a tool for testing Debian binary
packages. autopkgtest is Copyright (C) 2006-2018 Canonical Ltd and others.
See \fB/usr/share/doc/autopkgtest/CREDITS\fR for the list of
contributors and full copying conditions.
......@@ -189,38 +189,17 @@ Ubuntu systems these module options are typically already set.
.SS Debian
For Debian you can use
.BR vmdebootstrap(8)
.BR autopkgtest-build-qemu(1)
to build a suitable image. E. g. for unstable:
.RS
.EX
vmdebootstrap --verbose --serial-console --distribution=sid \\
.br
--customize=/usr/share/autopkgtest/setup-commands/setup-testbed \\
.br
--user=test/test --size=10000000000 --grub --image=autopkgtest-sid.raw
.br
qemu-img convert -O qcow2 autopkgtest-sid.raw autopkgtest-sid.img
.br
rm autopkgtest-sid.raw
autopkgtest-build-qemu unstable autopkgtest-unstable.img
.EE
.RE
.B vmdebootstrap
can only create a raw format image; it is recommended to convert it to qcow2 as
that is much smaller (in the order of 700 MB for qcow2 vs. the 10 GB as
specified above) and also supports additional features such as snapshots or
compression. You can run that command with setting the environment variable
.B AUTOPKGTEST_APT_PROXY
to a proxy which will be used by apt in the VM. If you have an apt proxy
configured on the host, this will be used automatically; otherwise you can run
e. g.
.RS
.EX
AUTOPKGTEST_APT_PROXY=http://10.0.2.2:8080 vmdebootstrap [...]
.EE
.RE
See \fBautopkgtest-build-qemu\fR(1) for more information.
.SS Ubuntu
......@@ -251,8 +230,8 @@ autopkgtest gdk-pixbuf -- qemu autopkgtest-trusty-i386-cloud.img
\fBautopkgtest\fR(1),
\fBautopkgtest-schroot\fR(1),
\fBautopkgtest-virt-lxc\fR(1),
\fBautopkgtest-build-qemu\fR(1),
\fBautopkgtest-buildvm-ubuntu-cloud\fR(1),
\fBvmdebootstrap\fR(8),
\fB/usr/share/doc/autopkgtest/\fR.
.SH AUTHORS AND COPYRIGHT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment