-
Notifications
You must be signed in to change notification settings - Fork 5
/
runqemu
executable file
·154 lines (141 loc) · 3.84 KB
/
runqemu
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
USAGE="Usage: `basename $0` [-i IMAGE_FILE] [-s SSH_PORT] [-q QEMU_EXE] BZIMAGE [QEMU_ARG, ...]"
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
IMGDIR=${DIR}/images
QEMU=qemu-system-x86_64
IMAGE=jessie.qcow2
SSH_PORT=3234
QUIET=quiet
KVM=-enable-kvm
MEM=2048
CORES=1
PMEM=""
IOPMEM=""
DEBUG=
CONNECT=connect
NVME=1
NVME_NOTUPSTREAM="-drive file=${IMGDIR}/nvme.qcow2,if=none,id=nvme1,snapshot=on \
-device nvme,drive=nvme1,serial=nvme1,namespaces=1,cmbsz=0,cmbloc=0 \
-drive file=${IMGDIR}/nvme2.qcow2,if=none,id=nvme2,snapshot=on \
-device nvme,drive=nvme2,serial=nvme2,namespaces=1,cmbsz=8388608,cmbloc=2"
NVME_UPSTREAM="-drive file=${IMGDIR}/nvme.qcow2,if=none,id=nvme1,snapshot=on \
-device nvme,drive=nvme1,serial=nvme1,cmb_size_mb=64 \
-drive file=${IMGDIR}/nvme2.qcow2,if=none,id=nvme2,snapshot=on \
-device nvme,drive=nvme2,serial=nvme2 \
-drive file=${IMGDIR}/nvme3.qcow2,if=none,id=nvme3,snapshot=on \
-device nvme,drive=nvme3,serial=nvme3 \
-drive file=${IMGDIR}/nvme4.qcow2,if=none,id=nvme4,snapshot=on \
-device nvme,drive=nvme4,serial=nvme4 \
-drive file=${IMGDIR}/nvme5.qcow2,if=none,id=nvme5,snapshot=on \
-device nvme,drive=nvme5,serial=nvme5 \
-drive file=${IMGDIR}/nvme6.qcow2,if=none,id=nvme6,snapshot=on \
-device nvme,drive=nvme6,serial=nvme6"
VIRTFS="-virtfs local,id=home,path=/home/,security_model=mapped,mount_tag=home"
ETH=1
ETH_NOTUPSTREAM="-device e1000,netdev=user0 -netdev user,id=user0 \
-device e1000,netdev=socket0 \
-netdev socket,id=socket0,${CONNECT}=localhost:1235 \
-redir tcp:$SSH_PORT::22"
ETH_UPSTREAM="-device e1000,netdev=user0 -netdev user,id=user0,hostfwd=tcp::${SSH_PORT}-:22"
UPSTREAM=0
while getopts hq:i:m:s:c:enpkdftuv OPT; do
case "$OPT" in
h)
echo $USAGE
exit 0
;;
q)
QEMU=$OPTARG
;;
i)
IMAGE=$OPTARG
;;
m)
MEM=$OPTARG
;;
s)
SSH_PORT=$OPTARG
;;
c)
CORES=$OPTARG
;;
e)
ETH=0
;;
n)
NVME=0
;;
p)
PMEM=128M!1024M
IOPMEM="-drive file=${IMGDIR}/iopmem.img,if=none,format=raw,id=iopmem \
-device iopmem,drive=iopmem"
;;
k)
KVM=
;;
d)
DEBUG="-s -S"
;;
f)
VIRTFS=
;;
t)
CONNECT=listen
;;
u)
UPSTREAM=1
;;
v)
QUIET=
;;
\?)
# getopts issues an error message
echo $USAGE >&2
exit 1
;;
esac
done
shift $((OPTIND-1))
KERNEL=$1
shift
if [ ! -z $PMEM ] ; then
PMEM="memmap=${PMEM}"
fi
# Accomodate the fact that upstream NVMe has a differnet set of
# options than the NVMe and LightNVM forks.
if [[ $NVME -ne 0 ]]; then
if [[ $UPSTREAM -ne 0 ]]; then
NVME=$NVME_UPSTREAM
else
NVME=$NVME_NOTUPSTREAM
fi
else
NVME=
fi
# Accomodate the fact that upstream QEMU has depreciated the -redir
# option (not yet done as it is just a warning for now).
if [[ $ETH -ne 0 ]]; then
if [[ $UPSTREAM -ne 0 ]]; then
ETH=$ETH_UPSTREAM
else
ETH=$ETH_NOTUPSTREAM
fi
else
ETH=
fi
# If the desired image does not exist then create it from the
# jessie-clean.qcow2 image.
if [ ! -f $IMAGE ] && [[ $IMAGE != */* ]]; then
IMAGE=$IMGDIR/$IMAGE
if [ ! -f $IMAGE ]; then
qemu-img create -f qcow2 -b $IMGDIR/jessie-clean.qcow2 $IMAGE
fi
fi
${QEMU} $DEBUG $KVM -m $MEM -smp ${CORES},cores=${CORES} \
$NVME $VIRTFS $IOPMEM $ETH \
-nographic \
-serial mon:stdio \
-kernel $KERNEL \
-append "nvme.use_cmb=24 root=/dev/sda2 rootfstype=ext4 console=ttyS0,38400n8 $QUIET $PMEM" \
$IMAGE \
$*