aboutsummaryrefslogtreecommitdiffstats
path: root/tools/create-image.sh
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/create-image.sh
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/create-image.sh')
-rwxr-xr-xtools/create-image.sh36
1 files changed, 35 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