How to change the default Boot Kernel on Linux Cloud Servers

2022-01-06 By Aaron 9367 Views linux kernel layerpanel
34 reviews

At times, it can happen that the server does not boot up correctly, because of issues such as file-system issues or OS loading issues. In such a scenario, a solution that can be tried for troubleshooting such issues is by changing the default boot kernel for the server via the Console of LayerPanel.


Ubuntu


  1. A general boot menu of an Ubuntu server with more than one kernel will be as below, with the first kernel at position 0, the second kernel at position 1 and so on.

    bootkernelubuntu1

  2. In order to change the default boot kernel, the grub configuration file /etc/default/grub needs to be edited. The parameter value that needs to be updated is for GRUB_DEFAULT.


    In the below example, if the kernel that needs to be set as the default one is the third one from the boot menu (position 2), then the value for GRUB_DEFAULT needs to be updated as 1>2.

    bootkernelubuntu2


    Here, 1 denotes the second entry of the Main menu and 2 denotes the third entry in the sub-menu.

    bootkernelubuntu3

    bootkernelubuntu4

  3. Execute the below command for rebuilding the grub configuration file.

    # update-grub
    
  4. Once the grub configuration file has been rebuilt, the server can be rebooted. Once the server is back online, the kernel with which the server has been booted up can be verified.


AlmaLinux

AlmaLinux is basically a community-driven project that is built from the source code of RedHat Enterprise Linux. It is also a fork of RHEL 8. For AlmaLinux servers having multiple kernel versions available, use grubby, the command-line tool used to configure bootloader menu entries.


  1. To list all the installed Kernel versions, use the following command.

    # grubby --info=ALL | grep ^kernel
    

    bootkernelalmalinux_1


    Now, you can also make sure to check the currently active Kernel version with the command.

    # uname -r
    

    bootkernelalmalinux_2

  2. To list the boot entry of the default kernel which is active now, is given below.

    # grubby –default-kernel
    

    bootkernelalmalinux_3

  3. Assuming we wish to change the default kernel which will be active after a reboot, you can do it by specifying the kernel boot entry explicitly in the following command.

    # grubby --set-default “<boot –kernel="" entry="">"
    

    bootkernelalmalinux_4

    NOTE: The kernel boot entry should be specified inside quotes. Once done, we can verify the default kernel that will be loading post a reboot.

  4. Once the server can be rebooted and the server is back online, the kernel with which the server has been booted up can be verified.

    bootkernelalmalinux_5


CentOS 8


  1. To identify and check the different versions of Kernel available, execute the following command.

    # rpm -qa | grep kernel | sort
    

    bootkernelcentos8_1


    The output of the above command will list all the versions of Kernel available. Now, the system has its way to number each of them. The first option will be given the number 0, the second option will be given as 1 and so on.

  2. Suppose if you would wish to have the 3rd kernel version in the list to be made default one, the following steps are done.

    # grub2-set-default 2
    

    bootkernelcentos8_2

  3. Once done, you can verify if the variable has gained the value, by the following command.

    # cat /boot/grub2/grubenv |grep saved
    

    bootkernelcentos8_3


    The saved_entry variable will get the value.

  4. After making the above changes, the Grub configuration file is to be rebuilt, and it can be achieved by following steps.

    # ls  -ld  /boot/grub2/grub.cfg
    


    This will show the grub configuration file details as output:

    bootkernelcentos8_4

  5. Final step is to rebuild the grub configuration done, and this is done using the following command.

    # grub2-mkconfig -o /boot/grub2/grub.cfg
    

    bootkernelcentos8_5


    Once the grub configuration file has been rebuilt, the server can be rebooted. Once the server is back online, the kernel with which the server has been booted up can be verified.


CentOS 7


  1. To identify and check the different versions of Kernel available, execute the following command.

    # awk -F\' /^menuentry/{print\$2} /etc/grub2.cfg
    


    The output of the above command will list all the versions of Kernel available. Now, the system has its way to number each of them. The first option will be given the number 0, the second option will be given as 1 and so on.

    bootkernelcentos7_1

  2. Suppose if you would wish to have the 3rd kernel version in the list to be made default one, the following steps are done.

    # grub2-set-default 2
    


    Once done, you can verify if the variable has gained the value, by the following command.

    # cat /boot/grub2/grubenv |grep saved
    


    The saved_entry variable will get the value:

    bootkernelcentos7_2

  3. After making the above changes, the Grub configuration file is to be rebuilt, and it can be achieved by following steps.

    # ls  -ld  /boot/grub2/grub.cfg
    


    This will show the grub configuration file details as output:

    bootkernelcentos7_3

  4. Final step is to rebuild the grub configuration done, and this is done using the following command.

    # grub2-mkconfig -o /boot/grub2/grub.cfg
    

    bootkernelcentos7_4

  5. Once the grub configuration file has been rebuilt, the server can be rebooted. Once the server is back online, the kernel with which the server has been booted up can be verified.


Related Tutorials

What do you think about this article?

Rate this article
LayerStack Promotion
Need assistance?

Try this guide to receive free bundled services at signup on a new free account.

Sign Up

Your Feedback Is Important

We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.