-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun_qemu
executable file
·94 lines (80 loc) · 1.83 KB
/
run_qemu
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
#!/bin/bash
set -eu
#
# REFERENCES:
# - https://www.collabora.com/news-and-blog/blog/2017/01/16/setting-up-qemu-kvm-for-kernel-development/
# - https://www.collabora.com/news-and-blog/blog/2017/03/13/kernel-debugging-with-qemu-overview-tools-available/
#
function print_usage {
echo "Usage: $(basename $0) <path/to/kernel/image> [options]"
echo " Options:"
echo " --arch [arch]: x86_64(default)|i386|aarch64|arm"
echo " --no-kvm: Disable KVM (only valid for Intel archs)"
echo " -h|--help: print this help message"
}
ARCH=x86_64
KVM="--enable-kvm"
SHORTOPTS="h"
LONGOPTS="arch:,no-kvm,help"
ARGS==`getopt -n "$(basename $0)" --options $SHORTOPTS --longoptions $LONGOPTS -- "$@"`
eval set -- "$ARGS"
while true;
do
case "$1" in
-h|--help)
print_usage
exit 0
;;
--arch)
shift
ARCH="$1"
;;
--no-kvm)
KVM=""
;;
--)
shift
break
;;
esac
shift
done
if [ $# -ne 1 ]; then
print_usage
exit -1
fi
KERNEL=$1
# Information required by plumbing layer
IMG=${IMG:-$(dirname $(realpath $0))/images/qemu-image-$ARCH.img}
if [[ "$ARCH" == "x86_64" || "$ARCH" == "i386" ]]; then
ARCH_OPTS=" \
-drive file=$IMG,format=raw,file.locking=off \
${KVM}"
CMD_LINE="root=/dev/sda console=ttyS0"
elif [[ "$ARCH" == "aarch64" ]]; then
ARCH_OPTS=" \
-drive file=$IMG,format=raw,file.locking=off \
-cpu cortex-a53 \
-machine virt"
CMD_LINE="root=/dev/vda"
elif [[ "$ARCH" == "arm" ]]; then
ARCH_OPTS=" \
-drive if=none,file=$IMG,format=raw,id=hd \
-device virtio-blk-device,drive=hd \
-cpu cortex-a15 \
-machine virt"
CMD_LINE="root=/dev/vda"
else
echo "ERROR: unknown arch $ARCH"
exit -1
fi
set -x
sudo qemu-system-$ARCH \
-kernel $KERNEL \
-s \
-append "$CMD_LINE" \
-smp cores=4,threads=2 \
--nographic \
-m 512 \
-net nic -net user,hostfwd=tcp::10022-:22 \
$ARCH_OPTS