X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=system%2Ftemplate-qemu%2Fqemu-start-node;h=7198b0352204e6062d5af6666b0c50339e6c71a6;hb=668b04ee255f8fc61d56e81b16d1fefa1de64773;hp=8556f4fc0d3c7e4020afdcb312d898f5c8f3f22e;hpb=3186b0ad726b273f629092591a250f19b112bc9d;p=tests.git diff --git a/system/template-qemu/qemu-start-node b/system/template-qemu/qemu-start-node index 8556f4f..7198b03 100755 --- a/system/template-qemu/qemu-start-node +++ b/system/template-qemu/qemu-start-node @@ -1,17 +1,34 @@ #!/bin/bash +# Thierry Parmentelat +# Copyright (C) 2010 INRIA +# +# it does the following: +# (*) close all file descriptors and redirect output to log.txt +# this is because it is designed for use through ssh from a remote test master controller +# (*) initialize a disk image if it does not exist yet +# (*) starts a qemu instance + # cd in this command's directory COMMAND=$(basename $0) cd $(dirname $0) ########## globals -RAM=1024 -DISK_SIZE=18G -HDA=hdd-cow2-${DISK_SIZE}.img -QEMU_CREATE_IMAGE="qemu-img create -f qcow2 $HDA ${DISK_SIZE}" +# 2 gigabytes ram +RAM=2048 +DISK_SIZE=100G +DISK_FORMAT=qcow2 +DISK_IMAGE=hdd-${DISK_FORMAT}-${DISK_SIZE}.img SCRIPT=qemu-ifup -TAP="tap,script=$SCRIPT" + +####### we want this script to be invokable through ssh without the ssh client to remain hanging +# close stdin +exec <&- +# redirect stdout +exec >> log.txt +# redirect stderr on stdout +exec 2>&1 ########## from the test environment # expected vars are MACADDR, NODE_ISO, HOSTNAME, IP and TARGET_ARCH @@ -19,26 +36,38 @@ CONFIG=qemu.conf [ -f "$CONFIG" ] || { echo "Config file for qemu $CONFIG not found in $(pwd)" ; exit 1 ; } . $CONFIG -# the launcher, depending on local/target archs +# NOTE: check if the machine supports 64bits. We'll add -no-kqemu only +# if it does. On 32bits host, qemu-system-x86_64 doesn't accept this +# parameter (although it's there in the man page) +function is_64bits () { + return $(cat /proc/cpuinfo | grep "^flags" | grep " lm " > /dev/null) +} + + +# the launcher, depending on target arch # make sure to check qemu-kill-node for consistency -archs="$(uname -i)+$TARGET_ARCH" -case $archs in - i386+i386) QEMU=qemu;; - i386+x86_64) QEMU=qemu-system-x86_64;; - x86_64+i386) QEMU=qemu;; - x86_64+x86_64) QEMU=qemu-system-x86_64;; -esac + +# use kvm if available +has_kvm=$(type -p qemu-kvm) +if [ -n "$has_kvm" ] ; then + QEMU="qemu-kvm" ; ARGS="" +else + case $TARGET_ARCH in + i386) QEMU=qemu ; ARGS="" ;; + x86_64) QEMU=qemu-system-x86_64 ; if is_64bits; then ARGS="-no-kqemu"; else ARGS=""; fi ;; + *) echo "Cannot handle TARGET_ARCH=$TARGET_ARCH"; exit 1 ;; + esac +fi echo "Running $COMMAND in $(pwd)" echo "Starting at $(date)" -#Creating new HDA if needed only -#using qcow2 disk image format which is essential to support VM snapshots -if [ -f $HDA ] ; then - echo "Using existing $HDA" +#Creating new DISK_IMAGE if needed only +if [ -f $DISK_IMAGE ] ; then + echo "Using existing $DISK_IMAGE" else - echo -n "Creating hard disk image (${DISK_SIZE}) as $HDA .. " - img=$($QEMU_CREATE_IMAGE) + echo -n "Creating hard disk image (${DISK_SIZE}) as $DISK_IMAGE .. " + img=$(qemu-img create -f ${DISK_FORMAT} $DISK_IMAGE ${DISK_SIZE}) if [ -z "$img" ];then echo "Failed" exit 1 @@ -46,9 +75,35 @@ else echo "Done" fi +echo 'Trying to load the kqemu module' +if modprobe kqemu &> /dev/null ; then + echo "kqemu loaded" +else + echo "WARNING : Could not modprobe kqemu" +fi + +echo 'Checking for a loaded kqemu module' +lsmod | grep kqemu +echo 'Checking for /dev/kqemu' +ls -l /dev/kqemu + +echo 'Cleaning up pid file' rm -f qemu.pid -#Command for running the Qemu Emulator -ARGS="-boot d -net nic,macaddr=${MACADDR} -net $TAP, -cdrom ${NODE_ISO} -hda ${HDA} -m ${RAM} -nographic -pidfile qemu.pid" -echo "Running $QEMU $ARGS < /dev/null" -exec $QEMU $ARGS < /dev/null + + +# qemu options +# basics +ARGS="$ARGS -m ${RAM}" +ARGS="$ARGS -hda ${DISK_IMAGE}" +ARGS="$ARGS -nographic" +ARGS="$ARGS -pidfile qemu.pid" +# boot from CD +ARGS="$ARGS -boot d" +ARGS="$ARGS -cdrom ${NODE_ISO}" +# set mac address +ARGS="$ARGS -net nic,macaddr=${MACADDR}" +# set init script +ARGS="$ARGS -net tap,script=${SCRIPT}" +echo "Running $QEMU $ARGS" +exec $QEMU $ARGS &