Simple introduction to Qemu

advertisement
Simple Qemu introduction
/26
1
Brief
• What is qemu and what can it do
• Build qemu in windows
• Debug the process in Qemu
• kgdb
2 /26
X86 virtualization tools
• VMware
• VirtualBox (Oracle)
• VirtualPC (MS)
• Qemu
3 /26
What can Qemu do
• Qemu is an emulator that emulate real
machines
• Supported platforms: arm MIPS x86….
4 /26
How to obtain Qemu
• Search your Linux distribution for binary
executables
• Build from source
5 /26
Qemu on windows?
• There are three ways
• 1. build it on Microsoft Windows Services
for UNIX (SFU)
• 2.built it on cygwin (same as linux)
• 2.use cygwin + mingw to build
• 3.mingw
6 /26
Cygwin
• Cygwin provides a posix layer on top of
windows services.
• Programs using Cygwin are nearly
needless to fix code due to the underlying
environment has no significant difference.
(in most cases only a re-compile is needed)
7 /26
Mingw
• Mingw aims to provide a gnu tool set for
windows. Ex: gcc, sed…
• Dev-c++ uses mingw-gcc
• Mingw does NOT provides posix emulation
layer.
• Mingw can not directly compile linux
programs.
8 /26
Installation and Directory look
• You can install Cygwin using the official
installer http://www.cygwin.com/
• After installation the Cygwin will have
directory mapping like this
– D:/aaa  /cygdrive/d/aaa
• In Mingw
– No such mapping
9 /26
Compile Qemu with Cygwin+mingw
•
•
•
•
•
•
•
First get these packages
gcc-mingw-core gcc-mingw-core-20050522-1.tar.bz2
gcc-mingw-g++ gcc-mingw-g++-20050522-1.tar.bz2
mingw-runtime mingw-runtime-3.16-1.tar.bz2
mingw-zlib-devel mingw-zlib-devel-1.2.3-3.tar.bz2
mingw-libbz2-devel mingw-libbz2-devel-1.0.5-3.tar.bz2
w32api w32api-3.13-1.tar.bz2
• P.s. there is a mirror site ftp.ntu.edu.tw provides the
cygwin package
10 /26
Build Qemu dependencies
• get SDL development package from
http://www.libsdl.org/ (p.s. the official site
only provides MSVC library )
• Or compile from source
11 /26
Build SDL in Cygwin
• Get yasm or nasm
• Get directX development header (optional)
• Get libunicows if your target is before
winNT
12 /26
Steps to compile SDL for mingw
• CPPFLAGS="-I/usr/include/mingw " CFLAGS="-
•
•
O4 -march=i686 -fomit-frame-pointer -funrollloops -I/include/w32api" CC="gcc -mno-cygwin"
CXXFLAGS="-O4 -march=i686 -fomit-framepointer -funroll-loops -I/include/w32api"
CXX="g++ -mno-cygwin" ./configure
LDFLAGS="-mno-cygwin" --prefix=/usr -libdir=/usr/lib/mingw -includedir=/usr/include/mingw
Make
make install
13 /26
Build Qemu
• CFLAGS="-O4 -march=i686" \
./configure --target-list="i386-softmmu" \
--cc="gcc -mno-cygwin" --host-cc=gcc
• make
• make install
14 /26
Test Qemu
• After you type make install. Qemu will be
installed in c:\program files\qemu (in xp)
• But qemu still lacks SDL.dll to run. SDL.dll
lies in your cygwin binary directory (ex:
d:\cygwin\bin)
15 /26
Qemu tools
• Qemu.exe emulator
• Qemu-img.exe disk image tool
16 /26
Create a new virtual machine-1
• Qemu-img create disk.image -f raw 2G
• On first boot (boot from CD)
– Qemu -boot d -m 512 -hda disk.image -cdrom
pathtoCDrom
– Later
– Qemu -boot c -m 512 -hda disk.image
17 /26
Create a new virtual machine-2
Qemu + VirtualBox /VMware
• Qemu can reads the following disk fromats
– Vdi(VirtualBox), vmdk(VMware), raw image
• VirtualBox reads vdi and vmdk
• You can start your existing VM without
VirtualBox…
• P.s. VitrualBox and VMware are faster
compared to Qemu since they does
dynamic code re-compilation in runtime
18 /26
gdb + Qemu?
• You can attach gdb to debug the program
(even kernel) running in Qemu
• Qemu has a build-in gdbserver that can be
attached to outside gdb
19 /26
Qemu + gdb how to-1
• Qemu -hda disk.image -S -s
-S tells qemu to stop and the beginning
-s tells qemu to start gdbserver for connection
20 /26
Qemu + gdb how to-2
• Take debug kernel as an example
• Start gdb with command “gdb vmlinux”
where vmlinux is the pre-build Linux
image with debug information
21 /26
Qemu + gdb how to-3
• gdb will take vmlinux as the debug
program and read symbol from it
• After gdb starts type “target remote
localhost:1234” to attach gdm with qemu
22 /26
Qemu + gdb how to-4
• Type “c” to continue the original program
• Type “b some_symbol_name” to set break
points at symbols in the program
• Type “p var_name” to print variable values
23 /26
Kgdb a Linux Kernel Source Level
Debugger
• Kgdb is a kernel patch. It patches a Linux kernel
•
•
•
•
to enable kernel debugging
It adds mianly a gdb stub
And a serial communication
Besides it patches the soure so that kernel gives
control to debugger when an unexpected fault
occurs
Using kgdb you can debug on real machines
24 /26
kgdb
• You can get kgdb and the special gdb here
kgdb.linsyssoft.com/getting.htm
• Note the kgdb is a patch. You needs no
make some modify if there is version
difference
• There is also a paid version kgdb-pro
which supports more recent kernel
25 /26
Q&A
26 /26
Download