Compile a new Kernel under Debian

chrisjrob's picture

Introduction

This is a very brief how to on building a custom kernel for a Debian-based system.  Please do feel free to improve the instructions:

Install build environment

$ sudo apt-get install build-essential

Get kernel source

Visit kernel.org and save appropriate Kernel into your Downloads.  I would tend to use wget for this purpose, but using your browser's downloader will work fine.  

Extract it

$ cd Downloads
$ sudo tar -xvvjf linux-3.3.tar.bz2 -C /usr/src/ (change names appropriately)
$ cd /usr/src/linux-3.3/

Configure

This process will take time, and will require some guess-work.  It will be helpful to retain your existing kernel config, but you will still probably have some questions to answer, taking the defaults is probably sensible, if you do not know better.

Retaining your existing kernel config:

$ make oldconfig
Or creating a new kernel config:
$ make menuconfig

Build

$ sudo make
To speed up the build, add "-j 4" to use 4 cores (or whatever your computer has available - but you will need plenty of RAM to benefit from this).  

Install

$ sudo make modules_install install

To speed up the install, add "-j 4" to use 4 cores (or whatever your computer has available - but you will need plenty of RAM to benefit from this).

Check

$ cd /boot/
Check there are files for this kernel - e.g. System.map-3.3.0, vmlinuz-3.3.0, initrd.img-3.3.0, config-3.3.0   If not then:
$ sudo update-initramfs -u -k 3.3.0 (or whatever)
OR
$ sudo update-initramfs -c -k 3.3.0 (or whatever)

Update grub

Check grub.cfg has the new kernel listed:
$ sudo update-grub

Restart and check kernel

Restart system in the usual way, then check running kernel:
$ uname -r

Further reading