Ubuntu 18.04 initially came with the 4.15 kernel, and since 4.15 is an Ubuntu LTS kernel, it’s still updated. New features, and new support for different processor architectures, keep getting added to newer releases of the kernel, and that means that over time, the 4.15 kernel will get further and further out of date for brand-new hardware, and there have also been some great improvements in disk performance scheduling that you’d miss with the older kernel.
Right now, the newest kernel offered for 18.04 by Ubuntu is 5.3, and that can easily be installed by installing the hwe (hardware enablement) stack. Once that’s installed, you will automatically be sent each new kernel as it is released.
There is a newer Ubuntu kernel, though, and that’s the 5.4 LTS kernel that comes with Ubuntu 20.04 Focal Fossa. It’s not currently offered for Ubuntu 18.04 and derivative distros, but you can easily fix that.
It would be possible to download the files needed to install the currently released 5.4 kernel from the Ubuntu repo website and install that, but it wouldn’t be kept up to date. The updates for 5.4 come from the 20.04 focal repository, so if you want the kernels to update, you will need that repo. If you just added that repo and did nothing else, you’d get hundreds of files trying to update from their 18.04 versions to the 20.04 versions, in effect trying to upgrade your whole PC to 20.04.
If you want to upgrade from 18.04 to 20.04 and you’re using an actual Ubuntu release, they have a procedure for that which makes it easy. If you’re using an Ubuntu derivative like Mint or Neon, it would be best to wait for the distro you use to adopt the new 20.04 LTS base. Just adding the 20.04 repo and letting ‘er rip could mess things up pretty spectacularly. Or maybe it will work… I don’t know. My bet is on it being screwed up by dependency issues, though.
In order to get the kernel to update from the 20.04 repo but not anything else, we will need to create a configuration file to tell APT, the package manager, what we want it to do.
If you navigate, using the file manager of your choice, to /etc/apt/preferences.d/, you will need to create a text file in there. In KDE Plasma, you can just copy and paste the below lines into the text editor and save it to /etc/apt/preferences.d
, and the editor will automatically ask to elevate to superuser privileges. Other distros, like Mint, would say “access denied,” so in that case, you could navigate to that folder, then right-click the background and select “Open as root.” Enter the password, then it will start a root copy of the file manager. You can then right click the background and tell it to create a new text file.
The filename I used is 99-focal-kernel, in the normal UNIX way of using numbers at the start of the filename to establish priority, but I am not sure it matters in this instance. Into the text file, copy and paste this:
Package: *
Pin: release v=20.04
Pin-Priority: 1
Package: linux-generic*
Pin: release v=20.04
Pin-Priority: 1100
Package: linux-image-generic*
Pin: release v=20.04
Pin-Priority: 1100
Package: linux-headers-generic*
Pin: release v=20.04
Pin-Priority: 1100
Then save the file.
That won’t accomplish anything by itself, but I will explain what the stuff means. You should not blindly accept any code that a person on the internet suggests if you don’t know what it does!
The first entry (each entry being three lines) sets all files in the version (v) 20.04 to a priority of 1, which is very low. That means that even if you enable the 20.04 repo, it will still take packages from any repo with a higher priority, which would be all of them. That first entry effectively turns off the 20.04 repo.
The next three entries create exceptions for the files that make up the kernel stack. That will assign a priority of 1100 to all of the files listed, making it prefer those above the ones it normally would. Note that the asterisk at the end of each (after ‘generic’) allows each of the entries shown to apply to (for example) linux-generic and linux-generic-hwe-18.04, so whichever stack you have installed, it will upgrade either (or both) to the newer kernel stack from 20.04.
The final step needed is to add the repository from 20.04. With the 99-focal-kernel file (or whatever you decided to call it) in place, you can now do that and have it only upgrade the three files that are listed, and their dependencies, like the actual kernel release that is current at the moment.
First, get fully up to date on updates if you’re not already. Make a backup too, whether it be with Timeshift, Veeam, or whatever other program you want to use. This should be quick and easy, but mistakes do happen, so prepare for that by having a backup first. Timeshift makes it easy, and is already preinstalled if you are using Mint.
If you know the URL of the closest Ubuntu server or mirror, you can use the graphical tool of your choice to add the repo. Be sure to set the distro to ‘focal’, and the components to ‘main’.
If you don’t know that URL, look for a file in /etc/apt
called sources.list
. If it’s not there, look inside /etc/apt/sources.list.d
, and one of the files inside should be the one. What you’re looking for is a line like this:
deb http://us.archive.ubuntu.com/ubuntu/ bionic main restricted
In my sources.list, it was the fourth line.
Highlight and copy that, then paste it at the bottom of the file, and change ‘bionic’ to ‘focal’. You can delete the ‘restricted’, ‘multiverse’, or ‘universe’ bits if you wish (only from your copy-pasted line, nor the original) if they are present. Make sure ‘main’ stays.
If you want an even newer kernel (still 5.4, but a newer Ubuntu revision of it), one that has not been through the full release process yet, paste the line again, but this time change ‘bionic’ to ‘focal-proposed’ instead. Having both would allow any dependencies required by the proposed repo to be pulled in correctly.
If you wanted, you could create a new file in /etc/apt/sources.list.d
, then paste the extra bits to that file instead, and it would act the same as if you added the text to another file in that directory or to the sources.list file itself.
If you’re using Neon, there might be a file in /etc/apt/preferences.d
called 99-xenial-overrides
. That file can make the system upgrade a few files that were not intended, so to prevent that, load the file into the text editor, and search-replace o=Ubuntu
with o=Ubuntu v=18.04
, then save.
Once that’s done, you can have your updater look for new updates. Don’t just accept what it proposes, though… be sure that it’s not trying to give you a large number of files. If it’s dozens or more of files, don’t proceed. The same goes if it wants to remove a bunch of stuff. Something went wrong, and if you continue, things will get messed up.
If that happens, some troubleshooting will be required. If you want to leave that for later, I would not advise just leaving it in that state; you might forget that the focal repo is installed, and the next time it wants to install all those extra files, you might let it update things you didn’t want updated. To prevent that, remove or comment out (put a # before the line in the text editor) the lines you added to sources.list or in any of the files within sources.list.d and save them again, being sure that the save worked and that it didn’t say “access denied’. If you reload the files available again with the package manager or software updater, it should get rid of all of the extra things it was trying to upgrade or remove.
If all goes well, it should only pull in a few files with names similar to the ones in the stuff you copy-pasted in, just with more stuff added on. On my Neon, it also wanted to upgrade gcc and some other things… I had already performed a backup, so I let it proceed to see if it would work with those upgrades, and it did.
If you’re an advanced user, this should be an easy project. If you’re not advanced but you know how to use Timeshift or another program to back up the system files, and you’ve verified that it works, you can proceed with relatively little fear, since you have a way of getting back to where you started. If you’re neither an advanced user nor a backup program user, I would not advise trying this!
I’ve done this with all three of my Neon installations as well as one test Mint installation, and it worked nicely in all of them. After this is done, the updater that you use, whichever one that may be, will automatically offer the new updates as they are released.
If you ever want to undo this and go back to the default setup (which I would advise before a distro upgrade), just use GRUB to boot from the original kernel (either 4.15 or 5.3), then edit the /etc/preferences.d/99-focal-kernel
file, or whatever you called it, and remove all but the first three lines, so that the only entry is * with a priority of 1. Save, then use whatever software update program you use, and tell it to reload or check for updates. It should automatically mark the files that were added for downgrade. Let it proceed if everything looks good, and then you can remove the ‘focal’ entries you added to sources.list or inside sources.list.d. After that, you can remove 99-focal-kernel, or whatever you called it.
If you use Neon and made the change to 99-xenial-updates, you could revert that also (it won’t change anything for now, but if you ever perform a distro upgrade, the old file being edited might cause it to ask you what to do with it at upgrade time, and that might not be something you know the answer to. The answer would be to use the package maintainer’s version, FWIW!)
Dell XPS 13/9310, i5-1135G7/16GB, KDE Neon 6.2
XPG Xenia 15, i7-9750H/32GB & GTX1660ti, Kubuntu 24.04
Acer Swift Go 14, i5-1335U/16GB, Kubuntu 24.04 (and Win 11)