How to Build and Install Linux Kernel
This text is a modified version of text by Jason Nieh at Columbia University.
This document will
tell you the steps you need to take to build and install linux kernel.
On each step, you will be told what command
to use. And then some explanation about what these commands actually do
will be given. At the end of this document, there are some useful links
on which this document is based.
1. log in as root or su to root
In a Linux system, each user is given an account that includes a user name
and home directory. In addition, there are special, system defined
accounts which have special privileges. The most important of these is
the root account, which is used by the system administrator (or known as
Super User). There are no restrictions on root. He or she can read,
modify, or delete any file on the system, change permissions and ownerships
on any file, and run special programs like those which partition a hard
drive or create file systems. The basic idea is that a person who cares
for the system logs in as root to perform tasks that cannot be executed
as a normal user. Because root can do anything, it is easy to make
mistakes that have catastrophic consequences. So you should take
care if you log in as root.
You will need to work as root to rebuild and install linux kernel. (Just
think if the normal user can modify the kernel, what'll happen?)
To do this, you can either log in as a root, or you can just execute the
command su - at the command window you opened.
2. Clean up the stale files
cd /usr/src/linux
make mrproper
By default, all the
linux kernel source code is installed under the directory /usr/src/linux.
(You can get the latest version of linux kernel from http://metalab.unc.edu/pub/linux/kernel/.
) There may have a lot of stale files remain in the whole source tree (because
of your previous builds or some other reason). But is important
to begin a kernel build with the source tree in a known condition because
no one knows actually how these stale files will affect your current build
. The command "make mrproper" will do it for you. It
will remove any configuration files along with the remains of any previous
builds that may be scattered around the source tree.
3. Configuring the kernel
The kernel , as the core of an operating system , handles the basic functions
of the operating system: memory allocation, process allocation, device
input and output, etc. Linux is a monolithic kernel; that is, it
is one, single, large program where all the functional components of the
kernel have access to all of its internal data structures and routines.
There are a lot of functional components can be configured, that is , you
can choose whether include it in the kernel or not. For example,
if you don't have a sound card installed on your machine, you won't need
to include any sound card driver in your kernel. ( I will describe briefly
what are these components that you can configure in the next section. )
The number
of the components you need to config is quite large. To get a small
kernel (thus occupy less computer resource) and to make the kernel compiling
process take less time, you may want to say "N" to as much components as
possible. But there will be a lot of components that you may have
no idea of them, thus you don't know whether it's necessary or not. That
is, it will be safe to say "N" to the components that are marked "not set"
in this configuration file. You can say "N" to more components if
you are sure of what you are doing.
make config --
an interactive text program, is the command to make the configuration.
Components are presented and you answer with Y (yes), N (no), or M (module).
Say "Y" if you want to include the component in the kernel, say "N" if
you don't want. "M" means module. Linux modules are lumps
of code that can be dynamically linked into the kernel at any point after
the system has booted. They can be unlinked from the kernel and removed
when they are no longer needed. Mostly Linux kernel modules are device
drivers, pseudo-device drivers such as network drivers, or file-systems.
You can
also type "?" to get a brief description of the configuration parameter.
That information is likely to be the most up-to-date.
Here I will provide
a brief description of the components that you will need to config on the
configuration step. /usr/src/linux/Documentation/Configure.help is
the place that you can find the detailed information about each parameters
of the configuration file.
-
Processor type and features
If you are building a Linux/Intel kernel on (or for) a machine that uses
a ``clone'' processor (for example, one made by Cyrix or AMD), it is recommended
to choose a Processor type of 386. Processors like 386 486SX doesn't
have a math coprocessor, but for any halfway modern machine it's
safe to say no to the Math emulation option.
-
Block devices , SCSI support , Character Devices, Mice
At least you
will need to include the options that support the hard disks in your PC.
We don't have SCSI drivers here, so you can say no to SCSI options.
You will
then be asked about the ``old disk-only'' and ``new IDE'' drivers. You
want to choose one of them; the main difference is that the old driver
only supports two disks on a single interface, and the new one supports
a secondary interface and IDE/ATAPI cdrom drives. The new driver is 4k
larger than the old one and is also supposedly ``improved,'' meaning that
aside from containing a different number of bugs, it might improve your
disk performance, especially if you have newer (EIDE-type) hardware.
-
Network Options, Network Device
You do not have to support Networking in your linux kernel. Since
the detailed configuration of network options need a good understanding
of networking, if you want to try and support Networking, just keep everything
as default.
-
Filesystems / Partition Types
The configure script will ask if you wish to support a list of filesytems
like minux filesytem, FAT, FAT32, NTFS, ISO9660 (for CD-ROM), ext2
, NFS, coda and others. You will need to say "Y" to EXT2 filesytem,
since it is the filesytem that linux used. You will also need
the support for /proc . It's not an actual filesystem on a disk;
this is a filesystem interface to the kernel and processes. Many process
listers (such as `ps') use it. And many important linux tools depend on
it. For other filesystems, I think you can say NO since it's
won't be used here.
-
Amateur Radio , IrDA subsystem, ISDN, Video , Joystick,
sound support
We don't need these functions here. It's safe to say no to all these things.
4. set up all the file dependencies
make dep
This insures that all of the dependencies (what files to be compiled for
each component you selected), such the include files, are in place.
5. COMPILING the kernel:
make bzImage do a "make bzImage" to create a compressed kernel image.
This step will usually takes a little more than 20 minutes.
If you
selected loadable module support and configured any of the parts of the
kernel as `modules', you will have to do "make modules" followed by "make
modules_install", otherwise continue to step 6.
make modules Depending on your configuration.,
the time needed for this step will be from several minutes to 1 hour .
make modules_install
6. Add the new Kernel to LILO
LILO (the LInux
LOader) is the most commonly used method to boot Red Hat Linux on Intel-based
systems. It is a separate boot loader which resides on your hard disk.
It is executed when the system boots from the hard drive and can automatically
boot Linux from a kernel image stored there. It can also be used as a first-stage
boot loader for several operating systems, which allows you to select the
operating system you to boot, like Linux or Windows. With LILO, the default
operating system is booted unless you press Shift during the boot-up sequence,
or if the prompt directive is given in the lilo.conf file. In either case,
you will be provided with a boot prompt, where you type the name of the
operating system to boot (such as ``linux'' or ``windows''). If you press
Tab at the boot prompt, a list of operating systems that the system knows
about will be provided.
The easy way to install
LILO is to edit the configuration file, /etc/lilo.conf. The command rewrites
the modified lilo.conf configuration to the boot sector of the hard disk,
and must be run every time you modify lilo.conf.
You would need to
modify /etc/lilo.conf and then execute "lilo" to add the new kernel image
you just built to the system. Thus you can choose to boot from your new
kernel the next time the system rebooted. Since the kernel you just
built is not tested, in other words it may can't work well or just can't
be booted, it's highly recommended that you make a backup of the original
kernel and also include this kernel in the lilo. With this, you can always
boot up from the original kernel if there is anything wrong with your new
kernel.
To add your new
kernel to LILO, you'll need to copy the kernel image (found in /usr/src/linux/arch/i386/boot/bzImage
after compilation) to the place where your regular bootable kernel is found
(it's /boot/ in our system).
cp
/usr/src/linux/arch/i386/boot/bzImage /boot/vmlinuz.new
(give the kernel image a new name)
Then you
will need to edit the lilo.conf file
vi /etc/lilo.conf
insert
4 lines to /etc/lilo.conf
image = /vmlinuz.test
label = linuxtest
root = /dev/hda5
read-only
Thus it will
be like this after the edition:
boot=/dev/hda
map=/boot/map
install=/boot/boot.b
prompt
timeout=50
image=/boot/vmlinz.test
label=linuxtest
root=/dev/hda5
read-only
image=/boot/vmlinz-2.2.5.15
label=linux
root=/dev/hda5
read-only
Save the
file and return to the command window, then run lilo
to add your
new kernel to LILO.
After
reinstalling LILO, you should be all set. Shutdown the system, reboot
(shutdown -r now ), and enjoy!
Reference
The Linux
Kernel HOWTO
Building
a Custom Kernel
Linux
Kernel README file (This is the same file as /usr/src/linux/README)
Linux
documentation on hardware configuration (The same as /usr/src/linux/Documentation/Configure.help)