Make Grub2 Boot Older Kernel Version in Ubuntu 20.04

Posted on In Linux

In a Linux system, we may have multiple kernels installed. Usually, it is the latest kernel configured to be the default one the system boot loader will use during automatic boot if there is no manual kernel choosing. In many cases, such as there is no driver ready yet for some devices in newer kernels, we may choose to use an older version of kernel installed to the system. In this post, we will go through the steps to make the system boot loader grub (version 2) to boot the older kernel installed to the system on Ubuntu 20.04.

Find the list of kernels installed and the grub menu entries

We need to first find out the grub menu entries. The tool grub-mkconfig prints the grub configuration file content it generates to STDOUT. We can grep relevant content from its STDOUT as follows.

$ sudo grub-mkconfig | grep -E 'submenu |menuentry '

You will see output as follows.

...
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-84d2ae45-10d0-4cd9-a958-85e582df668b' {
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-84d2ae45-10d0-4cd9-a958-85e582df668b' {
    menuentry 'Ubuntu, with Linux 5.4.0-33-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-33-generic-advanced-84d2ae45-10d0-4cd9-a958-85e582df668b' {
    menuentry 'Ubuntu, with Linux 5.4.0-33-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-33-generic-recovery-84d2ae45-10d0-4cd9-a958-85e582df668b' {
Found linux image: /boot/vmlinuz-4.15.0-101-generic
Found initrd image: /boot/initrd.img-4.15.0-101-generic
    menuentry 'Ubuntu, with Linux 4.15.0-101-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-101-generic-advanced-84d2ae45-10d0-4cd9-a958-85e582df668b' {
    menuentry 'Ubuntu, with Linux 4.15.0-101-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-101-generic-recovery-84d2ae45-10d0-4cd9-a958-85e582df668b' {
...

Here, we use the entry “Ubuntu, with Linux 4.15.0-101-generic” under menu “Advanced options for Ubuntu” as an example.

During booting time, grub reads the grub configuration file. grub-mkconfig that can generate the grub configuration file. We can update the grub-mkconfig‘s configuration file to change the grub configuration file.

Set grub-mkconfig configuration file

Grub has a configuration file under /etc/default/grub. The configuration file has a variable GRUB_DEFAULT specifying the default choice in grub.

Here, what we need to figure out is the format to select the 2 levels of the menu entries. In the configuration parameter, these 2 levels of entries should be all specified with a character > to separate them.

So for our purpose, change the config file by changing the line for setting GRUB_DEFAULT to

GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 4.15.0-101-generic"

Regenerate grub configuration file

We now can generate the configuration file. In Debian Linux distros and derivatives, there is a tool update-grub to do this by calling grub-mkconfig.

$ sudo update-grub

After it finishes successfully, the default entry in the Grub2 configuration file will be the one we set when we boot the Linux system next time.

One comment

  1. I want to thank you.

    My new kernel came default and it was not working. I fixed the issue, thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *