Thursday, December 19, 2013

Building and installing a vanilla Linux kernel on Ubuntu

This post describes a simple procedure to build and install a new Linux kernel on Ubuntu using the official source code from the kernel developers' Git repository. The aim is to produce a kernel that can be used as a drop-in replacement of the kernels shipped by Ubuntu and that neatly fits into the distribution. The procedure was tested with Linux 3.12 on Ubuntu 13.10.

  1. Ensure that you have enough free disk space. Building the kernel using the present procedure may require up to 13 GB (!) of storage.

  2. Install the necessary build tools:

    sudo apt-get install kernel-package git
  3. Download the kernel sources:

    git clone git://
  4. Check out the tag or branch for the kernel version you want to build. For example:

    cd linux
    git checkout v3.12
  5. Copy the configuration of the Ubuntu kernel. For the currently running kernel, use the following command:

    cp /boot/config-$(uname -r) .config
  6. Initialize new configuration options to their default values (See here for an explanation):

    yes "" | make oldconfig
  7. Use make-kpkg to compile the kernel and create Debian packages. You may want to use --append-to-version to add something to the version number, e.g. if you intend to apply patches to the kernel:

    fakeroot make-kpkg --initrd --append-to-version=-patched kernel-image kernel-headers
  8. Go back to the parent directory and install the generated packages using dpkg -i. This should take care of creating the initial ramdisk and configuring the boot loader. You can now reboot your system to load the new kernel.

No comments:

Post a Comment