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

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.

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
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.
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
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 ✅
Confirm it actually took effect
Don’t trust the config file — trust uname. After the reboot:
ubuntu@ip-172-31-11-86:~$ uname -r
4.15.0-136-lowlatency
If it still reports the old kernel, the GRUB_DEFAULT string didn’t match a real menu entry and GRUB quietly fell back to the first one. Re-run the two grep commands and copy the IDs again — they’re long, and it’s easy to lose a character.
An easier alternative: GRUB_DEFAULT=saved
Joining two menu entry IDs with a > is fiddly and breaks whenever a kernel update renumbers things. If you’d rather not hand-assemble the string, GRUB can remember a saved choice instead:
# /etc/default/grub
GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true
Then set the entry by name:
ubuntu@ip-172-31-11-86:~$ sudo update-grub
ubuntu@ip-172-31-11-86:~$ sudo grub-set-default "Advanced options for Ubuntu>Ubuntu, with Linux 4.15.0-136-lowlatency"
ubuntu@ip-172-31-11-86:~$ sudo grub-editenv list
grub-editenv list prints what’s currently saved, so you can verify before rebooting rather than after.
Stop apt from undoing your work
This is the step people miss. Unattended upgrades will happily install a newer kernel and, depending on your GRUB config, boot into it — putting you right back where you started. If you deliberately picked an older kernel, hold it:
ubuntu@ip-172-31-11-86:~$ sudo apt-mark hold linux-image-unsigned-4.15.0-136-lowlatency
ubuntu@ip-172-31-11-86:~$ sudo apt-mark showhold
Release it later with sudo apt-mark unhold <package>. Be deliberate about this: a held kernel also stops receiving security patches, so it’s a decision to revisit, not a permanent setting.
Doing this safely on a cloud instance
On a laptop, a kernel that won’t boot means picking a different entry from the GRUB menu. On an EC2 instance there is no menu — if the machine doesn’t come back, SSH simply never connects. A few precautions:
- Snapshot the root EBS volume before you reboot. It takes a minute and turns an unrecoverable instance into a five-minute restore.
- Know where the EC2 Serial Console is in the AWS Console before you need it. It’s the only way to interact with the GRUB menu on an instance that won’t boot.
- Leave the previous kernel installed. Never remove the kernel you’re currently running as part of the same change.
- Try it on a throwaway instance first if this is going into a runbook. Spinning one up from a known-good AMI costs pennies.
When /boot runs out of space
Kernels accumulate, and on Ubuntu’s small default /boot partition that eventually breaks apt mid-upgrade with a “No space left on device” error. Clear out the old ones:
ubuntu@ip-172-31-11-86:~$ dpkg --list | grep linux-image
ubuntu@ip-172-31-11-86:~$ sudo apt autoremove --purge
apt autoremove is the safe version — it won’t touch the running kernel or the one GRUB is set to boot. Only reach for apt purge linux-image-<version> on a specific kernel you’re certain you no longer need, and check uname -r first so you don’t remove the one you’re standing on.