Friday, 24 August 2012

How to alter default boot sequence using grub2 boot loader

This brief tutorial focuses on how to edit grub2 in order to change boot sequence on systems containing more then one OS. Grub2 is second generation boot-loader, going through rapid development and Linux proprietary introduces enhancements & fixes every known then to optimize the progressive grub2 boot-loader. Regarding alteration of boot order, Some tutorial out there on different webs suggest to assign a appropriate digit (0,1, or 2 depending on the desired location of boot option) to variable GRUB_DEFAULT located at /etc/default/grub. However, it does not work out for me and in any case it’s not the proper way to alter boot order. Following is the simple and appropriate way to change boot sequence.

Step 1.   To edit grub.cfg, you must have sufficient privileges or root privileges, so Login to root user.
[AnyUser@localhost ~]$ su -         //Switches to root user     
Password:                                                         //Enter root password

Step2.
[root@localhost ~]#  cat /boot/grub2/grub.cfg |grep Windows    
//mentions the exact menu entry for windows 7

Result:
menuentry 'Windows 7 (loader) (on /dev/sda1)' --class windows --class os $menuentry_id_option 'osprober-chain-32C8C533C8C4F5DF' {



[root@localhost ~]# grub2-set-default "Windows 7 (loader) (on /dev/sda1)"                       
 // Sets default option as window  menu entry

[root@localhost ~]# grub2-editenv list     // Verifies the requried default menuentry

Result:
saved_entry=Windows 7 (loader) (on /dev/sda1)


[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg   
//Construct the updated grub.cfg

 

After login to root user follow below steps to set default option to fedora.


[AnyUser@localhost ~]$ su -              
[root@localhost ~]#
cat /boot/grub2/grub.cfg |grep Fedora
[root@localhost ~]# grub2-set-default "Fedora Linux"
[root@localhost ~]# grub2-editenv list
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg

  
Note: Kernel update might causes to revert any changes made to /boot/grub/grub.cfg and then the same procedure had to be followed again. To get rid-off such repetition one must had to change the default menu entry at /etc/default/grub2/grub (i.e set GRUB_DEFAULT = Windows 7 (loader) (on /dev/sda1)). 
 
By Obzerver,

No comments:

Post a Comment