Kernel build and module lab planning
Quick answer
A kernel build produces a kernel image and related artifacts for a particular configuration and architecture. An external module is a separately built piece of kernel code. Before compiling or loading anything, establish the exact target release, prepared build tree, compiler requirements and a disposable recovery environment.
Think of the running kernel and its build tree as a matched pair. A module built for another configuration may fail to load even when the source compiles. Keep the original boot entry and test the candidate in a disposable guest, not on your workstation.
Prepare the practice environment
Run python3 lab-fixtures/advanced-kernel/setup.py from the extracted root as an ordinary user. Enter the printed private path and check pwd. Use fresh fixtures, Bash with set -e -o pipefail, LC_ALL=C and umask 077. The helper reads fictional records. No root, external network, module load or BPF attachment is required. Optional hardware inspection requires an authorized VM.
Prerequisites
Review: Container security and OCI orientation, Performance experiments.
How it works
A reliable plan separates build, installation, boot and runtime verification. Record the distribution package release, architecture, configuration, compiler and exact target build directory. uname -r describes the running kernel, not necessarily the one you intend to build. External modules normally use Kbuild; obj-m := demo.o describes a module target, not an instruction to load it. A prepared tree supplies generated headers and configuration; when symbol versioning is enabled, modules_prepare alone does not generate the required Module.symvers. Distribution patches and symbol versions matter even if two kernels share a base version. A successful compile does not prove that a module is compatible, correctly signed or safe. Inspect metadata with modinfo in a lab if the artifact exists. Use a disposable VM with a console, known-good boot entry, bounded resources and a tested snapshot/backup. The examples here only inspect tools and a fictional build manifest; the included Makefile is an ordinary, reviewed userspace teaching file, not Kbuild. Native compilation, signing, insertion and boot are separate manual gates.
Try the examples
make --version | grep -q '^GNU Make' && printf 'GNU Make available\n'Checks the tool identity only; the compiler and kernel tree still require separate checks.
Expected stdout:
GNU Make availableThe simple recipe is printed, not executed. GNU Make dry-run can still execute recursive or specially marked recipes and expansion-time commands; never use it as a sandbox for untrusted Makefiles.
Expected stdout:
printf '%s\n' 'build plan only'The fictional plan passes matching-release and rollback checks; the second plan is rejected. This does not prove real ABI compatibility.
Expected stdout:
ready: target and headers match; rollback plannedblocked: header release mismatchCommon mistakes
Never use a build success or matching release string as permission to load a module. Do not disable signature enforcement, install into the live boot tree, or use make -n on untrusted build files.
Practice
Compare the two plans in build.json. Identify the missing condition in the rejected plan, then write a checklist for compiler, target configuration, symbols, VM snapshot and recovery console. Do not build or load a module.
Related references
Study: make, modinfo. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Kernel build and module lab planning — Knowledge Check
Apply kernel engineering concepts to concrete local examples.
The running kernel differs from the target kernel for a module build. Which release does uname -r identify?
A reviewed Makefile is previewed with make -n. What evidence does that provide?
What may be missing after modules_prepare with symbol versioning?
What is needed before a module runtime lab?