Qemu 使用記錄

簡介

一直想研究qemu很久了,都是淺嘗輒止,看一半的文檔就不搞了,要下載那麼多的鏡像很討厭的。最近覺得這兩年實在是沒什麼長進確實應該深入看看了。

命令行

先了解這個命令怎麼用吧,首先下載個TinyCore-current.iso 官網上下載才16MB

qemu-system-i386  -m 2G -smp 2 -vga vmware TinyCore-current.iso -enable-kvm

不支持kvm就刪除-enable-kvm吧,硬件加速的。

自編譯內核啓動

  1. 編譯內核

     make menuconfig 
     make 
     make bzImage
    
  2. 編譯文件系統initrd,

     cd linux-5.0.4/arch/x84_64/boot
     mkinitramfs -o initrd.img
    
  3. 使用內核鏡像和文件系統

     qemu-system-x86_64 -kernel bzImage -initrd initrd.img
    

好了,內核已經跑起來了,基本的initcramfs文件系統,感覺可以用來調試內核啓動失敗的bug, 當然不能涉及到文件系統。

自己寫啓動初始化進程

#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
  printf("Hello world!\n");
  sleep(999999999);
}

編譯

gcc init.c -o init -static

創建鏡像並啓動

echo init | cpio -o -H newc | gzip > test.cpio.gz

OK, 可以啓動內核,執行這個程序了

qemu-system-x86_64 -m 512M -kernel ./bzImage -initrd test.cpio.gz

http://www.tinycorelinux.net/downloads.html

http://gruba.blogspot.com/2009/08/qemu-minimal-linux-kernel-config.html
https://blog.csdn.net/u014022631/article/details/81001263

https://www.linuxidc.com/Linux/2015-03/114461.htm
https://www.linuxidc.com/Linux/2015-03/114462.htm
https://www.jianshu.com/p/e4ea9e9d8308

https://main.lv/writeup/qemu_usage.md
https://unix.stackexchange.com/questions/48302/running-bzimage-in-qemu-unable-to-mount-root-fs-on-unknown-block0-0

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章