Building the Linux kernel from source means fetching the kernel source tree, configuring it for your hardware and needs, compiling the code into a compressed kernel image plus loadable modules, installing those artifacts in the right locations, and updating your bootloader so the new kernel actually runs. The key condition is that you need matching build tools, an existing bootable kernel to fall back on, and enough disk space—roughly 10–25 GB for the source and build output depending on configuration. You do not need to be a kernel developer. You need patience, a terminal, and a willingness to read compiler output carefully.

This guide walks through the standard approach on a mainstream distribution, explains what each step produces, and flags the places where builds commonly fail. Version-specific details—exact package names, menu layout, bootloader syntax—shift between distributions and kernel releases, so treat commands as templates to adapt rather than copy blindly.

Prerequisites: Tools, Space, and a Safety Net

Before touching a tarball, confirm four things.

Build tools. You need a C compiler, GNU Make, the binutils toolchain, and libraries for the kernel's cryptographic and compression routines. On Debian and Ubuntu systems the conventional set is build-essential, libncurses-dev, bison, flex, libssl-dev, libelf-dev, and bc; Fedora and related distributions use gcc, make, ncurses-devel, bison, flex, openssl-devel, elfutils-libelf-devel, and bc, typically pulled in through a development tools group. Packaged kernel headers for a different version won't help compile a new tree.

Disk space. The unpacked source is on the order of 1.5 GB. A full build with default settings can add several gigabytes of object files, and enabling debug information can balloon that considerably. Ten to fifteen gigabytes free is a comfortable floor for a desktop configuration; 25 GB or more gives headroom if you experiment with debug symbols.

A fallback boot entry. Never overwrite your only working kernel. Most distributions keep the previous kernel in the bootloader menu after an upgrade installs a new one, but if you install manually you must verify that the old entry still exists and boots before you reboot into your hand-built kernel.

Hardware awareness. Know your architecture (the commands below assume x86_64) and whether you boot via UEFI or legacy BIOS, because that affects bootloader handling later. Nothing about compiling changes with firmware type, but installation does.

A final preparatory step: decide why you're building. Enabling a driver your distribution doesn't ship, trimming the kernel for an embedded device, testing a patch, or learning the process are all valid and all suggest different configuration choices. That decision shapes the next section more than any other.

Getting the Kernel Source

You have two source routes: a released tarball from the official kernel archive, or a Git clone of the mainline repository.

Tarballs are simpler and reproducible. Download the .tar.xz for the version you want and unpack it:

Git is better if you want to track a stable branch or apply patches. A shallow clone of a specific stable branch limits download size:

Two clarifications matter here. First, the mainline version numbering has been sequential for years (6.x, with release candidates labeled -rc1 through -rc7 or so), so the version you pick should be a stable release rather than an arbitrary development snapshot unless you're deliberately testing. Second, the source tree you download is independent of your distribution's kernel—distribution kernels carry vendor patches and their own configuration, which you are replacing with your own choices.

If you plan to follow upstream changes, learn git describe and how stable branches are tagged; the repository's documentation covers the workflow.

Configuring the Build

Configuration is where the build earns its reputation for fiddliness. The kernel's build system generates a .config file describing every enabled feature, driver, and option, then compiles only what that file requests. There are several ways to get one.

Start from your running kernel's configuration. This is the most reliable path for a desktop or server, because the distribution has already resolved thousands of options for working hardware:

olddefconfig takes the old file, keeps every existing choice, and fills in newly introduced options with their defaults—important because options appear and disappear between kernel versions.

Start from a distribution default. Many trees ship arch/x86/configs/ fragments, and make defconfig produces a broad x86_64 configuration suitable as a base. Embedded and ARM work uses board-specific defconfig files.

Start from scratch. make menuconfig gives a text-based menu for browsing options; make nconfig offers a slightly friendlier interface; make xconfig provides a graphical one if Qt is installed. Command-line tools also exist: make config prompts line by line (painful, rarely worth it), and scripts/config can toggle individual symbols for scripted builds.

Three categories of choice will trip you up if you ignore them.

Modules versus built-in. Tristate options (marked M) can be compiled as loadable modules or built into the image. Drivers for hardware needed at boot—storage controllers for your root filesystem, for example—must be built in or loaded from an initramfs. Everything else is usually fine as a module.

Signing keys. Modern kernels verify module signatures, and builds commonly fail at the signing stage with errors about missing private keys or an empty CONFIG_MODULE_SIG_KEY. For a local test build, disabling module signature enforcement or generating a key is the usual fix; the exact symbols differ by version, so read the error rather than guessing. Distribution configs often point at a certificate path that doesn't exist on your machine.

Compression and image format. CONFIG_KERNEL_GZIP, XZ, ZSTD, and others control image compression. ZSTD typically decompresses fastest at boot, gzip is the most universally supported by bootloaders, and the choice barely affects correctness. Similarly, CONFIG_EFI_STUB matters if you boot the kernel directly through UEFI firmware rather than a bootloader.

If you're trimming for size, the technique is iterative: start from a known-good config, disable obvious subsystems (unused filesystems, exotic network protocols, hardware you don't own), rebuild, boot, and confirm. Comparing lsmod output from the running system against your config shortens this loop. The kernel's make localmodconfig automates part of that by disabling modules not currently loaded—useful on a laptop, risky on a server whose hardware is idle at the moment you run it.

Check success with make listnewconfig (lists options newly added since your base config) and by scanning .config for lines you care about with grep CONFIG_... .config. There's no "correct" configuration; there's only one that boots your machine and does what you need.

Compiling the Kernel and Modules

With .config in place, build:

The -j flag runs parallel jobs. Using the number of logical CPUs is a reasonable default; on memory-constrained machines, drop it, because each compiler process consumes substantial RAM and swapping will slow the build more than extra parallelism helps. Expect anywhere from a few minutes on a fast many-core desktop with a lean config to well over an hour on modest hardware. A first build from a full distribution config is on the slower end because nearly everything compiles.

The build proceeds in phases: generating headers and configuration files, compiling architecture-specific code, compiling drivers and subsystems, linking vmlinux, and finally producing the compressed boot image (arch/x86/boot/bzImage) and modules. Build output is mostly long compiler invocations; what you're watching for are error: lines and the fatal summary at the end.

Common failure modes and what they mean:

Missing headers or tools produce errors naming the absent file (openssl/ssl.h, elf.h, flex, bison). Install the corresponding development package and rerun. Configuration inconsistencies after switching base configs show up as questions during the build or as link errors. Running make olddefconfig again, or make clean followed by a reconfigure, usually resolves them. Module signing errors appear late, at the modules stage. Either configure a signing key or disable signature enforcement for a local build. Out-of-memory kills during parallel linking look like the compiler process vanishing. Reduce -j. Stale object files after changing configuration produce strange link failures. make clean removes build output while keeping .config; make mrproper removes configuration too, so avoid it unless you mean to start over.

For reproducibility and when reporting problems, capture the output: make -j$(nproc) 2>&1 | tee build.log. The kernel's build system is quite good at explaining what went wrong if you read the first error rather than the last.

To check success before installing anything, confirm that arch/x86/boot/bzImage exists and that make modules completed (a plain make includes modules by default on modern versions; older workflows separated the steps). You can also boot-test in a virtual machine, which is the safest sanity check available.

Installing Modules, the Kernel Image, and Firmware

A plain make install handles most of this, but understanding the pieces prevents surprises.

Modules go under /lib/modules//, where the release string comes from the kernel's version and any local version suffix. make modules_install copies them there and runs depmod to build the dependency map. If you set CONFIG_LOCALVERSION (for example to -custom), the directory name changes accordingly—this is how people keep multiple hand-built kernels from colliding.

The kernel image conventionally lands in /boot with a name like vmlinuz-. make install places it, along with System.map and often an initramfs, depending on the distribution's install hooks. On distributions that use installkernel scripts, this step interoperates with the package manager's conventions; on others, it's a simple copy.

An initramfs is needed if your root filesystem lives on a device whose driver is a module—common with LVM, LUKS encryption, or certain storage controllers. Distributions provide mkinitramfs (Debian/Ubuntu), dracut (Fedora and others), or mkinitcpio (Arch). The kernel source includes usr/gen_init_cpio and its own make install may generate a minimal one, but in practice you want the distribution's tool so hooks and firmware handling match. Firmware files themselves live under /lib/firmware and are separate from the kernel source; if your distribution's firmware package is installed, nothing more is needed.

Check success here by confirming three things: the module directory exists and contains files, the image is in /boot with a sensible size (several megabytes, not zero), and the initramfs covers your root device. Inspecting the initramfs listing (lsinitramfs or lsinitcpio) for your storage driver is a quick verification.

Making the New Kernel Bootable

How you register the kernel with the bootloader depends on what you use and whether you boot via UEFI.

GRUB on BIOS systems typically reads /boot/grub/grub.cfg, generated by update-grub (Debian/Ubuntu) or grub2-mkconfig -o /boot/grub2/grub.cfg (Fedora). The generator discovers kernels in /boot automatically, so running it after installation is usually sufficient. GRUB on UEFI works the same way from the user's perspective—the scripts handle the EFI partition.

systemd-boot uses loader entries in the EFI system partition. You write an entry file naming the kernel image and initramfs, or run the distribution's helper if one exists.

Direct EFI boot (no bootloader) requires CONFIG_EFI_STUB, a bootable EFI system partition, and either manual copying of the image to the EFI path or use of efibootmgr to add a boot entry. This is the least forgiving path; a mistake can leave the machine unbootable until you use firmware setup or a rescue medium.

Whatever the mechanism, verify before rebooting. List the boot entry contents and confirm your new kernel appears with the correct image path and initramfs. Confirm the old kernel's entry remains. If you're at all uncertain, keep a rescue USB drive nearby or confirm you can reach the firmware boot menu.

Booting the New Kernel and Verifying It Worked

Reboot, select the new kernel from the bootloader menu, and watch the boot messages. After login, uname -r should report your new release string—this is the primary success check.

Then look for problems that don't prevent booting: dmesg for errors and warnings, lsmod to confirm expected modules loaded, and device checks (network, sound, graphics, storage) for anything the old kernel handled and the new one doesn't. A missing driver usually means an option that was built-in in your source config is now a module or disabled; revisit .config, rebuild, and reinstall. journalctl -k -b on systemd systems gives a clean log of the current boot's kernel messages.

If the machine fails to boot, boot the previous kernel entry from the menu, then investigate from a working system. The most common causes are a missing storage driver in the initramfs, a wrong root device specification, or an image placed where the bootloader can't read it. Fixing these doesn't require rebuilding if only the initramfs or bootloader configuration is at fault.

Rebuilding Efficiently and Iterating

The kernel build system is incremental. After changing a few config options, make -j$(nproc) recompiles only affected files and relinks; this is often a minute or two rather than an hour. The classic edit-compile-test loop—change config or patch, rebuild, make modules_install install, regenerate the bootloader config, reboot—is the workflow to internalize.

Practical efficiency notes: keep .config under version control or copy it to a safe name, because it represents your design decisions and is easy to lose with make mrproper. Use CONFIG_LOCALVERSION to distinguish builds. If testing a patch, git format-patch/git am or patch -p1 apply cleanly to a matching tree version; applying a patch written against a different release will fail, and that failure is informative rather than something to force through.

Where the Process Breaks and When to Stop

The genuinely hard cases aren't compilation; they're configuration and installation mismatches. A build that compiles cleanly can still fail to boot because of a driver your hardware needs, a missing firmware file, or a bootloader entry pointing at the wrong path. Read the kernel's own documentation in Documentation/admin-guide/ and the README at the tree root—they're authoritative for the version you downloaded and describe the same steps this guide covers.

Stop and seek a distribution-specific guide or a kernel mailing list or forum when: you're building for custom or embedded hardware with vendor patches; your bootloader setup is unusual (encrypted boot, signed-boot chains, network boot); or you're modifying kernel code rather than configuring it. Those situations have requirements—toolchain versions, signing procedures, board support—that general instructions can't cover safely, and guessing can leave a system unbootable. For an ordinary desktop or server with standard hardware, the steps above are complete and low-risk provided you keep a fallback kernel.

One more limit worth stating: this guide describes the conventional out-of-tree build workflow. Distribution packagers build kernels through their own frameworks with packaging integration, and embedded projects use build systems like Yocto or Buildroot. The underlying make targets are the same, but the surrounding automation isn't, and mixing the two approaches causes confusing failures.