Skip to content

Latest commit

 

History

History
114 lines (88 loc) · 4.35 KB

01-environment.md

File metadata and controls

114 lines (88 loc) · 4.35 KB

Phase 0 — Environment, source acquisition & setup

This is the groundwork every later phase depends on: what the machine is, what we installed, and how we got a trustworthy kernel source.

The machine

Host OS Ubuntu 24.04.4 LTS (Noble) on WSL2
Running kernel 6.6 (microsoft-standard-WSL2) — we build newer kernels, we don't replace this one
CPU AMD Ryzen 5 5500, 12 logical cores (Zen 3)
RAM 15 GiB (+4 GiB swap)
Free disk 893 GiB
Pre-installed gcc/g++ 13.3, make 4.3, cmake 3.28, rustc 1.95 + 1.91.1 + nightly, git 2.43, Docker 29

Plenty of headroom: 12 cores make full kernel builds take minutes, and disk is a non-issue (each kernel build tree is ~2–4 GiB).

What we installed

Kernel builds need a few packages Ubuntu doesn't ship by default. We also pulled the LLVM stack (required for kernel kCFI and for Rust) and QEMU (to actually boot-test what we build).

# kernel build prerequisites
sudo apt-get install -y flex bison libssl-dev libelf-dev dwarves \
     zstd lz4 cpio kmod build-essential libncurses-dev pkg-config rsync
# LLVM toolchain (kCFI + Rust bindgen) and QEMU
sudo apt-get install -y clang lld llvm libclang-dev qemu-system-x86 qemu-utils
# Rust toolchain bits (Phase 3)
sudo apt-get install -y bindgen-0.71
rustup component add rust-src --toolchain 1.91.1-x86_64-unknown-linux-gnu

Resulting tool versions used by the builds:

Tool Version Used for
gcc / g++ 13.3.0 default C compiler (minimal kernel)
clang / lld / llvm 18.1.3 modern kernel (kCFI) + Rust builds
rustc 1.91.1 Rust kernel code (≥ 1.85 required)
bindgen 0.71.1 Rust↔C bindings (≥ 0.71.1 required)
pahole (dwarves) 1.25 BTF generation (eBPF CO-RE)
flex / bison 2.6.4 / 3.8.2 Kconfig / build-time parsers
qemu-system-x86_64 8.2.2 boot-testing every kernel
zstd 1.5.5 ZSTD-compressed kernel image

WSL2 + KVM

/dev/kvm exists on this WSL2 install (nested virtualization; kvm_amd loaded) but is restricted to the kvm group. To let QEMU accelerate guests:

sudo usermod -aG kvm "$USER"     # persistent
sudo chmod 0666 /dev/kvm         # this session (WSL resets perms on restart)

With KVM, the minimal kernel reaches userspace in 0.29 s; without it (pure TCG emulation) the same boot takes the better part of a minute.

Choosing the kernel version

We queried https://www.kernel.org/releases.json:

latest_stable : 7.1
stable        : 7.0.12
longterm      : 6.18.35, 6.12.93, 6.6.142, 6.1.175, 5.15.x, 5.10.x

The task asks for the newest kernel, so we standardised on Linux 7.1 for all three phases (newest features, best Rust support, newest hardware enablement).

Getting the source — two ways, both verified

Tarball (used for the minimal and modern builds). We verified its integrity against kernel.org's signed checksum list before trusting it:

curl -LO https://cdn.kernel.org/pub/linux/kernel/v7.x/linux-7.1.tar.xz
# our sha256 == the one published in sha256sums.asc:
#   691f44797fbe790dc8a321604c927087526ad27b6d649925d60f8eed0a2564a0  ✓
tar -I 'xz -T0' -xf linux-7.1.tar.xz -C src --strip-components=1

Git clone (used for the Rust phase, per the task's "clone via git"):

git clone --depth 1 --branch v7.1 \
  https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git rust-kernel

Note: we first tried the GitHub mirror torvalds/linux but it only carried up to v7.1-rc2 — final release tags propagate to kernel.org first. A shallow (--depth 1) clone keeps it to ~270 MB instead of multiple GiB of history.

Workspace layout

~/os_experiments/linux_kernel/
├── downloads/        linux-7.1.tar.xz (+ .sign)
├── src/              extracted 7.1 source (shared by minimal + modern)
├── build-minimal/    O= out-of-tree minimal build  + boot-test/
├── build-modern/     O= out-of-tree modern build
├── rust-kernel/      git clone, Rust-enabled (in-tree build)
├── modern.config     documented "modern features" Kconfig fragment
├── artifacts/        collected bzImages, configs, boot logs, run scripts
└── docs/             this documentation

Using O=<dir> for the minimal and modern builds means one pristine src/ tree feeds two completely separate configurations without ever cross-contaminating.