Disclaimer : This document is not valid and is not maintained anymore. |
For users who are not privy to kernel compilation, genkernel is a tool to automate this process. It can help you create a kernel image akin to those available on Gentoo Installation CDs, which are designed to auto-detect the hardware configuration of your system. Some users may also be interested in using genkernel for hardware requiring initialization and a working kernel before the system starts up. Since genkernel automatically compiles your kernel modules, you can use hardware that may require certain module parameters to be loaded for proper operation.
If you are either uncertain about how to compile a kernel, or are just unfamiliar with your hardware configuration, genkernel is a very handy tool. It is designed to take the pain out of the kernel compiling process, and supports most hardware by default.
However, if you know what drivers are required by your system, you may be able to further reduce the time taken to compile the kernel. This is possible since you can direct genkernel to only build drivers relevant to your hardware. Oftentimes, the number of drivers required by your system will be fewer (implying a shorter kernel compilation time) than the default configuration provides.
To obtain genkernel, run emerge genkernel from the command line. If you are using the Gentoo Reference Platform (GRP), remember to install binary packages by passing the -k flag to emerge. Since the GRP is bundled with an older version of genkernel, the flags may be different. In any case, consult genkernel --help for help on how to use the version of genkernel installed on your system.
Although there are several ways to run genkernel, the least-intrusive approach is provided by genkernel all. 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 flags to genkernel as root:
Code Listing 2.1: Running genkernel (with flags) |
# genkernel --splash --no-install --no-clean --menuconfig all
|
The above operation causes genkernel to create a framebuffer splash-enabled kernel (--splash) that will have to be manually installed (--no-install). While preparing the kernel source tree, genkernel will refrain from cleaning out any preexisting object files present in the source tree (--no-clean). A menu-driven kernel configuration utility will be displayed that allows the user to select which modules will be built for the system (--menuconfig).
There are other flags which alter the result provided by genkernel. For instance, replacing --no install with the --install flag allows genkernel to automatically install the new kernel in the /boot directory. Using the --mountboot flag allows genkernel to mount your /boot partition automatically, if necessary.
Remember, genkernel is designed to make kernel compilation easy and stress-free. For this reason, genkernel features several flags to ease the kernel compilation effort. For example, there are flags to help with kernel configuration, while others affect the actual compilation. Some flags even help debug the compilation process. For those interested in further optimization, there are flags that affect kernel assembling, packaging and even kernel initialization.
The rest of this chapter examines the functionality of various flags and actions available for genkernel. Some of the flags have variants which perform a converse operation. The converse variants carry the no- prefix, and their effects are enclosed within the square brackets, [].
The configuration flags listed below exist to help you decide what features should be enabled or disabled in the kernel prior to compilation. You can even choose whether or not the configuration file created in the process should be saved. The following are the primary configuration flags:
The following flags usually take effect during the actual compilation:
The following flags are supported by genkernel, and are passed to the relevant applications while the kernel is being assembled. These flags affect the compiler used for the kernel compilation process, albeit at a much lower level.
The use of debugging flags during the kernel compilation process controls the amount of information reported, as well as the presentation of said data.
The flags here are used to create certain effects during system startup. Some of these flags are primarily for aesthetics, while others may be essential for enabling certain features on the system.
The assortment of flags listed below are supported by genkernel, but do not fit neatly into any of the other categories:
An action tells genkernel what to build. Currently, the following actions are supported:
The last action, all, is recommended for most users since it builds the stages required for a functional kernel. Remember, an action simply tells genkernel what to build, not install.
To set up genkernel to work with your bootloader, three or four changes should be applied to the bootloader's configuration file:
Passing flags to genkernel from the command line can be cumbersome, especially if you have about a dozen flags:
Code Listing 3.1: Running genkernel (overloaded with flags) |
# genkernel --debuglevel=5 --no-color --no-mrproper --clean --splash \
--kerneldir=/path/to/alternate/kernel/sources --install --menuconfig \
--kernel-config=/path/to/preferred/configfile --save-config --mountboot all
|
Fortunately, there is a configuration file where most of the basic options can be set (or changed) as necessary. What follows is a rundown of the more relevant options:
By choosing the appropriate options in /etc/genkernel.conf, you can halve the number of flags passed to genkernel from the command line:
Code Listing 3.2: Running genkernel (with flags), after employing genkernel.conf |
# genkernel --splash --kerneldir=/path/to/alternate/kernel/sources \
--kernel-config=/path/to/preferred/configfile --install all
|
Identical results are obtained from both approaches, but the latter has most of the options stored in a script that can be modified at a later date.
4. Network-Booting with genkernel
Network Booting from an Installation CD
The genkernel utility can build kernel and initrd images that provide support for network booting, or netbooting. With any luck, you 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 Kernel and Initrd Images with Support for Netbooting
To enable support for netbooting, include the following options while configuring the kernel:
Warning: Support for netbooting with genkernel is experimental and may contain bugs. |
First, the kernel image must include the drivers for your Network Interface Cards (NIC). Normally, drivers for such devices will be compiled as modules. However, it is essential (for netbooting) that you have such drivers compiled directly into the kernel image and not as modules.
Code Listing 4.1: Configuring a 2.6.x series kernel to support your NIC driver |
Device Drivers --->
Networking Support --->
Ethernet (10 or 100Mbit) --->
[*] Ethernet (10 or 100Mbit)
<*> the driver for your network card
(Be sure to select <*> and not <M>)
|
Secondly, we suggest that you enable IP: kernel level autoconfiguration and the 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.
Code Listing 4.2: Configuring a 2.6.x series kernel to support DHCP |
Device Drivers --->
Networking Support --->
Networking options
[*] TCP/IP networking--->
[*] IP: kernel level autoconfiguration
[*] IP: DHCP support
(These options tell the kernel to send a DHCP request at bootup.)
|
Additionally, you should 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.
Code Listing 4.3: Configuring the kernel to support SquashFS |
File systems--->
Miscellaneous filesystems --->
[*] SquashFS 2.X - Squashed file system support
|
Once the compilation process is completed, create a compressed tarball (tar.gz) that contains the kernel's modules. This step is only necessary if your kernel version does not match the kernel image version on the Installation CD.
Code Listing 4.4: Creating a compressed tarball containing the kernel modules |
(Create a tar.gz containing all the modules) # cd / # tar -cf /tmp/modules-X.Y.Z.tar.gz /lib/modules/X.Y.Z/ |
Depending on your network boot mechanism, you will need to do some of the following steps:
Code Listing 4.5: Creating a boot image |
(Create an etherboot image) # emerge mknbi # cd /boot # mkelf-linux -params="root=/dev/ram0 init=/linuxrc ip=dhcp" kernel... initrd... > etherboot.img (Create a OpenBoot / SPARC64 TFTP image) # emerge sparc-utils # cd /boot # elftoaout kernel... -o kernel.aout # piggyback64 kernel.aout System.map-... initrd-... # mv kernel.aout openboot.img (This is the boot image) (PXE does not need any more steps, the kernel and initrd can be used as is) |
Finally, copy this kernel to your TFTP server. The details are architecture-dependent and are beyond the scope of this guide. Please refer to the documentation for your platform.
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 /nfs/livecd/add/ directory. All you have to do here is copy the modules-X.Y.Z.tar.gz archive to the /nfs/livecd/add/ directory.
Code Listing 4.6: Preparing the NFS share |
(This assumes that /nfs/livecd is an exported NFS share) # mount /tmp/gentoo-livecd.iso /mnt/cdrom -o loop # cp -p /mnt/cdrom /nfs/livecd # umount /mnt/cdrom (Copy the modules.tar.gz into /add) # mkdir /nfs/livecd/add # cp /tmp/modules-X.Y.Z.tar.gz /nfs/livecd/add |
The netboot images will ask your DHCP server for an IP as well as a root-path parameter. Both can be specified per host using a MAC address to identify machines:
Code Listing 4.7: Sample client dhcpd.conf setup |
...
host netbootableMachine {
hardware ethernet 11:22:33:44:55:66;
fixed-address 192.168.1.10;
option root-path "192.168.1.2:/nfs/livecd";
}
# Here, 192.168.1.2 is the NFS server
# While 192.168.1.10 will be the IP address of the netbooted machine
...
|
Netbooting itself is again very platform-specific. The important part is to specify the ip=dhcp and init=/linuxrc 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:
Code Listing 4.8: Netbooting Instructions |
# Etherboot - insert the etherboot disk into the drive and reboot # The kernel command line was specified when the image was constructed # Sparc64 - Hit Stop-A at the boot prompt ok boot net ip=dhcp init=/linuxrc # PXE - Setup pxelinux (part of syslinux), then create a pxelinux.cfg/default along the lines of: DEFAULT gentoo TIMEOUT 40 PROMPT 1 LABEL gentoo KERNEL kernel-X.Y.Z APPEND initrd=initrd-X.Y.Z root=/dev/ram0 init=/linuxrc ip=dhcp |
To Automate or not to Automate?
The purpose of genkernel is to provide an (easier) alternative to the time-tested approach to kernel compilation. As always, you are free to decide on whether or not you want to automate the kernel compilation process.
The contents of this document are licensed under the Creative Commons - Attribution / Share Alike license.