GRUB is an acronym of GRand Unified Bootloader and it is a Multi-boot loader package developed by GNU to support multiple operating systems. Whenever there are more than one operating systems installed on a system, GRUB would ask the user to select any one among them during boot-up process. One can delete or modify the boot entries, change the boot times and configure GRUB dynamically.
In this article, we would see how to change the default GRUB boot entry using CLI.
So, the scenario is, I'm having two operating systems Ubuntu and Windows 7, installed on my computer. The default boot entry is Ubuntu, i.e., Ubuntu would be booted if I don't select any of the operating systems at boot-up. Being a die hard gamer, I would want Windows 7 to be booted automatically. Presently, the GRUB boot order for me is something like this:
Ubuntu, with Linux 3.8.0-3-generic
Ubuntu, with Linux 3.8.0-3-generic (recovery mode)
Memory test (memtest86+)
Memory test (memtest86+, serial console 115200)
Windows 7 (loader) (on /dev/sda1)
Step 1: In order to change default boot entry, we need to edit /etc/default/grub file. Before that, lets take a back up for the said file so that if anything goes wrong, we can easily revert back to the previous state.
Step 2: Edit the file /etc/default/grub using your favorite text editor.
sudo cp /etc/default/grub /etc/default/grub.bak
Step 3: Find a line which says
sudo gedit /etc/default/grub
All the entries in the GRUB menu are zero-indexed. This means, if there are 'N' entries in the GRUB menu, the very first entry is indexed as 0 (Zero) and the last one is indexed as 'N-1'.
Step 4: Now, our aim is to make 'Windows 7', which is listed at 5th position and hence having index 4, as the default boot entry. So, edit the same line to that it reads as
Step 5: For the changes made above to be implemented, run the following command:
And you're done !!
Note: This method will not change the order of the entries in the GRUB menu, but it would certainly boot the selected operating system.
Credits: Santosh Patil, IIT Bombay.