The purpose of this post is to concisely list the steps needed to install a newer kernel version in Debian Jessie, and also to compile your own custom kernel. For more detailed documentation, you can refer to the Debian kernel handbook:
http://kernel-handbook.alioth.debian.org/
Upgrading and customizing a kernel isn't something that most people will need to do. If all you need is to compile a new module, simply install the headers for your existing kernel from the Debian repositories. However, it is sometimes necessary to install a newer kernel to provide support for hardware that isn't supported by version 3.16. Reasons to consider customizing the kernel include the removal of unnecessary modules, patching the kernel source for some added functionality, or to tinker and learn about the process of creating Debian kernel packages.
With that said, here a 3 ways to do it outlined below (1) Installing a pre-compiled kernel from Debian backports, (2) Patching and compiling a custom kernel from the Debian backports source files, and (3) Compiling a custom kernel from the official sources at kernel.org.
1. Installing pre-compiled 4.1 kernel using Debian backports.
This is the fastest way to obtain a newer kernel. Simply edit your sources.list file:
Code:
su
nano /etc/apt/sources.list
and add the following to the bottom of the file:
Code:
# jessie backports
deb http://http.debian.net/debian jessie-backports main contrib non-free
Hit ctrl+o, then enter to save the changes, and ctrl+x to exit the nano text editor. Next, run apt-get update as root:
To see what kernels are available:
Code:
apt-cache search linux-image
On my 64-bit computer, the output is:
Code:
root@pinto:~# apt-cache search linux-image
linux-headers-3.16.0-4-amd64 - Header files for Linux 3.16.0-4-amd64
linux-image-3.16.0-4-amd64 - Linux 3.16 for 64-bit PCs
linux-image-3.16.0-4-amd64-dbg - Debugging symbols for Linux 3.16.0-4-amd64
linux-image-amd64 - Linux for 64-bit PCs (meta-package)
linux-image-amd64-dbg - Debugging symbols for Linux amd64 configuration (meta-package)
nvidia-kernel-3.16.0-4-amd64 - NVIDIA binary kernel module for Linux 3.16.0-4-amd64
linux-headers-4.1.0-0.bpo.1-amd64 - Header files for Linux 4.1.0-0.bpo.1-amd64
linux-headers-4.1.0-0.bpo.1-rt-amd64 - Header files for Linux 4.1.0-0.bpo.1-rt-amd64
linux-image-4.1.0-0.bpo.1-amd64 - Linux 4.1 for 64-bit PCs
linux-image-4.1.0-0.bpo.1-amd64-dbg - Debugging symbols for Linux 4.1.0-0.bpo.1-amd64
linux-image-4.1.0-0.bpo.1-rt-amd64 - Linux 4.1 for 64-bit PCs, PREEMPT_RT
linux-image-4.1.0-0.bpo.1-rt-amd64-dbg - Debugging symbols for Linux 4.1.0-0.bpo.1-rt-amd64
linux-image-rt-amd64 - Linux for 64-bit PCs (meta-package), PREEMPT_RT
linux-image-rt-amd64-dbg - Debugging symbols for Linux rt-amd64 configuration (meta-package)
root@pinto:~#
As can be seen above, kernel version 3.16 is available in the Debian stable repositories, and version 4.1 is available from the backports. There are 2 versions of the 4.1 kernel, with and without the realtime (rt) patch. To install the newer kernel from backports:
Code:
aptitude -t jessie-backports install linux-image-4.1.0-0.bpo.1-amd64
You may also want to install headers to allow the compilation of modules for the new kernel:
Code:
aptitude -t jessie-backports install linux-headers-4.1.0-0.bpo.1-amd64
You will see an error message about possible missing firmware for for module r8169 (a realtek chip). That firmware can be installed with:
Code:
aptitude -t jessie-backports install firmware-realtek
You can install other non-free firmware with:
Code:
aptitude -t jessie-backports install firmware-linux
Grub is automatically updated with an entry for the new kernel. At bootup, the Grub menu will allow you to select between the Debian/GNU-Linux default and advanced options. The default is the newer 4.1 kernel, the advanced options allow you to choose between the 4.1 and 3.16 kernels and recovery modes. After rebooting, you can confirm the new kernel is installed by running uname -r. The output of uname -r should be: 4.1.0-0.bpo.1-amd64.
2. Compiling a custom 4.1 kernel from the Debian backports sources
If you need to customize the 4.1 kernel, the kernel sources are available from Debain backports to allow you to compile your own. You can check what sources are available using apt-cache search linux-source (after adding the backports repository as described above):
Code:
root@pinto:~# apt-cache search linux-source
linux-source-3.16 - Linux kernel source for version 3.16 with Debian patches
linux-source - Linux kernel source (meta-package)
linux-source-4.1 - Linux kernel source for version 4.1 with Debian patches
The output above shows the 4.1 kernel source is available with Debian patches applied. To install the 4.1 kernel source:
Code:
aptitude -t jessie-backports install linux-source-4.1
The installed source files can be found in the directory /usr/src. The linux-source-4.1 package created a directory linux-config-4.1 containing configurations for different processor architectures and the files linux-patch-4.1-rt.patch.xz and linux-source-4.1.tar.xz.
Next uncompress the source, rt patch, and symbolically link the source to /usr/src/linux:
Code:
cd /usr/src
tar xf linux-source-4.1.tar.xz
unxz linux-patch-4.1-rt.patch.xz
ln -s linux-source-4.1 linux
I am applying the rt patch to the kernel just as a demonstration. I don't really need a realtime kernel, but I'm applying the realtime patch to illustrate how a patch is applied:
Code:
cd /usr/src/linux
patch -p1 < /usr/src/linux-patch-4.1-rt.patch
A kernel patch is a file typically ending with the .patch extension. A patch modifies the source code and typically only works for a specific version of the source code. If you have a patch written for the 3.16 kernel, it will likely fail if you try and apply it to the 4.1 version of the source. Check for errors after applying the patch command. The above rt patch worked fine since it was written specifically for this kernel source.
The kernel source package comes with a bunch of configurations for different processor architectures in the directory /usr/src/linux-config-4.1/. Since I am applying the rt patch to the amd64 kernel, I'll use the configuration supplied:
Code:
cd /usr/src/linux/linux-config-4.1
unxz config.amd64_rt_amd64.xz
cp config.amd64_rt_amd64 /usr/src/linux/.config
Make sure that you have all the tools needed for compilation:
Code:
aptitude install build-essential
Now, adjust the kernel configuration as needed using make menuconfig. Make sure you have libncurses5-dev installed first:
Code:
aptitude install libncurses5-dev
Code:
cd /usr/src/linux
make menuconfig
You can navigate the menus and make changes following the instructions on the top of the screen. Once you have the configuration as you like it, save it and exit.
Then you can compile the kernel package with:
Code:
cd /usr/src/linux
make clean
make deb-pkg LOCALVERSION=-kernel_name KDEB_PKGVERSION=1
The above command compiles the packages with my local version name -kernel_name appended, and applies a version number 1. You can choose whatever name you like in place of "kernel_name". Be prepared to wait a long time for the packages to compile.
When it is done, the kernel and header deb files can be found in the directory /usr/src/:
linux-image-4.1.3-rt3-kernel_name_1_amd64.deb
linux-image-4.1.3-rt3-kernel_name-dbg_1_amd64.deb
linux-headers-4.1.3-rt3-kernel_name_1_amd64.deb
linux-libc-dev_1_amd64.deb
Install the kernel and headers with:
Code:
dpkg -i linux-image-4.1.3-rt3-kernel_name_1_amd64.deb
dpkg -i linux-headers-4.1.3-rt3-kernel_name_1_amd64.deb
The deb file with dbg contains debugging symbols, and the one with libc-dev contains headers for glibc. I'm not installing either of those. Reboot and grub has been automatically updated with the new kernel as default. You can select older kernels using the advanced option on the grub menu.
3. Compiling a custom 4.2 kernel using the official sources from kernel.org
If Debian backports doesn't have a kernel new enough, you can download the latest version as a tar.xz from kernel.org. Move it to /usr/src and extract it there:
Code:
cd /usr/src
tar xf linux-4.2.tar.xz
remove the old symbolic link to /usr/src/linux if there is one:
Code:
cd /usr/src
rm linux
create a new symbolic link:
Code:
cd /usr/src
ln -s linux-4.2 linux
If you have the 4.1 source from backports installed, You can grab a 4.1 configuration file from the ones supplied from the linux-source-4.1 package:
Code:
cd /usr/src/linux-config-4.1
unxz config.amd64_none_amd64.xz
cp config.amd64_none_amd64 /usr/src/linux/.config
If you don't have linux-source-4.1 installed and don't want to install it, you can grab a configuration file from whatever is the latest version of the kernel you are running:
Code:
cd /usr/src/linux
cp /boot/config-<version> .config
where "config-<version>" is the configuration file for the whatever is the latest kernel version you have installed.
Make sure that you have all the tools needed for compilation:
Code:
aptitude install build-essential
Run make oldconfig to answer questions about configuration options that are new in version 4.2 compared to the earlier version:
Code:
cd /usr/src/linux
make oldconfig
You can just keep hitting the enter key to accept default selections for all of the questions, or choose a different answer. The default option is the one in uppercase.
You can further tweak things if you like using make menuconfig. Make sure you have libncurses5-dev installed first:
Code:
aptitude install libncurses5-dev
Code:
cd /usr/src/linux
make menuconfig
Follow the directions at the top of the screen to navigate menus and make any changes to the configuration that you want. Save and exit, then compile the kernel with:
Code:
make clean
make deb-pkg LOCALVERSION=-kernel_name KDEB_PKGVERSION=1
I added my local version -kernel_name and version number 1. You can pick whatever name you like instead of "kernel_name". The resulting kernel and header deb files will be placed in /usr/src and can be installed with:
Code:
dpkg -i linux-image-4.2.0-kernel_name_1_amd64.deb
dpkg -i linux-headers-4.2.0-kernel_name_1_amd64.deb
When you reboot, the latest 4.2 kernel will be the default in the grub menu. After bootup, uname -r gives: 4.2.0-kernel_name as the output, confirming that you are running the new kernel.
Hope that this is helpful. Post replies or message me if the guide needs improvement. I tested all of this on a fresh install of Debian Jessie with default options, so it should work. I'm submitting this post from the same machine running the 4.2 kernel released yesterday that I compiled as described above.
NOTE: One problem that I ran into is disk space. You will need about 10-15 GB free for compilation of each kernel source that you use. Apparently, the default is to compile with debugging symbols that take up huge space. After you are done, you can free up space with:
Code:
cd /usr/src
rm -rf linux-4.2
rm -rf linux-source-4.1
Enjoy!