【内核学习】001编译和运行
compile the kernel
clone和compile在容器中操作
1 | docker run --privileged -d -it --name angel -v `pwd`:/root/code -w /root/code ghcr.io/falcon-infra/dev:ubuntu24.04 |
clone code
1 | git clone https://mirrors.tuna.tsinghua.edu.cn/git/linux-stable.git |
compile
1 | # 1. 生成默认配置 |
使用 BusyBox 创建最小 rootfs 的步骤如下:
- 下载并编译 BusyBox
1
2
3
4
5
6
7wget https://busybox.net/downloads/busybox-1.36.1.tar.bz2
tar xf busybox-1.36.1.tar.bz2
cd busybox-1.36.1
make defconfig
make menuconfig # 可选:静态编译 Settings → Build static binary (no shared libs)
make -j$(nproc)
make install
1 | # 1. 先拿一份默认配置 |
这里回到mac宿主机。
- 创建必要的目录结构
1 | cd rootfs |
- 创建基础设备节点
1 | cd rootfs/dev |
- 创建初始化脚本
1 | cd rootfs |
- 创建简单的fstab
1 | cat > etc/fstab << 'EOF' |
- 创建rootfs镜像
1 | cd rootfs |
- 使用QEMU启动
1
2
3
4
5
6
7
8
9
10qemu-system-aarch64 \
-machine virt \
-cpu cortex-a72 \
-smp 4 \
-m 2G \
-kernel linux-stable/arch/arm64/boot/Image \
-initrd busybox-1.36.1/rootfs.cpio.gz \
-append "console=ttyAMA0 rdinit=/init" \
-nographic \
-no-reboot