ubuntu14使用qemu調試linux核心

來源:互聯網
上載者:User

標籤:

    # 下載核心原始碼編譯核心    cd ~/LinuxKernel/    wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.18.6.tar.xz    xz -d linux-3.18.6.tar.xz    tar -xvf linux-3.18.6.tar    cd linux-3.18.6    make i386_defconfig    make # 一般要編譯很長時間,少則20分鐘多則數小時         # 製作根檔案系統    cd ~/LinuxKernel/    mkdir rootfs    git clone   # 如果被牆,可以使用附件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         # 啟動MenuOS系統    cd ~/LinuxKernel/    qemu -kernel linux-3.18.6/arch/x86/boot/bzImage -initrd rootfs.img

在執行 qemu -kernel linux-3.18.6/arch/x86/boot/bzImage -initrd rootfs.img 時報錯,沒有qemu這個命令。

正確做法:qemu-system-i386 -kernel linux-3.18.6/arch/x86/boot/bzImage -initrd rootfs.img

原因分析:

我以為沒有安裝qemu,於是開始安裝,按照http://jingyan.baidu.com/album/b907e627cfffc946e7891cd5.html的網址

sudo apt-get install qemu-kvm libvirt-bin virt-manager bridge-utils

lsmod | grep kvm

virsh -c qemu:///system list

但是後來發現這個網址:http://blog.csdn.net/xsckernel/article/details/8159548#comments

得知kvm是系統內建的,於是卸載了原來安裝的

sudo apt-get remove qemu-kvm

sudo apt-get remove libvirt-bin

sudo apt-get remove virt-manager

sudo apt-get remove bridge-utils

但是不知道為什麼 還存在kvm例如:lsmod | grep kvm

通過網址:http://zhangjun2915.blog.163.com/blog/static/3808623620103585320514/

得知 /usr/bin/qemu-system-x86_64就是qemu-kvm

於是我就在/esr/bin/目錄下看到:

 

從而確定了qemu-system-x86_64是類比64位系統,qemu-system-i386是類比32位系統。

於是最後一行命令改為:

qemu-system-i386 -kernel linux-3.18.6/arch/x86/boot/bzImage -initrd rootfs.img

可以運行效果是:

 

  • 重新設定編譯Linux使之攜帶調試資訊
 在原來配置的基礎上,在shell終端輸入:make menuconfig

會報錯,錯誤資訊如下:

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

scripts/kconfig/lxdialog/dialog.h:31:20: error: curses.h: 沒有那個檔案或目錄

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

參考網址:http://blog.chinaunix.net/uid-25896350-id-367612.html

解決辦法:sudo apt-get install libncurses5-dev

然後重新輸入:make menuconfig,效果如下:按空格選擇kernel hacking—>

按空格選擇 Compile -time checks and Complier options  -->

按空格選擇 [*] compile the kernel with debug info,然後儲存退出。

make重新編譯(時間較長) 使用gdb跟蹤調試核心
    qemu-system-i386 -kernel linux-3.18.6/arch/x86/boot/bzImage -initrd rootfs.img -s -S # 關於-s和-S選項的說明:    # -S freeze CPU at startup (use ’c’ to start execution)    # -s shorthand for -gdb tcp::1234 若不想使用1234連接埠,則可以使用-gdb tcp:xxxx來取代-s選項
另開一個shell視窗
    gdb    (gdb)file linux-3.18.6/vmlinux # 在gdb介面中targe remote之前載入符號表    (gdb)target remote:1234 # 建立gdb和gdbserver之間的串連,按c 讓qemu上的Linux繼續運行    (gdb)break start_kernel # 斷點的設定可以在target remote之前,也可以在之後
實驗效果:

ubuntu14使用qemu調試linux核心

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.