Handbook:Parts/Installation/Kernel/en

Firmware
Before getting to configuring kernel sections, it is beneficial to be aware that some hardware devices require additional, sometimes non-FOSS compliant, firmware to be installed on the system before they will operate correctly. This is often the case for wireless network interfaces commonly found in both desktop and laptop computers. Modern video chips from vendors like AMD, Nvidia, and Intel, often also require external firmware files to be fully functional. Most firmware for modern hardware devices can be found within the package.

It is recommended to have the package installed before the initial system reboot in order to have the firmware available in the event that it is necessary:

It is important to note that kernel symbols that are built as modules (M) will load their associated firmware files from the filesystem when they are loaded by the kernel. It is not necessary to include the device's firmware files into the kernel's binary image for symbols loaded as modules.

Microcode
In addition to discrete graphics hardware and network interfaces, CPUs also can require firmware updates. Typically this kind of firmware is referred to as microcode. Newer revisions of microcode are sometimes necessary to patch instability, security concerns, or other miscellaneous bugs in CPU hardware.

Microcode updates for AMD CPUs are distributed within the aforementioned package. Microcode for Intel CPUs can be found within the package, which will need to be installed separately. See the Microcode article for more information on how to apply microcode updates.

Kernel configuration and compilation
Now it is time to configure and compile the kernel sources. For the purposes of the installation, three approaches to kernel management will be presented, however at any point post-installation a new approach can be employed.

Ranked from least involved with least control over updates, to most involved with most control over updates:


 * Full automation: A Distribution Kernel is used to configure, automatically build, and install the Linux kernel, its associated modules, and (optionally, but enabled by default) an initramfs file. Future kernel updates are fully automated since they are handled through the package manager, just like any other system package. It is possible provide a custom kernel configuration file if customization is necessary. This is the least involved process, and is perfect for new Gentoo users, but offers the least amount of update control.
 * Genkernel (hybrid): New kernel sources are installed via the system package manager. System administrators use Gentoo's tool to generically configure, automatically build and install the Linux kernel, its associated modules, and (optionally, but not enabled by default) an initramfs file. It is possible provide a custom kernel configuration file if customization is necessary. Future kernel configuration, compilation, and installation require the system administrator's involvement in the form of running, , and potentially other commands for each update.
 * Manual configuration: New kernel sources are installed via the system package manager. The kernel is manually configured, built, and installed using the and a slew of  commands. Future kernel updates repeat the manual process of configuring, building, and installing the kernel files. This is the most involved process, but offers maximum control over the kernel update process.

The core around which all distributions are built is the Linux kernel. It is the layer between the user's programs and the system hardware. Although the handbook provides its users several possible kernel sources, a more comprehensive listing with more detailed descriptions is available at the Kernel overview page.

Installing the kernel sources
When installing and compiling the kernel for -based systems, Gentoo recommends the package.

Choose an appropriate kernel source and install it using :

This will install the Linux kernel sources in using the specific kernel version in the path. It will not create a symbolic link by itself without  being enabled on the chosen kernel sources package.

It is conventional for a symlink to be maintained, such that it refers to whichever sources correspond with the currently running kernel. However, this symbolic link will not be created by default. An easy way to create the symbolic link is to utilize eselect's kernel module.

For further information regarding the purpose of the symlink, and how to manage it, please refer to Kernel/Upgrade.

First, list all installed kernels:

In order to create a symbolic link called, use:

Alternative: Genkernel
If an entirely manual configuration looks too daunting, system administrators should consider using as a hybrid approach to kernel maintenance.

Genkernel provides a generic kernel configuration file, automatically generates the kernel, initramfs, and associated modules, and then installs the resulting binaries to the appropriate locations. This results in minimal and generic hardware support for the system's first boot, and allows for additional update control and customization of the kernel's configuration in the future.

Be informed: while using to maintain the kernel provides system administrators with more update control over the system's kernel, initramfs, and other options, it will require a time and effort commitment to perform future kernel updates as new sources are released. Those looking for a hands-off approach to kernel maintenance should use a distribution kernel.

For additional clarity, it is a misconception to believe genkernel automatically generates a custom kernel configuration for the hardware on which it is run; it uses a per-determined kernel configuration that supports most generic hardware and automatically handles the commands necessary to assemble and install the kernel, the associate modules, and the initramfs file.

Binary redistributable software license group
If the linux-firmware package has been previously installed, then skip onward to the to the installation section.

As a prerequisite, due to the  USE flag being enabled by default for the  package, the package manager will also attempt to pull in the  package. The binary redistributable software licenses are required to be accepted before the linux-firmware will install.

This license group can be accepted system-wide for any package by adding the  as an ACCEPT_LICENSE value in the  file. It can be exclusively accepted for the linux-firmware package by adding a specific inclusion via a file.

If necessary, review the methods of accepting software licenses available in the Installing the base system chapter of the handbook, then make some changes for acceptable software licenses.

If in analysis paralysis, the following will do the trick:

Installation
Explanations and prerequisites aside, install the package:

Generation
Compile the kernel sources by running. Be aware though, as compiles a kernel that supports a wide array of hardware for differing computer architectures, this compilation may take quite a while to finish.

Once genkernel completes, a kernel and an initial ram filesystem (initramfs) will be generated and installed into the directory. Associated modules will be installed into the directory. The initramfs will be started immediately after loading the kernel to perform hardware auto-detection (just like in the live disk image environments).

Introduction
Manually configuring a kernel is often seen as the most difficult procedure a Linux user ever has to perform. Nothing is less true - after configuring a couple of kernels no one remembers that it was difficult!

However, one thing is true: it is vital to know the system when a kernel is configured manually. Most information can be gathered by emerging which contains the  command:

Another source of system information is to run to see what kernel modules the installation CD uses as it might provide a nice hint on what to enable.

Now go to the kernel source directory and execute. This will fire up menu-driven configuration screen.

The Linux kernel configuration has many, many sections. Let's first list some options that must be activated (otherwise Gentoo will not function, or not function properly without additional tweaks). We also have a Gentoo kernel configuration guide on the Gentoo wiki that might help out further.

Enabling required options
When using, it is strongly recommend the Gentoo-specific configuration options be enabled. These ensure that a minimum of kernel features required for proper functioning is available:

Naturally the choice in the last two lines depends on the selected init system (OpenRC vs. systemd). It does not hurt to have support for both init systems enabled.

When using, the additional selections for init systems will be unavailable. Enabling support is possible, but goes beyond the scope of the handbook.

Enabling support for typical system components
Make sure that every driver that is vital to the booting of the system (such as SATA controllers, NVMe block device support, filesystem support, etc.) is compiled in the kernel and not as a module, otherwise the system may not be able to boot completely.

Next select the exact processor type. It is also recommended to enable MCE features (if available) so that users are able to be notified of any hardware problems. On some architectures (such as x86_64), these errors are not printed to, but to. This requires the package.

Also select Maintain a devtmpfs file system to mount at /dev so that critical device files are already available early in the boot process ( CONFIG_DEVTMPFS and CONFIG_DEVTMPFS_MOUNT ):

Verify SCSI disk support has been activated ( CONFIG_BLK_DEV_SD ):

Verify basic NVMe support has been enabled:

It does not hurt to enable the following additional NVMe support:

Now go to File Systems and select support for the filesystems that will be used by the system. Do not compile the file system that is used for the root filesystem as module, otherwise the system may not be able to mount the partition. Also select Virtual memory and /proc file system. Select one or more of the following options as needed by the system:

If PPPoE is used to connect to the Internet, or a dial-up modem, then enable the following options ( CONFIG_PPP, CONFIG_PPP_ASYNC , and CONFIG_PPP_SYNC_TTY ):

The two compression options won't harm but are not definitely needed, neither does the PPP over Ethernet option, that might only be used by ppp when configured to do kernel mode PPPoE.

Don't forget to include support in the kernel for the network (Ethernet or wireless) cards.

Most systems also have multiple cores at their disposal, so it is important to activate Symmetric multi-processing support ( CONFIG_SMP ):

If USB input devices (like keyboard or mouse) or other USB devices will be used, do not forget to enable those as well:

Optional: Building an initramfs
In certain cases it is necessary to build an initramfs - an initial ram-based file system. The most common reason is when important file system locations (like or ) are on separate partitions. With an initramfs, these partitions can be mounted using the tools available inside the initramfs.

Without an initramfs, there is a risk that the system will not boot properly as the tools that are responsible for mounting the file systems require information that resides on unmounted file systems. An initramfs will pull in the necessary files into an archive which is used right after the kernel boots, but before the control is handed over to the init tool. Scripts on the initramfs will then make sure that the partitions are properly mounted before the system continues booting.

To install an initramfs, install first, then have it generate an initramfs:

The initramfs will be stored in. The resulting file can be found by simply listing the files starting with initramfs:

Now continue with Kernel modules.

Listing available kernel modules
The modules that need to be loaded during each boot in can be added to files in the format of one module per line. When extra options are needed for the modules, they should be set in files instead.

To view all modules available for a specific kernel version, issue the following command. Do not forget to substitute " " with the appropriate version of the kernel to search:

Force loading particular kernel modules
To force load the kernel to load the module (which is the driver for a specific 3Com network card family), edit the  file and enter the module name within it.

Note that the module's file suffix is insignificant to the loading mechanism and left out of the configuration file:

Continue the installation with Configuring the system.