Building the Linux kernel from source lets you test fixes, experiment with configuration options, and run the very latest mainline code. The process is straightforward on any mainstream Linux distribution: clone the sources, generate a configuration based on your running kernel, compile, and install.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.
Before you start
If your system uses Secure Boot, you must either disable it in your BIOS setup utility or disable validation with:/lib/, and 100 MB in /boot/.
Install build dependencies
- Debian / Ubuntu
- Fedora
- openSUSE
Step-by-step build guide
Clone the kernel sources
Fetch a shallow clone of the Linux stable repository. This downloads only the latest snapshot and is much faster than a full clone.Then check out the latest mainline code:If you also need access to recent mainline releases and pre-releases, deepen the clone’s history:
Apply patches (optional)
If you want to test a proposed fix or patch, apply it now before configuring:If the patch does not apply cleanly, try without
-p1. To undo any changes, run:Tag your build (optional)
If you already have the same kernel version installed, or you applied a patch, add a unique tag so the new kernel installs alongside the existing one:Running
uname -r under your new kernel will then print something like 6.1-rc4-proposed_fix.Configure the kernel
Generate a build configuration trimmed to only the modules your running system actually uses:This uses your distribution’s running kernel as a base and disables modules for features not currently in use, which dramatically shortens compile time.If you have an existing Debian users: Remove a stale certificate reference that will otherwise cause the build to fail:To disable debug symbols and reduce disk usage from ~5 GB to under 1 GB:To browse all configuration options interactively, run
localmodconfig may omit drivers for devices that were not connected or features that were not exercised since the last boot — for example, USB peripherals you plug in occasionally or VPN drivers. If you need a feature that stops working, re-enable it and rebuild..config file you want to use as a base instead, copy it to ~/linux/.config and run:make menuconfig (requires ncurses development headers).Compile the kernel
Build the kernel image and all modules, using every available CPU core:If the build fails, re-run with verbose output to see the actual error:Packaging alternatives: You can produce distribution-ready packages instead of installing manually:
Install modules and kernel
On most distributions a single command installs the modules, copies the kernel image, generates an initramfs, and updates the bootloader:On Arch Linux and derivatives, After manual installation, generate an initramfs using your distribution’s tools, add the kernel to your bootloader configuration, then reboot.
installkernel is not available. Install manually:Update to a newer snapshot
When you want to build a newer mainline snapshot, fetch the latest changes and rebuild from your existing configuration:linux-6.2.y), add it before fetching:
Remove a kernel
All kernel files are identifiable by the kernel’s release name, making removal straightforward. Delete the modules directory:kernel-install, remove the remaining files and bootloader entry in one step:
/boot/initramfs-6.0.1-foobar.img or /boot/initrd.img-6.0.1-foobar) and update your bootloader configuration.
Next steps
Build requirements
Check minimum tool versions before your first build.
Coding style
Learn the kernel’s coding conventions before submitting patches.
