Add support for a runtime argument to choose the runtime type
[training-lab.git] / scripts / start_runtime
1 #!/bin/sh
2
3 SSH_PORT=2222
4 SHARE=/vagrant
5 MEM=512
6 TIMEOUT=600 # 10 minutes
7
8 # Are we native, or running under full emulation?
9 MACHINE=$(uname -m)
10 case $MACHINE in
11     aarch64)
12         if [ "$MACH"x = ""x ] || \
13                [ "$MACH"x = "aarch64"x ] || \
14                [ "$MACH"x = "arm64" ] ; then
15             MACH=aarch64
16             QEMU=qemu-system-aarch64
17             CPU_OPTS="-cpu host --enable-kvm"
18             MACH_OPTS="-machine virt,gic-version=host,kernel_irqchip=on"
19         elif [ "$MACH"x = "arm"x ] ||\
20                 [ "$MACH"x = "arm32" ] ; then
21             MACH=arm
22             QEMU=qemu-system-aarch64
23             CPU_OPTS="-cpu host,aarch64=off --enable-kvm"
24             MACH_OPTS="-machine virt,gic-version=host,kernel_irqchip=on"
25         else
26             echo "Unknown MACH $MACH; abort"
27             exit 1
28         fi
29         ;;
30     *)
31         if [ "$MACH"x = ""x ] || \
32                [ "$MACH"x = "aarch64"x ] || \
33                [ "$MACH"x = "arm64" ] ; then
34             MACH=aarch64
35             QEMU=qemu-system-aarch64
36             CPU_OPTS="-cpu cortex-a57"
37             MACH_OPTS="-M virt"
38         elif [ "$MACH"x = "arm"x ] ||\
39                 [ "$MACH"x = "arm32" ] ; then
40             MACH=arm
41             QEMU=qemu-system-arm
42             CPU_OPTS="-cpu cortex-a15"
43             MACH_OPTS="-M virt"
44         else
45             echo "Unknown MACH $MACH; abort"
46             exit 1
47         fi
48         ;;
49 esac
50
51 if [ "$DISK"x = ""x ] ; then
52     DISK=runtime-hd.img
53 fi
54
55 #DISPLAY="-vga none -nographic"
56 DISPLAY="-daemonize -vnc :1"
57 PFLASH="-pflash $MACH-OVMF.fd -pflash $MACH-storage.fd"
58
59 if [ "$CD"x != ""x ]; then
60     CD="-device virtio-scsi-pci,id=scsi -drive if=none,id=cd,file=$CD,readonly -device scsi-cd,drive=cd,bootindex=0"
61 fi
62
63 if [ "$NOSHARE"x = ""x ]; then
64     P9="-virtfs local,path=$SHARE/,mount_tag=host0,security_model=passthrough,id=host0"
65     if [ -f ~/.ssh/authorized_keys ]; then
66         cp ~/.ssh/authorized_keys $SHARE/runtime/vagrant-pub-key
67     fi
68     touch $SHARE/runtime/waiting_runtime_vm
69 fi
70
71 NET="-netdev user"
72 NET="$NET,id=eth0"
73 NET="$NET,hostfwd=tcp:127.0.0.1:${SSH_PORT}-10.0.2.15:22"
74 NET="$NET -device virtio-net-device,netdev=eth0"
75
76 CMD="$QEMU -m $MEM \
77     $DISPLAY \
78     $MACH_OPTS $CPU_OPTS \
79     $PFLASH \
80     -drive file=$DISK,format=raw,if=virtio \
81     $NET \
82     $CD \
83     $P9"
84
85 echo $CMD
86 $CMD
87
88 i=0
89 while true; do
90     echo "Waiting for qemu VM to come ready ($i seconds)"
91     if [ ! -f $SHARE/runtime/waiting_runtime_vm ]; then
92         echo "ready after $i seconds"
93         exit 0
94     fi
95     sleep 1
96     i=$(($i + 1))
97 done
98
99 # else the VM timed out
100 echo "qemu VM startup took too long: $i seconds. Abort"
101 exit 1