Question: How can configure grub to use a specific kernel?
Answer
You can configure grub via several ways to use a specific kernel or you can configure grub to use the latest one, or you can tell grub to pick one from a selection.
One specific kernel
If you inspect /etc/grub/grub.cfg you’ll see entries like this:
# the \ are mine, these are usually one big line but for blog purposes I
# multilined them
menuentry 'Debian GNU/Linux GNU/Linux, with Linux 6.12.8-amd64' --class debian \
--class gnu-linux --class gnu --class os $menuentry_id_option \
'gnulinux-6.12.8-amd64-advanced-5522bbcf-dc03-4d36-a3fe-2902be938ed4' {
You can use two identifiers to configure grub; you can use 'Debian GNU/Linux GNU/Linux, with Linux 6.12.8-amd64' or you can use the $menuentry_id_option
with gnulinux-6.12.8-amd64-advanced-5522bbcf-dc03-4d36-a3fe-2902be938ed4.
On Debian you can change grub by using /etc/default/grub.d directory to add a
customisation:
$ cat /etc/default/grub.d/local-config.cfg
GRUB_DEFAULT='Debian GNU/Linux GNU/Linux, with Linux 6.12.8-amd64'
# or
GRUB_DEFAULT=gnulinux-6.12.5-amd64-advanced-5522bbcf-dc03-4d36-a3fe-2902be938ed4
Now run sudo update-grub and notice this line in your /boot/grub/grub.cfg:
$ sudo grep gnulinux-6.12.5 /boot/grub/grub.cfg
set default="gnulinux-6.12.5-amd64-advanced-5522bbcf-dc03-4d36-a3fe-2902be938ed4"
Now the default boot option is set.
Per menu listing
You can also configure grub to use the menu listing, although this can be a bit finicky when you have submenus. For example, Debian ships with an advanced options menu:
# the \ are mine, these are usually one big line but for blog purposes I
# multilined them
submenu 'Advanced options for Debian GNU/Linux GNU/Linux' \
$menuentry_id_option 'gnulinux-advanced-5522bbcf-dc03-4d36-a3fe-2902be938ed4
If you want to select kernel from that section you need to do one or two
things. You can opt for the easy way and that is to select the nth option and
then the other nth option: GRUB_DEFAULT=1>2. Or you can pick the id:
GRUB_DEFAULT="gnulinux-advanced-5522bbcf-dc03-4d36-a3fe-2902be938ed4>gnulinux-6.12.5-amd64-advanced-5522bbcf-dc03-4d36-a3fe-2902be938ed4"
And possibly you can also pick it based on the label:
GRUB_DEFAULT="Advanced options for Debian GNU/Linux GNU/Linux>gnulinux-6.12.5-amd64-advanced-5522bbcf-dc03-4d36-a3fe-2902be938ed4"
But in all honesty I’ve never actually done this. But it seems logical.
Important: Always quote GRUB_DEFAULT when using > notation. Without
quotes, GRUB only sees the first part and ignores everything after >.
Disabling submenus
You can also disable submenus and that makes things a whole lot easier:
$ cat /etc/default/grub.d/local-config.cfg
GRUB_DISABLE_SUBMENU=y
GRUB_DEFAULT="4"
# or
GRUB_DEFAULT="gnulinux-6.12.5-amd64-advanced-5522bbcf-dc03-4d36-a3fe-2902be938ed4"
Save the last option
You can also tell grub to save the last picked option, which is what I have configured.
$ cat /etc/default/grub.d/local-config.cfg
GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true
Now when you select a kernel to boot with grub saves this choice. You can
inspect the file /boot/grub/grubenv to see which option got saved:
$ cat /boot/grub/grubenv
# GRUB Environment Block
# WARNING: Do not edit this file by tools other than grub-editenv!!!
saved_entry=gnulinux-advanced-5522bbcf-dc03-4d36-a3fe-2902be938ed4>gnulinux-6.16.11+deb14-amd64-advanced-5522bbcf-dc03-4d36-a3fe-2902be938ed4
This should be enough for you to configure grub to pick a kernel and roll with it.