Compiling Kernel   «Prev  Next»

Lesson 8Configuring the kernel
ObjectiveConfigure Linux Kernel Options before Compilation

Configure Linux Kernel Options before Compilation

Configuring your kernel correctly is crucial. Not only must you decide what kernel options to include, you must also decide if they are modular or built into the kernel. Linux makes it easy to set kernel options, but you must make sure you choose your options wisely.
Configure Linux Kernel options before compilation
Configuring Linux kernel options before compilation on Red Hat Linux typically involves several steps, primarily focused on using the kernel configuration utilities that come with the Linux source code. Here's a general approach to configuring the kernel options before compiling it:
  1. Install Necessary Development Tools and Dependencies Before you begin, ensure that you have the necessary tools and dependencies installed. You can install these on Red Hat Linux using the yum or dnf package managers (depending on your version of Red Hat):
    sudo yum groupinstall "Development Tools"
    sudo yum install ncurses-devel bison flex elfutils-libelf-devel openssl-devel
    
  2. Obtain the Kernel Source: You can download the latest kernel source from the [Kernel.org](https://www.kernel.org/) website or use the source provided by Red Hat through their packages. If you prefer to use the Red Hat distributed kernel with backports and patches, you can install it using:
    sudo yum install kernel-devel
    

    Or for a specific version:
    sudo yum install kernel-devel-$(uname -r)
    
  3. Prepare the Kernel Configuration:
    Navigate to the directory where the kernel source is located (e.g., /usr/src/kernels/$(uname -r)` for Red Hat specific kernels or your custom downloaded path). You configure the kernel using one of the following make menu commands:
    • make menuconfig: A text-based user interface that runs in the terminal. It's useful for SSH sessions or environments without a graphical interface.
      make menuconfig
      
    • make xconfig: A graphical configuration interface that requires Qt libraries.
      make xconfig
      
    • make gconfig: Another graphical configuration interface that requires GTK+ libraries.
      make gconfig
      
  4. Configure the Kernel Using make menuconfig or another tool, you can navigate through various kernel configuration options. These options allow you to enable or disable kernel features, set module support, and optimize for specific hardware. The configuration interface categorizes options into different sections, making it easier to manage:
    • Navigate through the different menu options to enable or disable specific features.
    • Modules can be built-in, modular (loadable as .ko files), or omitted entirely.
    • For a typical configuration, you might start with the default configuration file (/boot/config-$(uname -r)) and modify it as needed.
  5. Save the Configuration: Once you've made the necessary changes, save the configuration. This step is crucial as it updates the .config file with your selections.
  6. Compile the Kernel: After configuring, compile the kernel and its modules with:
    make
    make modules
    
  7. Install the Kernel: After successful compilation, install the kernel and modules:
    sudo make modules_install
    sudo make install
    
    This will also update the boot loader entries, typically managed by GRUB.
  8. Reboot and Select the Kernel: Finally, reboot your system. If necessary, select the new kernel from the boot menu to start using it.

Note: Always back up important data before installing a new kernel. Configuring and compiling the Linux kernel allows you to optimize the system but can lead to system instability if not done correctly. It's recommended to thoroughly test the new kernel in a non-production environment first.

Hardware Considerations

When choosing kernel options, consider the specific hardware on your system and your need for protocols and services. Here are some general guidelines to follow.
  1. Under Code Maturity Level Options, check Prompt for development and/or incomplete code/drivers. If you do not check this option, certain essential services (most notably rpc.nfsd) may not work correctly.
  2. Optimize for your computer's processor family.
  3. Turn off math emulation when your system has a dedicated math coprocessor. Intel 386 and 486 systems with a coprocessor, Pentiums, and Alphas all have on-processor math coprocessors.
  4. Turn off SMP (Symmetric Multi-Processor) support when your system only has a single CPU.
  5. Modularize as much hardware support as possible.
  6. Turn off ISDN [1] IrDA[2], and old CD-ROM drivers support, unless you have these capabilities or devices.
  7. Don't change the default sound configuration.
  • Configuring the kernel

    To configure the kernel, follow the following four steps.
    1. Change to the /usr/src/linux directory.
    2. Type make mrproper to restore the sources to a clean state.
    3. Copy one of Red Hat's default configuration files from the configs/ directory to arch/i386/defconfig. Red Hat provides these default configurations for a variety of hardware platforms. The settings inside of each make configuring the kernel easier.
    4. Type make oldconfig to create a starting Linux kernel configuration file from the default configuration copied in the previous step.
    5. Create the kernel configuration file using one of the standard configuration utilities: make xconfig, make menuconfig, or make config.
    6. Update the EXTRAVERSION= line in /usr/src/linux/Makefile.
    7. Type make dep to create the source dependencies and propagate configuration information to all makefiles in the development tree.
    8. Type make clean to remove old object files.

1) Step one: change into the /usr/src/linux directory. All subsequent commands will run relative to this directory.
1) Step one: change into the /usr/src/linux directory. All subsequent commands will run relative to this directory.

2) Step two: type make mrproper to restore the kernel sources to a clean state
2) Step two: type make mrproper to restore the kernel sources to a clean state.

3) Step three: copy a default configuration file to the arch/i386/defconfig file. In this example, you copied an Intel 686 default profile. Because a default profile already exists, Red Hat Linux will prompt you to overwrite the existing file. It is safe to answer
3) Step three: copy a default configuration file to the arch/i386/defconfig file. In this example, you copied an Intel 686 default profile. Because a default profile already exists, Red Hat Linux will prompt you to overwrite the existing file. It is safe to answer "y."

4) Step four: create a starting Linux kernel configuration file by typing make oldconfig. This incorporates the default configuration you copied in the previous step into your Linux kernel configuration.
4) Step four: create a starting Linux kernel configuration file by typing make oldconfig. This incorporates the default configuration you copied in the previous step into your Linux kernel configuration.

5) Step five: create the kernel configuration file using one of the standard configuration utilities: make xconfig, make menuconfig, or make config.
5) Step five: create the kernel configuration file using one of the standard configuration utilities: make xconfig, make menuconfig, or make config. make xconfig is X-based and menu driven; make menuconfig is VGA-based and menu driven; and make config is command-line driven. Try out all three possibilities and choose the one you find most comfortable to work with. make menuconfig is easy to use and text based, and it is often the best choice.

6) The colorized menu interface for make menuconfig is very useful. You can use the arrow keys to move up and down,  and the Enter key to move into submenus.
6) The colorized menu interface for make menuconfig is very useful. You can use the arrow keys to move up and down, and the Enter key to move into submenus. To build support for an item into the kernel, highlight the item and press Y. To build modular support, highlight the item and press M. To turn off support, highlight the item and press N.

7) Save your changes before you exit the configuration program.
7) Save your changes before you exit the configuration program.

8) Once you are outside of make menuconfig, you see that it prompts you for the next steps.
8) Once you are outside of make menuconfig, you see that it prompts you for the next steps.

9) Step six: update the EXTRAVERSION variable in the Linux kernel configuration makefile. You can set this to any value, but something you easily recognize and that is different from your last kernel configuration is recommended.
9) Step six: update the EXTRAVERSION variable in the Linux kernel configuration makefile. You can set this to any value, but something you easily recognize and that is different from your last kernel configuration is recommended. A good choice is simply to append a revision number to Red Hat's value, e.g. 2.2.14-5.0r1. Whatever value you choose, make sure it starts with a hyphen (-).

10) Step seven: type make dep to create the source dependencies and propagate configuration information to all makefiles in the development tree.
10) Step seven: type make dep to create the source dependencies and propagate configuration information to all makefiles in the development tree.

11) Step eight: type make clean to remove old object files.
11) Step eight: type make clean to remove old object files.


If you build the kernel in the future and use the same configuration, you do not need to perform steps two, three, and four.
You need to do these steps only the first time you are rebuilding a Red Hat Linux kernel. The next lesson presents the kernel and modules build and install procedures.

[1]ISDN: An acronym for Integrated Services Digital Network, ISDN is a standards specification for data transmission over telephone wires and other land-based media.
[2]IrDA: An acronym for Infrared Data Association, IrDA is an international standards body that plans the hardware and software requirements for wireless, infrared data communication.

SEMrush Software 8 SEMrush Banner 8