Building custom kernels for Linux + updating the system firmware.

Building custom kernels for Linux + updating the system firmware.

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.


The button will download the latest release.

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.


Curses interface to the kernel configuration menu.

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:

  • General setup ---> Local version and change it to "-your-hostname" (no spaces or capital letters!)
  • General setup ---> Default hostname and change it to "your-hostname" (no spaces or capital letters!)
  • General setup ---> Preemption Model and change it to "Preemptible Kernel (Low-Latency Desktop)"
  • Processor type and features ---> Processor family and change it to your current CPU family [Core2 / newer Xeon] if you have a fairly recent Intel CPU OR [Opteron/Athlon64/Hammer/K8] if you have a fairly recent AMD CPU).
  • Processor type and features ---> Timer frequency and set it to 1000 HZ.
  • Kernel hacking ---> Compile-time checks and compiler options ---> Debug information and select "Disable debug information".
  • Kernel hacking ---> Generic Kernel Debugging Instruments and select Magic SysRq Key option, as well as (0x01b6) Enable magic SysRq key functions by default.

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:


Compilation using multiple parallel tasks

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! =)

要查看或添加评论,请登录

Gabriel M.的更多文章

  • Docker 101

    Docker 101

    A (tiny) introduction to Docker. If you want to get your hands dirty with some Docker content, this quick introduction…

  • Debian complained about missing firmware during installation? Add missing 'non-free' firmware to installation image! :)

    Debian complained about missing firmware during installation? Add missing 'non-free' firmware to installation image! :)

    If you have installed Debian, you might have faced the screen below: And probably got very frustrated, because your…

  • Using Traps in Bash Scripts

    Using Traps in Bash Scripts

    Imagine that you have a script to perform some critical operation, one that would render the system completely unusable…

    2 条评论
  • Safer Bash Scripting Tips

    Safer Bash Scripting Tips

    I hope you are all well and safe. As "stay safe" is the most used expression during this COVID-19 period, I thought it…

    1 条评论
  • Pointers and 2D-arrays in C

    Pointers and 2D-arrays in C

    When taking the Engineering or CS undergrad path, like 1+1 leads to 2 (let's keep it simple here, shall we?), students…

    2 条评论
  • Linux Kernel Inotify Subsystem

    Linux Kernel Inotify Subsystem

    When dealing with Unix-style filesystems there must be a data structure that is capable of describing an object from…

  • Linux File I/O

    Linux File I/O

    When using system calls for dealing with file I/O, open(), read(), write() and close() are the four functions used to…

  • Shifting bits in C

    Shifting bits in C

    Have you ever asked yourself how much memory space do you waste when writing your code? Sometimes you just need a…

  • Improving your Linux box security

    Improving your Linux box security

    Did you know that more than never, during these quarantine days, there is a lot more malicious activities undergoing…

  • Build UnrealEngine on Linux, making it use less disk space! :)

    Build UnrealEngine on Linux, making it use less disk space! :)

    If you are playing with the amazing Unreal Engine on your Linux box, you might have noticed that the final size after…

社区洞察

其他会员也浏览了