Search notes:

Linux kernel compilation

Also referred to as «building the Linux kernel».

Prerequisites

Some prerequisites to compile the kernel include
tk and tcl are required in configuration step
533 rene @ debian 14:15:28 ~/github/linux/temp/TODO/kernel/compilation/make-targets/tinyconfig/linux-src make tinyconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/confdata.o
  HOSTCC  scripts/kconfig/expr.o
  LEX     scripts/kconfig/lexer.lex.c
/bin/sh: 1: flex: not found
sudo apt install -y flex bison

Config options

UEFI needs these config options.

Default configuration

The kernel includes a default configuration.
The default configuration is presented the first time menuconfig is run on a source tree.

Specifying an alternate config file

By default, the make system uses ./.config as build configuration file.
An alternate file can be chosen by setting the environment variable KCONFIG_CONFIG to the path of a config file or specyfing the alternate config file directly like so:
make KCONFIG_CONFIG=test.config

Specifying a separate build directory

By default, the generated files go into the same tree as the kernel sources. Invoking make with O=/path/to/output/dir allows to specify an alternative destination
cd /usr/src/linux-4.X
make O=/home/name/build/kernel menuconfig
make O=/home/name/build/kernel
sudo make O=/home/name/build/kernel modules_install install

Verbosity level

make V=1 prints detailed compile and link commands.
make V=2 also prints why a target is rebuilt.

TODO

The compiled kernel should be placed under arch/x86/boot/bzImage.
scripts/config (in the Kernel source tree) allows to manipulate options in a .config file from the command line.

See also

Documentation/admin-guide/quickly-build-trimmed-linux.rst is a guide that explains how to quickly compile kernels that are
Creating a kernel for debugging with QEMU and gdb.
Documentation/admin-guide/README.rst
gcc -mcmode=kernel

Index