While working on a recent project, I’ve found myself compiling and recompiling my kernel several times. I thought I would take the opportunity to write 10 Gentoo linux kernel tips.
kernel tips #10 – remove unnecessary modules
Removing modules probably doesn’t save too much space but removing features from being built into the kernel might … a little bit. Work slowly and verify your system works will all the peripherals after each pruning.
kernel tips #9 – find the perfect kernel
There are more kernel sources available than gentoo-sources. Perhaps one of the others is more appropriate.
find kernel options
# eix -A sys-kernel | grep sys-kernel | grep sources
kernel tips #8 – search previous kernels
Previous (and the current) kernel configurations are stored in /etc/kernels and can be searched with grep. See for yourself.
search previous kernel configs
# ls /etc/kernels/
kernel tips #7 – determine current modules in use
If you enable the option
CONFIG_PROC, you’ll have a gzip’ed configuration in
/proc listing your current kernel configuration. Searching it is easy. Here we will see which aes modules are installed.
search current kernel config
# cat /proc/config.gz | gunzip | grep -i aes
# CONFIG_SND_MAESTRO3 is not set
kernel tips #6 – figure out dependencies with help
Sometimes you’ll try to build a feature into the kernel but the only options will be module or none. Go for help. Really. You’ll see the dependencies for that feature. The most common scenario is that one of the dependencies is selected as a module so if you go and change the module to built-in, you can come back and have the additional ability to compile in the feature in question.
kernel tips #5 – navigate menuconfig by letter
You may have noticed that some of the letters are highlighted in menuconfig. You can use these letters to jump to the module of interest (so long as it is visible from the current screen). Since some letters are reserved, you man need to use the second letter of the module, menu, or sub-menu.
kernel tips #4 – determine current modules in use
Sometimes it is helpful to determine what drivers or modules are currently in use. There are at least two ways to get that list (which is probably helpful during initial install).
You can use lsmod like so
lsmod to determine current modules
# lsmod | sort -u
3w_9xxx 29241 0
3w_xxxx 20723 0
BusLogic 19341 0
Module Size Used by
aacraid 69484 0
ac 3289 0
acpi_cpufreq 4989 0
This list isn’t as extensive but works well for drivers.
lspci to search for drivers
lspci -v | grep Kernel | sort -u
Kernel driver in use: ahci
Kernel driver in use: ehci_hcd
Kernel driver in use: pata_via
Kernel driver in use: pcieport
Kernel driver in use: snd_hda_intel
Kernel driver in use: tg3
Kernel driver in use: xhci_hcd
Kernel modules: ahci
Kernel modules: ata_generic, pata_acpi, pata_via
Kernel modules: ehci-hcd
Kernel modules: snd-hda-intel
Kernel modules: tg3
Kernel modules: xhci-hcd
kernel tips #3 – change the extra version with each build
Each time you decide to change a feature or upgrade your kernel, you (probably) should change the name which will build a whole new set of modules and kernel. The important part is that should anything go wrong, you’ll have the old kernel and modules ready to boot as a backup.
kernel tips #2 – search within menuconfig
If you use menuconfig to build your kernel, you can search for specific components with the "/" key. For instance, if you want to see the modules associated with xen, use "/" followed by "xen". You can use this in pagers like less and more as well.
kernel tips #1 – use genkernel
If you use gentoo and install webapps, you should use webapp-config. If you use gentoo and compile your own kernel, you should use genkernel. If you’ve never taken the time to read the genkernel documentation, there are many great options. Here is my default command – a worthwhile alias or make permanent by editting
# genkernel --menuconfig --oldconfig --install --bootloader=grub --symlink --install --disklabel --makeopts=-j9 all
You still have to configure everything yourself, but genkernel will build the kernel, initrd, move them to
/boot, and copy the config to
/etc/kernels. Additionally, options like
--lvm will build the necessary tools into your initrd which is a real time-saver.