Linux kernel configuration

From Linux 101, The beginner's guide to all things Linux.

Jump to: navigation, search

Contents

[edit] Configuring the Kernel

First off, this will require a lot of reading! There are many options in the kernel configuration that you can use. After all, Linux can be run on anything from a desktop, to a server on many architectures, as well as smaller devices like mp3 players and PDAs. You'd expect that you need to properly configure your kernel so it knows you're running on a desktop and not an embedded computer.

Each option has a help screen. These are critical to you understanding what the option means. They exist for a reason. Most help pages also say "If in doubt, choose ___"

The thing you are unaccustomed to is how to decide what hardware you have. In Windows you had to go to the website of your particular hardware's manufacturer and download their software/drivers. Linux configures by chipset, not by company that produces the hardware. For example with wireless cards. There are about 4 common chipsets but many manufacturers.

This means usually before you configure your kernel that you will need to do some research on the hardware you have. If you have a desktop, you can open up your computer and look inside. Look at the chips on the devices (ie, network card, etc) and see what brand and model they are. Usually they write it on the chip (sometimes bizarre mix of letters and numbers), so copy this info down onto paper. If you have a laptop you can look online. It is likely that someone with a laptop like yours (and with more experience) has already put Linux on that laptop. Benefit from their experience.

Kernel configuration can be tricky, as there are many confusing options. It will probably take you a few tries the first time to get a kernel that works as you intended. Take your time, and when in doubt seek help.

If you elect not to build in support for particular hardware, then Linux will never use it. For example if on a laptop with a PCMCIA bus you do not include support for it, then you do not have a PCMCIA bus. On some hardware this might even mean it is not powered, thus saving your battery.

This is done to increase system security. What the root user elects not to enable hardware for, then there is no support for it. This helps things like someone coming up to your computer with a usb keychain drive and installing something on your computer without your consent.

The drawback to this method is when you install new hardware in your computer, usually it means you need to rebuild your kernel.

[edit] Built-In v. Modules

In the old days of computers, there was less resources to the system. In an effort to save memory and the like, the Linux developers created modules so code could optionally be installed without having to restart the computer. Later the ability to unload modules came.

However, with modern computers having such plentiful resources, the need for modules has weakened, but they are still a good idea.

Modules are useful for controlling the order in which hardware is recognized. All built-in features are enabled at boot. Modules are not loaded until your init scripts take over.

One good example for this is a laptop with a wired ethernet connection and wireless connection. Load the wired connection as built in. Load the wireless as a module. This ensures that eth0 is always the wired connection, and eth1 is always the wireless.

[edit] Configuring Commands

Before you run any of the next commands, you should get into root user with su and then get into the directory for your sources.

su
# cd /usr/src/linux-2.x.y

The Linux kernel can be configured using several methods:

# make config
Is the original, prompt for each option based configuration system. It is not recommended because it makes configuration very tedious.
# make menuconfig <-- *recommended*
This provides a curses-based menu which lets you select configuration options from a hierarchical listing, without going through each one. This is recommended if you are not using X Windows.
# make xconfig
This provides a Tcl/Tk based X Windows graphical interface for configuration. Options are represented in buttons and dialog boxes. This is one of the easiest configuration options.
# make gconfig
This is a GTK (GNOME) configuration setup. It's GUI like the xconfig but prettier. I do not think many people actually use this method though.

[edit] Updating your kernel version

When updating from, say kernel 2.4.x to 2.4.y (or 2.6.x to 2.6.y), you can save your previous configuration. After you configure the kernel, the configuration editor creates the .config file. If you copy this file from the old source directory (/usr/src/linux-2.4.x) to the new one (/usr/src/linux-2.4.y) then you can run:

# make oldconfig

You will be prompted for any new configuration options that were not present in the .config file. This is a sign that there are new features in the updated kernel. The prompts are of the make config style, but fortunately there are usually only a few to go through. Most of them you will likely answer N to.

Once that process finishes you can move onto the commands to build the kernel.

Note: This .config file is also good for saving your back-up kernel configuration.

[edit] Building the kernel

After your choice of config, you can proceed to the next steps in kernel building:

# make dep - omit this for kernel version 2.6.x and later
This command will compute all of the inter-source dependencies.
# make bzImage - the preferred image type is bzImage
This will compile the actual Linux kernel.
# make modules - builds the modules
This compiles the optional modules features you compiled in.
# modules_install - installs the modules
This installs the modules under /lib/modules/.

[edit] Loading the Kernel

Your kernel should be in your /usr/src/KERNEL-VERSION/arch/i386/boot directory as the file bzImage. This file should be copied into /boot.

Note: It is recommended that you do not overwrite your previous bzImage file. Should you have built a bad kernel, your previous kernel can be used to still boot your computer until you fix your new one. Name your file bzImageKERNELVERSION and you should never have this problem. For example: bzImage267 (2.6.7 with the dots taken out)

The next step is to configure the GRUB or LILO bootloaders. After you do this, you should be able to reboot.

Personal tools