UBUNTU14 debugging the Linux kernel with QEMU

Source: Internet
Author: User

# Download Kernel source code compile kernel CD~/linuxkernel/wget https://Www.kernel.org/pub/linux/kernel/v3.x/linux-3.18.6.tar.xzXz-d linux-3.18.6. Tar.xz Tar-XVF linux-3.18.6. Tar CD Linux-3.18.6make I386_defconfig make # usually compiles for a long time, less 20 minutes more hours # Create root file system CD~/linuxkernel/mkdir rootfs git clone # If you are wall, you can use the Attachment menu.zip CD menu gcc-o init linktable.c menu.c test.c-m32-Static–lpthread CD./rootfs CP ./menu/init./find.| Cpio-o-HNEWC |gzip-9>.. /rootfs.img # Launch Menuos system CD~/linuxkernel/Qemu-kernel linux-3.18.6/ARCH/X86/BOOT/BZIMAGE-INITRD rootfs.img

In the execution qemu-kernel linux-3.18. 6/ARCH/X86/BOOT/BZIMAGE-INITRD rootfs.img times wrong, no qemu this command.

Correct practice:qemu-system-i386-kernel linux-3.18.6/arch/x86/boot/bzimage-initrd rootfs.img

Cause Analysis:

I thought I didn't install QEMU, so I started the installation, according to Http://jingyan.baidu.com/album/b907e627cfffc946e7891cd5.html's URL

sudo apt-get install QEMU-KVM libvirt-bin virt-manager bridge-utils

Lsmod | grep KVM

Virsh-c Qemu:///system List

But later found this site: http://blog.csdn.net/xsckernel/article/details/8159548#comments

Know that KVM is the system comes with, so uninstalled the original installed

sudo apt-get remove QEMU-KVM

sudo apt-get remove Libvirt-bin

sudo apt-get remove Virt-manager

sudo apt-get remove bridge-utils

But I don't know why KVM exists. For example: Lsmod | grep KVM

By URL: http://zhangjun2915.blog.163.com/blog/static/3808623620103585320514/

To know that/usr/bin/qemu-system-x86_64 is QEMU-KVM

So I see it in the/esr/bin/directory:

The qemu-system-x86_64 is thus determined to be an analog 64-bit system,qemu-system-i386 is an analog 32-bit system.

So the last line of command changes to:

Qemu-system-i386-kernel LINUX-3.18.6/ARCH/X86/BOOT/BZIMAGE-INITRD rootfs.img

The effects that can be run are:

    • Reconfigure Linux to carry debug information
On the basis of the original configuration, in the shell Terminal input: Make Menuconfig

The error message is as follows:

In file included from scripts/kconfig/lxdialog/checklist.c:24:

Scripts/kconfig/lxdialog/dialog.h:31:20:error:curses.h: No file or directory

In file included from scripts/kconfig/lxdialog/checklist.c:24:

Reference URL: http://blog.chinaunix.net/uid-25896350-id-367612.html

Workaround: sudo apt-get install Libncurses5-dev

Then re-enter: Make Menuconfig, the effect is as follows: Press space to select kernel hacking->

Press space to select Compile-time checks and complier options-

Press space to select [*] compile the kernel with debug info, then save exit.

Make recompile (longer) use GDB to trace the debug kernel
    Qemu-system-i386-kernel LINUX-3.18.6/ARCH/X86/BOOT/BZIMAGE-INITRD Rootfs.img-s-S # Description of the-s and-sec    options:- S Freeze CPU at startup (with ' C ' to start execution)      for-gdb tcp::1234 If you do not want to use port 1234, you can replace the-s option with-gdb tcp:xxxx
Open another Shell window
    gdb    (gdb) file Linux-3.18.  6/vmlinux # Targe remote before loading symbol table    (GDB) in GDB interface target remote:1234  # Establishing a connection between GDB and Gdbserver , press C to allow the Linux on QEMU to continue running    (GDB)break Start_kernel # Breakpoint settings can be before target remote, or after
Experimental results:

UBUNTU14 debugging the Linux kernel with QEMU

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.