The grub2-set-default
command is used to set the default boot kernel for a Linux system that uses the GRUB2 bootloader. This command is useful when you have multiple kernels installed on your system and you want to choose which one will be booted by default.
Overview
The syntax for the grub2-set-default
command is as follows:
grub2-set-default [OPTION] MENU_ENTRY
The MENU_ENTRY
parameter specifies which kernel you want to set as the default. This is typically specified by the position of the kernel in the GRUB menu. For example, if you want to set the second kernel in the GRUB menu as the default, you would run the following command:
grub2-set-default 1
Note that the count starts from 0. Therefore, to set the second kernel as the default, you use 1 instead of 2.
After running the grub2-set-default
command, you need to regenerate the GRUB2 configuration file to apply the changes. You can do this by running the following command:
grub2-mkconfig -o /boot/grub2/grub.cfg
You can verify the current default boot entry by running the grub2-editenv list
command, which will display the saved entry.
Options
The following table lists the available options for the grub2-set-default
command:
Option | Description |
---|---|
-h, –help | Display help information and exit. |
-v, –version | Display version information and exit. |
Troubleshooting tips
If you are unsure which kernel to set as the default, you can view the available kernels by running the following command:
awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
If you are having trouble setting the default kernel, make sure that you have specified the correct menu position.
If you have recently updated your kernel and are having trouble booting, you may need to update your GRUB configuration file. You can do this by running the following command:
grub2-mkconfig -o /boot/grub2/grub.cfg
Notes
The grub2-set-default
command is only available on systems that use the GRUB2 bootloader.
This command should be run as the root user or with sudo privileges.