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 has been tested with Linux 3.12 on Ubuntu 13.10 and Linux 3.18 on Ubuntu 14.04. It also works with older kernels; e.g. it is possible to install a 2.6.39 kernel on Ubuntu 14.04, which is quite handy when developing kernel modules that need to be compatible with a wide range of kernel versions.
Ensure that you have enough free disk space. Building the kernel using the present procedure may require up to 13 GB (!) of storage.
Install the necessary build tools:
sudo apt-get install kernel-package git libssl-dev bison flex
Download the kernel sources:
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Check out the tag or branch for the kernel version you want to build. For example:
cd linux git checkout v3.12
Copy the configuration of the Ubuntu kernel. For the currently running kernel, use the following command:
cp /boot/config-$(uname -r) .config
Initialize new configuration options to their default values (See here for an explanation):
yes "" | make oldconfig
make-kpkgto compile the kernel and create Debian packages. You may want to use
--append-to-versionto 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 -j $(getconf _NPROCESSORS_ONLN)
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.
make-kpkgmay fail with the following error:
/etc/kernel/postinst.d/apt-auto-removal: 84: /etc/kernel/postinst.d/apt-auto-removal: cannot create /etc/apt/apt.conf.d//01autoremove-kernels.dpkg-new: Permission denied run-parts: /etc/kernel/postinst.d/apt-auto-removal exited with return code 2
This issue is documented in Ubuntu bug 1308183. To work around the problem, install version 13.003 of
kernel-packageas described in that bug report.