Easy Gentoo custom kernel guide

Almost as easy as running a binary kernel

Custom kernels on Gentoo can be tedious to make when you don’t know the best way to make them. The Gentoo wiki describes a few methods to try, but they require a lot of manual work. Have fun going back to make menuconfig to enable modules for a package you just installed.

Recently, I found a convenient way to significantly cut down on the time needed. This way, you get the control of a custom kernel but with only a few minutes of manual intervention at most.

The setup

There’s only two things you need:

  1. A binary kernel installed (sys-kernel/gentoo-kernel-bin)
  2. A program called modprobed-db1, available in the GURU overlay

modprobed-db is a program that creates and maintains a list of all kernel modules ever used by your computer. You can run a systemd user service or cron job occasionally to keep the list updated. Because modprobed-db needs a lot of modules to read from, you should start with a generic binary kernel that has almost everything enabled. Over time, modprobed-db will gather a list of every kernel module you ever used. This is a much better way to get all modules you’ll need, rather than manually guessing in the make menuconfig screen.

The second part of the trick is make localmodconfig. When you run this in the kernel sources directory, it reads from lsmod and enables all outputted modules as modules in the kernel config file. You can specify a file for it to read, instead of lsmod. By using the file modprobed-db maintains, you can immediately enable all kernel modules you ever used.

After that, you just compile and install. You’re using Gentoo, so if something doesn’t look right in dmesg, I’m sure you know how to deal with it.

Example

So in general, this is how this process works.

  1. Download sys-kernel/gentoo-kernel-bin. This also lets you quickly boot into a new Gentoo install instead of configuring a kernel immediately
  2. Download modprobed-db, initialize it, and make it run periodically
  3. Use your system normally for a few days, or manually try everything you would possibly do. For me, some things that require modules are:
    1. Various file systems on USB drives
    2. Bluetooth
    3. Steam
    4. Wireguard
    5. UFW
  4. When you think modprobed-db found enough kernel modules, install sys-kernel/gentoo-sources
  5. Go to the kernel sources directory and run this, assuming you run it as the user who ran modprobed-db:
    make LSMOD=$HOME/.config/modprobed.db localmodconfig
    
  6. Use make menuconfig to make any manual edits you want to, like baking things into the kernel
  7. Compile and reboot using your new custom kernel

That’s it. If you update your kernel every time a new minor version comes out, you can probably get away with make oldconfig to deal with new options. If you want to use your current version for a while, I’d recommend repeating the above process using the latest version of the binary kernel; just in case the kernel changed significantly. Make sure to read the man page of modprobed-db.

Enjoy your custom kernels on (relatively) easy mode.