|
|
Kernel Hacking Lesson #2: Configure Your Kernel
The Linux kernel comes with several configuration tools. Each one is
run by typing make <something>config in the top-level kernel source
directory. (All make commands need to be run
from the top-level kernel directory.)
make config
This is the barebones configuration tool. It will ask each and every
configuration question in order. The Linux kernel has a LOT of
configuration questions. Don't use it unless you are a masochist.
make oldconfig
This will take the config file named .config and only ask the
configuration questions which are not already answered in that file.
This is most often used when upgrading to a more recent version of the
kernel.
make menuconfig
This is the kernel hacker mainstay. This command pops up a text-based
menu-style configurator using the ncurses library. You can descend
into the menus that interest you and change only the configuration
options you care about.
make xconfig, make gconfig
If you're running Xwindows, these are prettier, clickable versions of
menuconfig. They tends to work less often than menuconfig since
they are more sensitive to buggy configuration input files than
menuconfig (and because more people use menuconfig). xconfig uses the
qt libraries, and gconfig uses the gtk libraries.
Each of the configuration programs produces these end products:
- A file named .config in the top-level directory containing all your
configuration choices.
- A file named autoconf.h in the include/linux/ directory
defining (or not defining) the CONFIG_*
symbols so that the C preprocessor knows whether or not they are
turned on.
If you have a working .config file for your machine, just copy it into
your kernel source directory and run make oldconfig. You should
double check the configuration with make menuconfig. If you don't
already have a .config file, you can create one by visiting each
submenu and turning on or off the options you need. menuconfig and
xconfig have a "Help" option that shows you the Configure.help entry
for that option, which may help you decide whether or not it should be
turned on. RedHat and other distributions often include sample .config
files with their distribution specific kernel source in a subdirectory
named configs in the top-level source directory. If you are compiling for
PowerPC, you have a variety of default configs to choose from in
arch/ppc/configs. make defconfig will copy the default ppc config
file to .config. If you know another source of default
configuration files, let us know.
Tips for configuring a kernel:
- Always turn on "Prompt for development... drivers".
- From kernel 2.6.8, you can add your own string (such as your
initials) at "Local version - append to kernel release" to personalize your
kernel version string (for older kernel versions, you have to edit the
EXTRAVERSION line in the Makefile).
- Always turn off module versioning, but always turn on kernel module
loader, kernel modules and module unloading.
- In the kernel hacking section, turn on all options except for
"Use 4Kb for kernel stacks instead of 8Kb". If you have a slow machine,
don't turn on "Debug memory allocations" either.
- Turn off features you don't need.
- Only use modules if you have a good reason to use a module. For
example, if you are working on a driver, you'll want to load a new
version of it without rebooting.
- Be extra sure you selected the right processor type. Find out what
processor you have now with cat /proc/cpuinfo.
- Find out what PCI devices you have installed with lspci -v.
- Find out what your current kernel has compiled in with dmesg |
less. Most device drivers print out messages when they detect a
device.
If all else fails, copy a .config file from someone else. The
grrls-only list is a good place to ask.
|