undo changeset:11658 - causes kexec crash anyway
[tests.git] / system / template-qemu / qemu-start-node
1 #!/bin/bash
2 # $Id$
3
4 # it does the following:
5 # (*) close all file descriptors and redirect output to log.txt 
6 #     this is because it is designed for use through ssh from a remote test master controller
7 # (*) initialize a disk image if it does not exist yet
8 # (*) starts a qemu instance 
9
10 # cd in this command's directory
11 COMMAND=$(basename $0)
12 cd $(dirname $0)
13
14 ########## globals
15 # 1 gigabyte ram
16 RAM=1024
17 DISK_SIZE=18G
18 DISK_FORMAT=qcow2
19 DISK_IMAGE=hdd-${DISK_FORMAT}-${DISK_SIZE}.img
20
21 SCRIPT=qemu-ifup
22
23 ####### we want this script to be invokable through ssh without the ssh client to remain hanging
24 # close stdin
25 exec <&-
26 # redirect stdout
27 exec >> log.txt
28 # redirect stderr on stdout
29 exec 2>&1
30
31 ########## from the test environment
32 # expected vars are MACADDR, NODE_ISO, HOSTNAME, IP and TARGET_ARCH
33 CONFIG=qemu.conf
34 [ -f "$CONFIG" ] || { echo "Config file for qemu $CONFIG not found in $(pwd)" ; exit 1 ; }
35 . $CONFIG
36
37 # the launcher, depending on target arch
38 # make sure to check qemu-kill-node for consistency
39 case $TARGET_ARCH in
40     i386)               QEMU=qemu ; ARGS="" ;;
41     x86_64)             QEMU=qemu-system-x86_64 ; ARGS="-no-kqemu" ;;
42     *)                  echo "Cannot handle TARGET_ARCH=$TARGET_ARCH"; exit 1 ;;
43 esac
44
45 echo "Running $COMMAND in $(pwd)"
46 echo "Starting at $(date)"
47
48 #Creating new DISK_IMAGE if needed only
49 if [ -f $DISK_IMAGE ] ; then
50     echo "Using existing $DISK_IMAGE"
51 else
52     echo -n "Creating hard disk image (${DISK_SIZE}) as $DISK_IMAGE .. "
53     img=$(qemu-img create -f ${DISK_FORMAT} $DISK_IMAGE ${DISK_SIZE})
54     if [ -z "$img" ];then
55         echo "Failed"
56         exit 1
57     fi
58     echo "Done"
59 fi
60
61 echo 'Checking for a loaded kqemu module'
62 lsmod | grep kqemu
63 echo 'Checking for /dev/kqemu'
64 ls -l /dev/kqemu
65
66 echo 'Cleaning up pid file'
67 rm -f qemu.pid
68
69
70
71 # qemu options
72 # basics
73 ARGS="$ARGS -m ${RAM}"
74 ARGS="$ARGS -hda ${DISK_IMAGE}"
75 ARGS="$ARGS -nographic"
76 ARGS="$ARGS -pidfile qemu.pid"
77 # boot from CD
78 ARGS="$ARGS -boot d"
79 ARGS="$ARGS -cdrom ${NODE_ISO}"
80 # set mac address
81 ARGS="$ARGS -net nic,macaddr=${MACADDR}"
82 # set init script
83 ARGS="$ARGS -net tap,script=${SCRIPT}"
84 echo "Running $QEMU $ARGS"
85 exec $QEMU $ARGS &