While most persons typically use the Ubuntu kernel-ppa for obtaining alternate or new kernels, you can also roll your own for a specialized VM, an embedded system, or just to geek out.
This method is a Debian sort of method in that at the very end you are left with .deb packages you can easily install or uninstall. Installing the created deb packages automatically updates your boot loader the same as installing a new kernel from your distribution.
Note: I originally posted this to various Ubuntu wiki pages, if steps look familiar!
1. Install the development tools needed if you have not already:
$ sudo apt-get install build-essential ncurses-base ncurses-dev fakeroot kernel-package
2. Fetch a kernel from http://www.kernel.org, full source.
3. Unpack the kernel sources:
$ tar xvjf linux-[version].tar.bz2
4. Change to that new directory:
$ cd linux-[version]/
5. Now time to make a default kernel configuration.
Here you can either copy an existing .config from an existing distribution kernel or use various provided defconfigs.
Issuing the command:
…creates a .config file as a base for your desired architecture. There are literally hundreds of defconfigs all located in linux-[version]/arch/ARCH/configs/xxx_defconfig
Some examples are below.
For a standard 32bit x86 PC, type: make i386_defconfig
For a standard 64bit x86_64 PC, type: make x86_64_defconfig
For Power G5 machines, type: make g5_defconfig
For Power G3 and G4 Macs, type: make pmac32_defconfig
For the PS3, type: make ps3_defconfig
There is even a wii_defconfig
6. Now type:
$ make menuconfig
…and now navigate around to enable other options that you may need.
(Ex: file system support, network and wireless modules, media and tv modules, any and everything you need!)
Press space bar once to enable support as a module
When you are finished, keep hitting ESC to exit and say ‘Yes’ you want to save.
7. Now type
$ fakeroot make-kpkg clean
…then start compiling with:
$ fakeroot make-kpkg --initrd kernel_image kernel_headers modules_image
This will take a long time to compile, probably at least an hour even on a recent i5/i7 box.
8. When your kernel has finished compiling, just install the debs:
$ cd .. $ sudo dpkg -i [ name of the kernel deb files such as linux-headers-3.*.deb linux-image-3.*.deb ]