-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
publish debug linux kernel with qemu and busybox
- Loading branch information
1 parent
f306caa
commit 71db5ca
Showing
2 changed files
with
127 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
--- | ||
title: "How to Debug Linux Kernel (with `qemu` & `busybox`)" | ||
date: 2024-09-25T17:00:55-05:00 | ||
draft: false | ||
toc: false | ||
images: | ||
tags: | ||
- kernel | ||
--- | ||
|
||
# How to Debug Linux Kernel (with `qemu` & `busybox`) | ||
|
||
## Outline | ||
|
||
- clone `linux` source code | ||
- clone `busybox` | ||
- check compile configs | ||
- generate `initramfs` by `busybox` | ||
- install `qemu` | ||
- boot kernel by `qemu` attached with user space from `busybox` | ||
- other configurations | ||
|
||
## Prepare Linux src | ||
|
||
> before get started, make sure you have `flex` & `bison` installed to config and compile linux kernel | ||
- clone [linux src](https://github.com/torvalds/linux.git) | ||
|
||
```bash | ||
git clone https://github.com/torvalds/linux.git | ||
cd linux | ||
``` | ||
|
||
- config it for minimal: | ||
|
||
```bash | ||
make allnoconfig | ||
``` | ||
|
||
- and enable following config by: | ||
|
||
```bash | ||
make menuconfig | ||
``` | ||
|
||
> 64-bit kernel ---> yes | ||
> General setup ---> Initial RAM filesystem and RAM disk (initramfs/initrd) support ---> yes | ||
> General setup ---> Configure standard kernel features ---> Enable support for printk ---> yes | ||
> Executable file formats / Emulations ---> Kernel support for ELF binaries ---> yes | ||
> Executable file formats / Emulations ---> Kernel support for scripts starting with #! ---> yes | ||
> Device Drivers ---> Generic Driver Options ---> Maintain a devtmpfs filesystem to mount at /dev ---> yes | ||
> Device Drivers ---> Generic Driver Options ---> Automount devtmpfs at /dev, after the kernel mounted the rootfs ---> yes | ||
> Device Drivers ---> Character devices ---> Enable TTY ---> yes | ||
> Device Drivers ---> Character devices ---> Serial drivers ---> 8250/16550 and compatible serial support ---> yes | ||
> Device Drivers ---> Character devices ---> Serial drivers ---> Console on 8250/16550 and compatible serial port ---> yes | ||
> File systems ---> Pseudo filesystems ---> /proc file system support ---> yes | ||
> File systems ---> Pseudo filesystems ---> sysfs file system support ---> yes | ||
> Processor type and features ---> Linux guest support ---> Support for running PVH guests ---> yes | ||
you may check `linux/.config` to see whether its configured successfully | ||
|
||
- then compile it: | ||
|
||
```bash | ||
make -j | ||
``` | ||
|
||
## Prepare BusyBox | ||
|
||
- clone [BusyBox](https://github.com/mirror/busybox.git) | ||
|
||
```bash | ||
git clone https://github.com/mirror/busybox.git | ||
``` | ||
|
||
- config it: | ||
|
||
```bash | ||
make defconfig | ||
``` | ||
|
||
- we're willing to compile it statically. | ||
so we need to enable the following features by: | ||
|
||
```bash | ||
make menuconfig | ||
``` | ||
|
||
> Settings ---> Build Options ---> Build static binary | ||
- then generate the rootfs by: | ||
|
||
```bash | ||
make install | ||
``` | ||
|
||
- modify rootfs: | ||
> create a file named `init` at the root of **\_install** under busybox with following content: | ||
```bash | ||
#!/bin/sh | ||
mount -t proc proc /proc | ||
mount -t sysfs sysfs /sys | ||
mount -t devtmpfs devtmpfs /dev | ||
|
||
echo "Booting BusyBox..." | ||
exec /bin/sh | ||
``` | ||
|
||
- create initramfs by: | ||
|
||
```bash | ||
cd _install | ||
find . | cpio -H newc -o | gzip > ../ramdisk.img | ||
``` | ||
|
||
## Install qemu | ||
|
||
```bash | ||
sudo apt install qemu-kvm | ||
``` | ||
|
||
## Boot the kernel and user space | ||
|
||
```bash | ||
qemu-system-x86_64 -nographic --append "console=ttyS0" -kernel ./vmlinux -initrd ../busybox/ramdisk.img | ||
``` |
This file was deleted.
Oops, something went wrong.