Add empty runtime VM provisioning script
[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             CPU_OPTS="-cpu host --enable-kvm"
17             MACH_OPTS="-machine virt,gic-version=host,kernel_irqchip=on"
18         elif [ "$MACH"x = "arm"x ]; then
19             MACH=arm
20             CPU_OPTS="-cpu host,aarch64=off --enable-kvm"
21             MACH_OPTS="-machine virt,gic-version=host,kernel_irqchip=on"
22         else
23             echo "Unknown MACH $MACH; abort"
24             exit 1
25         fi
26         ;;
27     *)
28         if [ "$MACH"x = ""x ] || \
29                [ "$MACH"x = "aarch64"x ] || \
30                [ "$MACH"x = "arm64" ] ; then
31             MACH=aarch64
32             CPU_OPTS="-cpu cortex-a57"
33             MACH_OPTS="-M virt"
34         elif [ "$MACH"x = "arm"x ]; then
35             MACH=arm
36             CPU_OPTS="-cpu cortex-a15"
37             MACH_OPTS="-M virt"
38         else
39             echo "Unknown MACH $MACH; abort"
40             exit 1
41         fi
42         ;;
43 esac
44
45 if [ "$DISK"x = ""x ] ; then
46     DISK=runtime-hd.img
47 fi
48
49 #DISPLAY="-vga none -nographic"
50 DISPLAY="-daemonize -vnc :1"
51 PFLASH="-pflash $MACH-OVMF.fd -pflash $MACH-storage.fd"
52
53
54 if [ "$NOSHARE"x = ""x ]; then
55     P9="-virtfs local,path=$SHARE/,mount_tag=host0,security_model=passthrough,id=host0"
56     if [ -f ~/.ssh/authorized_keys ]; then
57         cp ~/.ssh/authorized_keys $SHARE/runtime/vagrant-pub-key
58     fi
59     touch $SHARE/runtime/waiting_runtime_vm
60 fi
61
62 NET="-netdev user"
63 NET="$NET,id=eth0"
64 NET="$NET,hostfwd=tcp:127.0.0.1:${SSH_PORT}-10.0.2.15:22"
65 NET="$NET -device virtio-net-device,netdev=eth0"
66
67 CMD="qemu-system-$MACH -m $MEM \
68     $DISPLAY \
69     $MACH_OPTS $CPU_OPTS \
70     $PFLASH \
71     -drive file=$DISK,format=raw,if=virtio \
72     $NET \
73     $P9"
74
75 echo $CMD
76 $CMD
77
78 i=0
79 while true; do
80     echo "Waiting for qemu VM to come ready ($i seconds)"
81     if [ ! -f $SHARE/runtime/waiting_runtime_vm ]; then
82         echo "ready after $i seconds"
83         exit 0
84     fi
85     sleep 1
86     i=$(($i + 1))
87 done
88
89 # else the VM timed out
90 echo "qemu VM startup took too long: $i seconds. Abort"
91 exit 1