General Kernel Configuration

From Elvanör's Technical Wiki
Revision as of 12:34, 5 June 2025 by Elvanor (talk | contribs) (→‎AMD GPU)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This page helps with the configuration of the Linux kernel. Remember, configuring the kernel is easy - you just have to know which hardware you have quite well.

General Information

The kernel sources are unpacked in /usr/src (at least on Gentoo).

  • Once you are in the kernel source directory, use the following command to configure graphically your kernel:
make menuconfig
  • When migrating to a new kernel, copy your old .config file from the old kernel directory to the new one and type:
make oldconfig
  • The "/" key can be very useful for finding where a configuration option is present when using make menuconfig.

Hardware Detection

  • Basically, emerge pciutils lshw usbutils, which gives you lspci, lshw, and lsusb.

Kernel Configuration

Mandatory Gentoo options

  • Tmpfs support is required (TMPFS in File systems -> Pseudo filesystems).

Networking

  • If you use connection tracking, there is a maximum number of connections that can be tracked. If you have a server with a large number of connections and exceed this maximum, some packets will be dropped, and general network instability will happen. You can increase the number of maximum connections or completely disable this module to solve the problem.
  • Note that to be able to use iptables and use the "state" tracking, you need kernel support (at least on recent 4.x kernels).

HyperThreading Support

  • On certain hardware (maybe all new boxes), HT support will only work if you enable ACPI. It can be confusing, but this is really like this.
  • On newer kernels (3.5.7 and more), it seems HyperThreading support cannot be disabled. There is an option for SMT sheduler support, but this is only for the sheduler, it does not disable HyperThreading if you leave it off.

Choice of the scheduler

  • There is an I/O scheduler in the section Block Layer. This is different from the CPU scheduler. The SD scheduler is a *CPU* scheduler.
  • In vanilla-sources, apparently there is no choice for the CPU scheduler. Same is true for ck-sources (where SD scheduler is mandatory).

Real Time Clock (RTC) support

  • With recent kernels (2.6.25+), there are two areas for this configuration.
    • Device Drivers -> Character Devices
    • Device Drivers -> Real Time Clock
  • If Gentoo hangs when starting (when running the clock init script) and you are using the support in Character Devices, change it to use the one in Real Time Clock (which I guess is newer and better).

Building firmware into the kernel

  • The path in menuconfig is Device Drivers -> Generic Driver Options -> Firmware loader.

Device Drivers

  • Apparently you need CONFIG_BLK_DEV_SD (in SCSI / SCSI disk support), even if you use only SATA disks.

Executable file formats / Emulations

  • CONFIG_BINFMT_SCRIPT seems to be mandatory for booting.

Reading foreign partition tables

  • Each OS creates its own partition table format when initializing / formatting a disk. You can build support for reading these partition table formats with Linux; it's under File Systems -> Partition Types. Note that I don't really know what partition table format Linux uses.

SD/MMC card reader

  • You need to activate this support in the kernel if you have an integrated card reader (not an USB external reader). If lspci lists the host controller, build that module. Else, you need to build the SDHCI support on the platform specific bus module.

Firmware

  • Getting a list of loaded firmware files can be useful sometimes. For instance, if you compile the amdgpu kernel module as an external module (not built-in), it can give you the list of firmware files needed for your particular GPU model. To do this, you need to enable both CONFIG_FW_LOADER_DEBUG and CONFIG_DYNAMIC_DEBUG in the kernel configuration, and add the following to the boot command line (in GRUB):
loglevel=8 dyndbg="file drivers/base/firmware_loader/* +p"
  • It will then write those logs to dmesg.

AMD GPU

  • Generally speaking, you need to follow the instructions here. However, it's getting the firmware correctly loaded that is difficult. The easiest way to proceed is just to first build the amdgpu as an external module. As a module, it will automatically load the correct files from /lib/firmware (installed by the linux-firmware package).
  • Then you can use the above technique to get the list of actual firmware files loaded by the amdgpu module. Once you have that, you can build those firmware files into the kernel and get amdgpu built-in as well.
  • Note however that if you forget to get the full, correct list of firmware files in the kernel, your system will not only disable the amdgpu module, it will also not boot (mine froze just after the GRUB bootloader). An empty list of firmware files does not freeze the system - it just disables amdgpu.

Startup Parameters

  • The /etc/modprobe.d directory contains files filed with options that can be passed to the appropriate kernel module. For example, the ALSA modules. If you built the drivers not as a module, but directly into the kernel, you can pass these options as kernel startup parameters. The syntax is the following one:
snd-hda-intel.model=asus
  • Another example:
snd-sof-intel-hda-common.hda_model=alc287-yoga9-bass-spk-pin # kernel startup parameter
options snd-sof-intel-hda-common hda_model=alc287-yoga9-bass-spk-pin # configuration file inside /etc/modprobe.d
  • Additional documentation can be found in /usr/src/linux/Documentation/kernel-parameters.txt.