Handbook:Parts/Installation/Kernel/pl

Optional: Installing firmware and/or microcode
Before getting to configuring kernel sections, it is beneficial to be aware that some devices require additional firmware to be installed on the system before they will operate correctly. This is often the case for network interfaces, especially wireless network interfaces commonly used in both desktop and laptop computers. Modern video chips from vendors like AMD, Nvidia, and Intel, often need external firmware files to be fully functional. Most firmware for modern hardware is available in the package. On systems using graphics cards from these vendors, it is wise to emerge this firmware package in order to have it available before configuring and compiling the kernel.

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 bugs in CPU hardware.

Microcode updates for AMD CPUs are typically distributed with the aforementioned linux-firmware package. Microcode for Intel CPUs can be found in 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. There are three approaches for this:


 * 1) The kernel is manually configured and built.
 * 2) A tool called  is used to automatically build and install the Linux kernel.
 * 3) A Distribution Kernel is used to automatically build and install the Linux kernel like any other package.

Manual configuration is explained as the default choice since it is the best way to optimize an environment.

The core around which all distributions are built is the Linux kernel. It is the layer between the user programs and the system hardware. Gentoo provides its users several possible kernel sources. A full listing with description is available at the Kernel overview page.

Installing the sources
When manually 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:

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.

Activating 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.

Make sure that every driver that is vital to the booting of the system (such as SCSI controller, etc.) is compiled in the kernel and not as a module, otherwise the system will 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 ):

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 ( CONFIG_EXT2_FS, CONFIG_EXT3_FS , CONFIG_EXT4_FS , CONFIG_MSDOS_FS , CONFIG_VFAT_FS , CONFIG_PROC_FS , and CONFIG_TMPFS ):

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 ( CONFIG_HID_GENERIC and CONFIG_USB_HID, CONFIG_USB_SUPPORT , CONFIG_USB_XHCI_HCD , CONFIG_USB_EHCI_HCD , CONFIG_USB_OHCI_HCD ):

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.

Alternative: Using genkernel
If a manual configuration looks too daunting, then consider using. It will configure and build the kernel automatically.

works by configuring a kernel nearly identically to the way the installation CD kernel is configured. This means that when is used to build the kernel, the system will generally detect hardware it was built for support with at boot-time, just like the installation CD does. may be a useful solution for those users who may not be comfortable compiling their own kernels. Note that genkernel does not automatically generate a custom kernel configuration the hardware on which it is being run.

Now, let's see how to use genkernel. First, emerge the ebuild:

Next, edit the file so that the line containing  as second field has the first field pointing to the right device. If the partitioning example from the handbook is followed, then this device is most likely with the ext4 file system. This would make the entry in the file look like so:

Now, compile the kernel sources by running. Be aware though, as compiles a kernel that supports almost all hardware, this compilation will take quite a while to finish!

Once genkernel completes, a kernel, full set of modules and initial ram disk (initramfs) will be created. We will use the kernel and initrd when configuring a boot loader later in this document. Write down the names of the kernel and initrd as this information is used when the boot loader configuration file is edited. The initrd will be started immediately after booting to perform hardware autodetection (just like on the installation CD) before the "real" system starts up.

Configuring the modules
List the modules that need to be loaded automatically in files one module per line. Extra options for the modules, if necessary, should be set in files.

To view all available modules, run the following command. Don't forget to substitute " " with the version of the kernel just compiled:

For instance, to automatically load the module (which is the driver for a specific 3Com network card family), edit the  file and enter the module name in it. The actual file name is insignificant to the loader.

Continue the installation with Configuring the system.