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

Loïc Minier lool at dooz.org
Sun Nov 21 19:41:09 UTC 2010


On Sun, Nov 21, 2010, Roger Leigh wrote:
> 1) It's not checking if $system_arch == $chroot_arch for all
>    arches, just a limited hardcoded set; it should probably
>    exit 0 if the above condition is true before looking for
>    specific pairings.

 Ah right, I initially wanted to do this as I thought I'd add support
 for more arches, then I added support for more arches and forgot to
 update it, exactly as expected  :)

 I'm attaching an updated version which does just that, with a note that
 more biarch cases should be added

> 2) The licence is not the same as the schroot packages, which is
>    GPLv3+.  Would it be OK to have this licenced at GPLv2+ or 3+
>    for compatibility with the rest of the package?

 Yeah; it's just my boilerplate "public domain"-ish snippet, which
 includes permission to sublicense.  You're welcome to change the
 license to GPLv3+ when merging into schroot; you could also keep it as
 is and claim that schroot is distributed under GPLv3+.  (I'm keeping my
 local scripts under this permissive licensing because I'm copy-pasting
 shell snippets I write across scripts and projects.)

> 3) It would be nice to have a configuration in the script-config
>    file to disable support completely, enable it unconditionally,
>    or enable for selected architectures as at present.

 Ok; I wanted to add this support at some point anyway

 I'll look at adding this

> > # - 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
> 
> Setting in script-config will require writing a chroot facet object,
> which is something I'd really like to see support for.  I'm
> especially interested in support for kvm and qemu-kvm and qemu, so
> these would all fit under the same umbrella.
> 
> Currently, we do require that the guest is a chrooted filesystem,
> but I'd like to abstract that to allow running commands in entirely
> isolated virtual systems such as kvm.

 Awesome!  I guess remote machines, or cloud/EC2 vms come to mind as
 well

 It might make sense to look into libvirt for this

    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
# - add more biarch cases

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
if [ "$system_arch" = "$chroot_arch" ]; then
    info "qemu not needed (chroot for same architecture as the system); skipping $self"
fi
case "$system_arch:$chroot_arch" in
  i386:x86-64|x86-64:i386)
    info "qemu not needed (biarch); 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