aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAlexander Egorenkov <Alexander.Egorenkov@ibm.com>2020-09-09 07:16:28 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-09-13 16:05:25 +0200
commit86bd8f9d4864e042c137a8f7401bc86342a54a47 (patch)
tree33e12f3cc03076a1ab5bf35c2997e219e74dda0f /tools
parente5f38ffe77e33c32f7bc37b2969bf45f529274c8 (diff)
tools/create-image.sh: support for foreign architectures
Also update sy-env to be able to build the root image inside. Signed-off-by: Alexander Egorenkov <Alexander.Egorenkov@ibm.com>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/create-image.sh36
-rw-r--r--tools/docker/big-env/Dockerfile15
2 files changed, 50 insertions, 1 deletions
diff --git a/tools/create-image.sh b/tools/create-image.sh
index 0967b4c37..b702b75ab 100755
--- a/tools/create-image.sh
+++ b/tools/create-image.sh
@@ -16,6 +16,7 @@ if [ -z ${ADD_PACKAGE+x} ]; then
fi
# Variables affected by options
+ARCH=$(uname -m)
RELEASE=stretch
FEATURE=minimal
SEEK=2047
@@ -25,6 +26,7 @@ PERF=false
display_help() {
echo "Usage: $0 [option...] " >&2
echo
+ echo " -a, --arch Set architecture"
echo " -d, --distribution Set on which debian distribution to create"
echo " -f, --feature Check what packages to install in the image, options are minimal, full"
echo " -s, --size Image size (MB), default 2048 (2G)"
@@ -43,6 +45,10 @@ while true; do
display_help
exit 0
;;
+ -a | --arch)
+ ARCH=$2
+ shift 2
+ ;;
-d | --distribution)
RELEASE=$2
shift 2
@@ -69,6 +75,20 @@ while true; do
esac
done
+# Foreign architecture
+if [ $ARCH != $(uname -m) ]; then
+ # Check for according qemu static binary
+ if ! which qemu-$ARCH-static; then
+ echo "Please install qemu static binary for architecture $ARCH (package 'qemu-user-static' on Debian/Ubuntu/Fedora)"
+ exit 1
+ fi
+ # Check for according binfmt entry
+ if [ ! -r /proc/sys/fs/binfmt_misc/qemu-$ARCH ]; then
+ echo "binfmt entry /proc/sys/fs/binfmt_misc/qemu-$ARCH does not exist"
+ exit 1
+ fi
+fi
+
# Double check KERNEL when PERF is enabled
if [ $PERF = "true" ] && [ -z ${KERNEL+x} ]; then
echo "Please set KERNEL environment variable when PERF is enabled"
@@ -83,7 +103,21 @@ fi
sudo rm -rf $DIR
sudo mkdir -p $DIR
sudo chmod 0755 $DIR
-sudo debootstrap --include=$PREINSTALL_PKGS --components=main,contrib,non-free $RELEASE $DIR
+
+# 1. debootstrap stage
+
+DEBOOTSTRAP_PARAMS="--include=$PREINSTALL_PKGS --components=main,contrib,non-free $RELEASE $DIR"
+if [ $ARCH != $(uname -m) ]; then
+ DEBOOTSTRAP_PARAMS="--arch=$ARCH --foreign $DEBOOTSTRAP_PARAMS"
+fi
+sudo debootstrap $DEBOOTSTRAP_PARAMS
+
+# 2. debootstrap stage: only necessary if target != host architecture
+
+if [ $ARCH != $(uname -m) ]; then
+ sudo cp $(which qemu-$ARCH-static) $DIR/$(which qemu-$ARCH-static)
+ sudo chroot $DIR /bin/bash -c "/debootstrap/debootstrap --second-stage"
+fi
# Set some defaults and enable promtless ssh to the machine for root.
sudo sed -i '/^root/ { s/:x:/::/ }' $DIR/etc/passwd
diff --git a/tools/docker/big-env/Dockerfile b/tools/docker/big-env/Dockerfile
index ec225ed7c..a940cfb5e 100644
--- a/tools/docker/big-env/Dockerfile
+++ b/tools/docker/big-env/Dockerfile
@@ -24,6 +24,21 @@ FROM gcr.io/syzkaller/env
# NetBSD toolchain can be re-built with:
# ./build.sh -j72 -m amd64 -U -T ../tools tools
# ./build.sh -j72 -m amd64 -U -T ../tools -D ../dest distribution
+#
+# To build root image run:
+# docker run -it --rm --privileged --device /dev/loop0 gcr.io/syzkaller/big-env
+# mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
+# create-image.sh -a s390x -d buster
+
+RUN dpkg --add-architecture i386 && \
+ apt-get update && \
+ DEBIAN_FRONTEND=noninteractive apt-get install -y -q --no-install-recommends \
+ # required to build root images.
+ debootstrap ssh-tools qemu-user-static \
+ && \
+ apt-get -y autoremove && \
+ apt-get clean autoclean && \
+ rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log} /tmp/* /var/tmp/*
RUN curl https://storage.googleapis.com/syzkaller/fuchsia-toolchain.tar.gz | tar -C /syzkaller -xz
RUN curl https://storage.googleapis.com/syzkaller/netbsd-toolchain.tar.gz | tar -C /syzkaller -xz