| Lesson 7 | Prepare a Linux Kernel Build Environment |
| Objective | Select a source release, verify prerequisites, and create separate source and build directories. |
Preparation determines whether a kernel build is repeatable. Record the distribution, architecture, running kernel, selected source release, and intended configuration change. This lab builds an upstream kernel for an x86-64 Linux VM; it does not rebuild the vendor's RHEL source RPM.
Choose an appropriate stable or longterm release from the Linux Kernel Archives and record the exact version. A release candidate is a testing release, not a default production choice. The old rule that even minor versions are stable and odd minor versions are developmental does not describe current kernel release management.
Obtain source from the upstream project or your distribution's official source channel. Follow the Kernel Archives' signature-verification instructions before using a downloaded archive. Record any patches separately. A checksum copied from an untrusted download location does not independently establish authenticity.
The selected source tree's Documentation/process/changes.rst defines its tool requirements. Typical builds need a C compiler, assembler/linker, make, shell and scripting utilities, and packages supplying tools such as bc, bison, and flex. Configuration choices can additionally require OpenSSL development files, libelf development files, pahole, or Rust tools. Text menu configuration needs ncurses development support.
uname -m
gcc --version
make --version
ld --version
df -h "$HOME" /boot
free -h
Package names and minimum versions vary. Install them from the distribution's documented repositories, then compare the installed versions with the selected kernel's requirements. Allow space for source, object files, modules, and debug information; a full distribution-style configuration can consume much more storage than a small test build.
Extract the verified release archive under $HOME/kernel-lab. In the following examples, replace the placeholder with the exact release you downloaded. The source directory must already contain the extracted kernel tree.
version='REPLACE_WITH_SELECTED_RELEASE'
src="$HOME/kernel-lab/linux-$version"
build="$HOME/kernel-lab/build-$version-lab1"
test -f "$src/Makefile" && test -f "$src/Kconfig"
mkdir -p "$build"
Stop if the source checks fail. Use a clean source tree and an absolute output path. Subsequent lessons pass O="$build" consistently so configuration and generated files stay in that build directory. Compile as an ordinary user; reserve elevated privileges for installation.
The kernel-devel package used for building external modules against a distribution kernel is not a substitute for the complete upstream source needed to build a new kernel.
Take a VM snapshot, confirm console access, and retain the working kernel. Check whether Secure Boot is enabled and determine how locally built kernels and modules will be trusted. Resolve the signing process before installation rather than discovering a rejection at the next boot.
The next lesson creates a configuration in the build directory and assigns the custom kernel a distinct release suffix.