Kernel building 101 - By Randy Loux.
This is a BASIC view of rebuilding the kernel. It
is by no means the gospel. Please read the appropriate documentation
before attempting to modify your system parameters. I take no
responsibility whatsoever for your kernel. If it breaks in half, you
get to keep both halves.
Two ways to rebuild your kernel, install a whole new kernel. (about
6MB download), or patch up. I prefer to install a new one, and thus
won't cover patching up here.
What does the kernel do?
The kernel is the core of the Unix operating system. The kernel is
responsible for managing your system resources and peripheral devices.
It executes commands and instructions that have been passed to it by
the shell.
Where can I get one?
A kernel comes with every distribution of Linux. RedHat does not
install the kernel source by default, so you have to specify it.
Your kernel is located in /usr/src directory, and should be called
'linux'. Most times the kernel is named with the extension of it's
version, 'linux-2.0.30' for example.
Whole kernels and patches are available from many ftp sites around
the world. The best bet is to find one that is up to date, and is
close to you, but gets little traffic.
Populare sites are:
- sunsite.unc.edu
- tsx-11.mit.edu
- ftp.cdrom.com
- ftp.kernel.org
Why does the kernel need rebuilding? Why would you want to do it?
Kernels get rebuilt for a multitude of reasons. If you upgrade a
particular package, you may need to rebuild the kernel to support the
new version to ...
- ... add support for new hardware
- ... remove support for an obsolete piece of hardware, or
software.
What are the basics? What do I do?
- Research
- Make a boot disk.
- If you start playing with your
kernel, and you screw it up, you're severely
inconvenienced if you don't have a boot disk.
- Put a blank floppy in the disk drive and su to
root.
- cd /usr/src/linux/arch/i386/boot
- cat zImage > /dev/fd0
- Take the disk out, label it, and put it in a safe
place.
I got my boot disk, now what?
- Download the new kernel and put it in /usr/src
directory.
- Untar the file with: tar xvfz linux-2.0.X
- Build the config file (in one of the following three ways)
- Method ONE ...
- This is the text way. It's the way I learned. You
cannot stop if you make a mistake, and you cannot back
up. Does not recognize dependancies. You can make
mistakes, and it'll let you.
- Switch users to root. (su - root)
- Type: cd /usr/src/linux
- Type: make config
- Mothed TWO ...
- This is similar to the original installation procedure,
so newbies will find it familiar looking. You can back
up if you make a mistake, it remembers dependancies, so
if you forget something, it'll help you out.
- Switch users to root. (su - root)
- Type: cd /usr/src/linux
- Type: make menuconfig
- Method THREE ...
- This option is for users who are easily distracted by
shiny objects. :-) Has very pretty buttons, and looks
really official. Remembers dependancies, and lets you go
back if you make a mistake. It runs under X, so it can
be slow on older systems. It requires some special
libraries, so it may not work on all systems.
- log in and start X.
- Switch users to root. Type: su - root
- Set your display variable.
Type: DISPLAY=:0.0; export DISPLAY
- Type: cd /usr/src/linux
- Type: make xconfig
The questions. Oh my GOD, the questions!
- At my last count, there were well over 100 parameters to
be set as Y, N, or M to build the Linux kernel. I
cannot cover them all here.
- If you're smart enough to run Linux, you're smart enough
to press the <HELP> option when you don't know how
you should answer a particular question.
- Most of the questions come with a general explanation of
the option, and a suggestion on how you should answer.
- Once you have a good config file made, copy it to a safe
place so you can see how you answered the next time you
need to rebuild.
- Check the Kernel-HOWTO on sunsite for help with some of
the more common problems.
Config file is made, now what?
- Check your /etc/lilo.conf file. Make sure the line
"image = /boot/vmlinuz" says
'vmlinuz' and not vmlinuz-2.0.30, or
whatever kernel you're currently on. If it does, change it.
- Check /boot to make sure 'vmlinuz' is a
symlink to vmlinuz-2.0.30, and System.map is
a symlink to System.map-2.0.30.
- Once you're sure of this, rm the symlinks. This'll make sure
you have everything set up correctly for the new kernel once
it's done.
Consider modules
There are two schools of thought on kernels.
- Monolithic
- Generally for systems that do one specific task, a dedicated
web server, or ftp server. Systems that do one task, all the
time.
- Modular
- Pretty much everyone else. Production boxes, personal boxes,
machines that require flexibility to function under varying
conditions. Modular is faster (albeit arguably), smaller, and
more flexible. It allows you to use programs or options that
are basically incompatible. PPA and LP for example. PPA is a
module that allows you to use your parallel port for
misc. devices such as parallel scanners, or zip drives. LP is
the module that allows you to use your parallel port for
printers. They can't both be used at the same time, so you can
take one out, and put the other in when you need to use
it. (This is now a bad example since a patch has been made to
solve this, but you get the point.)
Time to compile
I strongly suggest you exit the X window system before doing this.
Compiling the kernel code will require most of your system resources,
and you don't want to waste precious memory and processor time on X.
- Log in as root.
- Type: cd /usr/src/linux
- Type: make dep
- This makes sure that all the dependancies are
where they're supposed to be.
- Type: make clean
- This removes old object files and other errata
that old versions of the kernel may leave
behind.
- Type: make zlilo
- This builds the new kernel, and places the
compressed kernel image 'vmlinuz' in the / (root)
directory, and installs the Lilo boot loader to
the master boot record.
- ** It is worth note that there are other options
to 'make zlilo'. You can also use one of the
following options, each of which have their own
advantages.
- Type: make zImage
- This option makes the compressed kernel image and
puts it in the directory:
/usr/src/linux/arch/i386/boot. Use this
option as one way to test your new kernel before
actually installing it. Once it's done, you can
cat it to a floppy, and boot from that floppy, or
edit /etc/lilo.conf and change the boot
image option to: 'image =
/usr/src/linux/arch/i386/boot/vmlinuz'. If
you do the latter, you'll need to re-run lilo
before you reboot the system. (lilo -b
/dev/hd?, where ? is the
letter of your primary drive.)
- Type: make zdisk
- This makes the compressed kernel image, and puts
it on a floppy. (Make sure you have the floppy in
the drive when you start!) This way, you can
boot on the new kernel from floppy before
actually installing it.
What if something goes wrong?
There are many things that can go wrong with a kernel compile.
But fear not! As long as you have followed these instructions (making
a boot disk, and keeping your old kernel code, etc.), you won't harm
your system, or your data in any way.
A good deal of the time, problems arise from having set a config
parameter incorrectly, requiring that you start over with building the
config file.
The best thing to do when a problem arises, is research the
issue.
- Check the Kernel-HOWTO, make sure you followed it correctly.
- Read the FAQ's.
- Read the documentation included with the kernel you downloaded.
- Read the newsgroups. (comp.os.linux.installation, etc.)
- Ask someone! Ask your fellow CLUG members!
The kernel compiled successfully!
If you're using modules (you may, or may not need any), you need to
make them.
- Type: make modules
- Type: make modules install
- That will compile the modules, and leave them in
/usr/src/linux/modules, where they can be accessed to
insert and remove from the kernel at your convienience.
- (for more information on modules, see the
module-howto)
- If you did 'make zlilo' (which I'll assume you did), the
kernel will be left in the / dir.
- Type: cd /boot
- If you haven't already removed the symlinks to your
current kernel & map, do it now.
- Type: rm vmlinuz ; rm System.map
- Type: mv /vmlinuz /boot/vmlinuz-2.0.33 (for example)
- Type: mv /System.map /boot/System.map-2.0.33
- Type: ln -s /boot/System.map-2.0.33 /boot/System.map
- Type: ln -s /boot/vmlinuz /boot/vmlinuz-2.0.33
- Type: lilo -b /dev/hd? (where ? is the letter
of your primary hard disk).
- The new kernel is now in place, restart your computer, and
watch for errors when it starts coming back up. If you miss
something, run 'dmesg|less' after you log in to see the boot
messages.
- Type: sync ; sync ; shutdown -r now
Testing!
- Type: uname -a
- This should return information about your system,
and what kernel you're running, make sure it's
the kernel version you just installed.
- Test your new kernel for no less than one week before
removing your old one.
- Make sure you test all your favorite programs, and even
those that you don't use frequently
A point of note. For Experienced users only!
After you successfully make a kernel, you can copy the .config
file out to a safe place and use it the next time you need to
recompile this kernel. (/root is generally a safe directory.)
All you'll need to do in the future, is edit the .config
file with your editor of choice and change the options
you need. (Once you open the file, it's pretty much self
explanatory)
Once you're done editing the file to taste, put it in
/usr/src/linux, and type: make oldconfig. That'll run
through the config file, set up the dependancy
information, and allow you to start off at 'make dep ;
make clean'. This is a big timesaver when you only
needto make minor changes.
Congratulations!
You're done! Let's see you do that in Windows. (I suppose
you could compile a Linux kernel in Windows with the proper tools, but
why?)
Randy Loux.
ra@choice.net
http://ww4.choice.net/~ra
|