Linux kernel configuration

From wikinotes

Documentation

kernel option docs https://www.kernel.org/doc/html/v6.1/admin-guide/kernel-parameters.html
tut: kernel programming guide https://sysprog21.github.io/lkmpg/

Locations

/etc/modprobe.d/*.conf load kernel modules on startup
/lib/modules/$(uname -r)/* kernel modules (modules.builtin lists builtin modules)

Kernel Options

Your can add boot options for your kernel.
The location depends on your bootloader, for systemd-boot it would be in a file like /boot/loader/entries/archlinux.conf.

# /boot/loader/entries/archlinux.conf

# ...
options rdblacklist=nouveau nofb nomodeset

Some bootloaders

Some useful kernel options

nofb       # disable framebuffer
nomodeset  # disable kernel modesetting (increased resolution)

Kernel Modules

/etc/modprobe.d/*.conf location of kernel-module files

Managing Kernel Modules

lsmod                                          # list loaded kernel modules
modinfo btusb                                  # list kernel options for btusb
modprobe btusb                                 # load 'btusb' kernel module
cat /lib/modules/$(uname -r)/modules.builtin   # list builtin kernel modules

Automatically loading kernel modules

Similar to other systemd files, you can gather a bunch of kernel modules in a single file. The syntax of the file is a newline separated list of modules. Their names will be exactly as they would be called by modprobe. A newline with a first character of '#', marks a comment.

/etc/modprobe.d/wiimote.conf

# /etc/modprobe.d/{yourname}.conf
uinput
btusb

Dynamic Kernel Modules (DKMS)

DKMS packages include kernel modules that are recompiled every time a new kernel is installed.
You can safely install/build these modules after an update without reboot, but you'll need to restart to use them (so the new kernel is used).
Most distros use the -dkms suffix to indicate a package like this.


Kernel Downgrades

Boot your distro off a USB stick, and chroot into your existing installation. You'll need to uninstall all packages that are particular to your kernel version like linux, linux-headers, virtualbox-host-modules, virtualbox-guest-modules.

# Connect to the internet
sudo mount /dev/sda2 /mnt
arch-chroot /mnt /bin/bash
cd /var/cache/pacman/pkg

pacman -Rs linux-3.9.7 linux-headers-3.9.7 virtualbox-host-modules virtualbox-guest-modules
pacman -U linux-3.7.1 linux-headers 3.7.1
exit

sudo reboot