http://www.cyberciti.biz/tips/compiling-linux-kernel-26.html

Exclamation3
After building my first LFS system, I realized the LFS project has great kernel docs
See http://www.linuxfromscratch.org/lfs/view/stable/chapter08/kernel.html
which really points to this great doc http://www.linuxfromscratch.org/hints/downloads/files/kernel-configuration.txt
Note unless in a chroot like in LFS, just use make menuconfig instead of all the LANG stuff

Compile Kernel into .deb package[-][--][++]

  • apt-get install build-essential libncurses5-dev
  • Download and extract kernel to your ~/build
  • cd ~/build/linux-3.x.x
  • make mrproper (just once, the first time, this will erase any .config in there)
  • If you want to convert an old config move it into ~/build/linux-3.x.x/.config and run make oldconfig, usually just press enter on each item it presents to use their default
  • make menuconfig will either create a default .config or use the one you have in your root
  • Setup kernel however you want, exit to save the new .config file
  • make-kpkg clean
  • CONCURRENCY_LEVEL=3 fakeroot make-kpkg --initrd --append-to-version=-amd64-mynewkernel kernel_image kernel_headers this compiles and creates 2 deb packages in ~/build/
  • cd .. then ls should see 2 new debs
  • dpkg -i linux-headers-3.x.x...deb first
  • Then dpkg -i linux-image-3.x.x...deb second
  • Look in /lib/modules/3.x.x should have a build and source symlink that point to /usr/src/linux-3.x.x if not create them
  • A initrd.img should have been created for you in /boot, if you want to rebuild this just run mkinitramfs -o /boot/initrd.img-3.x.x 3.x.x

Compile Kernel[-][--][++]

Install needed compilers

# apt-get install build-essential

Get Your desired kernel version

$ cd /tmp
$ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-x.y.z.tar.bz2
# tar -xjvf linux-2.6.25.tar.bz2 -C /usr/src
# cd /usr/src/linux-2.6.... (the new linux folder)

If you want your current kernels config, you can run # make oldconfig
which should create a .config file in /usr/src/linux2... I believe its the same one as the one in your /boot (current config), but \
double check that. Or else to be sure you can just copy /boot/config-2..., to /usr/src/linux2.../.config

Now look/edit the config either by editing .config or running

$ make menuconfig - Text based color menus, radiolists & dialogues. This option also useful on remote server if you wanna compile kernel remotely.
$ make xconfig - X windows (Qt) based configuration tool, works best under KDE desktop
$ make gconfig - X windows (Gtk) based configuration tool, works best under Gnome Desktop.

I use menuconfig, now save and edit

Compile Kernel (make sure still in /usr/src/linux2... folder)

$ make
$ make modules
$ su - (to become root)
# cd /usr/src/linux2.6...
# make modules_install

Install kernel (installs 3 files to /boot, System.map-xx, config-xx, vmlinux-xx, just kernel stuff, not initramfs yet)

# make install 

Create initramfs (sometimes the command is mkinitrd ...)

# cd /boot
# mkinitramfs -o initrd.img-2.6.xx 2.6.xx (sub your kernel version of course)

Now update your grub menu.lst, you can either edit manually, or just run

# update-grub

which edits menu.lst for you, but you will still need to set menu.lst defaults ...