-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathvmlaunch.sh
executable file
·59 lines (50 loc) · 1.14 KB
/
vmlaunch.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
#!/usr/bin/env bash
# This script launches a single VM, identified by its numeric ID.
set -xe
dir=$(dirname "$0")
# Grab the helpers
source "$dir/helpers.sh"
# Parse the argument (VM ID)
vmid=$1
vmname=$(id_to_name "$vmid")
vmdir="$dir/$vmname"
# Assign resources
case "$vmname" in
gateway|control*)
vcpus=2
memory=2G
;;
worker*)
vcpus=4
memory=4G
;;
esac
# Compute the MAC address
mac="52:52:52:00:00:0$vmid"
case $(uname -m) in
arm64|aarch64) qemu_arch=aarch64;;
x86_64|amd64) qemu_arch=x86_64;;
esac
case $(uname -s) in
Darwin)
efi="/opt/homebrew/share/qemu/edk2-${qemu_arch}-code.fd"
machine="virt,accel=hvf,highmem=on"
nic="vmnet-shared,start-address=192.168.1.1,end-address=192.168.1.20,subnet-mask=255.255.255.0"
;;
Linux)
efi="/usr/share/qemu/OVMF.fd"
machine="q35,accel=kvm"
nic="tap,script=$dir/tapup.sh"
;;
esac
# Launch the VM
qemu-system-${qemu_arch} \
-nographic \
-machine $machine \
-cpu host \
-smp $vcpus \
-m $memory \
-bios "$efi" \
-nic "$nic,mac=$mac" \
-hda "$vmdir/disk.img" \
-drive file="$vmdir/cidata.iso",driver=raw,if=virtio