Re: fakechroot + qemu user emulation
On Sat, Jan 22, 2011, Roger Leigh wrote:
> BTW, now all the work on schroot for squeeze is done, I just set up a
> 1.5.0 development release on the schroot master branch, and I'll look
> at getting your patch merged as soon as I find time.
Awesome; I'ved fixed a couple of bugs in my local version (attached),
but still didn't implement support for script config
--
Loïc Minier
#!/bin/bash
# Copyright (C) 2010 Loïc Minier <lool@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"
exit 0
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/"
Reply to: