Why? , A lot of people ask this question and its a good question to ask. There are many reasons to compile your own kernel , but the most common are
To learn about linux kernels
Speed up boot times by removing uneeded modules
To have the newest kernel
However if all you were wanting to do was remove a specific module , in my opinion it is a waste of time as the module could just as easy be blacklisted.
Don’t be afraid of compiling linux kernels remember to keep previous working kernels just in case , I personally keep 3 kernel versions , the generic , the the last known working kernel and the current.
To start off you will need to install build-essential, fakeroot, kernel-package and the latest stable kernel from http://kernel.org/
Once that is downloaded unpack it to /usr/src/$kernel_version also you will need to allow group ‘root’ or another group read/write access to /usr/src and /usr/src/$kernel_version (or any other group you wish to use).
Open the terminal in /usr/src/$kernel_version and run
It has come to my attention that there is some confusion about unpacking to /usr/src/$kernel_version. To explain lets say the version you have downloaded is the latest stable (as of 09/11/13) is linux-3.12.tar.xz , copy that to /usr/src then extract it with tar xJf linux-3.12.tar.xz Then /usr/src/$kernel_version would refer to /usr/src/linux-3.12.
make menuconfig – standard config can be run outside of X
make xconfig – can be run in X
make localmodconfig – looks at the loaded modules and disables whats not load
Please note whilst localmodconfig can be a good idea , it is possible to lose support for hardware where the module isn’t loaded , so I would recommend using one of the other two listed to make sure an important module isn’t missing and be careful other options, not related to a specific hardware, should be left at the default value if you do not understand them.
The next step is to clean the source tree , this is done with make-kpkg clean
To compile the kernel run fakeroot make-kpkg -j4 –initrd –revision=1.1 kernel_image kernel_headers
** the -j4 is the number of jobs that are run at once, i make this value twice the number of cpu’s
This will create two .debs in /usr/src , that can be installed with sudo dpkg -i *.deb
Also note that whilst you don’t need to create the kernel headers it maybe required for certain drivers i.e nvidia.