MelonBread.dev

I would like to tap into the #Gentoo Fediverse mind pool one more time if I could have some advice.

I am currently on the Gentoo-dist bin kernel and would like start compiling and customizing my own kernel, but I have never done anything like that before.

So here are my questions:

- What is the best way to start?
- Are there any good tools/scripts/etc that I should use?
- Is there anything I could/should do to protect myself for goofing up?

Thank you for your time!
replies
6
announces
1
likes
1

@rain
I haven't done it as I haven't needed to, but I've seen some stuff while hanging around gentoo places

1. Keep the dist-kernel around as a backup in case your manual kernel doesn't work
2. Follow the wiki
3. You can start with `make localmodconfig` to get a rough starting point of your current kernel's options and used modules

@its_a_me Oh this is very good info. I am taking note of all of this, thank you! 📓

@rain The by far easiest way to do it, is to use the Distribution Kernel (not -bin) and then make use of your own config snippets.

This means that you don't have to maintain your own configuration from scratch, which is boring, tedious and it takes forever. You can instead just apply your own changes on top of the configuration from the Distribution Kernel project, which will override whatever settings they have set.

https://wiki.gentoo.org/wiki/Project:Distribution_Kernel

@rain When it comes to my custom version of Linux-libre, I first run `make menuconfig` to apply the defaults (although I guess `make localmodconfig` will be useful in including all of the autoloaded modules and saving most of the work) and then I hand configure all relevant option in menuconfig and also disable many legacy things only useful for executing very old proprietary software.

When it's looking pretty good, I run; `make -j$(nproc) && make modules_install && make install && dracut --kver <new version> (for LUKS encrypted storage - I'd prefer it if I could go without an initramfs of course) && grub-mkconfig -o /boot/grub/grub.cfg` and I see if it boots, otherwise I continue shotgun surgery.

@rain

Starting point is wiki. You can look at running gentoo-kernel-bin. lsmod will give some hints to what you must enable. The actual config depends on installed packages and your hardware.

I have a script to check what is missing in my kernel config.

pc ~ # cat `which emerge-check-kernel-config`
#!/bin/sh

if [[ -z "$1" ]]; then
    echo "usage: $0 pkg"
    exit 1
fi

pkg="$1"
path=$(equery w ${pkg})
result=$(awk '/CONFIG_/{print}' <(ebuild ${path} setup);)
ebuild ${path} clean
if [[ -n "${result}" ]]; then
    echo ">>> ${pkg}"
    echo "${result}"
fi

To check all installed packages.

pc ~ # cat `which emerge-check-kernel-config-all`
#!/bin/sh

if which rg &>/dev/null; then
    rg -ls CONFIG_CHECK -g '*.ebuild' /var/db/pkg
else
    grep -lr CONFIG_CHECK /var/db/pkg/
fi | cut -d'/' -f5-6 | parallel emerge-check-kernel-config {}

The result will be something like this.

pc ~ # emerge-check-kernel-config perf
>>> perf
 *   CONFIG_DEBUG_INFO:  is not set when it should be.
 *   CONFIG_FTRACE:      is not set when it should be.
 *   CONFIG_FTRACE_SYSCALLS:     is not set when it should be.
 *   CONFIG_FUNCTION_TRACER:     is not set when it should be.
 *   CONFIG_KALLSYMS_ALL:        is not set when it should be.
 *   CONFIG_KPROBES:     is not set when it should be.
 *   CONFIG_KPROBE_EVENTS:       is not set when it should be.
 *   CONFIG_UPROBES:     is not set when it should be.
 *   CONFIG_UPROBE_EVENTS:       is not set when it should be.

Running emerge-check-kernel-config-all will take some time…

pc ~ # emerge-check-kernel-config-all
>>> dev-util/perf-6.7
 *   CONFIG_DEBUG_INFO:  is not set when it should be.
 *   CONFIG_FTRACE:      is not set when it should be.
 *   CONFIG_FTRACE_SYSCALLS:     is not set when it should be.
 *   CONFIG_FUNCTION_TRACER:     is not set when it should be.
 *   CONFIG_KALLSYMS_ALL:        is not set when it should be.
 *   CONFIG_KPROBES:     is not set when it should be.
 *   CONFIG_KPROBE_EVENTS:       is not set when it should be.
 *   CONFIG_UPROBES:     is not set when it should be.
 *   CONFIG_UPROBE_EVENTS:       is not set when it should be.

# skiped

Don’t delete gentoo-kernel-bin. It’s a good fallback if something is broken in your custom kernel.

Don't remove the kernel you're currently using until you're sure you got the one you built working the way you want. Maybe even then, still keep the distkernel there as a fallback.

@rain While grabbing your current kernel's config and running "make localmodconfig" is a decent way, and I'd recommend using config snippets like @hund mentioned, I'd avoid those if you're looking into "learning to do it yourself".
Modern-day "make defconfig" doesn't need a *lot* of tweaking to get going, and you'll learn more about what you're actually enabling, what you're building into the kernel vs as a module, and etc. Read the gentoo handbook and the wiki pages for your graphics etc.