编译x86_64 Linux内核并基于QEMU运行
编译并运行内核镜像
安装包准备
$ 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
参考
编译x86_64 Linux内核并基于QEMU运行的更多相关文章
- 编译aarch64 Linux内核并基于qemu运行
核心流程 首先,本文主要讲述如何编译Linux内核并在qemu虚拟机上运行.这里针对的架构是aarch64. 本文的实验平台是Ubuntu 16.04. 为了达成目标,我们需要有qemu.buildr ...
- 编译安装linux内核步骤
编译安装linux内核步骤: 一.获取内核源码 源码网址:www.kernel.org 二.解压内核源码 首先以root帐号登录,然后进入/usr/src子目录.如果用户在安装Linux时,安装了内核 ...
- 【转】6.4.6 将驱动编译进Linux内核进行测试
原文网址:http://www.apkbus.com/android-98520-1-1.html 前面几节都是将Linux驱动编译成模块,然后动态装载进行测试.动态装载驱动模块不会随着Android ...
- linux内核系列(一)编译安装Linux内核 2.6.18
1.配置环境 操作系统:CentOS 5.2 下载linux-2.6.18版本的内核,网址:http://www.kernel.org 说明:该编译文档适合2.6.18以上的Linux内核版本,只需所 ...
- 将MPLS编译进linux内核中
系统环境:linux kernel 2.6.35.(此环境是上一篇文章中将ubuntu内核替换后的环境) 编译过程如下: 1)首先需要下载patch文件:linux-kernel-v2.6.35-mp ...
- 将驱动编译进Linux内核
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- 如何编译安装Linux内核
操作系统环境 VMware workstation15 Pro ubuntu18.04 LTS 待编译内核5.3.10版本 内核下载地址 kernel.org 环境配置 在正式编译前需要安装部分软件. ...
- 编译最新linux内核(version 4.4.2)
环境:centos6.4 内核版本为2.6.32 目标:编译4.4.2内核,升级到 4.4.2 准备工作: 安装开发库和ncurses库 # yum groupinstall "Develo ...
- 以Qemu模拟Linux,学习Linux内核
文章名称:以Qemu模拟Linux,学习Linux内核作 者:five_cent文章地址:http://www.cnblogs.com/senix/archive/2013/02/21/29 ...
随机推荐
- CPU 使用率 100% 怎么办
CPU 使用率 100% 怎么办 独家号 码上实战 作者 flyhero原文链接 工作中遇到CPU使用率100%,不要慌,一起来找出原因并fix掉它. 记住这里大致流程,当线上突然遇到时,也不必手足无 ...
- ssh判断免密登陆
ssh判断免密登陆 [root@jenkins ~]# vi /opt/release_code.sh #!/bin/bash . /etc/init.d/functions #echo $WORKS ...
- IT菜鸟之DHCP
DHCP 动态主机配置协议(Dynamic host configuration protocol) 作用:分配网络地址 选项: excluded-address 排除地址 pool IP地址池(网段 ...
- OSI 七层参考模型与 TCP/IP 四层协议
OSI 七层参考模型 OSI (Open System Interconnect,开放系统互连参考模型)是由 ISO(国际标准化组织)定义的,它是个灵活的.稳健的和可互操作的模型,并不是协议,常用来分 ...
- MVC RadioButton控件
@Html.RadioButtonFor(m => m.IfValid, 1, new { @id = "radio1", @name = "rdolstState ...
- nginx 的基础知识(二)
Nginx 多进程网络模型 进程模型 nginx启动后以daemon的方式在后台运行,后台进程包括一个master进程和多个worker进程 master进程主要作用,接收来自外界的信号:向各work ...
- Linux Docker 部署 ASP.NET Core应用
一.系统环境 1.腾讯云轻量应用服务器CentOS7.6 二.操作流程及途中遇到的问题 1.SSH方式远程Linux ssh <username>@<IP address or do ...
- elasticsearch_dsl 操作
import elasticsearch from elasticsearch_dsl import Search, MultiSearch # Search-执行一个搜索,MultiSearch-同 ...
- 用python调试Appium和雷电模拟器连接时出现Original error: Could not find 'adb.exe' in PATH
用python调试Appium和雷电模拟器连接时出现Original error: Could not find 'adb.exe' in PATH 确定环境变量没错,用管理员启动Appium就不会出 ...
- VBScript学习第一天
编码工具:VbsEdit 1.MsgBox() 毫无例外,第一个要学的就是"Hello, World!" 直接输入: MsgBox ("Hello, World!&quo ...