How to prevent a specific kernel version from being removed while still upgrading the kernel package through GNOME Software?

I’ve found conflicting information about this, so does anyone have a clear solution for preserving a specific version of the kernel without excluding upgrades to the kernel package through GNOME Software using offline upgrades? Kernel versions later than 6.11.9 have a regression in the AMD GPU drivers, and I want to be able to test newer versions while making sure to not remove 6.11.9.

You have to boot your system with this Kernel you want keep. You can not substitute a Kernel version you are using while upgrade.

To make it active you can use the following procedure:

List all installed kernels
--------------------------

To get the index number of all the installed kernels:

  sudo grubby --info=ALL | grep -E "^kernel|^index"

The output should be something like this:

 index=0
 kernel="/boot/vmlinuz-5.15.10-200.fc35.x86_64"
 index=1
 kernel="/boot/vmlinuz-5.15.10-lqx1.0.fc35.x86_64"
 index=2
 kernel="/boot/vmlinuz-5.15.8-200.fc35.x86_64"
 index=3
 kernel="/boot/vmlinuz-5.15.8-lqx1.0.fc35.x86_64"

Change the default kernel using index
-------------------------------------

Now we can change the default kernel by using the index number:

 sudo grubby --set-default-index=1

Verify the default kernel
-------------------------

Verify that the right kernel has been set as default:

   sudo grubby --default-title

The output will be the default kernel title:

 Fedora Linux (5.15.10-lqx1.0.fc35.x86_64) 35 (Workstation Edition)

To control the whole upgrade I would use dnf upgrade in general. You see what is going on and still can exitw with N if it displays something you do not like.

Be careful with this procedure. It sets the index but does not appear to lock that kernel version to remain at that index location. If I set the default index to 1 then a later update installs a newer kernel, now the kernel version I was using is pushed down to index location 2.

My next boot should still use index 1 and that will be the kernel version that was previously at index 0.

As long as the user still has the default config where only 3 kernels are kept, the oldest kernel at index 2 will not get replaced when it is used as the default, since it cannot be pushed down further in the list.

Note that I have not tested this recently but it is my understanding that this is the way it works.

The currently booted kernel should never be removed, but the indexing and location in that list may change.

Autocomplete works for this in bash so it is not terribly difficult to do, but you have to run it each time after a kernel is upgraded.

sudo grubby --set-default=/boot/vmlinuz-6.11.10-300.fc41.x86_64

1 Like

Use at your own risk I only tested this on one kernel install and a reboot.
in /etc/kernel/install.d/
I made a file 99-setdefault.install it contained the following:

Either:
Use the currently booted kernel or un-remark the particular version and change the kernel to the version you’d like.

#!/usr/bin/bash
#sticky the currently booted kernel
_KERNEL="/boot/vmlinuz-$(uname -r)"
#sticky a particular version
#_KERNEL="/boot/vmlinuz-6.11.10-300.fc41.x86_64"

case "$1" in
    add)
        grubby --set-default=${_KERNEL}
        ;;
    *)
        ;;
esac

On a non-atomic installation it might be easier to put the desired kernel in /etc/default/grub:

GRUB_DEFAULT="Fedora Linux (6.11.8-300.fc41.x86_64) 41 (Workstation Edition)"

Names can be listed as such:

$ sudo sh -c 'grep title /boot/loader/entries/* | cut -d " " -f2-'

Fedora Linux (0-rescue-e10bec186fd44c14a9d835d9e9c3c668) 40 (Workstation Edition)
Fedora Linux (6.11.6-300.fc41.x86_64) 41 (Workstation Edition)
Fedora Linux (6.11.7-300.fc41.x86_64) 41 (Workstation Edition)
Fedora Linux (6.11.8-300.fc41.x86_64) 41 (Workstation Edition)
2 Likes
  1. Reboot after installing the newer kernel will start automatically in the most actual one.

  2. If still wanting to protect a certain Kernel after testing it, the procedure above has to be repeated.

  3. If everything works with the newer Kernel nothing has to be done and the whole thing will work as before.

  4. If new issues come up with newer kernel just repeat the procedure above, having in mind that this Index change keeps till the next kernel upgrade. @computersavvy thanks to remind.

Just for users who really relay on that specific kernel version. For users who prefer keeping up with the newest kernel and just have sporadically the need to secure a kernel, the first procedure is better, at least I see it so.

If I upgrade a Kernel I generally have a look on which one I are with uname -a

Or users who use Gnome Software for updates instead of manual dnf upgrades, since it upgrades the kernel offline.

1 Like