When using the latest version of Debian 9 stable, even with all updates installed, by default, you can’t get a very recent kernel via the standard repositories in your package manager. While the idea of using Debian stable is to remain stable and rather conservative, there are several benefits with installing a newer kernel and in some cases it’s the only option to get the OS to support all your hardware. The risk and impact on stability is small and the process is rather simple.
In the meanwhile, I updated the article for the most recent version of Debian: buster/10. You can find this article over here: https://jensd.be/968/linux/install-a-newer-kernel-in-debian-10-buster-stable.
I also created a YouTube video covering the same. Which you can find below. If you prefer to keep reading the blogpost covering Debian 9 (stretch), feel free to continue.
Some of the benefits are:
- Support for previously unsupported hardware: every kernel release has a list of added drivers. Especially when you have recent hardware, a newer kernel could be required to fully support your video card for example.
- Performance improvements and bug fixes: newer kernels often contain a lot of bug fixes, have new functions and performance tweaks. Here again, the most is to gain on newer hardware.
- New kernel options and security fixes
The most recent (stable) kernel that is available at the moment of writing is version 4.12, released 27/07/2017. You can find a complete overview of changes in every kernel version at https://www.kernel.org/ or http://kernelnewbies.org/LinuxVersions
The latest version of the kernel available, at the time of writing, via the standard repositories for Debian 9 is/was. As you can see this kernel is quite recent but Stretch has just been released:
jensd@deb:~$ cat /etc/debian_version 9.1 jensd@deb:~$ uname -r 4.9.0-3-amd64
There are basically two options to install a newer kernel in Debian stretch. The first is the easiest and this is what I will explain in this post. The second is not so easy. It is simply to compile a newer kernel yourself. While compiling a kernel nowadays isn’t rocket science anymore, the first way is still preferable and will save you a lot of time because others have been through the second method and present you the result of their work :)
Installing a newer kernel in Debian Stretch
The easiest way to install a newer kernel in Debian, is to install it from the backports. Backports are packages taken from the next Debian release (called “testing”), adjusted and recompiled for usage on the stable release. For this post, I’m starting with a minimal install (system tools only), the only packages I added after finishing the installation were sudo and aptitude.
In order to install a kernel from the backports, we need to add the backports-repository for our Debian version to the apt-sources and update the list of available packages:
jensd@deb:~$ echo "deb http://ftp.debian.org/debian stretch-backports main" | sudo tee -a /etc/apt/sources.list > /dev/null jensd@deb:~$ sudo apt-get update ... Reading package lists... Done
Now, you can browse the available kernels in the backports-rpository by adding -t wheezy-backports to your apt commands.:
jensd@deb:~$ aptitude search linux-image p linux-image-4.11.0-0.bpo.1-amd64 - Linux 4.11 for 64-bit PCs p linux-image-4.11.0-0.bpo.1-amd64-dbg - Debug symbols for linux-image-4.11.0-0.bpo.1-amd64 p linux-image-4.11.0-0.bpo.1-rt-amd64 - Linux 4.11 for 64-bit PCs, PREEMPT_RT p linux-image-4.11.0-0.bpo.1-rt-amd64-dbg - Debug symbols for linux-image-4.11.0-0.bpo.1-rt-amd64 i A linux-image-4.9.0-3-amd64 - Linux 4.9 for 64-bit PCs p linux-image-4.9.0-3-amd64-dbg - Debug symbols for linux-image-4.9.0-3-amd64 p linux-image-4.9.0-3-rt-amd64 - Linux 4.9 for 64-bit PCs, PREEMPT_RT p linux-image-4.9.0-3-rt-amd64-dbg - Debug symbols for linux-image-4.9.0-3-rt-amd64 i linux-image-amd64 - Linux for 64-bit PCs (meta-package) p linux-image-amd64-dbg - Debugging symbols for Linux amd64 configuration (meta-package) p linux-image-rt-amd64 - Linux for 64-bit PCs (meta-package), PREEMPT_RT p linux-image-rt-amd64-dbg - Debugging symbols for Linux rt-amd64 configuration (meta-package)
Before installing a newer kernel, it’s important that we upgrade installed packages to their newer versions in the backports-repo in order to be sure that dependencies will remain unbroken.
jensd@deb:~$ sudo apt-get -t stretch-backports upgrade
After the upgrade, choose a kernel from the list and install it with apt. Most of the installations would want the kernel without suffix. The rt-suffix stands for realtime and is mostly interesting for embedded projects or machines that will drive industrial hardware. dbg stands for debugging.
jensd@deb:~$ sudo apt-get -t stretch-backports install linux-image-4.11.0-0.bpo.1-amd64 Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: firmware-linux-free irqbalance libglib2.0-0 libglib2.0-data libnuma1 shared-mime-info xdg-user-dirs Suggested packages: linux-doc-4.11 debian-kernel-handbook The following NEW packages will be installed: firmware-linux-free irqbalance libglib2.0-0 libglib2.0-data libnuma1 linux-image-4.11.0-0.bpo.1-amd64 shared-mime-info xdg-user-dirs 0 upgraded, 8 newly installed, 0 to remove and 2 not upgraded. Need to get 45.4 MB of archives. After this operation, 211 MB of additional disk space will be used. Do you want to continue? [Y/n] y ... rocessing triggers for initramfs-tools (0.130) ... update-initramfs: Generating /boot/initrd.img-4.11.0-0.bpo.1-amd64 Processing triggers for systemd (232-25+deb9u1) ...
After the installation, reboot your system and select the newly installed kernel from the selection displayed in GRUB. Debian selects the new kernel by default.’
To verify that the new kernel is used after booting:
jensd@deb:~$ uname -r 4.11.0-0.bpo.1-amd64
Uninstalling unused kernels in Debian
When everything works as expected, you can safely uninstall the older kernel in order to clean up your system and to free up some space in /boot
To check which kernels are currently installed:
ensd@deb:~$ dpkg --get-selections|grep linux-image linux-image-4.11.0-0.bpo.1-amd64 install linux-image-4.9.0-3-amd64 install linux-image-amd64 install
Uninstall the old one:
jensd@deb:~$ sudo apt-get remove linux-image-4.9.0-3-amd64 Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: linux-image-4.9.0-3-amd64 linux-image-amd64 0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded. After this operation, 190 MB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 31737 files and directories currently installed.) Removing linux-image-amd64 (4.9+80+deb9u1) ... Removing linux-image-4.9.0-3-amd64 (4.9.30-2+deb9u2) ... I: /vmlinuz.old is now a symlink to boot/vmlinuz-4.11.0-0.bpo.1-amd64 I: /initrd.img.old is now a symlink to boot/initrd.img-4.11.0-0.bpo.1-amd64 /etc/kernel/postrm.d/initramfs-tools: update-initramfs: Deleting /boot/initrd.img-4.9.0-3-amd64 /etc/kernel/postrm.d/zz-update-grub: Generating grub configuration file ... Found linux image: /boot/vmlinuz-4.11.0-0.bpo.1-amd64 Found initrd image: /boot/initrd.img-4.11.0-0.bpo.1-amd64 done
That should be all it takes in order to install a recent kernel and cleanup older kernels on a Debian system. Not so difficult as you thought probably :)
Thanks for this guide. Nicely written and easy to understand. Haven’t tried it yet, however. I do have one question. What does installing all of these “backports” do to the upgrade process when Debian V10 comes out. I have read lots of “info” online, none of which makes much sense to me. Some say do nothing. Some say they all have to be uninstalled prior to a release upgrade. …
Can you give us some guidance here?
Backports are packages taken from the next Debian release (called “testing”), adjusted and recompiled for usage on Debian stable. Because the package is also present in the next Debian release, you can easily upgrade your stable+backports system once the next Debian release comes out. (In a few cases, usually for security updates, backports are also created from the Debian unstable distribution.)
dude,what a great guide!!!!!!!
this tips do work for kali-linux as well :=)
i did just test the Uninstalling unused kernels part inside 2017.2 x64
My problem is the other way around. When I upgraded I got boot issues (can’t boot basically with the new kernel). Could I uninstall the newer kernel and default to the previous one via the process you described here or is there a way to find the issue and fix it?
You don’t need to install kernel headers?
Great and very easy to follow. I wish Debian could advice their user in a similar way. Not everyone using Debian want to compile kernels.
nice writeup. installed 4.14 with no problem.
question: what does this do to the apt-get update/upgrade process going forward. do we always have to specify the stretch-backports in the upgrade command? if yes, what bad happens if we forget?
Thank you for the excellent article written with new Debian users in mind, such as myself (a student). Linux is excellent and the Linux community such “http://jensd.be/” is awesome!!!
“..Now, you can browse the available kernels in the backports-rpository by adding -t wheezy-backports to your apt commands.:…”
i take it you meant “…stretch-backports…”
Thank you for nice tutorial. I installed the
Linux nb-vortex 4.16.0-0.bpo.2-amd64 #1 SMP Debian 4.16.16-2~bpo9+1 (2018-06-26) x86_64 GNU/Linux.
…but how to select the newly installed kernel from the selection displayed in GRUB when you work on vps ? When i do reboot on vps and connection is closed, i cannot select grub.
I do this way.
# Uninstall the old one:
sudo apt-get purge -y $CURRENT_KERNEL
Excellent! Thank you very much.
Do you think you can do the same good work and explain how we can create an iso installer image with debian stretch but with kernel 4.12?
PS: i personally need it since kernel 4.12 adds support for a specific backplane and other option I do not have to install it.
use the synaptic package manager. to install new kernal release from backports.
search for linux-image-amd64 the go to package menu, and force package option, select backports addition
Thank’ s for thi how to, but when i reboot the grub don’t display the newest kernel?
Thank you very much!
I was in throuble wifi mi wi-fi network and with this upgrade in the kernel everything works like a charm! Have a nice sunday!
Excellent, clear tutorial. I installed 4.18.0-0.bpo.1-amd64 on my Linux Mint Debian Edition (LMDE 3 “Cindy”). Using it to send this, but haven’t tried it extensively yet. Thanks very much.
A newer kernel also means lots of potential security problems – that is a very important thing you should inform your readers about.
If you do not understand the details, do not follow blindly!
Thanks for this tutorial, can we do the same thing for a virtual machine running on openstask, I tried that but after a reboot the kernel still the same even if I have the newest one available when I do dpkg –get-selections|grep linux-image
Pingback: Upgrading the linux-image in Debian stretch – Vargolino
nice tutorial. from indonesia with love
I don’t know about all this… the simplest way I’ve found to install the latest kernel is to add the backports repository then simply run,
sudo apt-get update && sudo apt-get install -t stretch-backports linux-image-amd64 linux-headers-amd64
thats it. Doing it the way in this guide is typically not recommended as it will upgrade every software on the system that is newer in the backports repository. Backports is meant to be used “as needed” not an overall upgrade to the system. For that it is advised to move to a new branch like testing or unstable.
What is up with all the funny business in the first command, using tee? Why not echo the line directly into sources.list?
I did this
And now my rpi zero doesn’t connect to wifi?
How to sort this out?
wpa_supplicant.config file is present in my SD card (I verified)
Pingback: Debian Stretch升级当前最新稳定版内核 – 前端开发，JQUERY特效，全栈开发，vue开发
how to new user debian study the kernel and linux? did you have any suggestion?