* [Qemu-devel] [PATCH] linux-user: Some scripts to create linux container using qemu-linux-user.
@ 2013-01-14 21:36 Laurent Vivier
2013-01-14 21:54 ` Andreas Färber
2013-01-19 23:20 ` [Qemu-devel] [PATCH 1/3] scripts: extract ELF magics from qemu-binfmt-conf.sh Laurent Vivier
0 siblings, 2 replies; 5+ messages in thread
From: Laurent Vivier @ 2013-01-14 21:36 UTC (permalink / raw)
To: qemu-devel; +Cc: Riku Voipio, Laurent Vivier
* sudo qemu-update-binfmt.sh <target>
Call update-binfmts to install /bin/qemu-<target> as the binfmt interpreter.
* 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.sh).
- 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 <laurent@vivier.eu>
---
scripts/qemu-create-lxc.sh | 280 ++++++++++++++++++++++++++++++++++++++++++++
scripts/qemu-update-binfmt | 60 ++++++++++
2 files changed, 340 insertions(+)
create mode 100755 scripts/qemu-create-lxc.sh
create mode 100755 scripts/qemu-update-binfmt
diff --git a/scripts/qemu-create-lxc.sh b/scripts/qemu-create-lxc.sh
new file mode 100755
index 0000000..c6023de
--- /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 \
+ --arch=${DEBIAN_TARGET} \
+ ${DEBIAN_DIST} ${CONTAINER_PATH} \
+ ${DEBIAN_REPO} && \
+
+ # adding qemu binary
+
+ cp ${QEMU_BIN} ${CONTAINER_PATH}/bin && \
+ ${QEMU_PATH}/scripts/qemu-update-binfmt ${QEMU_TARGET}
+
+ # debian bootstrap second stage
+
+ chroot ${CONTAINER_PATH} debootstrap/debootstrap --second-stage
+
+ # configuration
+
+ cat >> ${CONTAINER_PATH}/etc/fstab <<!EOF
+# <file system> <mount point> <type> <options> <dump> <pass>
+proc /proc proc nodev,noexec,nosuid 0 1
+devpts /dev/pts devpts nodev,noexec,nosuid 0 1
+!EOF
+
+ echo "$CONTAINER_NAME" > ${CONTAINER_PATH}/etc/hostname
+ echo "c:2345:respawn:/sbin/getty 38400 console" >> ${CONTAINER_PATH}/etc/inittab
+
+ cat >> ${CONTAINER_PATH}/etc/network/interfaces <<!EOF
+auto eth0
+iface eth0 inet dhcp
+!EOF
+
+ cat >> ${CONTAINER_PATH}/etc/apt/sources.list <<!EOF
+deb ${DEBIAN_REPO} ${DEBIAN_DIST} main contrib non-free
+deb-src ${DEBIAN_REPO} ${DEBIAN_DIST} main contrib non-free
+!EOF
+
+ rm -f ${CONTAINER_PATH}/dev/ptmx
+
+ if [ "$DEBIAN_SIGN" != "" ]
+ then
+ HOME=/root chroot ${CONTAINER_PATH} gpg --keyserver pgpkeys.mit.edu --recv-key ${DEBIAN_SIGN}
+ HOME=/root chroot ${CONTAINER_PATH} gpg -a --export ${DEBIAN_SIGN} | chroot ${CONTAINER_PATH} apt-key add -
+ fi
+ chroot ${CONTAINER_PATH} apt-get update
+ chroot ${CONTAINER_PATH} dpkg-reconfigure tzdata
+ chroot ${CONTAINER_PATH} apt-get install locales
+ chroot ${CONTAINER_PATH} dpkg-reconfigure locales
+ chroot ${CONTAINER_PATH} passwd
+}
+
+create_lxc() {
+ cat > ${LXC_CONF} <<!EOF
+lxc.utsname = ${CONTAINER_NAME}
+
+lxc.network.type = veth
+lxc.network.flags = up
+lxc.network.link = lxcbr0
+lxc.network.name = eth0
+
+lxc.pts=1023
+lxc.tty=12
+
+lxc.rootfs = ${CONTAINER_PATH}
+
+lxc.cgroup.devices.deny = a
+lxc.cgroup.devices.allow = c 136:* rwm # pts
+lxc.cgroup.devices.allow = c 254:0 rwm # rtc
+lxc.cgroup.devices.allow = c 5:* rwm
+lxc.cgroup.devices.allow = c 4:* rwm # ttyXX
+lxc.cgroup.devices.allow = c 1:* rwm
+lxc.cgroup.devices.allow = b 7:* rwm # loop
+lxc.cgroup.devices.allow = b 1:* rwm # ram
+
+!EOF
+ lxc-create -n ${CONTAINER_NAME} -f ${LXC_CONF}
+}
+
+TARGET="$1"
+
+if [ "$TARGET" = "" ]
+then
+ echo "ERROR: you must provide a target." 1>&2
+ echo " Available targets are:" 1>&2
+ echo " $TARGET_LIST"
+ exit 1
+fi
+
+
+check_env
+check_target
+
+echo "DEBIAN_TARGET : ${DEBIAN_TARGET}"
+echo "QEMU_TARGET : ${QEMU_TARGET}"
+echo "CONTAINER_NAME: ${CONTAINER_NAME}"
+echo "CONTAINER_PATH: ${CONTAINER_PATH}"
+echo "QEMU_PATH : ${QEMU_PATH}"
+echo "LXC_CONF : ${LXC_CONF}"
+echo "DEBIAN_REPO : ${DEBIAN_REPO}"
+echo "DEBIAN_DIST : ${DEBIAN_DIST}"
+
+if lxc-list | grep -q ${CONTAINER_NAME}
+then
+ echo "${CONTAINER_NAME} already exists !" 1>&2
+ echo "you can remove it with :" 1>&2
+ echo " sudo lxc-destroy -n ${CONTAINER_NAME}" 1>&2
+ echo "[WARNING: this will remove the directory too]" 1>&2
+ exit 2
+fi
+
+if [ "$USER" != "root" ]
+then
+ echo "You need to be root to run this command" 2>&1
+ exit 3
+fi
+
+create_qemu
+create_root
+create_lxc
+
+chroot ${CONTAINER_PATH} uname -a
+
+echo "you can now start your container using:"
+echo " sudo lxc-start -n ${CONTAINER_NAME}"
diff --git a/scripts/qemu-update-binfmt b/scripts/qemu-update-binfmt
new file mode 100755
index 0000000..ebdd971
--- /dev/null
+++ b/scripts/qemu-update-binfmt
@@ -0,0 +1,60 @@
+#!/bin/bash
+
+name="$1"
+
+# probe cpu type
+cpu=`uname -m`
+case "$cpu" in
+ i386|i486|i586|i686|i86pc|BePC|x86_64)
+ cpu="i386"
+ ;;
+ mips*)
+ cpu="mips"
+ ;;
+ "Power Macintosh"|ppc64)
+ cpu="ppc"
+ ;;
+ armv[4-9]*)
+ cpu="arm"
+ ;;
+esac
+
+if [ "$name" = "$cpu" ]
+then
+ exit 0
+fi
+
+case $name
+in
+ m68k)
+ magic="\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04"
+ mask="\xff\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff"
+ ;;
+ alpha)
+ magic="\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90"
+ mask="\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff"
+ ;;
+ sparc32plus)
+ magic="\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x12"
+ mask="\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff"
+ ;;
+ mips)
+ magic="\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08"
+ mask="\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff"
+ ;;
+ ppc)
+ magic="\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14"
+ mask="\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff"
+ ;;
+ arm)
+ magic="\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00"
+ mask="\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff"
+ ;;
+ *)
+ echo "ERROR: unknown target $name" 1<&2
+ exit 1
+ ;;
+esac
+
+update-binfmts --install $name /bin/qemu-${name} \
+ --magic $magic --mask $mask
--
1.7.10.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] linux-user: Some scripts to create linux container using qemu-linux-user.
2013-01-14 21:36 [Qemu-devel] [PATCH] linux-user: Some scripts to create linux container using qemu-linux-user Laurent Vivier
@ 2013-01-14 21:54 ` Andreas Färber
2013-01-19 23:20 ` [Qemu-devel] [PATCH 1/3] scripts: extract ELF magics from qemu-binfmt-conf.sh Laurent Vivier
1 sibling, 0 replies; 5+ messages in thread
From: Andreas Färber @ 2013-01-14 21:54 UTC (permalink / raw)
To: Laurent Vivier; +Cc: Riku Voipio, qemu-devel, Alexander Graf
Am 14.01.2013 22:36, schrieb Laurent Vivier:
> * sudo qemu-update-binfmt.sh <target>
>
> Call update-binfmts to install /bin/qemu-<target> as the binfmt interpreter.
>
> * 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.sh).
> - 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 <laurent@vivier.eu>
> ---
> scripts/qemu-create-lxc.sh | 280 ++++++++++++++++++++++++++++++++++++++++++++
> scripts/qemu-update-binfmt | 60 ++++++++++
> 2 files changed, 340 insertions(+)
> create mode 100755 scripts/qemu-create-lxc.sh
> create mode 100755 scripts/qemu-update-binfmt
[...]
> diff --git a/scripts/qemu-update-binfmt b/scripts/qemu-update-binfmt
> new file mode 100755
> index 0000000..ebdd971
> --- /dev/null
> +++ b/scripts/qemu-update-binfmt
> @@ -0,0 +1,60 @@
> +#!/bin/bash
> +
> +name="$1"
> +
> +# probe cpu type
> +cpu=`uname -m`
> +case "$cpu" in
> + i386|i486|i586|i686|i86pc|BePC|x86_64)
> + cpu="i386"
> + ;;
> + mips*)
> + cpu="mips"
> + ;;
> + "Power Macintosh"|ppc64)
> + cpu="ppc"
> + ;;
> + armv[4-9]*)
> + cpu="arm"
> + ;;
> +esac
> +
> +if [ "$name" = "$cpu" ]
> +then
> + exit 0
> +fi
> +
> +case $name
> +in
> + m68k)
> + magic="\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04"
> + mask="\xff\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff"
> + ;;
[snip]
Déjà vu... qemu-binfmt-conf.sh already has the magics hardcoded and
registers them via /proc. Please either reuse that script (with a new
parameter if needed) or move the data to a shared script used by both so
that not one is updated and the other forgotten.
The one thing I dislike about the existing script is that it hardcodes
each path to /usr/local/bin, which for openSUSE we need to override.
Your script hardcodes /bin in only one place instead.
Regards,
Andreas
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 1/3] scripts: extract ELF magics from qemu-binfmt-conf.sh
2013-01-14 21:36 [Qemu-devel] [PATCH] linux-user: Some scripts to create linux container using qemu-linux-user Laurent Vivier
2013-01-14 21:54 ` Andreas Färber
@ 2013-01-19 23:20 ` Laurent Vivier
2013-01-19 23:20 ` [Qemu-devel] [PATCH 2/3] scripts: define qemu-update-binfmt Laurent Vivier
2013-01-19 23:21 ` [Qemu-devel] [PATCH 3/3] scripts: A script to create linux container using qemu-linux-user Laurent Vivier
1 sibling, 2 replies; 5+ messages in thread
From: Laurent Vivier @ 2013-01-19 23:20 UTC (permalink / raw)
To: Andreas Färber
Cc: Laurent Vivier, Riku Voipio, qemu-devel, Alexander Graf
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
scripts/binfmts-magic | 93 ++++++++++++++++++++++++++++++++++++++
scripts/qemu-binfmt-conf.sh | 104 +++++++++++++++++++------------------------
2 files changed, 140 insertions(+), 57 deletions(-)
create mode 100644 scripts/binfmts-magic
mode change 100644 => 100755 scripts/qemu-binfmt-conf.sh
diff --git a/scripts/binfmts-magic b/scripts/binfmts-magic
new file mode 100644
index 0000000..13ac820
--- /dev/null
+++ b/scripts/binfmts-magic
@@ -0,0 +1,93 @@
+qemu_target_list="i386 i486 alpha arm sparc ppc m68k mips mipsel \
+ mipsn32 mipsn32el mips64 mips64el sh4 sh4eb s390x"
+
+i386_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00'
+i386_mask='\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
+i386_family=i386
+
+i486_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00'
+i486_mask='\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
+i486_family=i386
+
+alpha_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90'
+alpha_mask='\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
+alpha_family=alpha
+
+arm_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00'
+arm_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
+arm_family=arm
+
+armeb_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28'
+armeb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+armeb_family=arm
+
+sparc_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02'
+sparc_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+sparc_family=sparc
+
+ppc_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14'
+ppc_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+ppc_family=ppc
+
+m68k_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04'
+m68k_mask='\xff\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+m68k_family=m68k
+
+# FIXME: We could use the other endianness on a MIPS host.
+
+mips_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08'
+mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+mips_family=mips
+
+mipsel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00'
+mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
+mipsel_family=mips
+
+mipsn32_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08'
+mipsn32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+mipsn32_family=mips
+
+mipsn32el_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00'
+mipsn32el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
+mipsn32el_family=mips
+
+mips64_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08'
+mips64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+mips64_family=mips
+
+mips64el_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00'
+mips64el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
+mips64el_family=mips
+
+sh4_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00'
+sh4_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
+sh4_family=sh4
+
+sh4eb_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a'
+sh4eb_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+sh4eb_family=sh4
+
+s390x_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16'
+s390x_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+s390x_family=s390x
+
+qemu_get_family() {
+ cpu=$(uname -m)
+ case "$cpu" in
+ i386|i486|i586|i686|i86pc|BePC|x86_64)
+ echo "i386"
+ ;;
+ mips*)
+ echo "mips"
+ ;;
+ "Power Macintosh"|ppc64)
+ echo "ppc"
+ ;;
+ armv[4-9]*)
+ echo "arm"
+ ;;
+ *)
+ echo "$cpu"
+ ;;
+ esac
+}
diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh
old mode 100644
new mode 100755
index 0da2618..6235637
--- a/scripts/qemu-binfmt-conf.sh
+++ b/scripts/qemu-binfmt-conf.sh
@@ -1,69 +1,59 @@
#!/bin/sh
# enable automatic i386/ARM/M68K/MIPS/SPARC/PPC/s390 program execution by the kernel
+MAGIC=$(dirname $(readlink -f "$0"))/binfmts-magic
+
+if [ ! -e "$MAGIC" ] ; then
+ echo "ERROR: file $MAGIC is missing !" 1>&2
+ exit 1
+fi
+
+. "$MAGIC"
+
+QEMU_PATH="$1"
+if [ "$QEMU_PATH" = "" ] ; then
+ QEMU_PATH=/usr/local/bin
+fi
+
# load the binfmt_misc module
if [ ! -d /proc/sys/fs/binfmt_misc ]; then
- /sbin/modprobe binfmt_misc
+ if ! /sbin/modprobe binfmt_misc ; then
+ exit 1
+ fi
fi
if [ ! -f /proc/sys/fs/binfmt_misc/register ]; then
- mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
+ if ! mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc ; then
+ exit 1
+ fi
+fi
+
+if [ ! -w /proc/sys/fs/binfmt_misc/register ] ; then
+ echo "ERROR: cannot write to /proc/sys/fs/binfmt_misc/register" 1>&2
+ exit 1
fi
# probe cpu type
-cpu=`uname -m`
-case "$cpu" in
- i386|i486|i586|i686|i86pc|BePC|x86_64)
- cpu="i386"
- ;;
- m68k)
- cpu="m68k"
- ;;
- mips*)
- cpu="mips"
- ;;
- "Power Macintosh"|ppc|ppc64)
- cpu="ppc"
- ;;
- armv[4-9]*)
- cpu="arm"
- ;;
-esac
+host_family=$(qemu_get_family)
# register the interpreter for each cpu except for the native one
-if [ $cpu != "i386" ] ; then
- echo ':i386:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-i386:' > /proc/sys/fs/binfmt_misc/register
- echo ':i486:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-i386:' > /proc/sys/fs/binfmt_misc/register
-fi
-if [ $cpu != "alpha" ] ; then
- echo ':alpha:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-alpha:' > /proc/sys/fs/binfmt_misc/register
-fi
-if [ $cpu != "arm" ] ; then
- echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-arm:' > /proc/sys/fs/binfmt_misc/register
- echo ':armeb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-armeb:' > /proc/sys/fs/binfmt_misc/register
-fi
-if [ $cpu != "sparc" ] ; then
- echo ':sparc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-sparc:' > /proc/sys/fs/binfmt_misc/register
-fi
-if [ $cpu != "ppc" ] ; then
- echo ':ppc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-ppc:' > /proc/sys/fs/binfmt_misc/register
-fi
-if [ $cpu != "m68k" ] ; then
- echo 'Please check cpu value and header information for m68k!'
- echo ':m68k:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-m68k:' > /proc/sys/fs/binfmt_misc/register
-fi
-if [ $cpu != "mips" ] ; then
- # FIXME: We could use the other endianness on a MIPS host.
- echo ':mips:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mips:' > /proc/sys/fs/binfmt_misc/register
- echo ':mipsel:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mipsel:' > /proc/sys/fs/binfmt_misc/register
- echo ':mipsn32:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mipsn32:' > /proc/sys/fs/binfmt_misc/register
- echo ':mipsn32el:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mipsn32el:' > /proc/sys/fs/binfmt_misc/register
- echo ':mips64:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mips64:' > /proc/sys/fs/binfmt_misc/register
- echo ':mips64el:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mips64el:' > /proc/sys/fs/binfmt_misc/register
-fi
-if [ $cpu != "sh" ] ; then
- echo ':sh4:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-sh4:' > /proc/sys/fs/binfmt_misc/register
- echo ':sh4eb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-sh4eb:' > /proc/sys/fs/binfmt_misc/register
-fi
-if [ $cpu != "s390x" ] ; then
- echo ':s390x:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-s390x:' > /proc/sys/fs/binfmt_misc/register
-fi
+
+for cpu in ${qemu_target_list} ; do
+ magic=$(eval echo \$${cpu}_magic)
+ mask=$(eval echo \$${cpu}_mask)
+ family=$(eval echo \$${cpu}_family)
+
+ if [ "$magic" = "" -o "$mask" = "" -o "$family" = "" ] ; then
+ echo "INTERNAL ERROR: unknown cpu $cpu" 1>&2
+ continue
+ fi
+
+ qemu="$QEMU_PATH/qemu-$cpu"
+ if [ "$cpu" = "i486" ] ; then
+ qemu="$QEMU_PATH/qemu-i386"
+ fi
+
+ if [ "$host_family" != "$family" ] ; then
+ echo "Setting $qemu as binfmt interpreter for $cpu"
+ echo ":$cpu:M::$magic:$mask:$qemu:" > /proc/sys/fs/binfmt_misc/register
+ fi
+done
--
1.7.10.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 2/3] scripts: define qemu-update-binfmt
2013-01-19 23:20 ` [Qemu-devel] [PATCH 1/3] scripts: extract ELF magics from qemu-binfmt-conf.sh Laurent Vivier
@ 2013-01-19 23:20 ` Laurent Vivier
2013-01-19 23:21 ` [Qemu-devel] [PATCH 3/3] scripts: A script to create linux container using qemu-linux-user Laurent Vivier
1 sibling, 0 replies; 5+ messages in thread
From: Laurent Vivier @ 2013-01-19 23:20 UTC (permalink / raw)
To: Andreas Färber
Cc: Laurent Vivier, Riku Voipio, qemu-devel, Alexander Graf
qemu-update-binfmt uses update-binfmts to set qemu as an ELF interpreter
for a given cpu type.
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
scripts/qemu-update-binfmt | 59 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
create mode 100755 scripts/qemu-update-binfmt
diff --git a/scripts/qemu-update-binfmt b/scripts/qemu-update-binfmt
new file mode 100755
index 0000000..eddcf89
--- /dev/null
+++ b/scripts/qemu-update-binfmt
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+if [ ! -f /usr/sbin/update-binfmts ] ; then
+ echo "ERROR: this scripts needs update-binfmts" 1>&2
+ exit 1
+fi
+
+MAGIC=$(dirname $(readlink -f "$0"))/binfmts-magic
+
+if [ ! -e "$MAGIC" ] ; then
+ echo "ERROR: file $MAGIC is missing !" 1>&2
+ exit 1
+fi
+
+. "$MAGIC"
+
+# interpreter to install
+
+cpu="$1"
+if [ "$cpu" = "" ] ; then
+ echo "ERROR: you need to specify the cpu target" 1>&2
+ echo " available targets are:" 1>&2
+ for target in $qemu_target_list ; do
+ echo " $target " 1>&2
+ done
+ exit 1
+fi
+
+# interpreter path
+
+QEMU_PATH="$2"
+if [ "$QEMU_PATH" = "" ] ; then
+ QEMU_PATH=/usr/local/bin
+fi
+
+# probe cpu type
+
+host_family=$(qemu_get_family)
+
+magic=$(eval echo \$${cpu}_magic)
+mask=$(eval echo \$${cpu}_mask)
+family=$(eval echo \$${cpu}_family)
+
+if [ "$magic" = "" -o "$mask" = "" -o "$family" = "" ] ; then
+ echo "INTERNAL ERROR: unknown cpu $cpu" 1>&2
+ exit 1
+fi
+
+if [ "$host_family" = "$family" ] ; then
+ echo "WARNING: don't install interpreter for current cpu !" 1>&2
+ exit 0
+fi
+
+qemu="$QEMU_PATH/qemu-$cpu"
+if [ "$cpu" = "i486" ] ; then
+ qemu="$QEMU_PATH/qemu-i386"
+fi
+
+update-binfmts --install $cpu ${qemu} --magic $magic --mask $mask
--
1.7.10.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 3/3] scripts: A script to create linux container using qemu-linux-user.
2013-01-19 23:20 ` [Qemu-devel] [PATCH 1/3] scripts: extract ELF magics from qemu-binfmt-conf.sh Laurent Vivier
2013-01-19 23:20 ` [Qemu-devel] [PATCH 2/3] scripts: define qemu-update-binfmt Laurent Vivier
@ 2013-01-19 23:21 ` Laurent Vivier
1 sibling, 0 replies; 5+ messages in thread
From: Laurent Vivier @ 2013-01-19 23:21 UTC (permalink / raw)
To: Andreas Färber
Cc: Laurent Vivier, Riku Voipio, qemu-devel, Alexander Graf
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 <laurent@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 \
+ --arch=${DEBIAN_TARGET} \
+ ${DEBIAN_DIST} ${CONTAINER_PATH} \
+ ${DEBIAN_REPO} && \
+
+ # adding qemu binary
+
+ cp ${QEMU_BIN} ${CONTAINER_PATH}/bin && \
+ ${QEMU_PATH}/scripts/qemu-update-binfmt ${QEMU_TARGET} /bin
+
+ # debian bootstrap second stage
+
+ chroot ${CONTAINER_PATH} debootstrap/debootstrap --second-stage
+
+ # configuration
+
+ cat >> ${CONTAINER_PATH}/etc/fstab <<!EOF
+# <file system> <mount point> <type> <options> <dump> <pass>
+proc /proc proc nodev,noexec,nosuid 0 1
+devpts /dev/pts devpts nodev,noexec,nosuid 0 1
+!EOF
+
+ echo "$CONTAINER_NAME" > ${CONTAINER_PATH}/etc/hostname
+ echo "c:2345:respawn:/sbin/getty 38400 console" >> ${CONTAINER_PATH}/etc/inittab
+
+ cat >> ${CONTAINER_PATH}/etc/network/interfaces <<!EOF
+auto eth0
+iface eth0 inet dhcp
+!EOF
+
+ cat >> ${CONTAINER_PATH}/etc/apt/sources.list <<!EOF
+deb ${DEBIAN_REPO} ${DEBIAN_DIST} main contrib non-free
+deb-src ${DEBIAN_REPO} ${DEBIAN_DIST} main contrib non-free
+!EOF
+
+ rm -f ${CONTAINER_PATH}/dev/ptmx
+
+ if [ "$DEBIAN_SIGN" != "" ]
+ then
+ HOME=/root chroot ${CONTAINER_PATH} gpg --keyserver pgpkeys.mit.edu --recv-key ${DEBIAN_SIGN}
+ HOME=/root chroot ${CONTAINER_PATH} gpg -a --export ${DEBIAN_SIGN} | chroot ${CONTAINER_PATH} apt-key add -
+ fi
+ chroot ${CONTAINER_PATH} apt-get update
+ chroot ${CONTAINER_PATH} dpkg-reconfigure tzdata
+ chroot ${CONTAINER_PATH} apt-get install locales
+ chroot ${CONTAINER_PATH} dpkg-reconfigure locales
+ chroot ${CONTAINER_PATH} passwd
+}
+
+create_lxc() {
+ cat > ${LXC_CONF} <<!EOF
+lxc.utsname = ${CONTAINER_NAME}
+
+lxc.network.type = veth
+lxc.network.flags = up
+lxc.network.link = lxcbr0
+lxc.network.name = eth0
+
+lxc.pts=1023
+lxc.tty=12
+
+lxc.rootfs = ${CONTAINER_PATH}
+
+lxc.cgroup.devices.deny = a
+lxc.cgroup.devices.allow = c 136:* rwm # pts
+lxc.cgroup.devices.allow = c 254:0 rwm # rtc
+lxc.cgroup.devices.allow = c 5:* rwm
+lxc.cgroup.devices.allow = c 4:* rwm # ttyXX
+lxc.cgroup.devices.allow = c 1:* rwm
+lxc.cgroup.devices.allow = b 7:* rwm # loop
+lxc.cgroup.devices.allow = b 1:* rwm # ram
+
+!EOF
+ lxc-create -n ${CONTAINER_NAME} -f ${LXC_CONF}
+}
+
+TARGET="$1"
+
+if [ "$TARGET" = "" ]
+then
+ echo "ERROR: you must provide a target." 1>&2
+ echo " Available targets are:" 1>&2
+ echo " $TARGET_LIST"
+ exit 1
+fi
+
+
+check_env
+check_target
+
+echo "DEBIAN_TARGET : ${DEBIAN_TARGET}"
+echo "QEMU_TARGET : ${QEMU_TARGET}"
+echo "CONTAINER_NAME: ${CONTAINER_NAME}"
+echo "CONTAINER_PATH: ${CONTAINER_PATH}"
+echo "QEMU_PATH : ${QEMU_PATH}"
+echo "LXC_CONF : ${LXC_CONF}"
+echo "DEBIAN_REPO : ${DEBIAN_REPO}"
+echo "DEBIAN_DIST : ${DEBIAN_DIST}"
+
+if lxc-list | grep -q ${CONTAINER_NAME}
+then
+ echo "${CONTAINER_NAME} already exists !" 1>&2
+ echo "you can remove it with :" 1>&2
+ echo " sudo lxc-destroy -n ${CONTAINER_NAME}" 1>&2
+ echo "[WARNING: this will remove the directory too]" 1>&2
+ exit 2
+fi
+
+if [ "$USER" != "root" ]
+then
+ echo "You need to be root to run this command" 2>&1
+ exit 3
+fi
+
+create_qemu
+create_root
+create_lxc
+
+chroot ${CONTAINER_PATH} uname -a
+
+echo "you can now start your container using:"
+echo " sudo lxc-start -n ${CONTAINER_NAME}"
--
1.7.10.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-01-19 23:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-14 21:36 [Qemu-devel] [PATCH] linux-user: Some scripts to create linux container using qemu-linux-user Laurent Vivier
2013-01-14 21:54 ` Andreas Färber
2013-01-19 23:20 ` [Qemu-devel] [PATCH 1/3] scripts: extract ELF magics from qemu-binfmt-conf.sh Laurent Vivier
2013-01-19 23:20 ` [Qemu-devel] [PATCH 2/3] scripts: define qemu-update-binfmt Laurent Vivier
2013-01-19 23:21 ` [Qemu-devel] [PATCH 3/3] scripts: A script to create linux container using qemu-linux-user Laurent Vivier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).