-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun-vm.sh
More file actions
executable file
·148 lines (143 loc) · 3.6 KB
/
Copy pathrun-vm.sh
File metadata and controls
executable file
·148 lines (143 loc) · 3.6 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
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
#!/bin/bash
CONSOLE=mon:stdio
SMP=4
MEMSIZE=$((8192))
KERNEL="Image"
FS=cloud.img
CMDLINE="earlycon=pl011,0x09000000" #log_buf_len=64M " #kvm-arm.mode=protected" # memblock=debug"
DTB=""
UNDERSCORE_S=""
SHARED_OPT=""
SSH_PORT=2222
GDB_PORT=""
GDB=""
MON_PORT=""
MON=""
BIOS_FILE=""
BIOS=""
usage() {
U=""
if [[ -n "$1" ]]; then
U="${U}$1\n\n"
fi
U="${U}Usage: $0 [options]\n\n"
U="${U}Options:\n"
U="$U -c | --CPU <nr>: Number of cores (default ${SMP})\n"
U="$U -m | --mem <MB>: Memory size (default ${MEMSIZE})\n"
U="$U -b | --bios <BIOS>: BIOS file\n"
U="$U -k | --kernel <Image>: Use kernel image (default ${KERNEL})\n"
U="$U -s | --serial <file>: Output console to <file>\n"
U="$U -i | --image <image>: Use <image> as block device (default ${FS})\n"
U="$U -a | --append <snip>: Add <snip> to the kernel cmdline\n"
U="$U --dtb <file> Use the supplied DTB instead of the auto-generated one\n"
U="$U -S Stop on startup, wait for GDB\n"
U="$U -x | --shared_dir: Shared directory path\n"
U="$U -p | --port: SSH port\n"
U="$U -g | --gdb: GDB port\n"
U="$U -m | --monitor: Monitor port\n"
U="$U -h | --help: Show this output\n"
U="${U}\n"
echo -e "$U" >&2
}
while :
do
case "$1" in
-c | --cpu)
SMP="$2"
shift 2
;;
-m | --mem)
MEMSIZE="$2"
shift 2
;;
-k | --kernel)
KERNEL="$2"
shift 2
;;
-b | --bios)
BIOS_FILE="$2"
BIOS="--bios ${BIOS_FILE}"
shift 2
;;
-s | --serial)
CONSOLE="file:$2"
shift 2
;;
-i | --image)
FS="$2"
shift 2
;;
-a | --append)
CMDLINE+=" $2"
shift 2
;;
--dtb)
DTB="-dtb $2"
shift 2
;;
-S)
UNDERSCORE_S="-S"
shift 1
;;
-x | --shared_dir)
SHARED_DIR="$2"
SHARED_OPT="-virtfs local,path=${SHARED_DIR},mount_tag=shared,security_model=none"
shift 2
;;
-p | --port)
SSH_PORT="$2"
shift 2
;;
-g | --gdb)
GDB_PORT="$2"
GDB="-gdb tcp::${GDB_PORT}"
shift 2
;;
-m | --monitor)
MON_PORT="$2"
MON="-monitor telnet:localhost:${MON_PORT},server,nowait"
shift 2
;;
-h | --help)
usage ""
exit 1
;;
--) # End of all options
shift
break
;;
-*) # Unknown option
echo "Error: Unknown option: $1" >&2
exit 1
;;
*)
break
;;
esac
done
if [[ -z "$KERNEL" ]]; then
echo "You must supply a guest kernel" >&2
exit 1
fi
# -netdev bridge,id=hn0,br=br0 \
# -device virtio-net-pci,netdev=hn0,id=nic1 \
# -machine secure=on \
# -machine mte=on \
# -machine iommu=smmuv3 \
# see https://www.qemu.org/docs/master/system/arm/virt.html
qemu-system-aarch64 -nographic -machine virt -m ${MEMSIZE} -cpu max -smp ${SMP} \
-machine virtualization=on \
-machine gic-version=3 \
${BIOS} \
-kernel ${KERNEL} ${DTB} \
-drive if=none,file=${FS},id=vda,cache=none,format=raw \
-device virtio-blk-pci,drive=vda \
-display none \
-serial ${CONSOLE} \
-append "console=ttyAMA0 root=/dev/vda rw ${CMDLINE}" \
-netdev user,id=net0,hostfwd=tcp::${SSH_PORT}-:22 \
-device virtio-net-pci,netdev=net0,mac=de:ad:be:ef:41:49 \
${SHARED_OPT} \
${GDB} \
${MON} \
${UNDERSCORE_S}