Change Default Fedora Kernel
September 11 2024 9:46pm • Est. Read Time: 2 MINThere will be times where you would like to revert back to an older kernel, but would like to not have to select it manually at each boot. Perhaps a regression was introduced, perhaps you have other reasons. Regardless of why, it's actually pretty easy to do in Fedora.
Some things to note:
- Once this is set, it will remain setup this way until a dnf update introduces a new kernel release.
- I recommend only doing this after you have triple checked that this older kernel will provide the desired workaround.
- Everything here is copy and paste into the terminal.
Selecting an older kernel, testing against it, then setting it as default.
1. Spend the needed time to test the older kernel and note which kernel you wish to make the default.
sudo grub2-reboot "0" && reboot
Arrow down and select the desired kernel, press enter, test to see if the issue is present. If the issue you were dealing with is not present, keep going. Generally the next kernel down is the best option.
2. Now that we are booted into an older kernel, let's get a list of the kernels available in a friendly copy/paste list. This will ensure we're using the correct formatting for pinning this kernel into place.
Let's also get the list of grubby indexes:
sudo grubby --info=ALL | grep -E "index=|kernel="
and this gives us something similar to:
index=0
kernel="/boot/vmlinuz-6.10.8-200.fc40.x86_64"
index=1
kernel="/boot/vmlinuz-6.10.7-200.fc40.x86_64"
index=2
kernel="/boot/vmlinuz-6.8.5-301.fc40.x86_64"
index=3
kernel="/boot/vmlinuz-0-rescue-01e1323b47964ad78fcc328112755153"
If index=0, kernel="/boot/vmlinuz-6.10.8-200.fc40.x86_64" is what we wish to avoid and we want index=1, kernel="/boot/vmlinuz-6.10.7-200.fc40.x86_64" instead, we would then pin index 1.
3. Set the new default kernel.
sudo grubby --set-default-index=1
Next, verify it took with:
sudo grubby --default-index
This should return with 1. Next, Reboot. Check kernel version with uname -r to make sure you are on the desired kernel.
If this works and confirmed working with uname -r, it will automatically update itself when a new kernel is released. No intervention needed.
(If the first attempt above fails, then try this below next)
Paste this into the terminal, press enter.
sudo sed -i 's/GRUB_DEFAULT=saved/GRUB_DEFAULT=1/' /etc/default/grub && sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
Reboot
Next, I'd make sure it worked by checking it.
grep GRUB_DEFAULT /etc/default/grub
In this page's example, would show GRUB_DEFAULT=1 which is correct.
Great, now my new default kernel is set. Reboot to test it. Check with after reboot with uname -r to make sure it worked.
Restoring to defaults with the sudo sed approach:
- It will remain with the =1 index until you restore it to =saved, regardless of upates.
- When a new kernel is installed, you will need to:
sudo grub2-reboot "0" && reboot
This will boot you into the newly installed kernel when it is updated.
Now set the GRUB file back to what it was previously, from =1 back to =saved.
sudo sed -i 's/GRUB_DEFAULT=1/GRUB_DEFAULT=saved/' /etc/default/grub && sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
sudo sed approach - Before rebooting, verify it shows as saved:
grep GRUB_DEFAULT /etc/default/grub
GRUB_DEFAULT=saved
Now things are back to their defaults.