Did You Know?
Donate to TecMint

LFCS - Linux Foundation Certified SysAdmin - Exam Preparation Guide

Kernel 3.12 Released – Install and Compile in Debian Linux

Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators

One of the biggest draws to using Linux is its easy customization and one of the most fun things to customize is the Kernel itself, the heart of the Linux Operating System. Chances are that you will most likely never have to compile your own kernel. The one that ships with your distribution and updates via your package management system is usually good enough, but there are times when it might be necessary to recompile the kernel.

Kernel Compilation in Debian

Kernel Compilation in Debian

Some of these reasons might be special hardware needs, the desire to create a monolithic kernel instead of a modularized one, optimizing the kernel by removing useless drivers, running a development kernel, or simply to learn more about Linux. In this case, we are going to compile a newly released Kernel 3.12, on Debian Wheezy. The newly released Kernel 3.12 has several new features, including some new drivers for the NVIDIA Optimus, and the Radeon Kernel Graphics Driver. It also offers huge improvements to the EXT4 filesystem, and some updates to XFS and Btrfs.

How to Compile and Install Kernel 3.12 in Debian

To get started, we are going to need some packages, namely fakeroot and kernel-package:

# apt-get install fakeroot kernel-package

Now, lets grab a latest source tarball from www.kernel.org or you may use following wget command to download it.

# wget -c https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.12.tar.xz

Now, let’s unpack the archive.

# tar -xvJf linux-3.12.tar.xz

After, extracting, a new kernel source directory will be created.

# cd linux-3.12

Now, we will want to configure the kernel. It is best to start with a configuration that you are currently using and work from there. To do this, we will copy the current configuration from the /boot directory to the current working directory and save it as .config.

# cp /boot/config-`uname –r`.config

To start with the actual configuration, you have one of two options. If you have X11 installed, you can run make xconfig, and have a nice GUI menu to assist you as you configure your Kernel. If you are running in a CLI environment, you can run make menuconfig. You will need the libncurses5-dev package installed to use menuconfig:

# apt-get install libncurses5-dev
# make menuconfig
Kernel Menuconfig

Kernel Menuconfig

As you will see, once you are in the configuration of your choice, that there are a ton of different options available for your Kernel. In fact, there are far too many for the scope of this tutorial. When selecting Kernel options, the best way is by trial and error, and doing plenty of Googling. It is the best way to learn. If you are simply just trying to update your Kernel to the most recent version, you don’t have to change anything and can simply select “Save Configuration”. Since we copied the current kernel’s configuration file to the new kernel’s .config file.

Save Kernel Config

Save Kernel Config

Be mindful that “Kernel module loader” is selected in “Loadable module support”. If it is not, and you are using kernel modules, it can seriously mess things up.

Kernel Modules

Kernel Modules

Once that is straight, it is time to clean the source tree.

# make-kpkg clean
make-kpkg clean

make-kpkg clean

Finally, it’s time to build the kernel package.

# fakeroot make-kpkg --append-to-version "-customkernel" --revision "1" --initrd kernel_image kernel_headers

As you will see above, we have exported a variable called CONCURRENCY_LEVEL. A general rule of thumb with this variable is to set it as the number of cores your computer has + 1. So, if you are using a quad core, you would:


This will greatly speed up your compilation time. The rest of the compilation command is pretty self-explanatory. With fakeroot, we are making kernel packages (make-kpkg), appending a string to name our kernel (“customkernel”), giving it a revision number (“1”) and we are telling make-kpkg to build both an image package and a header package. Once the compilation is finished, and depending on your machine, and number of modules you are compiling, it can take quite a long time, change directories to one back from the Linux source directory, and you should see two new *.deb files – one linux-image file and one linux-headers file:

New Kernel Deb Packages

New Kernel Deb Packages

You can now install these file like you would install any *.deb file with dpkg command.

# dpkg -i linux-image-3.12.0-customkernel_1_i386.deb linux-headers-3.12.0-customkernel_1_i386.deb
Post Installation

Post Installation

The new kernel, since it is a Debian package, will update everything you need, including the bootloader. Once installed, you simply reboot, and select the new kernel from your GRUB/LiLO menu.

New Kernel Selection

New Kernel Selection

Be sure to pay close attention to any error messages during the boot process so you can troubleshoot any issues. If, for whatever reason, your system doesn’t boot, you can always fall back to your last working Kernel and try again. The non-functional Kernel can always be removed with apt command.

# sudo apt-get remove linux-image-(non-working-kernel)
Rob is an avid user of Linux and Open Source Software, with over 15 years experience in the tech geek universe. Aside from experimenting with the many flavors of Linux, he enjoys working with BSDs, Solaris, and OS X. He currently works as an Independent IT Contractor.

Your name can also be listed here. Work as a Paid freelancer/writer at TecMint.
Download Free eBooks
Advanced Bash-Scripting Guide
Linux Bible
A Newbie's Getting Started Guide to Linux
Ubuntu Linux Toolbox: 1000+ Commands

28 Responses

  1. Lars says:

    Could you complite this nice guide with:

    How to compile/ path with the latest stable nvidia driver ?

    That would bee great

  2. Chris says:

    Thanks for the neat guide!
    I think there is a typo in the line “cp /boot/config-`uname -r` .config”.
    Doesn’t that have to be “cp /boot/config-`uname -r`* .config” instead?
    Anyway, many thanks for putting it together and publishing.


  3. Rob Krul says:


    The Nvidia driver itself is not included with the kernel source. You have to get the driver from Nvidia and install it. I’m going to write a how to for this tonight, and it should be published tomorrow or the next day.

    The article was a little unclear with this. It was supposed to read “support for Nvidia Optimus” but I forgot to add “support”. I will let the editor know.

    The new kernel allows you to run the Optimus driver natively, without having to rely on Bumblebee for added functionality. With the new kernel, you have access to things like GPU switching and so forth.

    Sorry if I created any confusion.

  4. André says:


    Thanks for the guide, it’s great, but i have a question.
    I use LMDE with 3.10 kernel and it’s not works perfectly. Sometimes couldn’t boot. So if I compile the 3.12 kernel I should copy the previous config from the /boot or I configure it with the menuconfig?

  5. zlfccnu says:

    I’ve run the make menuconfig but get an error:
    HOSTCC scripts/basic/fixdep
    /bin/sh: 1: scripts/basic/fixdep: Permission denied
    make[1]: *** [scripts/basic/fixdep] error 126
    make: *** [scripts_basic] error 2

    I am running with ‘su’ command and in the /dev/shm directory
    Thanks a lot!

  6. Andrés Reyes Douglas says:

    Thanks, great article.
    My first kernel compilation was on 1999…. (on a RedHat 6.0..a lot on time since that days), but the process and some concepts behind has not changed too much.
    I’m a Debian user since 2001 and currently using a custom (and optimized) kernel 3.11 for an Asus A45VJ.

    thanks again and greetings from Chile.

  7. totaba says:


    I am getting errors when install debs. Any recommendations?

    Error! Bad return status for module build on kernel: 3.12.2-customkernel (i686)

  8. Bill Donnelly says:

    I get the following message.

    root@debian:/home/bill# cd linux-3.12
    root@debian:/home/bill/linux-3.12# cp /boot/config-‘uname -r’*.config
    cp: missing destination file operand after `/boot/config-uname -r*.config’
    Try `cp –help’ for more information.

    Can you help?


  9. Vinder says:

    Great article,
    Easy to follow.

    Rob Krul, You said you would write a how to with the Nvidia driver.
    I cannot seem to find it?

  10. sanjay says:

    i wanted to install libraries using apt-get install command but its showing command not found. could just tell me which software package to be downloaded…

  11. David Nunes says:

    Thanks a million for this guide. Clear, concise, easy to understand. After browsing thorugh “Devian handbooks” and whatnot, I finally managed to compile my custom Kernel after reading this!

  12. Norman_RKN says:

    Thank you for this guide!
    it´s very helpfull and save a lot of nerves ;)
    btw: if you have trouble with error timestamp errorcode 2

    apt-get install bc



  13. Norman_RKN says:

    `/boot/config-uname -r*.config’ is not working
    you have latest working config copy to the sources like this:

    cp /boot/config-3.blabala /your/linux/sources/folder .config

  14. VolMi says:

    I found your guide ~2 months ago and it was the trigger for me to build my first kernel, since it looked so easy. Before, I refrained from trying it simply because I was afraid I could not use apt to manage my homebrew kernel mess. ;-)

    I keep my kernel updated this way ever since, using a simple scriptified version of your guide:

    So, thank you alot!


  15. Gauss says:

    The error with command “# cp /boot/config-`uname –r`.config” is in “-r” part. Delete the “-” before the “r” and write it again. You will see the diference.


  16. sney says:

    make-kpkg has been deprecated for years. Linux includes a debian package target in their stock makefile since 2.6.3x at least. Everything up to that point is fine, but tell your readers to ‘make deb-pkg’ instead. That also makes the concurrency easier since it’s just make, and it takes standard make options like -j.

    for more information: http://kernel-handbook.alioth.debian.org/

  17. firdaus says:

    it work for me,: cp /boot/config-3.2.0-4-amd64 ./.config

  18. Rinaldo says:

    Working fine for me, good post, thx

  19. Jeremy (Philippines) says:

    Its working, i now have linux-3.14 installed in my system. Thanks.

  20. Reis (Brasil) says:

    Thank you! I installed kernel 3.12.18 and is working perfectly. Again, thank you!

  21. Gaurav says:

    please!! describe “cp /boot/config-`uname -r` .config”

Leave a Reply

This work is licensed under a (cc) BY-NC | TecMint uses cookies. By using our services, you comply to use of our cookies. More info: Privacy Policy.
© 2012-2014 All Rights Reserved.