[Courses][Linux comands] customizing a 2.4 kernel
Carla Schroder
carla at bratgrrl.com
Wed Mar 24 18:46:43 EST 2004
I've been in a kernel building frenzy, so this week's course will be a
kernel-building howto. I'm on a mission, 'cause there's a lot of
misinformation out there masquerading as howtos. Thanks to the gang on
Techtalk for helping me over the bumpy parts.
You probably want to use kernel sources supplied by your distribution,
especially on distros like Red Hat, SuSE, and Mandrake, that ship heavily
modified kernels. Pristine kernels can be downloaded from kernel.org. Every
distribution has its own particular kernel building tools, and you can also
get nice pre-fab kernels to play with. As we are True Geeks, and scorn wussy
pre-fab kernels, we will customize our kernels all to heck.
This lesson focuses on customizing your stock kernel, and removing all the
unnecessary baggage. You can easily add things as well. Here's the steps:
Make hard copies of the outputs of dmesg, lscpi, /proc/cpuinfo, and lsusb.
This contains all of your hardware information.
Download and unpack new kernel sources into a folder in your home directory,
such as ~/src. CD to this directory.
Edit the new kernel makefile (~/src/linux-2.4.25/Makefile), giving a custom
value to EXTRAVERSION, such as EXTRAVERSION = -new-kernel. This gives your
new kernel a unique name (2.4.25-new-kernel), so you can easily identify it.
Then, download and unpack your shiny new sources into your home directory. I
like to use ~/src. No, do not use /usr/src/linux. That is bad and wrong. See
the README in your toplevel sources directory. Also read
Documentation/Changes, this tells gcc and other program versions you'll need.
There are tons of docs in the source tree, read them.
CD to your top-level sources directory, for example ~/src/linux-2.4.25.
Everything will be done from here.
$ make mrproper
$ make menuconfig
$ make dep
$ make bzImage
$ make modules
$ su
# make modules_install
# cp ~/src/arch/i386/boot/bzImage /boot/bzImage-2.4.25-new-kernel
# cp ~/src/System.map /boot/System.map-2.4.25-new-kernel
# ln -s /boot/System.map-2.4.25-new-kernel /boot/System.map
$ make clean
README says to use gcc 2.95.3. You can have multiple versions of gcc
installed. Select the one you want to use with
$ make bzImage CC=gcc-2.95.3
'make mrproper' cleans the build tree, removing configuration files,
dependency information, and object files. It is good to do this even with
freshly downloaded sources. Mr. Proper, according to popular lore, is the
European version of Mr. Clean, for those occasions when you need to make
something cleaner than clean. In this case, mrproper cleans the build tree
more thoroughly than make clean, which removes object files, but does not
touch configuration or dependency files.
'make menuconfig' is the most time-consuming, and most important part.
menuconfig contains abundant help for every item, read the help. You can
eliminate a lot of useless driver modules, ISDN support, PCMCIA/Cardbus,
which are unnecessary on a desktop machine, and fine-tune what you want
compiled statically, and what you want as loadable modules.
'make bzImage' compiles the new kernel. This can take up to an hour, depending
on the speed of your PC, and how complex your new kernel is.
'make modules' compiles all of the necessary modules.
'make modules_install' is the first operation that requires superuser
privileges. This installs your new modules in /lib/modules/2.4.25.
'cp ~/src/arch/i386/boot/bzImage /boot/bzImage-2.4.25-new-kernel' copies your
nice new kernel image to the /boot directory, and renames it. It is
important, when installing multiple kernels, to make sure each one has a
unique name. And to use the exact kernel name in your bootloader.
'cp ~/src/System.map System.map-2.4.25-new-kernel' copies the new System.map
to /boot.
'ln -s /boot/System.map-2.4.25-new-kernel /boot/System.map' creates a soft
link. It may be necessary to use ln -fs, to force overwriting of the existing
link. Be very careful of your typing here! A typo may render your system
unbootable.
'make clean' tidies up the build tree, sweeping away around 10 megabytes of
binary object files you don't need anymore.
Edit your bootloaders so they know about the new kernel, using the appropriate
values for your system:
GRUB sample config:
title Kernel 2.4.25, new kernel
root (hd0,5)
kernel /boot/bzImage-2.4.25-newkernel root=/dev/hda6 ro
savedefault
boot
LILO looks like this:
image=/boot/bzImage-2.4.25-newkernel
label=Kernel 2.4.25 new kernel
root=/dev/hda6
read-only
And remember to re-run LILO:
$ /sbin/lilo
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Carla Schroder
this message brought to you
by Libranet 2.8 and Kmail
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More information about the Courses
mailing list