From c99ea567263c932a5b6506b0725d14d087075bc4 Mon Sep 17 00:00:00 2001 From: Andreas Florath Date: Sun, 22 Jan 2017 17:28:41 +0000 Subject: [PATCH] Replace architecture-emulation-binaries with qemu-debootstrap The architecture-emulation-binaries element does for a limited number of architectures on Ubuntu exactly the same as `qemu-debootstrap`. `qemu-debootstrap` comes in the qemu-user-static package that is anyhow used when cross-building an image. This patch replaces the complete architecture-emulation-binaries element with a call to qemu-debootstrap. Change-Id: Ib9667307bfd3ff7592444a2ec5b04aa5365a1872 Signed-off-by: Andreas Florath --- .../README.rst | 24 ------- .../cleanup.d/01-cleanbinary | 12 ---- .../extra-data.d/01-copy-binary | 64 ------------------- .../debootstrap/root.d/08-debootstrap | 12 +++- 4 files changed, 10 insertions(+), 102 deletions(-) delete mode 100644 diskimage_builder/elements/architecture-emulation-binaries/README.rst delete mode 100755 diskimage_builder/elements/architecture-emulation-binaries/cleanup.d/01-cleanbinary delete mode 100755 diskimage_builder/elements/architecture-emulation-binaries/extra-data.d/01-copy-binary diff --git a/diskimage_builder/elements/architecture-emulation-binaries/README.rst b/diskimage_builder/elements/architecture-emulation-binaries/README.rst deleted file mode 100644 index 79aa40fcf..000000000 --- a/diskimage_builder/elements/architecture-emulation-binaries/README.rst +++ /dev/null @@ -1,24 +0,0 @@ -=============================== -architecture-emulation-binaries -=============================== - -This element enables execution for different architectures - -When building an image for an architecture that the host machine -can not execute, we need to chroot into the image to execute code, -and if the host architecture does not match, we need to emulate -the instructions. - -This element does the following: - - * copies the binary file into chroot /usr/bin environment. - Binary file is chosen based on host architecture and - image architecture the user is trying to build. - - If an image we are building for an architecture is not the host - architecture, install tools provided by qemu-user-static - (which needs to be installed) to allow us to run commands - inside the building image. - - This is tested on amd64/i386 architecture to build armhf and arm64 - ubuntu cloud images. diff --git a/diskimage_builder/elements/architecture-emulation-binaries/cleanup.d/01-cleanbinary b/diskimage_builder/elements/architecture-emulation-binaries/cleanup.d/01-cleanbinary deleted file mode 100755 index 76568bce8..000000000 --- a/diskimage_builder/elements/architecture-emulation-binaries/cleanup.d/01-cleanbinary +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then - set -x -fi -set -eu -set -o pipefail - -if [ -x "$TMP_MOUNT_PATH/tmp/clean_up_qemu_binary" ] ; then - "$TMP_MOUNT_PATH/tmp/clean_up_qemu_binary" - rm -rf "$TMP_MOUNT_PATH/tmp/clean_up_qemu_binary" -fi diff --git a/diskimage_builder/elements/architecture-emulation-binaries/extra-data.d/01-copy-binary b/diskimage_builder/elements/architecture-emulation-binaries/extra-data.d/01-copy-binary deleted file mode 100755 index ee970b01e..000000000 --- a/diskimage_builder/elements/architecture-emulation-binaries/extra-data.d/01-copy-binary +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash - -if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then - set -x -fi -set -eu -set -o pipefail - -function clean_up_arch_emulation { - cat <$TMP_MOUNT_PATH/tmp/clean_up_qemu_binary -#!/bin/bash - -set -eux -set -o pipefail - -sudo rm -rf "${TMP_MOUNT_PATH}${1}" -EOF - - sudo chmod +x "$TMP_MOUNT_PATH/tmp/clean_up_qemu_binary" -} - -function check_copy_file { - if [ -f "$1" ] ; then - if [ ! -f "${TMP_MOUNT_PATH}${1}" ]; then - sudo cp "$1" "$TMP_MOUNT_PATH/usr/bin" - clean_up_arch_emulation $1 - fi - else - echo "qemu binary file not found." - exit 1 - fi -} - -function copy_binary { - echo "checking for architecture compatibility..." - img_arch=$2 - if [[ "$host_arch" != "$img_arch" ]]; then - qemu_binary=$1 - check_copy_file $qemu_binary - else - echo "Emulation not required for this host/image architecture combination" - fi -} - -host_arch="$(uname -m)" - -case "$ARCH" in - "i386" | "amd64") - qemu_binary_file="/usr/bin/qemu-i386-static" - copy_binary $qemu_binary_file $ARCH - ;; - "armhf") - qemu_binary_file="/usr/bin/qemu-arm-static" - copy_binary $qemu_binary_file $ARCH - ;; - "arm64" | "aarch64") - qemu_binary_file="/usr/bin/qemu-aarch64-static" - copy_binary $qemu_binary_file $ARCH - ;; - *) - echo "architecture not supported" - exit 1 - ;; -esac diff --git a/diskimage_builder/elements/debootstrap/root.d/08-debootstrap b/diskimage_builder/elements/debootstrap/root.d/08-debootstrap index 36aa40ac9..87f90ecf3 100755 --- a/diskimage_builder/elements/debootstrap/root.d/08-debootstrap +++ b/diskimage_builder/elements/debootstrap/root.d/08-debootstrap @@ -34,6 +34,8 @@ DEBOOTSTRAP_TARBALL=$DIB_IMAGE_CACHE/debootstrap-${DISTRO_NAME}-${DIB_RELEASE}-$ http_proxy=${http_proxy:-} no_proxy=${no_proxy:-} +DEBOOTSTRAP_QEMU="" + if [ -n "$DIB_OFFLINE" -o -n "${DIB_DEBIAN_USE_DEBOOTSTRAP_CACHE:-}" ] && [ -f $DEBOOTSTRAP_TARBALL ] ; then echo $DEBOOTSTRAP_TARBALL found in cache. Using. sudo tar -C $TARGET_ROOT --numeric-owner -xzf $DEBOOTSTRAP_TARBALL @@ -47,7 +49,14 @@ else # Have to --include=python because of dib-run-parts # Have to --include=sudo for pre-install.d use of sudoers files # Have to --include=busybox because initramfs needs it - sudo sh -c "http_proxy=$http_proxy no_proxy=$no_proxy debootstrap --verbose \ + + if [ $(dpkg --print-architecture) != ${ARCH} ]; then + # Target architecture diffrent from host architecture: + # there is the need to call 'qemu-debootstrap'. + DEBOOTSTRAP_QEMU="qemu-" + fi + + sudo sh -c "http_proxy=$http_proxy no_proxy=$no_proxy ${DEBOOTSTRAP_QEMU}debootstrap --verbose \ --variant=minbase \ --components=${DIB_DEBIAN_COMPONENTS} \ --arch=${ARCH} \ @@ -64,7 +73,6 @@ else sudo rm -fr ${TARGET_ROOT}/etc/apt/sources.list \ ${TARGET_ROOT}/etc/apt/sources.list.d - echo Caching debootstrap result in $DEBOOTSTRAP_TARBALL if [ "${DIB_DEBOOTSTRAP_CACHE:-0}" != "0" ]; then sudo tar --numeric-owner -C $TARGET_ROOT -zcf $DEBOOTSTRAP_TARBALL --exclude='./tmp/*' .