Building a Custom Linux Kernel from Source

Compiling your own kernel used to be a rite of passage for Linux users in the late 90s and early 2000s, back when distro-provided kernels were generic to the point of missing hardware support you actually needed. It’s rarely necessary today, but it remains one of the best ways to actually understand how the kernel fits together.

Getting the Source

sudo apt install -y build-essential libncurses-dev bison flex \
  libssl-dev libelf-dev bc

wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.10.tar.xz
tar -xf linux-6.10.tar.xz
cd linux-6.10

Configuring the Build

Rather than starting from a blank config, base your build on the currently running kernel’s config so you don’t accidentally drop support for hardware you rely on:

cp /boot/config-$(uname -r) .config
make olddefconfig    # updates the config for the new kernel version

# Optional: interactively enable/disable specific features
make menuconfig

Building and Installing

# Use all available CPU cores to parallelize the build
make -j$(nproc)

sudo make modules_install
sudo make install

# Update the bootloader to include the new kernel entry
sudo update-grub
sudo reboot

A Word of Caution

Building takes anywhere from 15 minutes to over an hour depending on hardware, and a misconfigured kernel can leave you unable to boot — always keep your distro’s stock kernel as a fallback entry in GRUB so you can select it if the custom build has issues.