Technology Encyclopedia Home >How to change the boot order of GRUB in Linux?

How to change the boot order of GRUB in Linux?

To change the boot order of GRUB (GRand Unified Bootloader) in Linux, you typically edit the GRUB configuration file. Here’s how you can do it:

  1. Open the GRUB Configuration File:

    • On most Linux distributions, you can find the GRUB configuration file at /etc/default/grub.
    • Use a text editor to open this file. For example, you can use nano or vim:
      sudo nano /etc/default/grub
      
  2. Modify the GRUB_DEFAULT Parameter:

    • The GRUB_DEFAULT parameter determines which menu entry GRUB boots by default.
    • You can set it to the index of the menu entry you want to boot first (starting from 0) or to the exact name of the menu entry.
    • For example, to set the default boot entry to the second one in the list:
      GRUB_DEFAULT=1
      
  3. Update GRUB:

    • After making changes to the GRUB configuration file, you need to update GRUB to apply these changes.
    • On Debian-based systems (like Ubuntu), use:
      sudo update-grub
      
    • On Red Hat-based systems (like CentOS), use:
      sudo grub2-mkconfig -o /boot/grub2/grub.cfg
      
  4. Reboot the System:

    • Finally, reboot your system to see the changes take effect:
      sudo reboot
      

Example:
If you have a Linux system with multiple operating systems installed and you want to change the default boot OS from Windows to Linux, you would:

  • Open /etc/default/grub in a text editor.
  • Find the GRUB_DEFAULT line and set it to the index of the Linux entry.
  • Save the file and run sudo update-grub.
  • Reboot the system.

For cloud-related tasks, such as managing virtual machines or deploying applications, you might consider using services like Tencent Cloud’s Elastic Compute Service (ECS), which provides scalable and reliable cloud computing capabilities.