I just compiled my first kernel and this is what I did. This guide has since been updated following the recommendations by the good people in this thread. Kernel patching and building additional modules are not covered.
The default kernel that comes with Debian is better suited for servers. It's optimized for high thoughput and low interactivity. When you compile your own, you can among other things optimize it for the processor(s) you have. You can also remove any and all unneeded bloat, there's plenty of it to make the default kernel work on maximum number of system configurations out of the box. Compiling your own is fun, profitable and easy.
Basically it's a 4 step process
* Get the source
* Configure it
* Compile it
* Install it
So, here we go, install needed packages
- Code: Select all
sudo apt-get install kernel-package ncurses-dev bzip2 module-init-tools initramfs-tools procps fakeroot
If you plan on using the graphical configuration tools, gconfig or xconfig, you'll need additional packages, respectively libgtk2.0-dev libglib2.0-dev libglade2-dev for gconfig or libqt3-mt-dev for xconfig. There might be other dependencies too and if they're not satisfied you'll be notified once you try to invoke the graphical configurator.
To see what kernel you're now on, input
- Code: Select all
uname -r
Acquire a source, e.g.
- Code: Select all
sudo apt-get install linux-source-2.6.26
Make a user-writeable directory to avoid having to compile as root
- Code: Select all
mkdir ~/kernel_compiling/
Copy the source to that folder
- Code: Select all
cp /usr/src/linux-source-2.6.26.tar.bz2 ~/kernel_compiling/
Goto the directory
- Code: Select all
cd ~/kernel_compiling/
Extract the source
- Code: Select all
tar xjf linux-source-2.6.26.tar.bz2
Enter the extracted directory
- Code: Select all
cd linux-source-2.6.26/
(At this point you would apply any desired patches.)
(You might optionally want to copy a working template for the kernel .config to this directory, you can find some in /boot/.)
(If you're unsure whether you should do it, I recommend you do.)
- Code: Select all
cp /boot/config-$(uname -r) ./.config
To see what kind of a processor you have, input
- Code: Select all
cat /proc/cpuinfo
Configure the kernel options, there's more than one way to skin a cat, pick one, e.g.
- Code: Select all
make config

- Code: Select all
make menuconfig

- Code: Select all
make xconfig

- Code: Select all
make gconfig

I use GNOME so it felt natural for me to choose gconfig. It is pretty clumsy and unintuitive, for example clicking on the actual tick box doesn't do anything, instead you'll have to click on the Y/M/N letter in the very last column... Also, there seem to be undocumented features? Anyway, you can use Ctrl+F to search, Ctrl+G to find next occurrence and Shift+Ctrl+G to find previous occurrence. Quite handy after hitting the expand button. I find xconfig visually uglier but it has a much better search function. (Also activated by Ctrl+F.)
Y means integrated into the kernel and (theoretically) always active
M means built as a module and activated if required
N means not included in any form
One thing you should do is give it a distinctive name, e.g. your initials in general > local version (MUST be lower case), I used the letters 'me' for this example. Start with changing only the obvious things, the ones you're 300% sure of. You will repeat this process many times and will get to know the more esoteric ones... If this is your first time, don't be too bold! Once you're done, save changes and exit.
Clean the slate for kernel compiling
- Code: Select all
make-kpkg clean
If you have a multiprocessor machine, you'll want to make all processors work, do e.g.
- Code: Select all
export CONCURRENCY_LEVEL=2
Perform the actual compile, this will take anywhere from 10 minutes to 5 hours depending on your hardware and configuration choices (the more you selected, the longer it will take). You need to include kernel_headers if you want to compile some other modules against your kernel.
- Code: Select all
make-kpkg --rootcmd fakeroot --initrd --revision=custom.001 kernel_image kernel_headers
It then will give you all kind of chatter, warnings and notices during, it's quite normal. Only errors are serious, as in the process will halt. If you get an error about missing zlib.h, you need to install the zlib1g-dev package.
Once it's done through with no errors, goto the lower directory where the .deb we just created is
- Code: Select all
cd ..
Install the .deb package(s)
- Code: Select all
sudo dpkg -i *.deb
Then it's the moment of truth, the smoke test! Reboot and select from the list the new kernel with your initials or what ever ID you gave it at config time.
If it boots, nice, you made it, congrats!
Checklist
* network
* audio
* usb sticks
* cddvdrwcombo
* any queer peripherals
If not, reboot and select another kernel from the menu. Back to the drawing board...
You'll want to polish the kernel more, go back to the directory you extracted the source into. If everything worked out pretty nicely, make a backup of your .config. If it failed spectacularly, you might want to load a working .config and start working from it again.
Then do some more configuring, and cleanup, recompile... repeat until!

Hints and tips:
* Check out the time command to clock your compiles to see how long it takes.
* You might want to nice your compile, so you can use your computer while it is compiling.
* Try patching your kernel with something latest, e.g. http://tuxonice.net/
* Check out the Linux-Libre project for a blob free kernel. EDIT: No need anymore! (in Debian)

* I use xxdiff to compare different .config files.
* There's some good info available at http://kernelnewbies.org/FAQ