back

Building A Custom Kernel On Debian

You may want to use a custom kernel because the normal version you can get from the repos aren’t very good for you. They may have unnecessary parts included or do not support some kind of very specific hardware you have. You can also test out patches and provide feedback, disable something that is causing a conflict, and possibly increase the speed of your machine by a small amount. Hardening is also fun. Debian and Kicksecure Tor have pages on this (and obviously some others like gentoo). It is also generally a fun learning experience to build your own kernel.

General Process

Based on what pages you are reading, you may want to go through this in a different way. I am just explaining a way. First we need some packages so we sudo apt update && sudo apt install fakeroot build-essential libncurses-dev xz-utils libssl-dev flex libelf-dev bison -y. Then download the latest release of the kernel on kernel.org which is currently 6.3.3. We extract the linux kernel with tar xvf linux-6.3.3.tar.xz and cd into the folder.

The major part of this whole thing is configuration. We can copy our current configuration on our system with cp /boot/config-$(uname -r) .config. You then run make menuconfig. In this ncurses menu, make all the changes you want. Follow a guide for a type of configuration or search up each feature yourself. The linux kernel is very much a monolithic kernel and has a lot of modules to go through so have some fun and keep a copy of your configuration.

When you are finished configuring, run scripts/config --disable SYSTEM_TRUSTED_KEYS && scripts/config --disable SYSTEM_REVOCATION_KEYS to the certificate to let us compile and then sudo make. Depending on your hardware, this can take a very long time. After compiling, install the kernel modules with sudo make modules_install and then the kernel with sudo make install.

Reboot your machine and run uname -r to see what version your system is using. You can configure GRUB, or whatever bootloader you are using, to show you a selection of kernels to use on your system. Archwiki page on this.

Conclusion

Most of the process of making and installing your own kernel isn’t difficult but it gets very confusing with whether you should enable or disable some kernel modules and the effects you might not have thought of now that can turn out really bad later. This is why most people are better off using kernels configured by some other people.