-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrun-microvm.sh
More file actions
executable file
·97 lines (79 loc) · 2.91 KB
/
run-microvm.sh
File metadata and controls
executable file
·97 lines (79 loc) · 2.91 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash
#################################################################################
# Parameters
#################################################################################
# Kernel Image
KERNEL=$PWD/images/hello-vmlinux.bin
# Root Filesystem (rootfs) Image
ROOTFS=$PWD/images/echo-time-minvm-rootfs.ext4
# Number of vCPUs to allocate for the microvm
VCPU_COUNT=1
# Memory Size (MB) to allocate for the microvm. This sample allocates only 64 MB
MEM_SIZE_MIB=64
# Unix socket to communicate with Firecracker.
# This should match the socket parameter in the script used to run firecracker (start-firecracker.sh)
FIRECRACKER_SOCK=/tmp/firecracker-echo-time.sock
# Firecracker's log
FIRECRACKER_LOG=/tmp/firecracker-echo-time-log.fifo
# Make sure Firecracker log is clean
rm -f $FIRECRACKER_LOG
# Create named pipe (FIFO) for log
mkfifo $FIRECRACKER_LOG
# Firecracker's metrics
FIRECRACKER_METRICS=/tmp/firecracker-echo-time-metrics.fifo
# Make sure Firecracker metrics is clean
rm -f $FIRECRACKER_METRICS
# Create named pipe (FIFO) for metrics
mkfifo $FIRECRACKER_METRICS
#################################################################################
# Call Firecracker APIs to configure and run the micro vm
#################################################################################
# Configure logging
curl --unix-socket $FIRECRACKER_SOCK -i \
-X PUT 'http://localhost/logger' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"log_fifo":"'$FIRECRACKER_LOG'",
"metrics_fifo":"'$FIRECRACKER_METRICS'",
"level": "Error",
"show_level": true,
"show_log_origin": false
}'
# Configure the machine
curl --unix-socket $FIRECRACKER_SOCK -i \
-X PUT 'http://localhost/machine-config' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"vcpu_count":'$VCPU_COUNT',
"mem_size_mib":'$MEM_SIZE_MIB'
}'
# Set the guest kernel
curl --unix-socket $FIRECRACKER_SOCK -i \
-X PUT 'http://localhost/boot-source' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"kernel_image_path": "'$KERNEL'",
"boot_args": "console=ttyS0 reboot=k panic=1 pci=off"
}'
# Set the guest rootfs
curl --unix-socket $FIRECRACKER_SOCK -i \
-X PUT 'http://localhost/drives/rootfs' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"drive_id": "rootfs",
"path_on_host": "'$ROOTFS'",
"is_root_device": true,
"is_read_only": false
}'
# Start the guest machine:
curl --unix-socket $FIRECRACKER_SOCK -i \
-X PUT 'http://localhost/actions' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"action_type": "InstanceStart"
}'