                   A Guide To Building Your Own Kernel

*******************************************************************************
                             ***************
Andy Bailey's kernel building guide for Linux newbies. This is release 0.2.  
  This document is intended to be a guide for kernel building for those
                      unfamiliar with the process. 
                [Last revised 11/1/94 tafiatal@uncc.edu]
*******************************************************************************
                             ***************

SECTION 1.0 

Compiling a kernel that is optimized for your system is one of the most
important things one can do to make Linux perform well. Unfortunately,
it's also a rather daunting task for someone who has never compiled
anything, much less the main element of an operating system.
Fortunately, the process developed for compiling your own Linux kernel
is one that is fairly intuitive, and not particularly difficult. 

The kernel is the basic operating system. Its performance and stability
affect, in turn, the performance and stability of your entire system.
The kernel also handles communication with I/O devices of all types,
including the keyboard, the display, I/O ports, and storage devices. 

Using MS-DOS, devices aside from the standard ports and drives use a
piece of code called a driver. In Linux, support for only the most basic
hardware is included by default. Additional support must be included in
the kernel by recompiling. 

Usually, a distribution of Linux (as in the case of Slackware) includes
a unnecessarily large kernel, which includes drivers for a plethora of
hardware devices. This allows users to get the operating system
installed on a variety of configurations. Then, the installation program
will install a kernel, with a relatively small selection of hardware
drivers. This kernel will be used when booting from the hard disk, and
is often the kernel that is placed on the boot diskette that the
installation procedure creates for you. Sometimes, hardware that worked
when performing the installation is no longer recognized! 

SECTION 1.1 

Several things are necessary in order to build your new kernel. You will
need  gcc-2.4.5 or higher installed, in order to compile the source.
Generally, gcc  and make are installed and configured when installing
from an package such as Slackware. 

Another important topic is memory.  A kernel can be successfully
compiled in 4 MB of Ram, but only if a sizable swap file (of around 12 -
16 megs) is present.  Use the "free" command to make sure you have a
swap file enabled.  If you do not have a swap file or partition, see the
manual pages for mkswap and swapon. You would type

man mkswap 

to read the manual pages for mkswap, for example.

SECTION 2.0

The first step is to obtain the source for the new kernel. There are
several  ways in which you can get the kernel source. One is to use the
source for the  kernel that is included on the distribution of Linux you
are using. You can  also find these sources for newer releases of the
kernel at several FTP sites around the world. 

Before you install a new kernel source tree, you may wish to "set aside"
your old source tree, just in case things don't work out.  You
can do this by typing:

cd /usr/src
mv linux old-linux

This will move your old kernel source into /usr/src/old-linux.  Any time
you want to replace whatever new kernel source you've installed with the
original source tree, just type:

mv /usr/src/old-linux /usr/src/linux

Once you have obtained the kernel source, you'll need to extract it from
its archived form.  Generally the command for this will look somewhat
like the following: 

mv linux-1.x.x.tar.gz /usr/src 
tar -xvzf linux-1.x.x.tar.gz 

[ where 'x' represents the kernel revision ] 

This should put the kernel source into the /usr/src/linux directory of
your drive, replacing anything you had there before.

There are several other methods for obtaining new kernel source code;
normally, the source code can be updated without being completely
changed. This is called a patch, and is generally the way some most
incremental-change interim releases come out.  Patches are discussed in
Appendix B at the end of this document. 

SECTION 2.1

At this point, it's time to configure and build your personal kernel. 

The first thing you should do is prepare for emergency.  The kernel
build isn't in any way hazardous to your system, but it is possible to
accidentally erase important files when you are logged in as root.
Backup if you can, and be sure you have a boot floppy with your old
kernel handy.  If you don't have one you can, and should, make one now. 

Put a blank DOS formatted floppy into drive A:  and type:

dd bs=8192 if=/vmlinuz of=/dev/fd0  
rdev -R /dev/fd0 1 

This creates a rescue disk for booting your Linux system in the event of
problems with the new kernel. 

The following command simply puts a copy of the kernel on a DOS
diskette; this is good for keeping a backup copy, but you can't boot
from a disk made this way.

mcopy /vmlinuz a: 

Now that you're ready to go on, cd to directory /usr/src/linux. If your
kernel source installed properly, you're ready to proceed.  "Make" is
the program used to manage the compilation.  Read the man page for make
if you would like more information. 

To decide on which options to include in the kernel type

make config 

Make will begin to run, and you will be presented with a list of
questions about devices which you would like to include in the kernel.
You wont gain any performance by including lots of extra drivers. In
fact, this will make a larger kernel, which takes up more memory.  You
may want to answer yes to any hardware you plan to purchase soon, if you
don't want to recompile again. 

There are a large number of hardware devices supported, and it's
important to include everything you'll need.  If you should accidentally
answer incorrectly, you can stop the make (hit ctrl-c) and start over. 
The options in the configuration change as new kernels are released, so
examine Appendix A for a description and recommendation of which support
you should install. 

Once the config is done, its time to prepare the source to be compiled. 
Type:  

make dep; make clean 

This will set up dependencies, and clean up any outdated object code
that might be in the kernel's subdirectories.  This is especially
important if you have previously compiled a kernel, and have installed a
newer kernel source package over it.  

Now, you can move on to the actual build.  To start the build, type:

cd /usr/src/linux
make zlilo 

This will build the kernel based on your desired configuration, and
install  it into LILO for you.  After the build and install are complete
type: 

rdev -R /vmlinuz 1 

to make your new kernel read-only.  (This will prevent annoying
boot-time error messages ;-)

SECTION 2.2

BOOTING FROM A FLOPPY 

In order to boot the new kernel from a floppy, it needs only to be
copied to  a formatted disk (DOS format is fine) that can be used in the
boot floppy drive  (fd0).  You can do this the same way you installed
your new kernel on your hard drive.  Type:

cd /usr/src/linux
make zdisk
rdev -R /dev/fd0 1 

This disk can now be used to boot your computer into Linux. 
   APPENDIX A:  Descriptions of drivers for config 

Generally, it is ok to accept defaults for support options you aren't 
familiar with, except device drivers.  The configuration script is
designed  with ease of installation in mind.  The following lists some
of the most commonly available options. 

Kernel Options

Kernel Math Emulation 

If your machine does not possess a math coprocessor, you will need to 
include floating point math emulation.  If you do have a math
coprocessor,  this isn't necessary. 

CPUs which nearly always need Kernel Math Emulation: 386SX, 386DX, and 486SX.

Normal Hard Disk Support 

Support for IDE hard drives.  Most PCs are equipped with such drives. 
Include this support. 

XT harddisk support 

Support for MFM/RLL type Hard Drives.  Not necessary, if your system
does not have such a drive.   None of the computers sold today use this
type of drive.

TCP/IP networking 

If you plan to use TCP/IP network sevices, even via loopback, include 
this.  If you are just setting up a machine to run by itself, with no
connections to the outside world, you may omit this.

Limit memory to low 16MB 

Limits addressing of ram in machines with older DMA controllers.   You
shouldn't have to worry about this unless your machine has more than
16MB of RAM.

System V IPC 

System V Interprocess-communication.  Provides support for programs
running concurrently to talk to one another. 

Use -m486 flag for 486-specific optimizations 

Takes advantage of extra features in the 486 cpu. If you have a 486 or
Pentium cpu, include this. Using this option on a 386 won't increase
speed, and will actually make a slightly slower kernel. 


SCSI support 

If your system uses any SCSI devices (hard drive, CD-ROM, tape backup) 
then include this. 

During SCSI configuration, if you choose to include SCSI support, you
will be prompted for general devices (disk, tape, CDROM, etc), and then
controller drivers.  Include support for only those devices which your
system has installed.  SCSI support is too complex to cover here; it may
be necessary to consult the SCSI HOWTO if you are unsure about what scsi
devices you use. 

Network device support 

Include this if you will be connecting to a network, even via modem. 
This section will ask you about the type of network device (Ethernet
card, SLIP via modem, etc.) you use.  Note: SLIP and PPP dialup
connections are categorized as network devices; if you plan to use a
dialup net connection, you must activate support here. 

CDROM drivers

Sony CDU31A CDROM driver support 

Include this if you have a Sony CDU-31A or CDU-33A cd rom drive.  This
drive has a spring-pop-out caddyless drawer, and a rectangular green LED
centered beneath it. 

Mitsumi CDROM driver support 

Include this if you have a Mitsumi CDROM drive.  This is a very common
cd reader.  In some models, the whole drive chassis slides out for cd
insertion.  Later models use a motorized tray type mechanism.

Matsushita/Panasonic CDROM driver support 

Include this if you have a SoundBlaster-type drive. This is the kind of
drive that is usually included with the Creative  Audio multimedia kits.
It has a uniquely shaped faceplate, with a caddyless motorized drawer
which makes it recognizable, but has no external brand markings.


Filesystems

Standard (minix) fs support 

Support for the standard file system. Include this. 

Extended fs support 

Support for the obsolete (first) extended file system. Don't include
this unless you have a partition that uses the old extfs. 

Second extended fs support 

Include this. This is the de facto Linux native file system. 

xiafs filesystem support 

Commonly used on Linux floppies; optional.  Minix works just as well.

msdos fs support 

Include this if you plan to access information from a DOS partition of
your hard drive, or DOS formatted floppies.  It is advisable to include
this; it is very useful.

proc filesystem support 

Include this.  This allows the system to set up a directory of files
which are windows into your system's memory, which allows you to monitor
your machine at the hardware level.

ISO9660 cdrom filesystem support 

Include this if you use a cd-rom drive; this allows Linux to read
standard ISO-9660 CDROMs, which includes most MS-DOS and Mac CDs sold
today. 

OS/2 HPFS filesystem support (read only) 

Include this if you would like to read from an OS/2 HPFS partition. 

System V and Coherent filesystem support 

Include this if you need to access a Coherent or SYS V file system. 

Character devices

Parallel printer support 

Include this if you use a printer connected to your computer's parallel port.

Mouse support

If you have one of the following bus-type mice, include it.  Serial mice
are included by default. 

Logitech busmouse support (Logitech mice using a interface card.)  
PS/2 mouse (Included with late-model Gateway and IBM systems.)
C&T 82C710 mouse port support (as on TI Travelmate.)  
Microsoft busmouse support (MS Mouse using an interface card.)  
ATIXL busmouse support (mouse connected to ATI Graphics card.) 

Selection (cut and paste for virtual consoles) 

Include this if you'd like to be able to use a mouse to manipulate text
on the terminal screen.  Note: having selection active currently
prevents X-Windows from starting up properly.  If you plan to use
X-Windows, you may want to consider leaving this one out.

QIC-02/QIC-117 tape support 

If you have a tape backup drive attached to your floppy drive
controller, you may be able to use it under Linux using the ftape
package.  Enable this option to try it.

Sound card support

Include this if you use a sound card, or a PC speaker sound driver. 

Kernel hacking 

It's not necessary to include this.  This option simply produces kernel
debugging information.

APPENDIX B: Source code patches

Using patches 

It is sometimes possible to obtain a tarred and gzipped pre-patched 
kernel, especially with stable releases (like 1.0.9). If you'd like to
experiment with the development kernel (series 1.1.x), you can upgrade
to a new  version by obtaining a patch, rather than downloading the
entire source  tree.  As of the last revision of this guide, the
following full kernels were available on sunsite.unc.edu:
    1.1.13              1.1.35
    1.1.23              1.1.45
    1.1.29              1.1.52
    1.1.33              1.1.59
Note: 1.1.60 is known to break a number of important things, including
Domain Name service.  If you want the latest kernel, upgrade directly to
1.1.61 or later.

It's possible to update your kernel source to a greater revision,
without replacing all of the source code. This is done with patches. 
Generally, the patch will be one tarred and gzipped file. 

For example, if your current kernel is 1.1.21, and you would like to
upgrade to 1.1.22, simply obtain patch22.gz.  Gunzip it in the /usr/src
directory, and type 

patch -p0 <patch22 

If there are several patchfiles, repeat the step for each patch file
name.  If you would like to patch up to version 1.1.50, obtain patches
23-50, and repeat the process for each one. 

Then follow the regular build process, making certain to 

make dep ; make  clean 

to ensure a proper build. 

APPENDIX C: Where to get the source 

Kernel source is available on most Linux ftp sites. 

sunsite.unc.edu: /pub/Linux/kernel/v1.x  
tsx-11.mit.edu: /pub/linux/kernel/v1.x  
ftp.funet.fi: /pub/OS/Linux/PEOPLE/Linus/v1.x 

Please use the site closest to you.  Not only will your download
complete more quickly, everyone between you and the more-distant sites
will appreciate it as well.  Sunsite is located at UNC Chapel Hill, in
North Carolina, USA.  Tsx-11 is in Cambridge, Massachusetts, at MIT. 
Funet.fi is in Finland; it is an ftp server for the University of
Helsinki, where our man Linus goes to school.

This Guide was originally written by Andy Bailey, and revised on 11/2/94
by Trevor Fiatal, tafiatal@uncc.edu.  Please mail suggestions and/or
comments to: kguide@coetech7-pc.uncc.edu.  The latest revision will
generally be available on sunsite.unc.edu.
