How to Compile your own Kernel in Ubuntu / Debian / Mint

By | 2011/07/15

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. Next, copy an existing kernel configuration:

$ cp /boot/config-YOURCURRENTKERNEL .config

6. Now type:

$ make menuconfig

…and now navigate around to enable other options that you may need. (OPTIONAL)

Press space bar once to enable support as a module . This is generally desired over built-in modules <*> in _most_ cases. If you forget something, you can always go back to this step later and recompile your kernel again.

When you are finished, keep hitting ESC to exit and say ‘Yes’ you want to save.

ncurses_menu

7. Now type

$ fakeroot make-kpkg clean

…then start compiling with:

$ fakeroot make-kpkg --jobs=4 --initrd kernel_image kernel_headers modules_image

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 ]

And now you are done! Reboot into your new kernel.