The Internet is filled with outdated / incorrect / complicated / wrong ways to compile the Linux kernel. It's not difficult to do. I simply cannot account for all the incorrect posts.
Get the kernel source: curl -O http://www.kernel.org/pub/linux/kernel/2.6/linux-<version>.tar.bz2
Will put the kernel source file into the working directory. If you're wondering how one would know what to put for <version>, you go into the kernel archive using a web browser, and you look for the exact <version> you want. If you don't know what version you want, stick with the latest stable version, as listed on this page:
http://kernel.org/
There is a link on that page to the
/pub/linux
directory. When you get to
/pub/linux
click on
kernel
and then
2.6
The kernel source files are
.tar.bz2
OR
.tar.gz.
The other files in the directory are used for verifying the authenticity of the kernel.
** OPTIONAL **
If you wish to verify the kernel source file, download the proper
.sign
file, and get the kernel.org public encryption key here:
http://kernel.org/signature.html
Then install the
gpg
package, and verify the kernel is properly signed.
** END OPTIONAL **
Install the development or lsb package for your distro. Move the kernel source file to:
/usr/src
su
password
mv linux-<version>.tar.bz2 /usr/src
Uncompress the
bz2
archive:
tar jxvf linux-<version>.tar.bz2
The screen will scroll. Remove the:
linux
soft link:
rm linux
Make a new soft link to the new kernel source directory:
ln -s linux-<version> linux
Change directory to linux:
cd linux
Get a config file to start with:
cp /boot/config-`uname -r` .config
Apply and patches:
patch -p 1 < <patch>.diff
Configure the kernel:
make oldconfig
The new kernel will work if you agree with everything the configure program suggests. If you disagree, and change something, it will usually be ok.
make menuconfig
OR
make xconfig
Now, make the changes to the kernel configuration that you desire, and save the
.config
file. Don't worry about ruining the kernel config. If the new kernel doesn't boot, you can boot using the old kernel and repeat the above steps to copy the config file from
/boot/
And configure the kernel again.
Give the kernel a unique name:
nano Makefile
Put something meaningful after
EXTRAVERSION =
AND
NAME =
such as the date, preceded by a hyphen. Name the kernel after an attractive female, using lowercase only. If you need to use numbers in the name of an attractive female ... Ok, Save:
Makefile
Compile the kernel:
make clean
make all
make modules_install
make install
After you do the
make install
step, there is a command line left on the screen, beginning with
sh
You need to:
chmod +x /usr/src/linux-<version>/arch/x86/boot/install.sh
and then type the entire command left by:
make install
and execute it.
Now you should have:
/boot/initrd-<version>
/boot/System.map-<version>
/boot/vmlinuz-<version>
Check
/boot/grub/menu.lst
for a new entry.
nano /boot/grub/menu.lst
Put a
# and a space
in front of
hiddenmenu
and
splashimage
Check for your new entry, which should read
title <something> <version>
root(hdx,y)
kernel /vmlinuz-<version> root=<something>
initrd /initrd-<version>
make
default=0
timeout=5
If the entry for your new kernel is in
/boot/grub/menu.lst
the machine should boot with the new kernel.
The main rule for compiling a new kernel, or a kernel rebuild, is remove unnecessary options, such as unnecessary drivers, from the kernel config. You must know your hardware. But you can reduce the size of the kernel considerably, which is good. Usually a kernel rebuild is due to a patch being applied, requiring recompilation.