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:
- A binary kernel installed (
sys-kernel/gentoo-kernel-bin
) - A program called
modprobed-db
1, 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.
- Download
sys-kernel/gentoo-kernel-bin
. This also lets you quickly boot into a new Gentoo install instead of configuring a kernel immediately - Download
modprobed-db
, initialize it, and make it run periodically - Use your system normally for a few days, or manually try everything you would possibly do.
For me, some things that require modules are:
- Various file systems on USB drives
- Bluetooth
- Steam
- Wireguard
- UFW
- When you think
modprobed-db
found enough kernel modules, installsys-kernel/gentoo-sources
- 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
- Use
make menuconfig
to make any manual edits you want to, like baking things into the kernel - 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.