RAM for test nodes = 1.5 Gb
[tests.git] / system / template-qemu / qemu-start-node
1 #!/bin/bash
2
3 # Thierry Parmentelat <thierry.parmentelat@inria.fr>
4 # Copyright (C) 2010 INRIA 
5 #
6 # it does the following:
7 # (*) close all file descriptors and redirect output to log.txt 
8 #     this is because it is designed for use through ssh from a remote test master controller
9 # (*) initialize a disk image if it does not exist yet
10 # (*) starts a qemu instance 
11
12 # cd in this command's directory
13 COMMAND=$(basename $0)
14 cd $(dirname $0)
15
16 ########## globals
17 # historically we used 1Gb nodes but with fedora20 bootcd with qemu this is not enough
18 # OTOH our test infra is old so 2Gb would be a lot
19 RAM=$((1024+512))
20 DISK_SIZE=100G
21 DISK_FORMAT=qcow2
22 DISK_IMAGE=hdd-${DISK_FORMAT}-${DISK_SIZE}.img
23
24 SCRIPT=qemu-ifup
25
26 ####### we want this script to be invokable through ssh without the ssh client to remain hanging
27 # close stdin
28 exec <&-
29 # redirect stdout
30 exec >> log.txt
31 # redirect stderr on stdout
32 exec 2>&1
33
34 ########## from the test environment
35 # expected vars are MACADDR, NODE_ISO, HOSTNAME, IP and TARGET_ARCH
36 CONFIG=qemu.conf
37 [ -f "$CONFIG" ] || { echo "Config file for qemu $CONFIG not found in $(pwd)" ; exit 1 ; }
38 . $CONFIG
39
40 # NOTE: check if the machine supports 64bits. We'll add -no-kqemu only
41 # if it does. On 32bits host, qemu-system-x86_64 doesn't accept this
42 # parameter (although it's there in the man page)
43 function is_64bits () {
44     return $(cat /proc/cpuinfo | grep "^flags" | grep " lm " > /dev/null)
45 }
46
47
48 # the launcher, depending on target arch
49 # make sure to check qemu-kill-node for consistency
50
51 # use kvm if available
52 has_kvm=$(type -p qemu-kvm)
53 if [ -n "$has_kvm" ] ; then
54     QEMU="qemu-kvm" ; ARGS=""
55 else
56     case $TARGET_ARCH in
57         i386)           QEMU=qemu ; ARGS="" ;;
58         x86_64)         QEMU=qemu-system-x86_64 ; if is_64bits; then ARGS="-no-kqemu"; else ARGS=""; fi ;;
59         *)                      echo "Cannot handle TARGET_ARCH=$TARGET_ARCH"; exit 1 ;;
60     esac
61 fi
62
63 echo "Running $COMMAND in $(pwd)"
64 echo "Starting at $(date)"
65
66 #Creating new DISK_IMAGE if needed only
67 if [ -f $DISK_IMAGE ] ; then
68     echo "Using existing $DISK_IMAGE"
69 else
70     echo -n "Creating hard disk image (${DISK_SIZE}) as $DISK_IMAGE .. "
71     img=$(qemu-img create -f ${DISK_FORMAT} $DISK_IMAGE ${DISK_SIZE})
72     if [ -z "$img" ];then
73         echo "Failed"
74         exit 1
75     fi
76     echo "Done"
77 fi
78
79 echo 'Trying to load the kqemu module'
80 if modprobe kqemu &> /dev/null ; then
81     echo "kqemu loaded"
82 else
83     echo "WARNING : Could not modprobe kqemu"
84 fi
85
86 echo 'Checking for a loaded kqemu module'
87 lsmod | grep kqemu
88 echo 'Checking for /dev/kqemu'
89 ls -l /dev/kqemu
90
91 echo 'Cleaning up pid file'
92 rm -f qemu.pid
93
94
95
96 # qemu options
97 # basics
98 ARGS="$ARGS -m ${RAM}"
99 ARGS="$ARGS -hda ${DISK_IMAGE}"
100 ARGS="$ARGS -nographic"
101 ARGS="$ARGS -pidfile qemu.pid"
102 # boot from CD
103 ARGS="$ARGS -boot d"
104 ARGS="$ARGS -cdrom ${NODE_ISO}"
105 # set mac address
106 ARGS="$ARGS -net nic,macaddr=${MACADDR}"
107 # set init script
108 ARGS="$ARGS -net tap,script=${SCRIPT}"
109 echo "Running $QEMU $ARGS"
110 exec $QEMU $ARGS &