How to compile a Linux kernel
![]()
First, setup a Debian Linux machine
Load the appropriate kernel "source tree"
fetch a clean kernel source from ftp.kernel.org
from directory /pub/linux/kernel/
copy the kernel tar-ball (i.e., the tar.gz file) to /usr/src
cd /usr/src
tar -zxvf kenerl-source.tar.gz
If you are compiling a LRP kernel, fetch the LRP kernel source from
http://www.ibiblio.org/pub/Linux/distributions/linux-router/dists/2.9.8/kernel/
or
http://www.tux.org/pub/distributions/tinylinux/linux-router/dists/2.9.8/kernel/
file to fetch is 2.2.19-1-LRP.linux.tar.gz
copy 2.2.19-1-LRP.linux.tar.gz to /usr/src
cd /usr/src
tar -zxvf 2.2.19-1-LRP.linux.tar.gz
rename directory 2.2.19-1-LRP.linux to linux ( mv 2.2.19-1-LRP.linux linux )
|
Optional: find and apply various patches
vi
/usr/src/linux/net/ipv4/Makefile Apply
John Hardin's VPN PPTP patch: (you probably want this patch for LRP
kernels) Apply John Hardin's bug fix patch
that fixes kfree_skb() [avoid kernel panic under heavy
masquerade load] |
Load a configuration file
(assuming you found a file called config (Debian) or
(LRP), copy it to /usr/src/linux/ )
(if you are experienced with Linux kernels, you can create your own
config
using
make menuconfig below, skip the load config step)
cd /usr/src/linux
make menuconfig
choose "Load an Alternate Configuration File", name of the file
to load is "config"
Tab to exit. "Do you want to save your new kernel configuration
?"
answer "Yes"
(the new config file is now saved as a "hidden" file
/usr/src/linux/.config
store it in a safe place, it is the most important record of your
kernel
build )
Compile and install the kernel Disclaimer
| Debian method: | non-Debian method: (LRP kernel also uses this method) |
| make dep make-kpkg clean |
make dep clean bzImage |
| make-kpkg
--revision=my.1.0
kernel_image and/or make-kpkg --revision=my.1.0 kernel_headers |
make modules
modules_install result is stored in /lib/modules/2.2.19 or /lib/modules/2.2.19-1-LRP |
| result is a new kernel in Debian packaged format, /usr/src/kernel-image-2.2.19_my.1.0_i386.deb |
new kernel called bzImage at /usr/src/linux/arch/i386/boot/bzImage LRP kernel: rename bzImage to linux. Copy linux to your LRP boot floppy. |
| cd /usr/src dpkg -i kernel-image-2.2.19_my.1.0_i386.deb |
mv bzImage /boot/linux |
| vi /etc/lilo.conf add
a few lines like this ,
lilo (don't forget lilo or it won't boot) |
To compile one kernel module driver
Load the appropriate kernel "source tree"
fetch a kernel source from ftp.kernel.org
,from directory /pub/linux/kernel/
copy the kernel tar ball (i.e., the tar.gz file) to /usr/src
cd /usr/src
tar -zxvf kenerl-source.tar.gz
the "root" of the source directory should be /usr/src/linux
For LRP, fetch the LRP kernel source from
http://www.ibiblio.org/pub/Linux/distributions/linux-router/dists/2.9.8/kernel/
from directory /linux-router/dists/2.9.8/kernel/
file to fetch is 2.2.19-1-LRP.linux.tar.gz
copy 2.2.19-1-LRP.linux.tar.gz to /usr/src
cd /usr/src
tar -zxvf 2.2.19-1-LRP.linux.tar.gz
rename directory 2.2.19-1-LRP.linux to linux ( mv 2.2.19-1-LRP.linux linux )
Load a configuration file
(assuming you found a file called config (Debian) or
(LRP), copy it to /usr/src/linux/ )
(if you are experienced with Linux kernels, you can create your own
config
using
make menuconfig below, skip the load config step)
cd /usr/src/linux
make menuconfig
choose "Load an Alternate Configuration File", name of the file
to load is "config"
Tab to exit. "Do you want to save your new kernel configuration
?"
answer "Yes"
(the new config file is now saved as a "hidden" file
/usr/src/linux/.config
store it in a safe place, it is the most important record of your
kernel
build )
Set dependencies
make dep
Compile one single kernel module:
For example, for scyld drivers, make a directory called
/usr/src/linux/scyld,
copy driver source files (and supporting files) from ftp.scyld.com/pub/network to
/usr/src/linux/scyld
(e.g. 3c59x.c pci-scan.c pci-scan.h
kern_compat.h
)
(For ne2k-pci.c, you also need to copy 8390.h
from /usr/src/linux/drivers/net to
/usr/src/linux/scyld
)
(if you get version.h error message: cd
/usr/src/linux,
make include/linux/version.h )
cd /usr/src/linux/scyld
gcc -D__KERNEL__ -DMODULE
-I/usr/src/linux/include/
-O3 -c 3c59x.c
or
gcc -D__KERNEL__ -DMODULE
-I/usr/src/linux/include/
\
-Wall -Wstrict-prototypes -O3 -c 3c59x.c
or
gcc -D__KERNEL__ -DMODULE
-I/usr/src/linux/include/
\
-Wall -Wstrict-prototypes \
-include/usr/src/linux/include/linux/modversions.h
-DMODVERSIONS -O3 -c 3c59x.c
Short cut:
How to compile one kernel module driver for LRP kernel 2.2.19-1-LRP,
without loading the full kernel source tree.
For Debian Sarge kernel modules, see this page.
Load
the
LRP "kernel headers":
create a directory called /usr/src/linux/include
fetch the LRP kernel headers 2.2.19-1-LRP.header.tar.gz
copy the file 2.2.19-1-LRP.header.tar.gz to /usr/src/linux/include
cd /usr/src/linux/include
tar -zxvf 2.2.19-1-LRP.header.tar.gz
Fix 2 broken links:
cd /usr/include
rm asm
rm linux
ln -s /usr/src/linux/include/asm asm
ln -s /usr/src/linux/include/linux linux
Compile the Scyld drivers
fetched from scyld web site:
create a directory called /usr/src/linux/scyld
copy driver source files (and any support files) from ftp.scyld.com/pub/network to
/usr/src/linux/scyld
(e.g. tulip.c pci-scan.c pci-scan.h
kern_compat.h
)
(For ne2k-pci.c, you also need to copy 8390.h
from /usr/src/linux/drivers/net to
/usr/src/linux/scyld
)
cd /usr/src/linux/scyld
gcc -D__KERNEL__ -DMODULE -I/usr/src/linux/include/
-O3
-c tulip.c
Compile the Intel eepro 100 or pro/100
driver
fetched from Intel driver support web site:
(Note: recent versions of e100 driver from Intel support web site will
refuse
to compile under 2.2 kernel)
create a directory called /usr/src/linux/intel
copy the Intel driver source into some directory, for example,
/usr/src/linux/intel
cd /usr/src/linux/intel
tar zxvf e100-2.1.15
cd e100-2.1.15
cd src
make
© 2001-2004 Nicholas Fong,
Burnaby,
B.C., Canada
Last revision date: January 25, 2004