How to Change the Linux Boot Order by Editing the GRUB Bootloader
When using Linux, you may sometimes have multiple kernel versions installed. If you want to change the kernel used for the next boot, you can achieve this by editing the GRUB bootloader settings. Here, we will explain the method using “GRUB_DEFAULT=saved".
Check the Current Kernels
Verify the list of kernels recognized by GRUB. Run the following command to display the available bootable kernel entries.
sudo grep menuentry /boot/grub2/grub.cfg # UbuntuやCentOSで使用
Output example:
menuentry 'CentOS Linux (6...'
menuentry 'CentOS Linux (5...'
Make a note of the kernel names and order displayed here.
Change the Default GRUB Kernel
1. Edit the GRUB Configuration File
Run the following command to open the GRUB configuration file.
sudo nano /etc/default/grub
Set “GRUB_DEFAULT” as follows:
GRUB_DEFAULT=saved
With this setting, the last selected kernel will automatically become the default for the next boot.
However, you need to manually select the intended kernel for the first time only. To do this, run the following command.
sudo grub2-set-default 'CentOS Linux (6...'
2. Update the Configuration
After making changes, run the following command to update the settings.
RHEL/CentOS-based systems:
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
Verify That the Changes Took Effect
Reboot the system and confirm that the new kernel is running.
uname -r
If the output contains your desired kernel version, it was successful.
Cautions
- Incorrectly modifying GRUB settings may prevent your system from booting. Please make changes carefully.
- If you want to test multiple kernels while implementing this, it is recommended to keep a live kernel image saved for recovery.
Editing GRUB allows you to customize your Linux system to fit your needs. Try adjusting the settings to match your environment.