I have a software package running on Ubuntu 20.04.4 that requires a version 5.4 kernel. The kernel I've been running was 5.13. I figured out how to install a version 5.4.0-107, which was the latest at the time I'm writing this question. However, I want my system to remain on the 5.4 kernel, and still get whatever updates Canonical provides for 5.4. How do I "pin" a general kernel version and still get security updates?
-
1You can have both GA (5.4) & HWE (currently 5.13) kernels installed on a system using default & documented procedures. Some closed-source kernel modules (ie. nvidia video drivers) can prevent this, but why didn't you just use the commands on the Ubuntu wiki to have both GA & HWE stacks installed - https://wiki.ubuntu.com/Kernel/LTSEnablementStack (this is not new, and has been available as per prior LTS releases) – guiverc Apr 18 '22 at 17:08
-
@guiverc I have added a link to the wiki in my answer and made edits based on it. Thanks. – user68186 Apr 18 '22 at 18:48
1 Answers
Warning
This answer is specific to Ubuntu version 20.04 LTS (and later). This approach will only work on LTS versions of Ubuntu that either came with the HWE kernels installed, or if the HWE kernels were installed at a later date.
Note: It is advised to keep Ubuntu Desktop 20.04 LTS with the kernel flavor picked during installation. This is for HWE flavor. Changing to track GA kernel may result in regressions of performance, hardware support, and certified features.
Note 2: This answer is not for OEM kernels.
Make sure you have the 5.4 kernels and headers
Open a terminal and use this command:
sudo apt install --install-recommends linux-generic
If everything is already installed, then you will see a message saying so. Otherwise some packages will get installed.
If NVIDIA drivers are required check appropriate level and install them:
ubuntu-drivers list
And then install appropriate NNN version of the drivers:
sudo apt install --install-recommends linux-modules-nvidia-NNN-generic
Once you have the latest kernel version 5.4 installed, use the Advanced menu in GRUB to boot from the latest 5.4 kernel and make sure everything works as expected.
Purge the HWE kernels
While you are booted to the latest 5.4 kernel you can remove the 5.13 kernels and headers using the following command:
sudo apt remove --purge linux-generic-hwe-20.04
This will stop the system getting kernel 5.13 updates. This does not remove the the kernels, headers, modules, and modules-extra packages HWE versions.
The following command will remove all the 5.13 kernel , headers, modules, and modules-extra packages:
sudo apt remove --purge linux-hwe-* linux-modules-5.1* linux-modules-5.8.0-* linux-modules-5.6.0-*
Be careful with the *
in this command.
Reference: Ubuntu Kernel LTS Enablement Stack Wiki
Hope this helps
-
Thank you! I'm not sure how to test this until a kernel update is released, but I will return here and mark it as "answered" the next time the kernel gets upgraded. – Don't be A Smug Know-it-All Apr 18 '22 at 16:25
-
Unfortunately I have to add that this no longer works since (K)ubuntu 22.04.2. Regardless what I try I am stuck on kernel 5.19. So I am unable to switch permanently to the 5.15 LTS one. The main problem is that the command
sudo apt install --install-recommends linux-generic
has no effect because since 22.04.2 the default "GA" kernel is 5.19 not 5.15. There should really exist an option to default to the last LTS kernel not only to the newest HWE one. Yes, there exist the possibility to install a preferred kernel via a separate PPA but this should work without doing it that way. – Clemens May 24 '23 at 11:11 -
@Clemens I am sorry my answer does not work for you. You may want to ask a new question with a link to this question and explain why this answer does not work for you. That explanation will prevent your question being closed as a duplicate of this one. When you say "the command
sudo apt install --install-recommends linux-generic
has no effect." what exactly happens? The old kernel doesn't get installed? The old kernel gets installed but the new HWE kernel gets used in any case? Be specific in your new question. Leave a comment below when you ask your question so that I know. – user68186 May 24 '23 at 16:19 -
1Yes, I was stuck for whatever reason on kernel 5.19. However, it looks that I have found a solution. I booted up manually with a 5.15 kernel and then I purged all 5.19 related ones with command:
sudo apt remove --purge linux-image-5.19.0-38-generic linux-modules-5.19.0-38-generic linux-headers-5.19.0-38-generic linux-modules-extra-5.19.0-38-generic
. I have repeated this up to latest kernel 5.19.0-41. Now I am again on 5.15.0-72. And yes, also the commandsudo apt remove linux-{image,headers}-generic-hwe-22.04
was applied. Until now it looks fine, so I am not forced to a 5.19.x release. – Clemens May 25 '23 at 17:46 -
A final note, - it looks that I had to apply also
sudo apt-get install linux-image-generic
to receive newer 5.15 kernels on 22.04 LTS. For whatever reason I would have stayed otherwise on 5.15.0-72. ;-) – Clemens Jun 23 '23 at 18:13 -
@Clemens You may want to ask a new updated question specific to your own problem (hardware, OS etc.) and then answer your own question. Finally, accept your answer as correct. Comments care manly for asking for clarifications and may be deleted at anytime. Further, comments are not searchable. So, if you ask your own question and answer it, it will help others. Let me know if you do this with a comment here. I will up vote your answer. – user68186 Jun 23 '23 at 19:31