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.

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.
Back up your system before you begin. Installing a self-compiled kernel modifies boot-critical files. While the risk of data loss is low, having a recovery medium on hand is good practice.

Before you start

If your system uses Secure Boot, you must either disable it in your BIOS setup utility or disable validation with:
mokutil --disable-validation
After running this command, reboot. The Shim bootloader will prompt you to confirm disabling validation using a one-time password you create. You also need at least 12 GB free in your home directory for sources and build artifacts, 150 MB in /lib/, and 100 MB in /boot/.

Install build dependencies

sudo apt install bc binutils bison dwarves flex gcc git make openssl \
  pahole perl-base libssl-dev libelf-dev

Step-by-step build guide

1

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.
git clone --no-checkout --depth 1 -b master \
  https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git ~/linux/
cd ~/linux/
Then check out the latest mainline code:
git checkout --detach origin/master
If you also need access to recent mainline releases and pre-releases, deepen the clone’s history:
git fetch --shallow-exclude=v6.0 origin
If you want all versions and commits available at once and a large download does not bother you, perform a full clone instead:
curl -L \
  https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/clone.bundle \
  -o linux-stable.git.bundle
git clone linux-stable.git.bundle ~/linux/
rm linux-stable.git.bundle
cd ~/linux/
git remote set-url origin \
  https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
git fetch origin
git checkout --detach origin/master
2

Apply patches (optional)

If you want to test a proposed fix or patch, apply it now before configuring:
patch -p1 < ../proposed-fix.patch
If the patch does not apply cleanly, try without -p1. To undo any changes, run:
git reset --hard
3

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:
echo "-proposed_fix" > localversion
Running uname -r under your new kernel will then print something like 6.1-rc4-proposed_fix.
4

Configure the kernel

Generate a build configuration trimmed to only the modules your running system actually uses:
yes "" | make localmodconfig
This uses your distribution’s running kernel as a base and disables modules for features not currently in use, which dramatically shortens compile time.
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.
If you have an existing .config file you want to use as a base instead, copy it to ~/linux/.config and run:
make olddefconfig
Debian users: Remove a stale certificate reference that will otherwise cause the build to fail:
./scripts/config --file .config --set-str SYSTEM_TRUSTED_KEYS ''
To disable debug symbols and reduce disk usage from ~5 GB to under 1 GB:
./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
To browse all configuration options interactively, run make menuconfig (requires ncurses development headers).
5

Compile the kernel

Build the kernel image and all modules, using every available CPU core:
make -j $(nproc --all)
If the build fails, re-run with verbose output to see the actual error:
make V=1
Packaging alternatives: You can produce distribution-ready packages instead of installing manually:
make -j $(nproc --all) bindeb-pkg
6

Install modules and kernel

On most distributions a single command installs the modules, copies the kernel image, generates an initramfs, and updates the bootloader:
command -v installkernel && sudo make modules_install install
On Arch Linux and derivatives, installkernel is not available. 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 manual installation, generate an initramfs using your distribution’s tools, add the kernel to your bootloader configuration, then reboot.
7

Reboot

reboot
Select the new kernel from the bootloader menu if it is not already the default.

Update to a newer snapshot

When you want to build a newer mainline snapshot, fetch the latest changes and rebuild from your existing configuration:
cd ~/linux/
git fetch --depth 1 origin
# The next command discards any local code changes:
git checkout --force --detach origin/master
make olddefconfig
make -j $(nproc --all)
command -v installkernel && sudo make modules_install install
reboot
To track a stable/longterm branch (for example linux-6.2.y), add it before fetching:
git remote set-branches --add origin linux-6.2.y
git fetch --shallow-exclude=v6.0 origin

Remove a kernel

All kernel files are identifiable by the kernel’s release name, making removal straightforward. Delete the modules directory:
sudo rm -rf /lib/modules/6.0.1-foobar
On distributions that support kernel-install, remove the remaining files and bootloader entry in one step:
command -v kernel-install && sudo kernel-install -v remove 6.0.1-foobar
If that command is unavailable or leaves files behind, remove them manually:
rm -i /boot/{System.map,vmlinuz}-6.0.1-foobar
Then remove the matching initramfs (typically /boot/initramfs-6.0.1-foobar.img or /boot/initrd.img-6.0.1-foobar) and update your bootloader configuration.
Be careful with wildcards when deleting by release name. A pattern like 6.0* will also match 6.0.11.

Next steps

Build requirements

Check minimum tool versions before your first build.

Coding style

Learn the kernel’s coding conventions before submitting patches.

Build docs developers (and LLMs) love