Usually minor Kernel upgrades are pretty safe. They're tested in a lot of environments before being released. But that' doesn't mean there are zero bugs. In case you need to downgrade the Kernel version on Ubuntu Linux, here's how you can safely do this.
In this example we're on a Ubuntu 22.04 LTS (Jammy) and we want to downgrade from 5.15.0-75 to 5.15.0-73.
Install older Kernel version
Usually (some) older Kernel versions should still be installed on your Ubuntu Linux, unless you have removed them manually or they were purged. You can verify which Kernel versions are installed with the following command:
ck@ubuntu:~$ dpkg -l|grep linux-image
ii linux-image-5.15.0-73-generic 5.15.0-73.80 amd64 Signed kernel image generic
ii linux-image-5.15.0-75-generic 5.15.0-75.82 amd64 Signed kernel image generic
If the needed version is not yet installed, you can manually install the older Kernel by appending the wanted version number to the package name:
ck@ubuntu:~$ sudo apt-get install linux-image-5.15.0-73-generic
Boot older Kernel version from GRUB
All installed Kernel versions are listed in the Grub Boot Loader Menu. This menu (very quickly) shows up when booting your Ubuntu Linux. By default the latest Kernel version is automatically selected and will be used for booting the system. But by moving the cursor down to "Advanced options for Ubuntu" and selecting this with [ENTER], you will have different Kernel versions as boot choice.
I can't see the GRUB menu!
ck@ubuntu:~$ grep TIMEOUT /etc/default/grub
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
Change the values to:
GRUB_TIMEOUT_STYLE=menu
GRUB_TIMEOUT=5
Followed by the command sudo update-grub. At the next system (re-)boot, the GRUB menu should show up.
Once the system has booted, make sure the older Kernel version is active:
ck@ubuntu:~$ uname -a
Linux ubuntu.example.com 5.15.0-73-generic #80-Ubuntu SMP Mon May 15 15:18:26 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Remove newer Kernel version
The Linux Kernel is split into multiple packages; simply removing the "linux-image…" package won't be enough due to dependencies to other related packages. Let's take a look which packages are installed for the 5.15.0-75 version:
root@ubuntu:~# dpkg -l|grep 5.15.0-75
ii linux-headers-5.15.0-75 5.15.0-75.82 all Header files related to Linux kernel version 5.15.0
ii linux-headers-5.15.0-75-generic 5.15.0-75.82 amd64 Linux kernel headers for version 5.15.0 on 64 bit x86 SMP
ii linux-image-unsigned-5.15.0-75-generic 5.15.0-75.82 amd64 Linux kernel image for version 5.15.0 on 64 bit x86 SMP
ii linux-modules-5.15.0-75-generic 5.15.0-75.82 amd64 Linux kernel extra modules for version 5.15.0 on 64 bit x86 SMP
ii linux-modules-extra-5.15.0-75-generic 5.15.0-75.82 amd64 Linux kernel extra modules for version 5.15.0 on 64 bit x86 SMP
To remove all these packages, we can run the following command:
root@ubuntu:~# apt-get remove $(dpkg -l|grep 5.15.0-75 | awk '{print $2}' | tr "\n" " ")
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
linux-headers-5.15.0-75 linux-headers-5.15.0-75-generic linux-image-unsigned-5.15.0-75-generic linux-modules-5.15.0-75-generic linux-modules-extra-5.15.0-75-generic
0 upgraded, 0 newly installed, 5 to remove and 0 not upgraded.
After this operation, 597 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 175113 files and directories currently installed.)
Removing linux-headers-5.15.0-75-generic (5.15.0-75.82) ...
Removing linux-headers-5.15.0-75 (5.15.0-75.82) ...
Removing linux-modules-extra-5.15.0-75-generic (5.15.0-75.82) ...
Removing linux-image-unsigned-5.15.0-75-generic (5.15.0-75.82) ...
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-5.15.0-75-generic
/etc/kernel/postrm.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.15.0-73-generic
Found initrd image: /boot/initrd.img-5.15.0-73-generic
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
done
Removing linux-modules-5.15.0-75-generic (5.15.0-75.82) ...
The command above removes the package names which contain the unwanted newer version (5.15.0-75) in it. By removing the Kernel packages, this automatically triggers an update of the GRUB boot loader; the 5.15.0-75 is removed from the GRUB configuration.
To properly get rid of all remaining package files, we can now purge the 5.15.0-75 packages:
root@ubuntu:~# apt-get purge $(dpkg -l|grep 5.15.0-75 | awk '{print $2}' | tr "\n" " ")
Verify GRUB configuration
Now that the 5.15.0-75 packages were removed, let's verify the GRUB configuration:
root@ubuntu:~# cat /boot/grub/grub.cfg | grep 5.15
set default="5.15.0-73-generic"
linux /boot/vmlinuz-5.15.0-73-generic root=UUID=34b699ba-8e51-43de-bbbd-f900f396dcaa ro vultr
initrd /boot/initrd.img-5.15.0-73-generic
menuentry 'Ubuntu, with Linux 5.15.0-73-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.15.0-73-generic-advanced-34b699ba-8e51-43de-bbbd-f900f396dcaa' {
echo 'Loading Linux 5.15.0-73-generic ...'
linux /boot/vmlinuz-5.15.0-73-generic root=UUID=34b699ba-8e51-43de-bbbd-f900f396dcaa ro vultr
initrd /boot/initrd.img-5.15.0-73-generic
menuentry 'Ubuntu, with Linux 5.15.0-73-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.15.0-73-generic-recovery-34b699ba-8e51-43de-bbbd-f900f396dcaa' {
echo 'Loading Linux 5.15.0-73-generic ...'
linux /boot/vmlinuz-5.15.0-73-generic root=UUID=34b699ba-8e51-43de-bbbd-f900f396dcaa ro recovery nomodeset dis_ucode_ldr
initrd /boot/initrd.img-5.15.0-73-generic
Our wanted 5.15.0-73 Kernel version is now the only 5.15 entry in the GRUB configuration.
Beware of automatic updates
If you have automatic updates (APT auto upgrades) enabled, the newer Kernel versions will be installed automatically. If you want to remain on that particular Kernel version, you should put the relevant Kernel package to "hold":
root@ubuntu:~# apt-mark hold linux-image-*