-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartVM
executable file
·127 lines (106 loc) · 2.4 KB
/
startVM
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
CONFIG=config.vm
TEST=false
QEMUCTL=
EMUOPTS=
function usage() {
echo "$1 <config.vm> [options] [-- emulator options]"
echo "options:"
echo " -t Test only. Print command and exit."
echo " -h | --help Print this help screen and exit."
echo " -c Enable qemuctl GUI."
echo " -- Options after -- will be passed to the emulator"
}
while [ "$1" != "" ]; do
case "$1" in
-t) TEST=true ;;
-h|--help)
usage $0
exit 0
;;
-c) QEMUCTL="qemuctl -qemu" ;;
--)
while [ "$2" != "" ]; do
EMUOPTS+=" $2"
shift
done
;;
*)
if [ "$CONFIG" == "" ]; then
CONFIG="$1"
else
echo "Invalid options '$1'"
exit 1
fi
;;
esac
shift
done
if [ ! -e "$CONFIG" ]; then
echo "Config file '$CONFIG' not found"
exit 1
fi
# Defaults
EMU=kvm
MEM=2000
IMAGE=disk.qcow2
IF=vmtap
MAC=
NET_MODEL=virtio
SOUND= #"-soundhw all"
DISK_OPTS="cache=none,if=virtio"
VIDEO=
MOUSE="-device usb-tablet"
KEYBOARD=
MISC="-usb -rtc base=localtime -monitor stdio"
KEYMAP="-k en-us"
DSP=
NICE="nice -n 5"
EXTRA=
. "$CONFIG"
# Check configuration
if [ "$ID" == "" ]; then
"ID not set in '$CONFIG'"
exit 1
fi
if [ "$VIDEO" == "" ]; then
VIDEO="-vga qxl -spice port=$((5930 + $ID)),disable-ticketing \
-device virtio-serial-pci \
-device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
-chardev spicevmc,id=spicechannel0,name=vdagent"
fi
if [ "$MAC" == "" ]; then
MAC="02:00:00:00:00:$ID"
fi
VDE="-net vde,sock=/var/run/vde2/${IF}.ctl"
NIC="-net nic"
if [ "$MAC" != "" ]; then
NIC+=",macaddr=$MAC"
fi
if [ "$NET_MODEL" != "" ]; then
NIC+=",model=$NET_MODEL"
fi
if [ "$IMAGE" != "" ]; then
if [ ! -e "$IMAGE" ]; then
echo "Cannot find image '$IMAGE'"
exit 1
fi
DISK="-drive file=$IMAGE"
if [ "$DISK_OPTS" != "" ]; then
DISK+=",$DISK_OPTS"
fi
fi
# Build command
INPUT="$KEYBOARD $MOUSE"
NET="$NIC $VDE"
OPTS="-m $MEM $SOUND $NET $DISK $VIDEO $INPUT $MISC $KEYMAP $EXTRA"
CMD="$NICE $DSP $QEMUCTL $EMU $OPTS $EMUOPTS"
# Unlimit memory
ulimit -v unlimited
# Run it
echo "Starting VM: $CMD"
if $TEST; then
echo "Just a test"
else
eval $CMD
fi