-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun-guest.sh
More file actions
executable file
·125 lines (120 loc) · 3.3 KB
/
Copy pathrun-guest.sh
File metadata and controls
executable file
·125 lines (120 loc) · 3.3 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
#!/bin/bash
CONSOLE=mon:stdio
SMP=2
MEMSIZE=$((4096))
KERNEL="Image"
FS=cloud.img
CMDLINE="earlycon=pl011,0x09000000" #log_buf_len=64M " #kvm-arm.mode=protected" # memblock=debug"
DTB=""
UNDERSCORE_S=""
SHARED_OPT=""
GUEST_32=""
USER_NETWORK_STRING=" -netdev user,id=net0,hostfwd=tcp::2222-:22 \
-device virtio-net-pci,netdev=net0,mac=de:ad:be:ef:41:48"
TAP_NETWORK_STRING=" -netdev tap,id=mytap0,ifname=tap0,script=no,downscript=no,vhost=on \
-device virtio-net-pci,netdev=mytap0,mac=de:ad:be:ef:41:48"
NETWORK_STRING=${USER_NETWORK_STRING}
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 -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 -w | --guest_32: Run guest in AArch32 state\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 -t | --tap: Use tap network instead of user network, vhost is enabled\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
;;
-s | --serial)
CONSOLE="file:$2"
shift 2
;;
-i | --image)
FS="$2"
shift 2
;;
-a | --append)
CMDLINE="$2"
shift 2
;;
-w | --guest_32)
GUEST_32=",aarch64=off"
shift 1
;;
--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=passthrough"
shift 2
;;
-t | --tap)
NETWORK_STRING=${TAP_NETWORK_STRING}
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
qemu-system-aarch64 -nographic -machine virt,gic-version=3 -m ${MEMSIZE} -cpu host${GUEST_32} \
-smp ${SMP} -enable-kvm \
-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}" \
${NETWORK_STRING} \
${SHARED_OPT} \
-gdb tcp::12345 \
-monitor telnet:localhost:23456,server,nowait \
${UNDERSCORE_S}