编译并运行内核镜像

安装包准备

$ sudo apt install git
$ sudo apt install build-essential kernel-package fakeroot libncurses5-dev libssl-dev ccache flex bison libelf-dev

下载 Linux 源码

# 使用 git 下载 Linux 源码并切换到合适的 commit,或者直接从官网下载 tarball
$ git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

linux内核镜像编译运行及gdb调试

$ cd linux
$ make ARCH=x86_64 x86_64_defconfig
$ make ARCH=x86_64 menuconfig # 打开 `Kernel hacking -> Compile-time checks and compiler options -> Compile the kernel with debug info -> Provide GDB scripts for kernel debugging`
$ make -j
$ qemu-system-x86_64 -no-kvm -kernel arch/x86/boot/bzImage -hda /dev/zero -append "root=/dev/zero console=ttyS0" -serial stdio -display none # 由于没有根文件系统,并不会进入 shell,使用 Ctrl+C 退出

使用 gdb 调试内核启动流程

$ qemu-system-x86_64 -s -S -no-kvm -kernel arch/x86/boot/bzImage -hda /dev/zero -append "root=/dev/zero console=ttyS0 nokaslr" -serial stdio -display none
# 重新开一个 shell session
$ cd /path/to/your/linux
$ gdb ./vmlinuz
(gdb) target remote localhost:1234
(gdb) break start_kernel
(gdb) c
(gdb) layout src
...

使用 buildroot 编译 rootfs

在使用 buildroot 编译 rootfs 时,若在内网使用,记得设置代理服务器。

$ git clone git://git.buildroot.net/buildroot
$ cd buildroot
$ make menuconfig
# select `Target Options -> Target Architecture -> x86_64`
# select `Filesystem images -> ext2/3/4 root file system -> ext4`
$ make -j

运行带有 rootfs 的 linux kernel

$ cd /path/to/your/linux
$ qemu-system-x86_64 -no-kvm -kernel arch/x86/boot/bzImage \
-boot c -m 2048M -hda ../buildroot/output/images/rootfs.ext4 \
-append "root=/dev/sda rw console=ttyS0,115200 acpi=off nokaslr" \
-serial stdio -display none

参考

最新文章

  1. SQL Server 跨网段(跨机房)FTP复制
  2. [转]Efficiently Paging Through Large Amounts of Data
  3. ApplicationContext.xml文件详解
  4. POJ 1743 后缀数组不重叠最长重复子串
  5. 《iOS开发指南》正式出版-源码-样章-目录,欢迎大家提出宝贵意见
  6. 安装tcpreplay时报错:configure: error: libdnet not found
  7. 贴近浏览器窗口右侧的jqueryui dialog快速从左侧调整大小时对话框大小设置不准确的问题
  8. form 和 ngModel
  9. Lambda&Java多核编程-6-方法与构造器引用
  10. js监听浏览器离开页面操作
  11. MYSQL一键安装
  12. 2019年3月2日-小雨.md
  13. 基于.Net进行前端开发的技术栈发展路线(三)
  14. Chrome浏览器的版本查看 以及V8 javascript 引擎版本查看
  15. NLog类库使用探索——编程配置
  16. gitlab 建立本地仓库
  17. Scala进阶之路-Scala高级语法之隐式(implicit)详解
  18. quick player no exit
  19. 教程:如何手动安装Xamarin与Xamarin for VisualStudio
  20. los中预览文件

热门文章

  1. Linux 操作系统(二)搜索文件命令find、locate、which、whereis、grep、wc
  2. shell基础之bus实战(if 练习)
  3. C++的构造函数为何不能为虚函数
  4. 标准Gitlab命令行操作指导
  5. Web应用漏洞-NGINX各类请求头缺失对应配置
  6. 通过Maven打jar包&运行
  7. GO学习-(19) Go语言基础之网络编程
  8. gasshopper之python电池输出dict结构
  9. Docker_Swarm集群系统
  10. 五、部署LNMP环境(linux + nginx + mysql + php)