Building custom kernels for Linux + updating the system firmware.
Gabriel M.
Linux Systems Engineer | IT Infrastructure | Security | Virtualization | Automation | AI | C and Shell Scripting
In this post I'll show you how you can replace your current Linux kernel with a new one built entirely from the sources, your way!
Building custom kernels can be a bit challenging at first, especially if you have never built software from sources before. However, having a custom kernel can be useful if you want to tailor your Linux system to better fit the hardware you have at your disposal.
First, let's check the current environment.
As we can see, I am currently running the latest stock kernel available at this date (Feb. 14 2025) for a Debian stable system.
Before you can build your kernel, you will need the proper tools! Let's get them:
sudo apt install libncurses-dev make gcc libelf-dev libssl-dev bison flex build-essential dwarves debhelper
Now, in order to replace that kernel with a newer version, let's first head to the official kernel project and repository web site, which can be accessed at https://www.kernel.org/ . From that page, you can either hit the button, or choose a different source to download.
For this post, I'll go with the latest 6.13.2 version.
After that file is downloaded, you will need to extract it. As a good practice, you should put it in /usr/src/
# Assuming you saved it in your ~/Downloads directory and you have write permission to the src directory.
tar xf ~/Downloads/linux-6.13.2.tar.xz -C /usr/src
Now, you should have something similar to this:
Building a custom kernel entirely from scratch cab be challenging for you on your first attempt. You also need a good understanding of the underlying hardware for which you are building the kernel. To make this exercise simpler while giving you a small taste of how it feels building your custom kernel, let's use the current configuration as a start and tweak small changes from there.
cd linux-6.13.2
cp /boot/config-6.1.0-31-amd64 .config
With the 2 commands above you literally copied the current kernel's config into the sources directory, as the .config file, so it can be used to configure the new kernel. The next step is to run the config tool.
# This command calls the Curses interface to the kernel configuration menu.
make menuconfig
The menu that will appear when you run the above command is quite long and full of sub-menus. It would take a tremendous amount of time to go through each and every option in there. I'll leave that to you. For now, let's just change a few options so you can get the grasp of it.
领英推荐
Let's make a few changes. After every change, remember to go back to the main screen, before you proceed to the next "bullet" below.
Go to:
Once you have finished your adjustments, it is time to save the configuration and build the kernel packages. =)
Hit the "<EXIT>" button and select "<YES>" when prompted if you want to save the configuration.
Then, build the kernel packages with the "make" command. If you have multiple CPUs available in your system (and you mostly do!), let's use multiple parallel jobs to build the kernel.
# Assuming you have 4 cores and want 2 jobs per core
make --jobs 8 bindeb-pkg
This will take some time to complete. You should see something similar to this:
After the above command is finished, you should see the kernel package files in the directory 1 level higher than the current 6.13.2 sources.
Just head to the directory 1 level above, and install the Debian packages.
Bonus: update the system firmware to the latest version.
Head to https://www.kernel.org/pub/linux/kernel/firmware/ and download the latest firmware package from that directory.
Then, extract it to your system. I will assume you downloaded the file to your ~/Downloads directory. Proceed as follows to extract the new firmware and also to update your initramfs:
sudo tar xf ~/Downloads/linux-firmware-20250211.tar.xz --strip-components=1 -C /lib/firmware/
sudo update-initramfs -u
Then, reboot your system.
You should see your new kernel in action if you typed uname -r
Happy hacking! =)