Skip to content

How to change and set the default Kernel in Ubuntu Machine?

Updated:Β atΒ 01:05 PM

Have you ever encountered a situation where you need to change the default kernel of your Ubuntu machine and switch to a different one? Ubuntu logo

I have faced this situation myself, and after spending some time, I’ve come across a simple method to change your Ubuntu kernel to the one of your choice.

For this post, I am using an Ubuntu 18.04 machine running on AWS. ubuntu ami

To check the kernel of the Ubuntu machine, SSH into the machine using your terminal. Use the following command to check the current kernel version.

ubuntu@ip-172–32–11–86:~$ uname -r
5.4.0-1103-aws

To see the list of installed kernels for this Ubuntu machine, use the following command in your terminal

ubuntu@ip-172–32–11–86:~$ dpkg-query -W -f='${Package} ${Version}\n' | grep -E '^(linux.*)'

You will get a list of installed kernels for your Ubuntu machine. Choose the kernel to be set and install it using the following command.

ubuntu@ip-172–32–11–86:~$ sudo apt install linux-image-unsigned-4.15.0-136-lowlatency

Install Kernel The next step is to set the Grub default Kernel. There will be two parts. First, you need to grab the $menuentry_id_option with the following command:

ubuntu@ip-172-31-11-86:~$ grep submenu /boot/grub/grub.cfg
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-9cf7073a-6786-43dc-895e-8bbebe712a1e' {

Copy gnulinux-advanced-9cf7073a-6786–43dc-895e-8bbebe712a1e

Secondly, you need to get the specified kernel version.

ubuntu@ip-172-31-11-86:~$ grep 4.15.0-136 /boot/grub/grub.cfg

Here, I have only copied the version of the kernel from the above list of installed kernels. Default Grub Copy gnulinux-4.15.0–136-lowlatency-advanced-9cf7073a-6786–43dc-895e-8bbebe712a1e highlighted in green.

To set the default GRUB, open the grub file /etc/default/grub using the editor of your choice (vim, nano, etc). Join the two copied strings with a > and set it to the GRUB_DEFAULT in the grub file.

gnulinux-advanced-9cf7073a-6786–43dc-895e-8bbebe712a1e>gnulinux-4.15.0–136-lowlatency-advanced-9cf7073a-6786–43dc-895e-8bbebe712a1e Update Grub Save the file and use the following command to update the grub.

ubuntu@ip-172-31-11-86:~$ sudo update-grub
ubuntu@ip-172-31-11-86:~$ sudo reboot

After your machine reboots, you will have your choice of kernel set as the default kernel βœ…

========================================================================================================================
If you find this story helpful and want to see similar stories, feel free to support me with a virtual coffee πŸ˜‰πŸ‘‡πŸ»

β˜• https://ko-fi.com/mnzel1β˜•