Linux - set next boot kernel [duplicate]
Solution 1:
Display Grub Menu Entries from Command Line
I created a script grub-menu.sh
to make it easy to find the menu entry number:
Booting with Grub Menu Entry Number
If you wanted to reboot into Kernel 4.4.0-131
you would use:
sudo grub-reboot "1>6"
Getting the bash script grub-menu.sh
You can find the bash script in this Q&A: Display grub menu and options without rebooting?
Solution 2:
It seems the kernel you want to boot is in a submenu of grub (just look at the complete grub.cfg
). man grub-reboot
says:
Please note that menu items in submenus or sub-submenus require specifying the submenu components and then the menu item component. The titles should be separated using the greater-than character (
>
) with no extra spaces. Depending on your shell some characters including>
may need escaping. More information about this is available in the GRUB Manual in the section about the 'default' command.
Maybe something like grub-reboot '2>2'
will work for you.
Solution 3:
I've been in a similar situation, and wanted a simple way to reboot into a different kernel or set the default. The menus that are generated in Ubuntu do make this less than trivial.
I've put together a script called boot-kernel that makes this easier. Its not perfect, but works well for at least official ubuntu kernels.
$ sudo ./boot-kernel --setup-only
changing GRUB_DEFAULT from 0 to "saved" in /etc/default/grub
apply change to /etc/default/grub
--- /etc/default/grub 2018-01-12 19:40:38.681080878 +0000
+++ /tmp/boot-kernel.GXbsRC 2018-01-12 19:40:50.525044373 +0000
@@ -3,7 +3,7 @@
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
-GRUB_DEFAULT=0
+GRUB_DEFAULT=saved
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=0
execute: update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.0-109-generic
Found initrd image: /boot/initrd.img-4.4.0-109-generic
Found linux image: /boot/vmlinuz-4.4.0-108-generic
Found initrd image: /boot/initrd.img-4.4.0-108-generic
done
$ sudo ./boot-kernel /boot/vmlinuz-4.4.0-108-generic
GRUB_DEFAULT already set to 'saved'. no change necessary.
selected /boot/vmlinuz-4.4.0-108-generic. entry: Advanced options for Ubuntu>Ubuntu, with Linux 4.4.0-108-generic
execute: grub-reboot "Advanced options for Ubuntu>Ubuntu, with Linux 4.4.0-108-generic"