Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/DeelerDev/linux/llms.txt

Use this file to discover all available pages before exploring further.

The Linux kernel build system uses GNU Make and a layered Kconfig configuration framework. This page walks you through every step required to go from a fresh checkout to a running, self-compiled kernel — covering required tools, configuration strategies (including the localmodconfig trimmed-config approach), build commands, and installation. It also notes common pitfalls such as Secure Boot restrictions and distro-specific adjustments.

Required build dependencies

You need the following minimum tool versions before building. Run ./scripts/ver_linux inside the source tree to check what is installed.
ToolMinimum version
GNU C (gcc)8.1
GNU make4.0
bash4.2
binutils2.30
flex2.5.35
bison2.0
bc1.06.95
perl5
Python3.9.x
openssl + libcrypto1.0.0
pahole (dwarves)1.22
Install everything in one shot using your distribution’s package manager:
sudo apt install bc binutils bison dwarves flex gcc git make openssl \
  pahole perl-base libssl-dev libelf-dev
openssl and its development headers are required even if you do not plan to use Secure Boot, because many distribution kernel configurations enable it for x86 by default.

Build flow

1

Prepare for Secure Boot

On systems with Secure Boot enabled, self-compiled kernels will be rejected at boot unless you either sign them or disable the restriction.The quickest approach on mainstream x86 Linux distributions is to disable validation for your local environment:
mokutil --disable-validation
This prompts you to set a one-time password. Reboot, and when the Shim bootloader shows the MOK management screen, select Change Secure Boot state and enter the password characters it requests. Alternatively, disable Secure Boot entirely in your BIOS setup utility.
2

Get the source

Clone the Linux stable git repository. A shallow clone saves bandwidth and works well for building and testing:
git clone --no-checkout --depth 1 -b master \
  https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git ~/linux/
cd ~/linux/
git checkout --detach origin/master
To also access recent stable/longterm releases (for example, the 6.1.y series), add the branch and deepen the history:
git remote set-branches --add origin linux-6.1.y
git fetch --shallow-exclude=v6.0 origin
If you want the absolute latest mainline code before it syncs to the stable mirror, add Linus’s tree as an additional remote: git remote add mainline https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
3

Configure the kernel

Choose a configuration strategy based on your goal.Trimmed config (recommended for testing and day-to-day use)localmodconfig uses your currently loaded modules as a guide, disabling drivers your system is not using. This dramatically reduces compile time:
yes "" | make localmodconfig
localmodconfig only includes modules that were loaded at the time you ran the command. Drivers for devices you have not recently used — external storage, VPNs, virtual machines — may be omitted. For production systems, consider recording loaded modules over several weeks with modprobed-db and passing the result with LSMOD=.
Generic config based on your running kernelIf you want to match your distribution’s configuration more closely:
make olddefconfig
Interactive configurationTo browse and toggle options manually:
make menuconfig   # text-based (requires ncurses)
make xconfig      # graphical (requires Qt5)
Debian-specific adjustmentOn Debian, remove a stale certificate reference that would cause a build failure:
./scripts/config --file .config --set-str SYSTEM_TRUSTED_KEYS ''
make olddefconfig
4

Tag your build (optional but recommended)

If you already have a kernel of the same version installed, or if you applied patches, add a unique tag so the new kernel installs alongside the existing one without conflict:
echo "-mybuild" > localversion
Running uname -r on the booted kernel will then show something like 6.1.0-rc4-mybuild.
5

Compile

Build the kernel image and all modules in parallel across all available CPU cores:
make -j$(nproc)
The current kernel version is 7.1.0-rc3 (“Baby Opossum Posse”), as defined in the top-level Makefile.If the build fails, re-run with verbose output to isolate the error:
make V=1
You can also build directly to a distributable package instead of using the default targets:
make -j$(nproc) bindeb-pkg
6

Install modules and kernel

On most mainstream distributions a single command handles both module installation and kernel image installation, then updates the bootloader and generates an initramfs:
command -v installkernel && sudo make modules_install install
On distributions such as Arch Linux that do not ship an installkernel script, install manually:
sudo make modules_install
sudo install -m 0600 $(make -s image_name) /boot/vmlinuz-$(make -s kernelrelease)
sudo install -m 0600 System.map /boot/System.map-$(make -s kernelrelease)
After the manual install, generate an initramfs using your distribution’s tool and add the kernel entry to your bootloader configuration.
Install modules before the kernel image. Many distributions generate the initramfs during installkernel and require the modules to be present at that point.
7

Boot the new kernel

Reboot and select the new kernel from the bootloader menu if it is not already the default:
reboot
After booting, verify the running kernel version:
uname -r

Rebuilding for a newer version

Once you have a trimmed .config from the first build, use olddefconfig rather than localmodconfig for subsequent builds so you keep your configuration intact:
cd ~/linux/
git fetch --depth 1 origin
git checkout --force --detach origin/master
make olddefconfig
make -j$(nproc)
command -v installkernel && sudo make modules_install install
reboot

Removing a kernel

Kernel files are stored in exactly two places, both named after the kernel’s release name, making removal straightforward. Replace 6.1.0-mybuild with your actual release name:
sudo rm -rf /lib/modules/6.1.0-mybuild
command -v kernel-install && sudo kernel-install -v remove 6.1.0-mybuild
# If kernel-install is unavailable, remove files manually:
rm -i /boot/{System.map,vmlinuz}-6.1.0-mybuild
Never remove the kernel you are currently running. Confirm the running kernel with uname -r before deleting any kernel files.

Space requirements

Building a typical x86 kernel configured with localmodconfig requires approximately 12 GB in the source directory. With debug symbols disabled the build artifacts shrink to around 1 GB; with them enabled, expect roughly 5 GB. The installed kernel needs about 150 MB in /lib/modules/ and 100 MB in /boot/. To disable debug symbols and save space:
./scripts/config --file .config -d DEBUG_INFO \
  -d DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT -d DEBUG_INFO_DWARF4 \
  -d DEBUG_INFO_DWARF5 -e CONFIG_DEBUG_INFO_NONE
make olddefconfig

Build docs developers (and LLMs) love