Compiling a Linux Kernel
Updated September 16, 2002
Created May 8, 2001


Autogenerated Site Map
Search this Site!:
Search this site powered by FreeFind

Updated kernel compiling instructions can be found here: kernel.html

(Under Construction!)

It is often difficult to find good instructions to successfully compile a kernel. I have finally tracked down all the steps I feel are necessary to successfully compile a kernel and boot to it. As all other tasks in unix, there is more than one way to compile a kernel - this is the method I use and it seems to work quite well.


Preparing to Compile the Kernel

Make an alternate listing in /etc/lilo.conf.
A good way to make sure you can come back up after creating a new kernel, is to save the old one.

Make a boot disk?
Some people feel comfortable with a boot disk for their current running system. This is not necessary as far as compiling a new kernel is involved, all that is necessary is to make a backup of the kernel in the /boot directory and a few other changes as listed in the above section "making an alternate listing in /etc/lilo.conf."

Note about making a boot disk: If you have an append line in /etc/lilo.conf, this line will not be copied to the boot disk. This is not entirely a bad thing, this only means that if the append line is required, don't expect the boot disk to work without keying in the append line when booting to the floppy. The alternative to this is to copy the mkbootdisk script to the /tmp directory, and alter /tmp/mkbootdisk. You would want to add the append line you need in the /tmp/mkbootdisk in the /etc/lilo.conf section. Also in this section, you would want to copy the existing section so that you have one choice available with no append line as you may need to move a controller, change the amount of memory, etc.


Decide whether you will be configuring an SMP (Symmetric MultiProcessing) kernel or not:

If building an SMP kernel:
cd /boot
rm System.map
rm vmlinuz
rm modules
ln -s System.map-2.2.14-5.0smp System.map
ln -s vmlinuz-2.2.14-5.0smp vmlinuz
ln -s modules-info-2.2.14-5.0smp module-info
cd /usr/src/linux

If building a Non-SMP kernel:
cd /boot Start by configuring /boot
rm System.map
rm vmlinuz
rm modules
Next lets remove the current soft links
ln -s System.map-2.2.14-5.0 System.map
ln -s vmlinuz-2.2.14-5.0 vmlinuz
ln -s modules-info-2.2.14-5.0 module-info
Now lets make new soft links to the real files
cd /usr/src/linux
Now lets make configuration changes in /usr/src/linux

Determine whether you are building a single processor kernel or an SMP kernel. Adjust the soft links in /boot accordingly.
Now lets get into position to build the kernel.
make mrproper first time only
make xconfig (or menuconfig or config) Be sure to store the configuration in a file for later retrieval, if you run mrproper again it will wipe out your default kernel config file. So storing the configuration in a different file will make it a snap to get the configuration back.
vi Makefile If creating an SMP kernel, then find the line at the top that shows "extraversion = -5.0" and add "smp" to the end of the line "extraversion = -5.0smp"
vi /etc/lilo.conf  

Compiling the Kernel

cd /boot Determine whether you are building a single processor kernel or an SMP kernel. Adjust the soft links in /boot accordingly.
rm System.map
ln -s System.map-2.2.14-5.0 System.map
rm vmlinuz
ln -s vmlinuz-2.2.14-5.0 vmlinuz
rm modules
ln -s modules-info-2.2.14-5.0 module-info
This is how to prepare to build a single processor kernel
rm System.map
ln -s System.map-2.2.14-5.0smp System.map
rm vmlinuz
ln -s vmlinuz-2.2.14-5.0smp vmlinuz
rm modules
ln -s modules-info-2.2.14-5.0smp module-info
This is how to prepare to build an SMP (multi-processor) kernel
cd /usr/src/linux Now lets get into position to build the kernel.
make mrproper first time only
make xconfig (or menuconfig or config) Be sure to store the configuration in a file for later retrieval, if you run mrproper again it will wipe out your default kernel config file. So storing the configuration in a different file will make it a snap to get the configuration back.
vi Makefile If creating an SMP kernel, then find the line at the top that shows "extraversion = -5.0" and add "smp" to the end of the line "extraversion = -5.0smp"
vi /etc/lilo.conf  
make clean  
make dep  
make bzImage  
make modules  
make modules_install  
make install  

Once you know you are able to build kernels ok, you can combine the last steps in the following line:
make clean dep bzImage modules modules_install install

You can even throw on a "; shutdown -r now" at the end of the above line to do everything and finish with a reboot (make sure you have a good boot disk or an extra copy of the kernel in your /boot directory in case your new kernel doesn't work):
make clean dep bzImage modules modules_install install; shutdown -r now


Other related utilities:
mkinitrd
mkbootdisk
depmod


Here are some more steps for building an initrd which is useful if you will be booting from a SCSI controller and will be using the driver as a module rather than statically built in:
Check your /etc/conf.modules to make sure there are entries for your SCSI modules

/sbin/mkinitrd -v -f /boot/initrd-2.2.14-5.0.img 2.2.14-5.0
/sbin/lilo -v


Slackware Linux
isn't autodetecting the array controller for customer

insmod cpqarray.o

check /etc/conf.modules for presence of:
alias scsi_hostadapter cpqarray

create a new initrd w/ support for cpqarray.o
/sbin/mkinitrd -v -f /boot/initrd-2.2.12-20.img 2.2.12-20

Check that /etc/lilo.conf is correct:
boot=correct place for LILO
root=correct root partition
image=correct kernel image
initrd=points to correct initrd just created

Here's a sample

boot=/dev/ida/c0d0p1
map=/boot/map
install=/boot/boot.b
prompt
timeout=50
image=/boot/vmlinuz-2.2.5-15
        label=linux
        root=/dev/ida/c0d0p6
        initrd=/boot/initrd-2.2.5-15.img
        read-only

run /sbin/lilo -v

Reboot, system should come up on the new kernel and the initrd (contains module info for cpqarray.o).



Notes from Anthony Platt:

The last screen appears saying the install is complete and to press OK to
reboot. this is where we do our kernel recompile.

so switch to console 2 <ALT F2>

cd to the root directory

cd /

change root to /mnt

chroot /mnt

now change to your /usr/src/linux directory

cd /usr/src/linux

type in

make menuconfig

this starts the menu version of the kernel config options
Anything with a "*" means compile into the kernel
Anything with a "M" means make this as a module

so we choose

code maturity level options
unselect the little *

exit back to the main menu

choose processor type and features

pick your processor type ie choose 586 if you have a pentium
unless you have heaps of memory change the Max memory to 1gig default
if your cpu has a co processor (most pentiums will :-) ) remove math
emulation
leave MTRR selected
leave SMP unselected

exit to main menu

leave loadable modules alone

select general settings
deselect Advanced power managment

exit to main menu

select plug and play
deselect plug and play support

exit to main menu

select block devices
remove Enchanced IDE support (only if you don't have any IDE devices !!!!)
remove Old hard disk MFM RLL support
remove multiple devices drive support <software raid support>
remove XT hard disk support
remove Mylex DAC960 support
remove parallel port IDE device support
select Compaq SMART 2 support 

exit to main menu

networking options can be left alone at this point
SCSI support can be left alone at this point
Network device support can be left alone at this point
Amateur radio support can be left alone at this point

select IrDA subsystem support
deselect support <as i don't think you will have any infared hardware in
your machine >

exit to main menu

ISDN device support can be left alone at this point

select Old CD-ROM support
deselect support for this at present....as it is only for old CDROMS
attached to sound cards etc.

exit to main menu

select character device support
deselect Extended dumb serial support
deselect Non standard serial port support

select mice

deselect all but PS2 mice if you are using a PS2 mouse, else leave all alone

exit to character device menu

Select video for linux
deselect video for Linux support if you don't have any video hardware boards

exit to character device menu

select joystick support
deselect Joystick support <no time to play games>

exit to character device menu

exit to main menu

File systems options can be left alone at this point
Console drivers options can be left alone at this point

Select sound
deselect sound support 

exit to main menu

select Kernel hacking
deselect Magic sys request key

Exit to main menu

press ESC Key

Choose yes to save this new kernel configuration

OK thats the kernel options selected
now we recompile the kernel

type

make dep clean bzImage

yes capital "I" on bzImage

go make a cup of coffee as this will take a while

When it is finished <and no error messages ??>
should say something like
System is 542Kb etc

next make the modules <drivers> type

make modules

have a beer this time <grin> as it will now compile the modules (drivers)
for you.

Finished?? the compile that is not the beer.......

now move the newly made kernel to the boot directory

mv /usr/src/linux/arch/i386/boot/bzImage /boot

change to the /lib/modules directory

cd /lib/modules

have a look whats here

ls

we see a directory called whatever your kernel version is

move the old directory 2.2.XX and rename it something else

ie if your modules directory is called 2.2.14 move it to 2.2.14-old or
something similar

mv 2.2.14 2.2.14-old

change back to our source directory

cd /usr/src/linux

install our newly created modules

make modules_install

this will move all our newly created drivers to /lib/modules/2.2.XX

change to the /lib/modules diectory and you will see we have our old + our
new modules directories here

cd /lib/modules

ls

now we edit the lilo.conf file so we can boot off our newly made kernel

vi /etc/lilo.conf

here is the original lilo.conf file
yours will differ slightly on the kernel versions

ie mine is 2.2.13-7mdk
yours might be 2.2.14 or something similar

================
boot=/dev/ida/c0d0p1
map=/boot/map
install=/boot/boot.b
prompt
timeout=50
image=/boot/vmlinuz-2.2.13-7mdk
    label=linux
    root=/dev/ida/c0d0p4
    initrd=/boot/initrd-2.2.13-7mdk.img
    read-only
===============

change it to this

==================
boot=/dev/ida/c0d0p1
map=/boot/map
install=/boot/boot.b
prompt
timeout=50
image=/boot/bzImage <<

now switch back to the install screen ALT F1

press Enter on the OK button to reboot and hopefully find our compaq server
with linux installed up and running

Then one needs to complete the process of making a boot disk. and a couple of other things that need to be done.


Other resources for compiling your own kernel:

As you can see this same page contains some info on compiling your own kernel (http://www.cpqlinux.com/kernel.html).
The Linux HOWTO also lists a few steps in compiling your own kernel (http://www.compaq.com/products/servers/linux/compaq-howto.html).
Josh's Linux Guide also speaks about how to build your own kernel (http://jgo.local.net/LinuxGuide/linux-kernel.html).

The official documentation can be found at the following sources:

http://linuxdocs.org/HOWTOs/Kernel-HOWTO.html
This document has more references listed in section 11 that points to more documents: http://linuxdocs.org/HOWTOs/Kernel-HOWTO-11.html:
Sound-HOWTO: sound cards and utilities
SCSI-HOWTO: all about SCSI controllers and devices
NET-2-HOWTO: networking
PPP-HOWTO: PPP networking in particular
PCMCIA-HOWTO: about the drivers for your notebook
ELF-HOWTO: ELF: what it is, converting..
Hardware-HOWTO: overview of supported hardware
Module mini-HOWTO: more on kernel modules
Kerneld mini-HOWTO: about kerneld
BogoMips mini-HOWTO: in case you were wondering
Most of the above documents are listed at: http://linuxdocs.org/HOWTOs/HOWTO-INDEX/os.html#OSKERNEL



Notes:
make clean
make mrproper
make oldconfig
make dep
make include/linux/version.h
make bzImage
make modules
make modules_install

Search this Site!:
Search this site powered by FreeFind

Homepage: http://www.cpqlinux.com
Site Map: http://www.cpqlinux.com/sitemap.html