While newer version of a package on Linux system is generally a good thing, and we should upgrade it, there is times when we should hold on to the older version.

For instance, Fedora 32 just released a newer version of the kernel package 5.8.4 recently, and with this version, the zfs module, version 0.8.4, can’t be built. Therefore, if your Fedora system uses ZFS, like some of my machines, you’ll end up not seeing any ZFS dataset or pools.

So one way to prevent the kernel package from automatically upgrading to the 5.8 branch and screw up our ZFS kernel module is to lock the curruent or older version. Let’s learn how to do this using dnf.

First, list the available versions of the kernel package.

➜ sudo dnf info kernel
Last metadata expiration check: 0:03:23 ago on Sun 30 Aug 2020 11:41:31 PM AEST.
Installed Packages
Name         : kernel
Version      : 5.7.15
Release      : 200.fc32
Architecture : x86_64
Size         : 0.0
Source       : kernel-5.7.15-200.fc32.src.rpm
Repository   : @System
From repo    : updates
Summary      : The Linux kernel
URL          : https://www.kernel.org/
License      : GPLv2 and Redistributable, no modification permitted
Description  : The kernel meta package

Name         : kernel
Version      : 5.7.16
Release      : 200.fc32
Architecture : x86_64
Size         : 0.0
Source       : kernel-5.7.16-200.fc32.src.rpm
Repository   : @System
From repo    : updates
Summary      : The Linux kernel
URL          : https://www.kernel.org/
License      : GPLv2 and Redistributable, no modification permitted
Description  : The kernel meta package

Available Packages
Name         : kernel
Version      : 5.8.4
Release      : 200.fc32
Architecture : x86_64
Size         : 24 k
Source       : kernel-5.8.4-200.fc32.src.rpm
Repository   : updates
Summary      : The Linux kernel
URL          : https://www.kernel.org/
License      : GPLv2 and Redistributable, no modification permitted
Description  : The kernel meta package

According to the above output, it’s a good idea to lock version 5.7.16.

➜ sudo dnf versionlock kernel-5.7.16-200.fc32
[sudo] password for kenno:
No such command: versionlock. Please use /usr/bin/dnf --help
It could be a DNF plugin command, try: "dnf install 'dnf-command(versionlock)'"

It looks like I’m missing the DNF versionlock plugin. So, let’s install it.

➜ sudo dnf install 'dnf-command(versionlock)'

Okay, so we’re ready to lock the kernel to 5.7.16.

➜ rpm -q kernel
kernel-5.7.14-200.fc32.x86_64
kernel-5.7.15-200.fc32.x86_64
kernel-5.7.16-200.fc32.x86_64

➜ sudo dnf versionlock add kernel-5.7.16-200.fc32.x86_64
Last metadata expiration check: 0:09:57 ago on Mon 31 Aug 2020 12:13:33 AM AEST.
Adding versionlock on: kernel-0:5.7.16-200.fc32.*

We can also verify or check what packages are being version-locked:

➜ sudo dnf versionlock list
Last metadata expiration check: 0:21:46 ago on Mon 31 Aug 2020 12:13:33 AM AEST.
kernel-0:5.7.16-200.fc32.*

To remove a versionlocked package.

➜ sudo dnf versionlock delete kernel-0:5.7.16-200.fc32.*
Last metadata expiration check: 0:26:18 ago on Mon 31 Aug 2020 12:13:33 AM AEST.
Deleting versionlock for: kernel-0:5.7.16-200.fc32.*

Update:

It turned out that, I need also to version-lock a few more kernel related packages.

# dnf versionlock list
Last metadata expiration check: 0:41:27 ago on Mon 31 Aug 2020 12:13:33 AM AEST.
kernel-core-0:5.7.16-200.fc32.*
kernel-0:5.7.16-200.fc32.*
kernel-modules-extra-0:5.7.16-200.fc32.*
kernel-modules-0:5.7.16-200.fc32.*

References: