On this page
There are good reasons to pin a kernel. A driver or kernel module your software depends on only builds against one version. A new kernel introduced a regression. A vendor certified their product on a specific release. Whatever the reason, Ubuntu will happily install a newer kernel on the next upgrade and boot into it, so you have to tell GRUB what you want.
This guide was first written in 2018 for Ubuntu 16.04 on EC2. The approach still works, but the commands have been updated for 22.04, 24.04 and 26.04, and it now uses a safer way to test a kernel on a server you can't reach if boot fails.
Ubuntu 22.04 default kernel version, and what you are running
uname -r
dpkg --list 'linux-image-*' | grep ^ii The first command shows the running kernel, the second lists every kernel installed. For reference, these are the kernels each release shipped with (Canonical's kernel lifecycle page has the full HWE schedule):
| Release | GA kernel | Notes |
|---|---|---|
| Ubuntu 22.04 | 5.15 | HWE track moves to newer kernels, ending at 6.8 |
| Ubuntu 24.04 | 6.8 | HWE track follows later interim releases |
| Ubuntu 26.04 | 7.0 | Newest LTS |
On cloud instances the running kernel is usually a provider flavour, such as 6.8.0-1021-aws rather than -generic. That matters later.
Install the kernel version you want
If the kernel you want isn't in the list yet, install it. The standard kernel metapackage:
sudo apt update
sudo apt install -y linux-generic Or a specific version, if it is still in the archive:
apt-cache search linux-image-6.8.0 | grep generic | tail -5
sudo apt install -y linux-image-6.8.0-45-generic linux-modules-extra-6.8.0-45-generic The version numbers here are examples; use one from the search output. The old guide installed linux-image-extra-virtual, a 16.04-era package that current releases don't use.
Ubuntu choose kernel from the GRUB menu entries
Before touching anything, back up the GRUB defaults and list the menu entries by name (the GNU GRUB manual explains the naming rules if your menu looks different):
sudo cp /etc/default/grub /etc/default/grub.bak
grep -E "(menuentry|submenu) " /boot/grub/grub.cfg | cut -d "'" -f2 You will see something like this:
Ubuntu
Advanced options for Ubuntu
Ubuntu, with Linux 6.8.0-1021-aws
Ubuntu, with Linux 6.8.0-1021-aws (recovery mode)
Ubuntu, with Linux 6.8.0-45-generic
Ubuntu, with Linux 6.8.0-45-generic (recovery mode) Specific kernels live inside the Advanced options for Ubuntu submenu. GRUB addresses them as the submenu title, a >, then the entry title, all in one string:
Advanced options for Ubuntu>Ubuntu, with Linux 6.8.0-45-generic The 2018 version of this guide used the long gnulinux-... IDs instead of titles. Those work too, but titles are readable and survive being copied into a ticket.
Ubuntu switch kernel for one boot to test it
On a server you can only reach over SSH, never make an untested kernel the permanent default. If it doesn't boot, you have no console to pick another one. Boot it once instead:
sudo sed -i 's/^GRUB_DEFAULT=.*/GRUB_DEFAULT=saved/' /etc/default/grub
sudo update-grub
sudo grub-reboot "Advanced options for Ubuntu>Ubuntu, with Linux 6.8.0-45-generic"
sudo reboot grub-reboot sets the kernel for the next boot only. If the machine comes back, check uname -r. If it doesn't, a plain reboot from your cloud console returns it to the previous default, and you have lost nothing.
Ubuntu change default kernel permanently
Once the test boot works, save it as the default:
sudo grub-set-default "Advanced options for Ubuntu>Ubuntu, with Linux 6.8.0-45-generic"
sudo reboot Ubuntu GRUB set default kernel in the config file
Because GRUB_DEFAULT=saved is already set, no update-grub is needed for the command above. If you would rather keep the choice visible in the config file, put the full string directly in /etc/default/grub as GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 6.8.0-45-generic" and run sudo update-grub.
To stop the next upgrade from pulling in a newer kernel and making you do this again, hold the kernel metapackages:
sudo apt-mark hold linux-generic linux-image-generic linux-headers-generic Held kernels stop getting security fixes
apt-mark unhold later instead of discovering a two-year-old kernel during an audit.
Cloud images and EC2
Two things behave differently on AWS, GCP and other cloud images.
Files in /etc/default/grub.d/ override /etc/default/grub. Ubuntu cloud images ship settings there, and anything defined in those files wins because they are read afterwards. If your change seems ignored, check them:
grep -r GRUB_DEFAULT /etc/default/grub /etc/default/grub.d/ Provider kernels exist for a reason. The -aws kernel carries drivers and tuning for EC2's networking and storage. Switching an EC2 instance to -generic usually works, but test the network throughput and the EBS volume performance after the switch, and keep the provider kernel installed so you can go back. If you run workloads like a Jitsi Meet videobridge or a Kurento media server, where network performance is the whole point, stay on the provider kernel unless you have a specific reason not to.
When a server needs a specific kernel for every future instance, bake it into an image rather than repeating these steps each time. AWS VM Import/Export covers bringing a locally built VM into EC2, and installing the AWS CLI is the prerequisite for most of that tooling.
Frequently Asked Questions
How do I change kernel in Linux?
On Ubuntu and Debian: install the kernel, find its GRUB menu entry, boot it once with grub-reboot, then make it permanent with grub-set-default. RHEL, Rocky and Fedora use grubby --set-default instead of editing GRUB entries by name.
What is the default kernel version in Ubuntu 22.04?
Ubuntu 22.04 shipped with the 5.15 GA kernel. Systems on the hardware enablement (HWE) track move to newer kernels, ending with 6.8 from Ubuntu 24.04. uname -r shows the one you are running, and cloud images often use a provider flavour such as -aws.
What was the default kernel in Ubuntu 16.04?
Ubuntu 16.04 shipped with Linux 4.4, and its HWE track ended on 4.15. The release left standard support in April 2021, so on a 16.04 server upgrading the whole release matters far more than choosing a kernel.
How do I boot an older kernel just once?
Set GRUB_DEFAULT=saved in /etc/default/grub and run update-grub once. Then sudo grub-reboot with the menu entry name boots that kernel on the next restart only, and falls back to the saved default after. It is the safe way to test on a remote server.
Why does my GRUB_DEFAULT change have no effect?
Either update-grub was not run afterwards, or a file in /etc/default/grub.d/ sets the same variable and overrides it, which is common on cloud images. Also check that the menu entry text matches exactly, including the 'Advanced options for Ubuntu>' submenu prefix.
How do I stop Ubuntu from upgrading my chosen kernel?
Hold the metapackage that pulls in new kernels, for example sudo apt-mark hold linux-generic linux-image-generic, or the -aws variants on EC2. Remember to unhold it later, because held kernels stop receiving security fixes.
What happened to linux-image-extra-virtual?
It was a package from the Ubuntu 16.04 era that added extra driver modules to the virtual kernel. Current releases do not use it. Install linux-generic for the standard kernel, or linux-generic-hwe-