Change the Boot Kernel Version in Linux

Spread the love

Sometimes when you upgrade your Linux (Ubuntu/Debian) the Kernel may be updated too and it can cause some issues, like sound card stopped working, or some other server utilities, for example ocfs2/o2cb.

To fix it you might need to switch your Boot kernel from the latest (upgraded) to the previous (old) one, follow the steps below.

All the command samples below will be represented for Ubuntu linux distributive, it should not be a problem to find the relative commands for your specific Linux dist.

List Kernel Versions

Get the currently installed kernel menu entries using below command (this specific one will show up to 7 entries, you can change it to up to 2 or 10, or whatever you like):

sudo grub-mkconfig | grep -iE "menuentry 'Ubuntu, with Linux" | awk '{print i++ " : "$1, $2, $3, $4, $5, $6, $7}'

You should see something like this:

Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/50-cloudimg-settings.cfg'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.5.0-1019-oracle
Found initrd image: /boot/initrd.img-6.5.0-1019-oracle
Found linux image: /boot/vmlinuz-5.15.0-1052-oracle
Found initrd image: /boot/initrd.img-5.15.0-1052-oracle
Found linux image: /boot/vmlinuz-5.15.0-1049-oracle
Found initrd image: /boot/initrd.img-5.15.0-1049-oracle
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.
Adding boot menu entry for UEFI Firmware Settings ...
done
0 : menuentry 'Ubuntu, with Linux 6.5.0-1019-oracle' --class ubuntu
1 : menuentry 'Ubuntu, with Linux 6.5.0-1019-oracle (recovery mode)'
2 : menuentry 'Ubuntu, with Linux 5.15.0-1052-oracle' --class ubuntu
3 : menuentry 'Ubuntu, with Linux 5.15.0-1052-oracle (recovery mode)'
4 : menuentry 'Ubuntu, with Linux 5.15.0-1049-oracle' --class ubuntu
5 : menuentry 'Ubuntu, with Linux 5.15.0-1049-oracle (recovery mode)'

So in my case (since it is ran on my machine) I have only 6 entries, 3 linux kernel versions.

Edit GRUB_DEFAULT

To see your current kernel version which is used to boot your system run the following command:

ubuntu@mailserver:/$ uname -r
6.5.0-1019-oracle

If you have any issues with your current kernel, modify GRUB_DEFAULT=<your_kernel_number> to boot from specific kernel version:

sudo nano /etc/default/grub

For example, if you want to change your kernel version to 5.15.0-1052-oracle which is menu entry number 2 in my list of available kernels, you will need to change GRUB_DEFAULT value to “1>2” (more details about the format here), so it will look like:

...
GRUB_DEFAULT="1>2"
...

If you need to change it back to the default kernel – just change it to 0:

...
GRUB_DEFAULT=0
...

And save the file.

Apply and Reboot

Apply the changes to your GRUB by the following command:

sudo update-grub

And reboot your system:

sudo reboot

After that, once the system is up, check your current kernel version:

uname -r

If everything is OK you should see the kernel you set in GRUB_DEFAULT in /etc/default/grub file.


Comments

Leave a Reply