Building and Booting a Custom Linux Kernel: How GRUB works?.

Why Does GRUB Default to Older Kernels?

When you install multiple Linux kernels on a system, GRUB (the GRand Unified Bootloader) manages the boot menu entries for each kernel version. By default, GRUB usually boots the latest installed kernel. However, this behavior can sometimes lead to unexpected booting into an older or different kernel version than the one you just installed, especially when:

  • The new kernel entry is not the first one listed in GRUB’s configuration.
  • GRUB’s GRUB_DEFAULT setting points to a specific menu entry or index.
  • There are multiple kernel entries including recovery modes and advanced options.
  • The system has multiple Linux distributions or complex boot setups.

How GRUB_DEFAULT Works

The /etc/default/grub file contains the GRUB_DEFAULT variable that controls which menu entry GRUB boots by default. It can be set in several ways:

  • GRUB_DEFAULT=0 — boots the first menu entry (index 0).
  • GRUB_DEFAULT=saved — boots the last selected menu entry (requires GRUB_SAVEDEFAULT=true).
  • GRUB_DEFAULT="Advanced options for Debian>Debian GNU/Linux, with Linux 6.1.0-custom+" — boots a submenu entry by exact menu path (recommended when using custom kernels).

Why You Need to Update GRUB_DEFAULT for Your Custom Kernel

After installing a custom kernel, GRUB adds a new menu entry with a name like:

Debian GNU/Linux, with Linux 6.1.0-custom+

However, this entry might not be the first in the list. If GRUB_DEFAULT=0 or points to another default, the system will boot an older kernel instead.

By explicitly setting GRUB_DEFAULT to your custom kernel’s menu entry string, GRUB boots the right kernel every time without manual intervention.


How to Find the Correct GRUB Menu Entry Name

You can list all menu entries with:

grep "menuentry '" /boot/grub/grub.cfg

This outputs lines like:

menuentry 'Debian GNU/Linux, with Linux 6.1.0-custom+' --class debian ...

Use the exact text inside the single quotes (including any submenu path if needed) to set GRUB_DEFAULT.


Updating GRUB_DEFAULT Example

Edit /etc/default/grub:

sudo nano /etc/default/grub

Change or add:

GRUB_DEFAULT="Advanced options for Debian GNU/Linux>Debian GNU/Linux, with Linux 6.1.0-custom+"

Then update GRUB config:

sudo update-grub

Summary

  • GRUB boots the default kernel based on the GRUB_DEFAULT setting.
  • Installing a new kernel adds new menu entries but doesn’t automatically set it as default.
  • Setting GRUB_DEFAULT to the exact menu entry string ensures your custom kernel boots by default.
  • This is especially important on servers or cloud machines where you can’t select kernels manually at boot.