two brown and white penguins walking on stone covered field

Building a Gentoo Linux Kernel on Debian

Debian is a solid Linux distribution with nearly nothing to complain about besides its well aged software. And in my case this ‘nearly nothing’ was more about the nearly than the nothing as due to the old kernel, fstrim didn’t do its job. So I decided to build a new kernel. But as I am running Gentoo on my main boxes here, I decided to give that a go. Okay, you got me here… I was lazy and I had the sources already on my other machine and I didn’t fancy to download another tarball.

For a start you can copy the current version of the gentoo-sources from a gentoo machine or download the sources from and add the Gentoo Patchset manually using your trusty old friend ‘patch’. For those of you who need a reminder on how to patch the kernel, it’s calling ‘patch -p0 < path/to/patch.txt’ from within the kernel source directory.

As soon as our sources are patched and in place, it’s time to get the debian kernel configuration. The easiest way is to copy it from /boot as Debian does not use /proc/config or /proc/config.gz

cp /boot/config-4.19.0-12-amd64 /usr/src/linux-5.9.2-gentoo/.config

Please do not copy this command as the versions were the current versions at the time of writing and may vary on your system.

As our .config here is from an older kernel, there are a few things to adjust. Luckily the kernel brings a make command, namely ‘make oldconfig’. After invoking that command, you’ll be asked a couple of questions depending on your versions. Feel free to employ google if you are not sure about what to choose or simply use the default values. Don’t worry if you’ve choosen the wrong answer at some point, as you can always copy the original Debian config over and start over.

If you are someone who knows what they are doing, you can now invoke ‘make menuconfig’ to get rid of the drivers you do not use – or change any setting you wish. Don’t be shy, it’s really not that hard to deselect hardware components that are NOT in your system and make your kernel more steamlined. Worst case is that it won’t boot and you still have a running kernel to switch to.

Now it’s time to actually build the kernel the Debian way. But don’t be afraid, you don’t need to sacrifice a virgin to complete the build process: make deb-pkg does the trick as well. In case you want to speed up the process a little, you may use “make deb-pkg -j6” whereas the number after -j should be the number of cores on your computer. Hitting enter will now start the build process leaving you with a couple of debian packages in /usr/src that can be installed using

dpkg -i ../*.deb

After the packages are installed, it’s time for the moment of truth: rebooting the system. If you haven’t changed the default config and went with the default values on make oldconfig, there’s a very good chance of a booting system with a shiny new kernel. If not, it’s not the end of the world either, as you can always select the old kernel in grub.


Leave a Reply

Your email address will not be published. Required fields are marked *