aboutsummaryrefslogtreecommitdiffhomepage
path: root/content
diff options
context:
space:
mode:
Diffstat (limited to 'content')
-rw-r--r--content/2019-10-27-kernel-debugging-qemu/Dockerfile1
-rwxr-xr-xcontent/2019-10-27-kernel-debugging-qemu/build_initrd.sh12
-rwxr-xr-xcontent/2019-10-27-kernel-debugging-qemu/build_kernel.sh10
-rw-r--r--content/2019-10-27-kernel-debugging-qemu/index.md9
-rwxr-xr-xcontent/2019-10-27-kernel-debugging-qemu/run.sh5
5 files changed, 22 insertions, 15 deletions
diff --git a/content/2019-10-27-kernel-debugging-qemu/Dockerfile b/content/2019-10-27-kernel-debugging-qemu/Dockerfile
index 9da22f3..a2fe4c8 100644
--- a/content/2019-10-27-kernel-debugging-qemu/Dockerfile
+++ b/content/2019-10-27-kernel-debugging-qemu/Dockerfile
@@ -22,6 +22,7 @@ RUN apt update \
# Run & debug.
qemu-system-x86 \
gdb \
+ cgdb \
telnet \
# Convenience.
ripgrep \
diff --git a/content/2019-10-27-kernel-debugging-qemu/build_initrd.sh b/content/2019-10-27-kernel-debugging-qemu/build_initrd.sh
index fd82990..f5bece4 100755
--- a/content/2019-10-27-kernel-debugging-qemu/build_initrd.sh
+++ b/content/2019-10-27-kernel-debugging-qemu/build_initrd.sh
@@ -6,7 +6,7 @@ fi
set -e
-BUSYBOX=busybox-1.33.1
+BUSYBOX=busybox-1.36.1
INITRD=$PWD/initramfs.cpio.gz
## Build busybox
@@ -20,7 +20,7 @@ echo "[+] configure & build $BUSYBOX ..."
cd $BUSYBOX
make defconfig
sed -i 's/# CONFIG_STATIC .*/CONFIG_STATIC=y/' .config
-make -j4 busybox
+make -j$(nproc --ignore=2) busybox
make install
## Create initrd
@@ -38,17 +38,13 @@ cat <<EOF > init
mount -t proc none /proc
mount -t sysfs none /sys
+mount -t devtmpfs none /dev
exec setsid cttyhack sh
EOF
chmod +x init
-# 3. create device nodes
-$SUDO mknod dev/tty c 5 0
-$SUDO mknod dev/tty0 c 4 0
-$SUDO mknod dev/ttyS0 c 4 64
-
-# 4. created compressed initrd
+# 3. created compressed initrd
find . -print0 \
| cpio --null -ov --format=newc \
| gzip -9 > $INITRD
diff --git a/content/2019-10-27-kernel-debugging-qemu/build_kernel.sh b/content/2019-10-27-kernel-debugging-qemu/build_kernel.sh
index 7ae3014..2789a0e 100755
--- a/content/2019-10-27-kernel-debugging-qemu/build_kernel.sh
+++ b/content/2019-10-27-kernel-debugging-qemu/build_kernel.sh
@@ -2,8 +2,8 @@
set -e
-LINUX=linux-5.13.2
-wget https://cdn.kernel.org/pub/linux/kernel/v5.x/$LINUX.tar.xz
+LINUX=linux-6.6.2
+wget https://cdn.kernel.org/pub/linux/kernel/v6.x/$LINUX.tar.xz
unxz $LINUX.tar.xz && tar xf $LINUX.tar
cd $LINUX
@@ -28,11 +28,15 @@ CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_PROC_FS=y
CONFIG_SYSFS=y
# debugging
+CONFIG_DEBUG_KERNEL=y
CONFIG_DEBUG_INFO=y
+## tinyconfig sets DEBUG_INFO_NONE, overwrite with toolchain default else
+## DEBUG_INFO will not be enabled.
+CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y
CONFIG_PRINTK=y
CONFIG_EARLY_PRINTK=y
EOF
make tinyconfig
./scripts/kconfig/merge_config.sh -n ./kernel_fragment.config
-make -j4
+make -j$(nproc --ignore=2)
diff --git a/content/2019-10-27-kernel-debugging-qemu/index.md b/content/2019-10-27-kernel-debugging-qemu/index.md
index 518b3d5..bda445b 100644
--- a/content/2019-10-27-kernel-debugging-qemu/index.md
+++ b/content/2019-10-27-kernel-debugging-qemu/index.md
@@ -8,6 +8,8 @@ tags = ["linux", "qemu"]
**EDIT**:
- 2021-07-15: Added `Appendix: Dockerfile for Kernel development` and updated
busybox + Kernel versions.
+- 2023-11-23: Fix ramdisk vs ramfs ([ref][ramfs-vs-ramdisk]), and use
+ `devtmpfs` and updated busybox + Kernel versions.
The other evening while starring at some Linux kernel code I thought, let me
setup a minimal environment so I can easily step through the code and examine
@@ -15,7 +17,7 @@ the state.
I ended up creating:
- a [Linux kernel][linux-kernel] with minimal configuration
-- a minimal [ramdisk][initrd] to boot into which is based on [busybox][busybox]
+- a minimal [initramfs][initramfs] to boot into which is based on [busybox][busybox]
In the remaing part of this article we will go through each step by first
building the kernel, then building the initrd and then running the kernel using
@@ -31,7 +33,7 @@ This allows us to merge a fragment file into the current configuration by
running the `scripts/kconfig/merge_config.sh` script.
Let's quickly go over some customizations we do.
-The following two lines enable support for gzipped initramdisks:
+The following two lines enable support for gzipped initramfs:
```config
CONFIG_BLK_DEV_INITRD=y
CONFIG_RD_GZIP=y
@@ -78,6 +80,7 @@ cat <<EOF > init
mount -t proc none /proc
mount -t sysfs none /sys
+mount -t devtmpfs none /dev
exec setsid cttyhack sh
EOF
@@ -217,6 +220,8 @@ docker run -it kernel-dev
[linux-kernel]: https://www.kernel.org
[initrd]: https://www.kernel.org/doc/html/latest/admin-guide/initrd.html
+[ramfs]: https://www.kernel.org/doc/html/latest/filesystems/ramfs-rootfs-initramfs.html
+[ramfs-vs-ramdisk]: https://www.kernel.org/doc/html/latest/filesystems/ramfs-rootfs-initramfs.html#ramfs-and-ramdisk
[busybox]: https://busybox.net
[qemu]: https://www.qemu.org
[gdb]: https://www.gnu.org/software/gdb
diff --git a/content/2019-10-27-kernel-debugging-qemu/run.sh b/content/2019-10-27-kernel-debugging-qemu/run.sh
index b0a84ae..b9548ad 100755
--- a/content/2019-10-27-kernel-debugging-qemu/run.sh
+++ b/content/2019-10-27-kernel-debugging-qemu/run.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-VER=5.13.2
+VER=6.6.2
# Launch the emulator with our kernel.
qemu-system-x86_64 \
@@ -21,4 +21,5 @@ trap "kill $QEMU_PID" EXIT
sleep 0.5
# Attach debugger to qemu and load the kernel symbols.
-gdb -ex 'target remote :1234' ./linux-$VER/vmlinux
+which cgdb >& /dev/null && GDB=cgdb || GDB=gdb
+$GDB -ex 'target remote :1234' -ex 'set style enabled off' ./linux-$VER/vmlinux