Genkernel/de

genkernel is a tool used to automate the build process of the kernel and initramfs. Some of the general features include:


 * Configuring the kernel sources;
 * Building the compressed kernel and copying it to
 * Creating an initramfs and copying it to
 * Creating symlinks in
 * Adding custom content to the initramfs such as encryption related files, boot splash images, extra modules, and more;
 * Compressing the initramfs;
 * Configuring the bootloader.

Emerge
Initiate the installation of genkernel:

Genkernel Aufruf
The general form of genkernel invocation is as follows:

Optionen
The actual behavior of genkernel depends on a large variety of options, the majority of which can be set/unset in the file or passed via the genkernel command on each invocation. Options passed over the command line take precedence over options defined in. The configuration file is very well documented, however some of the most commonly used options will be explored in this article. The goal is for the reader to be familiar with common genkernel invocations. For a more complete set of explanations refer to the comments in itself or to the output of the man genkernel command.

Options acting on user interactivity
The configuration options listed below help the user decide how to interact with the configuration process. Users can even choose whether or not the configuration file created in the process should be saved. The following are considered primary configuration options:

Options acting on the resulting system
The configuration options listed here defines which features will or will not be enabled in the resulting kernel and initrd.

Options acting on the choice of the tools used for building
The following options are supported by genkernel, and are passed to the relevant applications while the kernel is being assembled. These options affect the compiling tools used for the kernel compilation process, albeit at a much lower level.

Options acting on the compilation process
The following options usually take effect during the actual compilation:

Debugging options
The use of debugging options during the kernel compilation process controls the amount of information reported, as well as the presentation of said data.

Actions
The action passed on the command line with the genkernel [options …] action tells genkernel what action to perform. The following actions are supported:


 * all
 * Builds all stages — the initrd, kernel image and modules.


 * bzImage
 * Only builds the kernel image.


 * kernel
 * Only builds the kernel image and modules.


 * initramfs
 * Only builds the initramfs/ramdisk image.


 * ramdisk</tt>
 * Only builds the initramfs/ramdisk image.

genkernel first invocation
Although there are several ways to run genkernel, the least-intrusive approach recommended for most users is provided by genkernel all</tt>. Here, a generic configuration which works well for most systems is used. As was mentioned earlier, this approach is not without drawbacks; most of the modules created are useless to the average user and may increase compile time. Below is an illustration of a more efficient approach, achieved by passing certain options to genkernel as root:

The above operation causes genkernel to create a framebuffer splash-enabled kernel that will have to be manually installed. While preparing the kernel source tree, genkernel will refrain from cleaning out any preexisting object files present in the source tree. A menu-driven kernel configuration utility will be displayed that allows the user to select which modules will be built for the system.

Replacing  with the   option allows genkernel to automatically install the new kernel in the  directory, and will create symlinks if   is specified. Using the  option allows genkernel to mount the  partition automatically, if necessary.

Using genkernel to change the kernel
The first thing that should be done is to allow the triggering of make menuconfig</tt> in the file:

Dateiverwaltung durch genkernel
While using genkernel, the user has to be aware of some aspects relating to kernel configuration and kernel image files management and the way the kernel sources are handled by the system.

Source files used by genkernel
After an emerge -u gentoo-sources</tt>, whenever new sources are available, a new kernel source directory is created under to host them. Normally, the active kernel sources directory is pointed to by the symlink.

The directory might look like this:

The symlink can be changed in different ways.


 * If the  USE is set the  symlink is automatically updated to point to the newly emerged sources.


 * If the  USE is not set, the user can change the destination of the symlink using the eselect kernel list</tt> followed by the eselect kernel set</tt> command.

genkernel will always use the sources pointed by the symlink.

Kernel configuration file used by genkernel
If a kernel compilation has already been run with the active kernel sources, there might be a file inside the directory that contains the kernel configuration that has been applied while creating the last bzimage of the kernel. This file is named, for example where x86_64 might be substituted with the system's architecture, 3.7.9 might be substituted with the version of the sources used and r1 with the release of the sources.

It is this file that is used as a starting configuration when running  genkernel --menuconfig all</tt>.

If it is the first time that genkernel is run with the new kernel sources, or if the previous result has not been saved, this file is substituted with a default configuration file that resides at where x86_64 is substituted with the actual architecture.

Saving the compiled configuration
If the  genkernel option is activated, either from the command line or inside, the compiled kernel configuration is saved (with the name given above) into the  directory. At the same time, the configuration is saved in the file in  directory but this file is not reused on the next genkernel all</tt> run.

Installing the kernel and initramfs into the /boot directory
Specifying the  option when invoking genkernel, will ask genkernel to install the kernel image and the initramfs into the  directory. In order to run  a convenient manner, set the following in the  file:


 * The first parameter speaks for itself.


 * The second parameter tells genkernel to save the compiled kernel configuration into


 * The last two options tell genkernel to automatically update the grub configuration. In practice, the following happens:
 * If a previous kernel image with the same name already exist, it is renamed by appending to its name. A symlink  is automatically created that points to it.
 * The new kernel takes the place of any kernel with the same name into . If it is the first time a kernel is compiled, a symlink kernel is automatically created that points to the new kernel.

After running genkernel --menuconfig all</tt>, the directory might look like this:

Configuring the bootloader
The symlinks presented above in the bootloader's configuration can be used so that, even if the new kernel is not bootable, the user can always boot on the old one.

To allow the kernel and intird provided by genkernel to run correctly, provide a minimum information in bootloader's configuration file :
 * Add  to the kernel parameters passed to the kernel image, where  points to the root partition.
 * If splash is used, add a suitable mode line such as  to the parameters passed to the kernel and also add   or   depending on the verboseness required through the boot process.
 * Add the initrd information as required by the bootloader. Consult the Bootloader Configuration Chapter of the Gentoo Handbook for details on how to make the bootloader initrd-aware.

Here is how the file might look.

Preserving the working files
The genkernel application automatically saves new changes to the files. If previous changes are to be preserved, then the following actions need to be taken.


 * The first file to preserve is the kernel configuration file in If the source has not changed prior to the recompilation of the kernel, the previously used name for this file will be used. So copying the previous configuration file under a different name helps in preserving the information while keeping the file available as a starting point for a new configuration.


 * The second important thing is to preserve the already bootable kernel and initramfs images. The way to accomplish this depends on the context:
 * If the last kernel compiled is bootable, running genkernel will rename this kernel (and similarly initramfs) image to and create a new . This mean that even if the new kernel is not bootable, users will always be able to boot the old one.
 * If the last kernel compiled is not bootable and sources haven't changed since the user compiled a bootable one, prior to running genkernel, first delete the new kernel image and remove the .old</tt> suffix from the last bootable one. Without this, if the newly compiled kernel is not bootable for the second time, the bootable will be kicked out by the renaming of the non bootable, giving the user an unbootable system. Use the same reasoning for initramfs.

Using previous kernel configuration while changing the sources
The previous configuration can be used through the make menuconfig</tt> option in as follows:

From an installation CD
The genkernel utility can build kernel and initrd images that provide support for network booting, or netbooting. With any luck, users should be able to netboot any recent computer into the environment provided by the Installation CD.

The magic lies in genkernel's linuxrc script: it will try to netmount the Installation CD using NFS. From there, the init scripts of the Installation CD can take over, as if the CD was present locally.

Building the kernel and initramfs with netboot support
To enable support for netbooting, include the following options while configuring the kernel:

First, the kernel image must include the drivers for the system's Network Interface Cards (NIC). Normally, drivers for such devices will be compiled as modules. However, it is essential (for netbooting) that such drivers are compiled directly into the kernel image and not as modules.

Be sure to select &lt;*&gt;</tt> and not &lt;M&gt;</tt>.

Secondly, it is suggested that IP: kernel level autoconfiguration is enabled as well as IP: DHCP support options. This avoids an unnecessary layer of complexity since the IP address and the NFS path to the Installation CD can be configured on a DHCP server. Of course, this means the kernel command line will remain constant for any machine — which is very important for etherbooting.

These options tell the kernel to send a DHCP request at bootup.

Additionally, enable SquashFS because most modern Gentoo Installation CDs require it. Support for SquashFS is not included with the generic kernel source tree. To enable SquashFS, apply the necessary patches to the generic kernel source or install gentoo-sources.

Once the compilation process is completed, create a compressed tarball (tar.gz) that contains the kernel's modules. This step is only necessary if the kernel version does not match the kernel image version on the Installation CD.

To create an archive containing all the modules:

Depending on the network boot mechanism, one of the following steps need to be followed:

To create an etherboot image:

To create a OpenBoot / SPARC64 TFTP image:

The file is the boot image.

Finally, copy this kernel to the TFTP server. The details are architecture-dependent and are beyond the scope of this guide. Please refer to the documentation for the specific platform of interest.

NFS setup
To setup a NFS share that contains the Installation CD, use the loop device to mount the ISO image and then copy the contents of the CD into the NFS share. As a nice extra, genkernel's initrd scripts will extract all tar.gz files located in the directory. All that needs to be done here is copy the archive to the  directory.

The following assumes that is an exported NFS share:

Now copy the file into :

DHCP setup
The netboot images will ask the DHCP server on the network for an IP as well as a  option. Both can be specified per host using a MAC address to identify machines:

Netbooting instructions
Netbooting itself is again very platform-specific. The important part is to specify the  and   parameters on the kernel command line, as this will bring up the network interface and tell the initrd scripts to mount the Installation CD via NFS. Here are some platform-specific tips.

For etherboot, insert the etherboot disk into the drive and reboot. The kernel command line was specified when the image was constructed. With Sparc64, hit - at the boot prompt and enter:

For PXE, setup pxelinux (part of syslinux), then create a along the lines of:

Introduction
If an initramfs is installed with genkernel, then take a look at the various boot options that can (or should) be defined in the bootloader configuration. The most common ones are added to this guide.

Loading LVM or software-RAID
If the system uses LVM or software-RAID, the initramfs has to be built using the  and   options. Do not forget to enable support during boot as well. This can be done using the dolvm and domdadm options.

Booting in single-user mode
If for some reason boot-up fails, rescuing the system by booting in the single-user mode is still possible. This will only load the really necessary services and then drop the user to a rescue (root) shell.

External resources

 * genkernel's source code repository (GitWeb).