Linux

How to Change GRUB Boot Order in Linux Within a Minute

Change Grub Boot Order
Change Grub Boot Order

When you install multiple operating systems on your computer, you are going to interact with grub at one point or another. Now grub is a boot loader that comes default with most Linux operating systems. GRUB stands for GNU GRand Unified Bootloader. It is responsible for loading your operating system from your hard disk to your main memory. By default GRUB comes with the default boot entry which is the first boot entry. You can also modify this behavior of grub and change grub boot order. You can even hide the grub menu from user and only show it when specific key is pressed.

How to change GRUB boot order

To change GRUB boot order, you need to make some modifications to the GRUB configuration file located at /etc/default/grub. So fire up your terminal and open the GRUB configuration file by typing in the below command. I used the vi as my text editor for sake of this tutorial. You can use whatever text editor you are comfortable with. Such as nano, gedit, atom etc .

#vi /etc/grub/default/grub 

When changing the GRUB boot order, the GRUB configuration file may look bit different depending upon your base distribution.


# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"

Once the file is opened, look for the GRUB_DEFAULT directive. This GRUB directive selects the default boot entry while booting. Value of GRUB_DEFAULT is the index of grub menu item to which you would like to boot to by default. It is usually set to zero. Note that the menu items are zero-indexed so zero means the first boot entry.  So count starts from zero. If you want to set the default boot entry to 3rd position put GRUB_DEFAULT value to 2, if you want to set the default boot entry to 4th position put the GRUB_DEFAULT value to 3 and so forth. Once the GRUB boot order is changed save the file.

Also check our article on how to play around Linux Files.

Once the file is saved then all you have left to change the grub boot order is generate the boot configuration file. Now this varies from distribution to distribution.

In Debain or Debian based distro such as Ubuntu, Mint, Kali etc. use the following command.

#sudo update-grub

In Rad Hat based system such as CentOS, Fedora, Scientific Linux etc. use the command below

#grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg

or

#sudo grub2-mkconfig -o /boot/grub/grub.cfg

In arch  or arch based systems such as Manjaro, Antergos, BlackArch etc. use the following command

# grub-mkconfig -o /boot/grub/grub.cfg

Be careful while editing GRUB configuration parameters to change the GRUB boot order. If not configured properly you might up end with unbootable system.

About the author

Ajay Verma

A Computer Science Graduate, who works extensively on open source projects. His Areas Of interest are: Network Security, Linux Administration, FOSS, Python, and C programming.

Add Comment

Click here to post a comment