Environment construction
1.1. Preparatory work
(1). QEMU Virtual Machine
(2). BusyBox Software
(3). linux-3.5.4 kernel
(4). DDD Debug tool (in Terminal input sudo apt-get install DDD installation)
1.2. Compiling the kernel
(1) Establishment of working directory: Mkdir-p ~/work/qemu
(2) switch to this directory: CD ~/work/qemu
(3) Download Linux kernel
(4) Decompression core: TAR-JXVF linux-3.5.4.tar.bz2
(5) Switch to linux-3.5.4 directory: CD linux-3.5.4
(6) Configure compilation options: Makemenuconfig
Description: May be missing dependent package Ncurses-dev input: sudo apt-get install ncurses-dev Some versions of Linux source may be: sudo apt-get install Libncurses5-dev
The compile options are selected:
Kernelhacking–>kerneldebugging–> compile the kernel with debug info
Kernelhacking–> compilethe kernel with frame pointers
(7) Compile: Make (note: Do not install the kernel after compiling, if there are errors when compiling, please check if there are fewer compile tools installed)
(8) Copy the file Bzimage to the parent directory: CP Arch/x86/boot/bzimage. /
1.3. Installing the QEMU virtual machine
(1) Download the QEMU installation file
(2) Install the library file before you install QEMU. Open Terminal input sudo apt-get install gcc libsdl1.2-dev zlib1g-dev libasound2-devpkg-config libgnutls-dev Pciutils-dev
(3) switch to the QEMU source directory input./configure Generate makefile
(4) Enter make to start compiling (if Automake package is missing, enter sudo apt-get install autoconf automake libtool installation)
(5) Enter sudo make install to start installation
1.4. Making the root file system
(1) Switch directory: CD ~/WORK/QEMU
(2) Create size 10M to root filesystem: DD If=/dev/zero of=rootfs.img bs=1m count=10
(3) Format the root file with the ext3 type: Mkfs.ext3 rootfs.img
(4) Create rootfs directory: mkdir rootfs
(5) Mount the rootfs.img to the Rootfs directory: sudo mount-t ext3-o loop rootfs.img rootfs
(6) Switch to ROOTFS directory: CD rootfs
(7) Creation of three directories: mkdir DEV proc Sys
1.5. Install BusyBox to the root file system
(1) Download BusyBox
(2) Unzip, switch to BusyBox source directory, configure busybox compile option: Make Menuconfig
A. Select static compilation : Busyboxsettings->build Options->buildbusybox as a static binary
B. Cancellation of Networkingutilities->iptunel
C. Cancellation of networkingutilities->inetd
(2) Compile: Make
(3) Install the BusyBox file system into the root file system you just created: Make install Config_prefix=~/work/qemu/rootfs
(4) Switch to QEMU directory: CD ~/work/qemu
(5) Uninstalling the root file system: sudo umount rootfs
1.6. Verification process
(1) Write C validator in ~/work directory TEST_FORK.C
#include <unistd.h>
#include <sys/types.h>
int main ()
{
pid_t pid;
Pid=fork ();
}
(2) Compiling C program
Gcc-c-G-STATICTEST_FORK.C
Gcc-o test_fork-static TEST_FORK.O
Because BusyBox is compiled into static, the C program can be run in the QEMU virtual machine and must be compiled to static. This allows the Test_frok command to run in the virtual machine
(3) Enter the sudo mount-t ext3-o loop rootfs.img rootfs command to mount the root file system of the QEMU virtual machine.
(4) Enter the CP Fork rootfs/bin command to test the fork into the bin/folder of the root file system
(5) Uninstalling the root file system: sudo umount rootfs
(6) Start QEMU
A. Open terminal input, input command switch to ~/WORK/QEMU directory: CD ~/work/qemu
B. Enter qemu-system-i386-s-kernel bzimage-hda rootfs.img-append "Root=/dev/sdainit=/bin/ash rw"-monitor stdio start Qemu (64-bit Computer Please change i386 to x86)
Note: RW represents an open virtual machine that can be read and written.
-monitor stdio means that the console in QEMU is transferred to the terminal without ctrl+alt+2 switching
C. Enter "Gdbserver tcp::1234" in console
D. Open another terminal, enter the command CD ~/work/qemu/linux-3.5.4 switch to the ~/misc/qemu/linux-3.5.4 directory
E. Running Dddvmlinux (no ddd input sudo apt-get installddd installation)
F. Enter commands in the DDD Command Window target remote localhost:1234 connect the QEMU virtual machine to the console of the DDD
G. Enter B do_fork the command window in DDD to add a breakpoint on the Do_fork function
H. Enter in the command window of DDD to have the virtual machine continue execution
(7) Enter the Test_fork command in the QEMU virtual machine terminal so that the kernel is interrupted at the Do_fork function. You can debug this function in a variety of ways.
Do not understand can give me a message.