10

I am having a 5.10.0-11-cloud-amd64 kernel and have installed 5.10.0-12-amd64 kernel on Debian 11.2. I want to set 5.10.0-12-amd64 as the default kernel temporarily.I am new to Grub, How to set the default kernel as 5.10.0-12-amd64? My /lib/modules:

5.10.0-10-cloud-amd64  5.10.0-11-cloud-amd64  5.10.0-12-cloud-amd64
5.10.0-11-amd64        5.10.0-12-amd64

My /boot/ only has grub folder and no grub2 folder. Command grep -e "menuentry " -e submenu -e linux /boot/grub/grub.cfg yields :

### BEGIN /etc/grub.d/10_linux ###
set linux_gfx_mode=
export linux_gfx_mode
menuentry 'Debian GNU/Linux' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-ccb4ba21-fd62-42c9-b8eb-75a437b1747d' {
    linux   /boot/vmlinuz-5.10.0-12-cloud-amd64 root=UUID=ccb4ba21-fd62-42c9-b8eb-75a437b1747d ro console=tty0 console=ttyS0,115200 earlyprintk=ttyS0,115200 consoleblank=0 
submenu 'Advanced options for Debian GNU/Linux' $menuentry_id_option 'gnulinux-advanced-ccb4ba21-fd62-42c9-b8eb-75a437b1747d' {
    menuentry 'Debian GNU/Linux, with Linux 5.10.0-12-cloud-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.10.0-12-cloud-amd64-advanced-ccb4ba21-fd62-42c9-b8eb-75a437b1747d' {
        linux   /boot/vmlinuz-5.10.0-12-cloud-amd64 root=UUID=ccb4ba21-fd62-42c9-b8eb-75a437b1747d ro console=tty0 console=ttyS0,115200 earlyprintk=ttyS0,115200 consoleblank=0 
    menuentry 'Debian GNU/Linux, with Linux 5.10.0-12-cloud-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.10.0-12-cloud-amd64-recovery-ccb4ba21-fd62-42c9-b8eb-75a437b1747d' {
        linux   /boot/vmlinuz-5.10.0-12-cloud-amd64 root=UUID=ccb4ba21-fd62-42c9-b8eb-75a437b1747d ro single console=tty0 console=ttyS0,115200 earlyprintk=ttyS0,115200 consoleblank=0
    menuentry 'Debian GNU/Linux, with Linux 5.10.0-12-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.10.0-12-amd64-advanced-ccb4ba21-fd62-42c9-b8eb-75a437b1747d' {
        linux   /boot/vmlinuz-5.10.0-12-amd64 root=UUID=ccb4ba21-fd62-42c9-b8eb-75a437b1747d ro console=tty0 console=ttyS0,115200 earlyprintk=ttyS0,115200 consoleblank=0 
    menuentry 'Debian GNU/Linux, with Linux 5.10.0-12-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.10.0-12-amd64-recovery-ccb4ba21-fd62-42c9-b8eb-75a437b1747d' {
        linux   /boot/vmlinuz-5.10.0-12-amd64 root=UUID=ccb4ba21-fd62-42c9-b8eb-75a437b1747d ro single console=tty0 console=ttyS0,115200 earlyprintk=ttyS0,115200 consoleblank=0
    menuentry 'Debian GNU/Linux, with Linux 5.10.0-11-cloud-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.10.0-11-cloud-amd64-advanced-ccb4ba21-fd62-42c9-b8eb-75a437b1747d' {
        linux   /boot/vmlinuz-5.10.0-11-cloud-amd64 root=UUID=ccb4ba21-fd62-42c9-b8eb-75a437b1747d ro console=tty0 console=ttyS0,115200 earlyprintk=ttyS0,115200 consoleblank=0 
    menuentry 'Debian GNU/Linux, with Linux 5.10.0-11-cloud-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.10.0-11-cloud-amd64-recovery-ccb4ba21-fd62-42c9-b8eb-75a437b1747d' {
        linux   /boot/vmlinuz-5.10.0-11-cloud-amd64 root=UUID=ccb4ba21-fd62-42c9-b8eb-75a437b1747d ro single console=tty0 console=ttyS0,115200 earlyprintk=ttyS0,115200 consoleblank=0
    menuentry 'Debian GNU/Linux, with Linux 5.10.0-11-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.10.0-11-amd64-advanced-ccb4ba21-fd62-42c9-b8eb-75a437b1747d' {
        linux   /boot/vmlinuz-5.10.0-11-amd64 root=UUID=ccb4ba21-fd62-42c9-b8eb-75a437b1747d ro console=tty0 console=ttyS0,115200 earlyprintk=ttyS0,115200 consoleblank=0 
    menuentry 'Debian GNU/Linux, with Linux 5.10.0-11-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.10.0-11-amd64-recovery-ccb4ba21-fd62-42c9-b8eb-75a437b1747d' {
        linux   /boot/vmlinuz-5.10.0-11-amd64 root=UUID=ccb4ba21-fd62-42c9-b8eb-75a437b1747d ro single console=tty0 console=ttyS0,115200 earlyprintk=ttyS0,115200 consoleblank=0
### END /etc/grub.d/10_linux ###
### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###

Thanks telcoM for providing the above command

2

2 Answers 2

15

First, check /etc/default/grub. There should be a GRUB_DEFAULT= variable in it. If it is set to GRUB_DEFAULT=0 or unset, the default will be to boot the first entry in the boot menu (entry #0). If it is set to anything other than GRUB_DEFAULT=saved, the only way to reliably change the default will be to edit GRUB_DEFAULT= in /etc/default/grub and then run update-grub (or grub-mkconfig > /boot/grub/grub.cfg) as root.

If the setting is GRUB_DEFAULT=saved, then two commands, grub-reboot and grub-set-default will be usable. The former will set the kernel to boot for one boot only and then will return to the previous default. The latter will switch the GRUB default entry until you change it again, either by using grub-set-default or by selecting something else in the GRUB boot menu.

The simplest form of default setting specifies just the menu entry number (starting from entry #0 at the top). But modern GRUB menu is usually constructed to have the newest kernel in the first position, then a submenu of all the other kernels in the second position, and any other OSs and other custom entries after that submenu.

To view the GRUB menu in useful way, run grep -e "menuentry " -e submenu -e linux /boot/grub/grub.cfg. (The space after menuentry is needed to filter out some false hits.) You will see a number of fairly long menuentry and submenu lines, in the exact same order the real menu will have. Also, the entries of the submenu will be indented, while the main menu entries won't be. This will allow you to see the structure of the currently active GRUB menu without rebooting the system.

The title of the topmost menu item is usually unhelpfully just "Debian GNU/Linux" with no kernel version number, but the command I gave above will also list the linux /boot/vmlinuz-<kernel version number> ... command that is part of the first menu entry block, and that will reveal the exact kernel version that will be booted by the topmost entry.

If you need to select a menu entry that is within the submenu (i.e. its menuentry line is indented), then the default entry specification should be the identifier of the submenu line, a > character, and then the identifier of the actual menu entry you want. The menu entry identifiers can be menu entry numbers (starting from 0 in each menu), identifier strings (the quoted strings after the $menuentry_id_option on each menuentry or submenu line), or the visible titles of each menu item and submenu.

The identifier strings for Linux kernels seem to be of the form gnulinux-simple-<Linux root filesystem UUID> for the first entry, and gnulinux-<kernel version>-advanced-<Linux root filesystem UUID> for the entries in the "Advanced options ..." submenu.

The visible menu item titles in US English-configured Debian 11 are "Debian GNU/Linux" for the first item, "Advanced options for Debian GNU/Linux" for the submenu, and "Debian GNU/Linux, with Linux " for the non-recovery-mode entries in the submenu.

So, assuming your GRUB menu has no other OSs complicating the matters, you could set the 5.10.0-12-amd64 kernel as the default until you change it back by editing the GRUB_DEFAULT= line in your /etc/default/grub to:

GRUB_DEFAULT="1>Debian GNU/Linux, with Linux 5.10.0-12-amd64"

and running update-grub as root.

If you want more flexibility, you might instead set GRUB_DEFAULT=saved, run update-grub, and then run grub-set-default "1>Debian GNU/Linux, with Linux 5.10.0-12-amd64" to change the default until you change it back, or run grub-reboot "1>Debian GNU/Linux, with Linux 5.10.0-12-amd64" to change the default for one boot only.

The 1> prefix comes from the requirement to first select the submenu entry, and the fact that it's always the second entry in the main GRUB menu (i.e. menu item #1).

If you used grub-set-default, you can return to whatever kernel is currently the "latest" according to simple alpha-numeric sorting, by using grub-set-default 0.

Remember, the first entry in each menu level is numbered #0. With your menu entries, you could specify the menuentry 'Debian GNU/Linux, with Linux 5.10.0-12-amd64' line with menu entry numbers as:

GRUB_DEFAULT="1>2"

i.e. the second entry (entry #1) opens the submenu, and then pick the third entry (entry #2) of the submenu.

Or with menu titles as:

GRUB_DEFAULT="Advanced options for Debian GNU/Linux>Debian GNU/Linux, with Linux 5.10.0-12-amd64"

Or with menu ID strings as:

GRUB_DEFAULT="gnulinux-advanced-ccb4ba21-fd62-42c9-b8eb-75a437b1747d>gnulinux-5.10.0-12-amd64-advanced-ccb4ba21-fd62-42c9-b8eb-75a437b1747d"

Or with any combination of the above methods.

The advantage of using the menu titles or ID strings is that they keep referring to the same kernel even if you install & remove kernel packages, as long as the chosen kernel is still available. Using the menu item numbers would require you to check (and adjust if necessary) the settings after each kernel update, so if used together with any kind of automatic updates, it might cause nasty surprises.

6
  • 1
    It might be worth to note that "saved" will silently fail when lvm is used, as grub refuses to write to lvm-managed partitions. Commented Mar 15, 2022 at 0:19
  • Good point. GRUB's write support is very very simple: basically it relies on a /boot/grub/grubenv file already existing with enough space allocated to it, so GRUB will just change existing file contents without changing the total length of the file, so it won't have to make any changes to the filesystem metadata. For this reason, on anything that is more complex than a plain filesystem (i.e. LVM or software RAID) GRUB might refuse writing altogether, out of abundance of caution.
    – telcoM
    Commented Mar 15, 2022 at 6:35
  • Does the menu entry identifier start with 0 as topmost entry or the first sub menu entry? Commented Mar 22, 2022 at 6:52
  • 0 would be the topmost entry of the main menu. If the second entry at the main menu is a submenu, the first entry of the submenu would be 1>0. But the documentation recommends using menu identifier strings or menu titles instead of the numbers, for whatever reason.
    – telcoM
    Commented Mar 22, 2022 at 8:42
  • I have pasted the output of your command in the question and I am going to use GRUB_DEFAULT='3>Debian GNU/Linux, with Linux 5.10.0-12-amd64'for the third indented submenu entry i.e. menuentry 'Debian GNU/Linux, with Linux 5.10.0-12-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.10.0-12-amd64-advanced-ccb4ba21-fd62-42c9-b8eb-75a437b1747d' {Please can you verify it?? Commented Mar 24, 2022 at 6:50
0

Cloud images are built without support for features that are unnecessary in cloud environments.

Most hardware drivers are disabled, x32 ABI support is disabled, as are microcode updates and machine check exceptions.

The kernel that you choose will depend on the utility that you will give to the instance.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .