-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_vm.sh
executable file
·63 lines (54 loc) · 1.69 KB
/
start_vm.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
#!/bin/bash
display_usage() {
echo -e "\nUsage: $0 [vm1 vm2 vm3] [normal netmap]\n"
}
# check whether user had supplied -h or --help . If yes display usage
if [[ ($# == "--help") || $# == "-h" ]]; then
display_usage
exit 0
fi
# display usage if the script is not run as root user
if [[ "$EUID" -ne 0 ]]; then
echo "This script must be run as root!"
exit 1
fi
# if less than two arguments supplied, display usage
if [ $# -le 1 ]; then
echo "This script must be run with at least two arguments."
display_usage
exit 1
fi
CUR_PATH=$(pwd)
VM_NAME="$1"
NUM="${VM_NAME: -1}"
BACK_IFNAME="$3"
if [ "$2" == "normal" ]; then
NET_FRONTEND="virtio-net-pci"
NET_BACKEND="tap"
BACK_IFNAME=""$VM_NAME".cp"
IFUP_SCRIPTS=",script=no,downscript=no"
elif [ "$2" == "netmap" ]; then
# Make sure netmap module is loaded
if ! lsmod | grep "netmap" &>/dev/null; then
echo "netmap module is not loaded. Loading."
modprobe netmap
fi
NET_FRONTEND="ptnet-pci"
NET_BACKEND="netmap"
if [ ! -n "$BACK_IFNAME" ]; then
BACK_IFNAME="vale2:1}2"
echo "Backend interface name not specified, using default: $BACK_IFNAME"
fi
IFUP_SCRIPTS=",passthrough=on"
else
echo "Unknown network type"
display_usage
exit 1
fi
# Boot the vm
sudo qemu-system-x86_64 \
"$CUR_PATH"/"$VM_NAME".img \
-m 2G --enable-kvm -pidfile $VM_NAME.pid \
-serial file:"$VM_NAME".log \
-device e1000,netdev=mgmt,mac=00:AA:BB:CC:01:99 -netdev user,id=mgmt,hostfwd=tcp::202"$NUM"-:22,hostfwd=tcp::300"$NUM"-:3000 \
-device "$NET_FRONTEND",netdev=data1,mac=00:0a:0a:0a:0"$NUM":01, -netdev $NET_BACKEND,ifname="$BACK_IFNAME",id=data1"$IFUP_SCRIPTS" &