On 20.01.2013, at 00:21, Laurent Vivier wrote:

> sudo qemu-create-lxc.sh <target>
> 
> This script mixes linux container, binfmt and qemu to create hybrid linux
> container : <target> container on an host kernel.
> 
> It will create "light" emulated virtual machine with several steps :
> - create a linux-user qemu-<target>
> - define it as the binfmt interpreter (using qemu-update-binfmt).
> - install a base debian system under /containers/<target> using debootstrap.
>  and set a minimal configuration.
> - define a linux container
> 
> Then you can start the container using : sudo lxc-start -n virt<target>
> 
> TARGETS STATUS:
> 
> alpha: cannot run debootstrap --second stage*, but chroot is usable
> m68k: need patches from qemu-m68k, after that, all is working fine.
> mips: container can be started, but console login hangs.
> ppc: works fine*
> sparc: cannot run debootstrap --second stage (cannot fork)
> raspberrypi: (=armhf+raspbian) works*
> 
> * needs patches I sent to the mailing-list previously
> 
> Signed-off-by: Laurent Vivier <laur...@vivier.eu>
> ---
> scripts/qemu-create-lxc.sh |  280 ++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 280 insertions(+)
> create mode 100755 scripts/qemu-create-lxc.sh
> 
> diff --git a/scripts/qemu-create-lxc.sh b/scripts/qemu-create-lxc.sh
> new file mode 100755
> index 0000000..4d51e61
> --- /dev/null
> +++ b/scripts/qemu-create-lxc.sh
> @@ -0,0 +1,280 @@
> +QEMU_PATH=$(dirname $(dirname $(readlink -f $0)))
> +
> +TARGET_LIST="i386 m68k alpha sparc mips ppc raspberrypi"
> +
> +set_i386() {
> +     : nothing specific
> +}
> +
> +set_m68k() {
> +     DEBIAN_REPO=http://archive.debian.org/debian
> +     DEBIAN_DIST=etch-m68k
> +     DEBIAN_SIGN=55BE302B
> +
> +        CONFIGURE_PARAMS=--m68k-default-cpu=m68040
> +}
> +
> +set_alpha() {
> +     DEBIAN_REPO=http://archive.debian.org/debian
> +     DEBIAN_DIST=lenny
> +}
> +
> +set_sparc() {
> +     QEMU_TARGET=sparc32plus
> +}
> +
> +set_mips() {
> +     : nothing specific
> +}
> +
> +set_ppc() {
> +     DEBIAN_TARGET=powerpc
> +}
> +
> +set_raspberrypi() {
> +     DEBIAN_REPO=http://archive.raspbian.org/raspbian
> +     DEBIAN_DIST=wheezy
> +     DEBIAN_SIGN=""
> +     DEBIAN_TARGET=armhf
> +     QEMU_TARGET=arm
> +}
> +
> +check_target() {
> +     found=0
> +     for available in $TARGET_LIST
> +     do
> +             if [ "$available" = "$TARGET" ]
> +             then
> +                     found=1
> +                     break;
> +             fi
> +     done
> +     if [ $found -eq 0 ]
> +     then
> +             echo "ERROR: unknown target $TARGET" 1>&2
> +             exit 1
> +     fi
> +
> +     # generic values
> +
> +     CONTAINER_NAME=virt${TARGET}
> +     CONTAINER_PATH=/containers/${TARGET}
> +     LXC_CONF=$HOME/lxc-${TARGET}.conf
> +
> +     DEBIAN_REPO=http://ftp.debian.org/debian
> +     DEBIAN_DIST=stable
> +     DEBIAN_SIGN=""
> +     DEBIAN_TARGET=$TARGET
> +
> +     QEMU_TARGET=$TARGET
> +
> +     CHECK_BIN=check_default
> +
> +     # target specific values
> +
> +     set_$TARGET
> +
> +     
> QEMU_BIN=${QEMU_PATH}/build-${QEMU_TARGET}/${QEMU_TARGET}-linux-user/qemu-${QEMU_TARGET}
> +}
> +
> +check_m68k() {
> +     if ${QEMU_BIN} -cpu help | grep -q ">m68040"
> +     then
> +             echo "Found an existing qemu-m68k, use it !" 1>&2
> +             return 0
> +     fi
> +     echo "Found an existing qemu-m68k, but with no m68040 emulation" 1>&2
> +     echo "Please, remove it" 1>&2
> +     echo "m68040 emulation is available from " 1>&2
> +     echo "git clone git://gitorious.org/qemu-m68k/qemu-m68k.git"
> +     exit 1
> +}
> +
> +check_default() {
> +     test -e ${QEMU_BIN}
> +}
> +
> +installed_dpkg() {
> +     dpkg --status "$1" > /dev/null 2>&1
> +}
> +
> +check_env() {
> +     if [ ! -e /etc/debian_version ]
> +     then
> +             echo "ERROR: this script works only on Debian based distro" 1>&2
> +             exit 1
> +     fi
> +     for pkg in zlib1g gcc make debootstrap lxc
> +     do
> +             if  ! installed_dpkg $pkg
> +             then
> +                     echo "ERROR: $pkg is needed" 1>&2
> +                     exit 1
> +             fi
> +     done
> +}
> +
> +create_qemu() {
> +     if [ -e "${QEMU_BIN}" ]
> +     then
> +             if ${CHECK_BIN}
> +             then
> +                     return 0
> +             fi
> +     fi
> +     echo "cd ${QEMU_PATH} && \
> +     mkdir build-${QEMU_TARGET} && \
> +     cd build-${QEMU_TARGET} && \
> +     ../configure --static ${CONFIGURE_PARAMS} \
> +                  --target-list=${QEMU_TARGET}-linux-user && \
> +     make" | sudo -i -u ${SUDO_USER}
> +     if ! ${CHECK_BIN}
> +     then
> +             echo "ERROR: generated qemu binary is invalid !" 1>&2
> +             exit 1
> +     fi
> +}
> +
> +create_root() {
> +     # sanity check
> +
> +     if [ $(readlink -f ${CONTAINER_PATH}/) = "/" ]
> +     then
> +             echo "ERROR: invalid path ${CONTAINER_PATH}" 1>&2
> +             exit 1
> +     fi
> +
> +     # check directory
> +
> +     if [ -e "${CONTAINER_PATH}" ]
> +     then
> +             echo "${CONTAINER_PATH} already exists" 1>&2
> +             echo "Please, remove it" 1>&2
> +             exit 1
> +     fi
> +
> +     # Debian bootstrap
> +
> +     mkdir -p "${CONTAINER_PATH}"
> +     debootstrap --foreign \

I don't think anything running debootstrap belongs in generically sounding QEMU 
source code.


Alex


Reply via email to