技术知识库
在 Ubuntu 26.04 搭建 Running Linux Kernel 5.0 实验环境
在 Ubuntu 26.04 搭建 Running Linux Kernel 5.0 实验环境
摘要
本手册负责实验平台的主机预检和主线导航。依次完成后,将得到 Linux 5.0 ARM64 内核、External BusyBox initramfs、Built-in initramfs,以及可写的 Debian 12 ARM64 ext4 长期实验系统。
1. 确认源码仓库
cd /home/martin-zou/workspace/runninglinuxkernel_5.0
git branch --show-current
git rev-parse HEAD
git status --short
本轮分支为 rlk_5.0。如果工作树已有修改,先确认归属,不覆盖或清理现有内容。
2. 检查主机与空间
uname -a
cat /etc/os-release
uname -m
df -h /home/martin-zou/workspace
nproc
主机应为 x86_64;目标 ARM64 程序不能直接在主机 CPU 上执行,需交叉编译和 QEMU。
3. 安装平台依赖
sudo apt update
sudo apt install \
build-essential \
gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu \
flex bison bc libssl-dev libncurses-dev \
qemu-system-arm qemu-user-binfmt \
debootstrap debian-archive-keyring \
cpio gzip bzip2 wget e2fsprogs
4. 验证关键工具
aarch64-linux-gnu-gcc --version
flex --version
bison --version
qemu-system-aarch64 --version
qemu-aarch64 --version
debootstrap --version
cat /proc/sys/fs/binfmt_misc/qemu-aarch64
binfmt 应显示 enabled。
5. 按顺序完成主线
- 编译 Linux 5.0 ARM64 内核
- 使用 BusyBox 制作 ARM64 initramfs
- 将 BusyBox initramfs 内置到 Linux 5.0 ARM64 Image
- 从 Debian 官方仓库构建 ARM64 ext4 根文件系统
- 交叉编译并加载 Linux 5.0 ARM64 Hello World 模块
前四项是平台构建 runbook;第五项开始使用该平台进行书本内核实验。
6. 最终产物检查
file /home/martin-zou/workspace/runninglinuxkernel_5.0/build/arm64/arch/arm64/boot/Image
file /home/martin-zou/workspace/busybox-1.37.0/_install/bin/busybox
ls -lh /home/martin-zou/workspace/busybox-1.37.0/rootfs-v2.cpio.gz
file /home/martin-zou/workspace/runninglinuxkernel_5.0/build/arm64-builtin/arch/arm64/boot/Image
ls -lh /home/martin-zou/workspace/debian-arm64.ext4
已验证环境
ARM64 GCC: 15.2.0
Flex: 2.6.4
Bison: 3.8.2
QEMU: 10.2.1
Linux: 5.0.0+
BusyBox: 1.37.0, AArch64 static
长期用户空间: Debian 12 bookworm ARM64
故障索引
- 生成 ARM64 配置时提示 flex not found
- 编译 Linux 5.0 时缺少 OpenSSL 头文件
- BusyBox 1.37 menuconfig 在 GCC 15 下误报缺少 ncurses
- BusyBox 1.37 ARM64 编译遇到 SHA-NI 与 TC 兼容性错误
- Linux 5.0 QEMU 中熵不足导致 systemd SSH 和 HTTPS 阻塞
- Ubuntu 26.04 中 qemu-user-static 是虚拟包