[buildd-tools-devel] Bug#604268: QEMU linux-user support

Loïc Minier lool at dooz.org
Sun Nov 21 17:55:23 UTC 2010


Package: schroot
Version: 1.4.15-1
Severity: wishlist
Tags: patch

        Hi there

 I wrote a setup.d snippet which once dropped into
 /etc/schroot/setup.d/11qemu will arrange for a static qemu linux-user
 to be copied into the chroot on setup.  These are provided for many
 architectures in the qemu-user-static (Debian) or qemu-kvm-extras
 (Ubuntu) packages.

 Basically this works thanks to binfmt-misc which will tell the host
 kernel to run a helper program whenever it tries running programs which
 match a specific binary pattern.  The above packages set this up as
 well, so it "just works" upon installation.

 There are limitations to syscall emulation: some syscalls aren't
 implemented, and some things are plainly not simulated (for instance if
 you access files like /proc/cpuinfo, it will return the host's cpuinfo,
 not some simulated one).

 Using QEMU syscall emulation is slow.  Nevertheless, this happens to
 just work for many packages, and it's sometimes handier to use this
 than a porter machine.  It's faster than QEMU machine emulation
 (qemu-system-*).

 I'm attaching the setup.d wrapper; I've used it successfully to start
 sessions in an armel chroot and with sbuild:
    sbuild -d natty --arch armel hello_2.6-1.dsc

 I just downloaded my chroot from Launchpad as I explained in
 Debian #602571, but "qemu-debootstrap" is a debootstrap wrapper doing
 pretty much the same thing which allows creating chroots for schroot
 just as if you'd use debootstrap.  I named my schroot config entry
 "natty-armel" for the above to be picked up.

   Cheers,
-- 
Loïc Minier
-------------- next part --------------
#!/bin/bash
# Copyright (C) 2010 Loïc Minier <lool at dooz.org>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# SOFTWARE IN THE PUBLIC INTEREST, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# Except as contained in this notice, the name of the author shall not be used
# in advertising or otherwise to promote the sale, use or other dealings in
# this Software without prior written authorization from the author.
#
# depends: file, qemu-user-static | qemu-kvm-extras
#
# TODO
# - allow setting the qemu interpreter in the script-config file
# - allow forcing use of qemu even when not particularly needed
# - test support for all architectures
# - add support for more architectures

set -e

self="$(basename "$0")"

. "$SETUP_DATA_DIR/common-data"
. "$SETUP_DATA_DIR/common-functions"

if [ "$STAGE" != "setup-start" ]; then
    info "Stage isn't setup-start; skipping $self"
    exit 0
fi

# outputs QEMU architecture name for specified ELF file; returns 0 on success
# and 1 on failure
get_arch() {
    local file="$1"
    local ouput

    if ! which file >/dev/null; then
        warn "You need \"file\" to use $self"
        return 1
    fi

    if ! output="$(LC_ALL=C file -b "$file")"; then
        warn "Couldn't run \"file -b $file\""
        return 1
    fi

    case "$output" in
      "ELF 32-bit LSB executable, ARM,"*|"ELF 32-bit LSB shared object, ARM,"*)
        echo "arm"
      ;;
      "ELF 32-bit LSB executable, Intel 80386,"*|"ELF 32-bit LSB shared object, Intel 80386,"*)
        echo "i386"
      ;;
      "ELF 32-bit LSB executable, MIPS,"*|"ELF 32-bit LSB shared object, MIPS,"*)
        echo "mipsel"
      ;;
      "ELF 32-bit MSB executable, MIPS,"*|"ELF 32-bit MSB shared object,"*)
        echo "mips"
      ;;
      "ELF 32-bit MSB executable, SPARC32PLUS,"*|"ELF 32-bit MSB shared object, SPARC32PLUS,"*)
        # XXX or is it just sparc?
        echo "sparc32plus"
      ;;
      "ELF 32-bit MSB shared object, PowerPC "*|"ELF 32-bit MSB executable, PowerPC "*)
        echo "powerpc"
      ;;
      "ELF 64-bit LSB executable, Alpha "*|"ELF 64-bit LSB shared object, Alpha "*)
        echo "alpha"
      ;;
      "ELF 64-bit LSB executable, x86-64,"*|"ELF 64-bit LSB shared object, x86-64,"*)
        echo "x86-64"
      ;;
      *)
        warn "Unrecognized file output \"$output\""
        return 1
      ;;
    esac
    return 0
}

if ! system_arch="$(get_arch /bin/true)"; then
    warn "Couldn't identify host architecture; skipping $self"
    exit 0
fi

if ! chroot_arch="$(get_arch "$CHROOT_PATH/bin/true")"; then
    warn "Couldn't identify chroot architecture; skipping $self"
    exit 0
fi

# skip cases where system_arch is the same as chroot_arch, and cases supported
# by biarch
case "$system_arch:$chroot_arch" in
  arm:arm|i386:i386|x86-64:x86-64|i386:x86-64|x86-64:i386)
    info "qemu not needed; skipping $self"
    exit 0
  ;;
esac

if ! qemu="$(which qemu-$chroot_arch-static)"; then
    warn "Couldn't find qemu-$chroot_arch-static; skipping $self"
    exit 0
fi

mkdir -p "$CHROOT_PATH/usr/bin/"
cp -f "$qemu" "$CHROOT_PATH/usr/bin/"



More information about the Buildd-tools-devel mailing list