-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_firecracker.sh
executable file
·65 lines (52 loc) · 2.09 KB
/
start_firecracker.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash -e
SB_ID="${1:-0}" # Default to sb_id=0
RO_DRIVE="$PWD/rootfs.ext4"
KERNEL="$PWD/vmlinux"
TAP_DEV="fc-${SB_ID}-tap0"
#KERNEL_BOOT_ARGS="panic=1 pci=off reboot=k tsc=reliable quiet 8250.nr_uarts=0 ipv6.disable=1"
KERNEL_BOOT_ARGS="console=ttyS0 reboot=k panic=1 pci=off nomodules ipv6.disable=1"
API_SOCKET="/tmp/firecracker-sb${SB_ID}.sock"
CURL=(curl --silent --show-error --header Content-Type:application/json --unix-socket "${API_SOCKET}" --write-out "HTTP %{http_code}")
curl_put() {
local URL_PATH="$1"
local OUTPUT RC
OUTPUT="$("${CURL[@]}" -X PUT --data @- "http://localhost/${URL_PATH#/}" 2>&1)"
RC="$?"
if [ "$RC" -ne 0 ]; then
echo "Error: curl PUT ${URL_PATH} failed with exit code $RC, output:"
echo "$OUTPUT"
return 1
fi
# Error if output doesn't end with "HTTP 2xx"
if [[ "$OUTPUT" != *HTTP\ 2[0-9][0-9] ]]; then
echo "Error: curl PUT ${URL_PATH} failed with non-2xx HTTP status code, output:"
echo "$OUTPUT"
return 1
fi
}
logfile="$PWD/output/fc-sb${SB_ID}-log"
#metricsfile="$PWD/output/fc-sb${SB_ID}-metrics"
metricsfile="/dev/null"
touch $logfile
# Setup TAP device that uses proxy ARP
MASK_LONG="255.255.255.252"
#MASK_SHORT="/30"
FC_IP="$(printf '169.254.%s.%s' $(((4 * SB_ID + 1) / 256)) $(((4 * SB_ID + 1) % 256)))"
TAP_IP="$(printf '169.254.%s.%s' $(((4 * SB_ID + 2) / 256)) $(((4 * SB_ID + 2) % 256)))"
FC_MAC="$(printf '02:FC:00:00:%02X:%02X' $((SB_ID / 256)) $((SB_ID % 256)))"
#ip link del "$TAP_DEV" 2> /dev/null || true
#ip tuntap add dev "$TAP_DEV" mode tap
#sysctl -w net.ipv4.conf.${TAP_DEV}.proxy_arp=1 > /dev/null
#sysctl -w net.ipv6.conf.${TAP_DEV}.disable_ipv6=1 > /dev/null
#ip addr add "${TAP_IP}${MASK_SHORT}" dev "$TAP_DEV"
#ip link set dev "$TAP_DEV" up
KERNEL_BOOT_ARGS="${KERNEL_BOOT_ARGS} ip=${FC_IP}::${TAP_IP}:${MASK_LONG}::eth0:off"
# Start Firecracker API server
rm -f "$API_SOCKET"
#./firecracker --api-sock "$API_SOCKET" --id "${SB_ID}"
sleep 0.015s
# Wait for API server to start
#while [ ! -e "$API_SOCKET" ]; do
# echo "FC $SB_ID still not ready..."
# sleep 0.01s
#done