Boot previous kernel version – Ubuntu 16.04

The one who new to Ubuntu like me may face difficulty in understanding grub.cfg. But making Ubuntu to boot into older or previous kernel version is really simple. The configuration is same like Redht except small change in syntax.

Select kernel version

Edit file /etc/default/grub and navigate to directive “GRUB_DEFAULT”. And choose the kernel to boot by default. The given syntax will boot system with previous to current kernel version.

GRUB_DEFAULT=”1>3″

1 = chooses advanced menu from main menu. It always remains same.

3 = chooses previous to current kernel version. Change number according to required kernel version.

Do you struck at identifying kernel number?

No issues, use below command to list available kernel version in system.

#grep -A100 submenu  /boot/grub/grub.cfg |grep menuentry

submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-5ceda2b3-ed38-4f60-9937-a4f979f3745b' {
            menuentry 'Ubuntu, with Linux 4.4.0-104-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-104-generic-advanced-5ceda2b3-ed38-4f60-9937-a4f979f3745b' {
            menuentry 'Ubuntu, with Linux 4.4.0-104-generic (upstart)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-104-generic-init-upstart-5ceda2b3-ed38-4f60-9937-a4f979f3745b' {
            menuentry 'Ubuntu, with Linux 4.4.0-104-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-104-generic-recovery-5ceda2b3-ed38-4f60-9937-a4f979f3745b' {
            menuentry 'Ubuntu, with Linux 4.4.0-31-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-31-generic-advanced-5ceda2b3-ed38-4f60-9937-a4f979f3745b' {
            menuentry 'Ubuntu, with Linux 4.4.0-31-generic (upstart)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-31-generic-init-upstart-5ceda2b3-ed38-4f60-9937-a4f979f3745b' {
            menuentry 'Ubuntu, with Linux 4.4.0-31-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-31-generic-recovery-5ceda2b3-ed38-4f60-9937-a4f979f3745b' {

The lines starting with “menuentry” are the available kernel version for us. The first entry can be selected using numeric zero “0”.  From above output the numeric value three (3) will select previous kernel version ‘Ubuntu, with Linux 4.4.0-31-generic’. To choose recovery mode of same previous kernel version use numeric value five (5).

Note: Do not forget “Zero”. First kernel version is pointed using zero (0).

Time to update grub.cfg

This command updates the /boot/grub/grub.cfg with value what we set above.

#sudo /usr/sbin/update-grub

Does your system do not have the command? Then copy the below script and execute it.

#!/bin/sh
set -e
exec grub-mkconfig -o /boot/grub/grub.cfg "$@"

Using recovery mode

Assume menu timeout set to zero (0). It is not possible to choose previous kernel version from menu during boot. What if system does not boot at all with current default kernel version? Simple, boot with Live CD and change the /boot/grub/grub.cfg straight away.

#mount /dev/sda1 /mnt
#vi /boot/grub/grub.cfg
set default="1>3"

Sample output

From value “1>3”, the numeric “1” chooses second option from main menu which is Advanced options for Ubuntu. Refer the main menu snap below.

Ubuntu_grub_main_menu
Ubuntu_grub_main_menu

The second numeric “3” chooses fourth available kernel version. Refer sub menu snap below.

Ubuntu_grub_sub_menu
Ubuntu_grub_sub_menu

Upon boot validate kernel version.

sundar@test03:~$ uname -r
4.4.0-31-generic

Hope this article served you the needed information. Post your comments below. If you like the page kindly comment as +1.

2 thoughts on “Boot previous kernel version – Ubuntu 16.04

  1. +1
    Didn’t realise, that the “submenu” in reality is the second entry and thus my attempts with 0>2 and the like where in total vain. Thanks for taking the time to show a complete example.

Comments are closed.