.Howto: Switch Ubuntu 22.04 from the HWE kernel back to the GA kernel on a headless server - Chris Stretton

Chris Stretton

Mar 24, 2024

Howto: Switch Ubuntu 22.04 from the HWE kernel back to the GA kernel on a headless server

You may find yourself in a position where you would like to roll Ubuntu LTS back from the HWE kernel to the default (GA) kernel versions.

This could be due to incompatible modules, or things like the controvercies surrounding ZFS’s mismatched kernel module and user-land zfsutils-linux package.

[!WARNING]
This post details how to change the core building blocks of your server. Errors in this process could result in prolonged downtime or data loss. I am not responsible for your server or the data on it. If you are unsure, seek help from official Ubuntu support resources

Ensure the GA kernel is installed

To begin, you need to ensure that the GA kernel is still installed. In most cases it will be as the migration to the HWE kernel does not remove it.

You can list all installed kernels with the following command:

sudo dpkg -l | grep linux- | grep ii | sort

however if it is not you can re-install it with the following command:

sudo apt install linux-generic linux-image-generic

At the time of writing, the current GA kernel version is 5.15.0-101

Boot onto the GA kernel

Now you need to reboot onto the GA kernel, if you have physical access to the server with a keyboard (or via a KVM) this is simple, you can reboot and in the GRUB menu select Advanced options for Ubuntu and then the GA kernel version.

If you do not have this level of access (a remote server or a server with no keyboard and monitor) you can update GRUB to automatically select the kernel you wish.

To do this:

Read your existing grub config, this is located at /boot/grub/grub.cfg

You are looking for menuentry and submenu options in a list. This file describes the same boot menu GRUB shows when you start the server.

You need to identify the number of the menu entry that corresponds to the GA kernel, starting from 0. This is typically under submenu 1 (Advanced options for Ubuntu)

In my case the menu entry `Ubuntu, with Linux 5.15.0-101 was the 5th menuentry in the Advanced options for Ubuntu submenu, giving it a number of 4.

This gives us a combined menu order of 1>4.

Once you have identified your menu order, you can edit the file /etc/default/grub as root with your text editor of choice.

sudo vim /etc/default/grub

Now you need to change the GRUB_DEFAULT variable to match your identified menu order. The existing entry will typically be:

GRUB_DEFAULT=0

Change this to your menu order

GRUB_DEFAULT="1>4"

Note the quotes and ensure that there are no spaces.

Once done you need to update GRUB to use the new configuration

sudo update-grub

Now you can reboot your server onto the GA kernel.

Once on the GA kernel

Now you need to examine your system and check that everything is running properly. You may have switched to the HWE kernel because of its improved hardware support, so check that everything is working as you expect before you continue.

If you encounter problems and need to return to the HWE kernel again you can reboot back into it. If you have updated your GRUB_DEFAULT variable above, repeat the steps but set the variable back to 0

Remove the HWE kernels

Now you have a stable system running back on the GA kernel, it is time to remove the HWE kernels and HWE kernal meta-packages.

To remove the meta-packages you can run the following:

sudo apt remove linux-generic-hwe-22.04 linux-image-generic-hwe-22.04

Again you can list installed kernels with the following

sudo dpkg -l | grep linux- | grep ii | sort

You need to identify kernels that are 6.x (at the time of writing) and remove them using apt.

In my case, the command needed was

sudo apt remove linux-headers-6.2.0-39-generic linux-headers-6.5.0-25-generic linux-hwe-6.2-headers-6.2.0-39 linux-hwe-6.5-headers-6.5.0-25 linux-image-6.5.0-25-generic linux-modules-6.5.0-25-generic linux-modules-extra-6.5.0-25-generic

But this will vary from system to system.

Ensure you remove the linux-headers, linux-image, linux-modules and linux-modules-extra packages for the installed kernels.

This should leave you with a system containing only the GA kernels and header.

Now finally if you have updated GRUB_DEFAULT above, you need to set it back to 0 and re-run sudo update-grub.

You should now be only using the GA kernels on your Ubuntu server.

OLDER > < NEWER