Technology Encyclopedia Home >How to configure GRUB in Linux?

How to configure GRUB in Linux?

Configuring GRUB (GRand Unified Bootloader) in Linux involves editing the GRUB configuration file to customize the boot process. This includes setting the default operating system, adjusting the timeout before booting the default OS, and adding or modifying kernel parameters.

To configure GRUB:

  1. Locate the GRUB Configuration File: The main configuration file for GRUB is usually located at /etc/default/grub.

  2. Edit the GRUB Configuration File: Use a text editor like nano or vim to edit the file. For example:

    sudo nano /etc/default/grub
    
  3. Modify GRUB Settings:

    • GRUB_DEFAULT: Sets the default operating system to boot. It can be set to a menu entry number or the name of the menu entry.
      GRUB_DEFAULT="Ubuntu, with Linux 5.4.0-42-generic"
      
    • GRUB_TIMEOUT: Sets the time in seconds before the default OS boots. If set to -1, GRUB will wait indefinitely.
      GRUB_TIMEOUT=10
      
    • GRUB_CMDLINE_LINUX: Allows you to add kernel parameters. For example, to enable verbose mode:
      GRUB_CMDLINE_LINUX="verbose"
      
  4. Update GRUB: After saving the changes, update GRUB to apply them.

    sudo update-grub
    
  5. Reboot: Restart the system to see the changes take effect.

    sudo reboot
    

Example: If you want to set the default OS to Ubuntu and have GRUB wait for 5 seconds before booting, you would set:

GRUB_DEFAULT="Ubuntu, with Linux 5.4.0-42-generic"
GRUB_TIMEOUT=5

For cloud environments, if you are managing Linux instances on a cloud platform like Tencent Cloud, you might need to configure GRUB remotely through SSH or the cloud provider's management console. Tencent Cloud offers services like Cloud Virtual Machine (CVM) where you can manage Linux instances and configure GRUB as needed.