Boot a specific installed Ubuntu kernel using grub-reboot and grub-set-default.
This allows you to pick what kernel you want to boot on next reboot, or set the default, without having to know much about how grub works or editing config files.
Usage: boot-kernel [options] [kernel]
call grub-reboot or grub-set-default to boot the provided kernel.
options:
-n | --dry-run do not make changes, only report what would be done.
--setup-only only setup 'saved' in /etc/default/grub.
do not supply kernel with --setup-only.
--default run 'grub-set-default' rather than 'grub-reboot'
Examples:
* boot kernel /boot/vmlinuz-4.13.0-17-generic next time.
$ boot-kernel /boot/vmlinuz-4.13.0-17-generic
* edit /etc/default/grub to enable 'saved'
$ boot-kernel --setup-only
* set the default kernel.
$ boot-kernel --default /boot/vmlinuz-4.15.0-22-generic
$ reboot
Here is an example of using boot-kernel on a 16.04 instance to toggle back and forth between the HWE kernel and the generic -virtual kernel.
-
Install a second kernel.
% apt-get install -qy linux-image-virtual-hwe-16.04 % ls /boot/vmlinuz-* /boot/vmlinuz-4.13.0-45-generic /boot/vmlinuz-4.4.0-128-generic
-
run with
--setup-only
to setup. Note that setup would be done anyway if necessary.% ./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-06-14 20:28:15.832442556 +0000 +++ /tmp/boot-kernel.1FIHGf 2018-06-14 20:28:18.520417934 +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.13.0-45-generic Found initrd image: /boot/initrd.img-4.13.0-45-generic Found linux image: /boot/vmlinuz-4.4.0-128-generic Found initrd image: /boot/initrd.img-4.4.0-128-generic done
-
boot into the older kernel. With a 4.4 and 4.13 kernel installed we would normally reboot into 4.13.
% sudo ./boot-kernel /boot/vmlinuz-4.4.0-128-generic GRUB_DEFAULT already set to 'saved'. no change necessary. selected /boot/vmlinuz-4.4.0-128-generic. entry: Advanced options for Ubuntu>Ubuntu, with Linux 4.4.0-128-generic execute: grub-reboot "Advanced options for Ubuntu>Ubuntu, with Linux 4.4.0-128-generic"
That used
grub-reboot
to update/boot/grub/grubenv
to set thenext_entry
.% head -n 2 /boot/grub/grubenv # GRUB Environment Block next_entry=Advanced options for Ubuntu>Ubuntu, with Linux 4.4.0-128-generic
Now reboot and see that it worked.
% reboot ... % uname -r 4.4.0-128-generic
Because it used
grub-reboot
and notgrub-set-default
the next time we will reboot back into the default/newest kernel.% head -n 2 /boot/grub/grubenv # GRUB Environment Block next_entry=
-
Make this the default.
% sudo ./boot-kernel --default /boot/vmlinuz-4.4.0-128-generic GRUB_DEFAULT already set to 'saved'. no change necessary. selected /boot/vmlinuz-4.4.0-128-generic. entry: Advanced options for Ubuntu>Ubuntu, with Linux 4.4.0-128-generic execute: grub-set-default "Advanced options for Ubuntu>Ubuntu, with Linux 4.4.0-128-generic" Searching for GRUB installation directory ... found: /boot/grub % head -n 2 /boot/grub/grubenv # GRUB Environment Block saved_entry=Advanced options for Ubuntu>Ubuntu, with Linux 4.4.0-128-generic
- Power Bare Metal: Note, that on power8 bare metal systems (such as ubuntu ppc64el) the boot loader used is not actually grub2, it is petitboot. petitboot does not seem to support this function. I've filed upstream petitboot issue 24.
This was originally put together from googling. The following articles were helpful: