GNU GRUB is a bootloader, capable of loading various operating systems when the system starts up. GRUB stands for GRand Unified Bootloader. It is the successor to LILO (LInux LOader), the original bootloader for Linux-based proprietary Operating Systems. GRUB has the following advantages over LILO:
- GRUB support unlimited no of boot selections, while LILO supports only 16.
- Unlike LILO, GRUB supports booting over a network.
- LILO does not have an interactive command interface like GRUB.
Well, before we begin with this tutorial lets understand how GRUB actually works.
When you switch on a computer, the first thing that occurs is a POST, commonly known as Power On Self Test. This basically checks the computer for various devices that are connected to the computer and subsequently the BIOS comes into further action. The BIOS then transfers the control to the boot device, which can be any BIOS-recognized device.
The first sector stored on a hard disk is called Master Boot Record (MBR), which is usually 512 bytes long and contains a very small piece of code called primary boot loader and partition table describing the various partitions on the disk.
The MBR then loads the active partition and loads it into the memory and passes the control to it.
GRUB works in 3 stages
Stage 1: It is located in the MBR and mainly points to the second stage, however it normally loads up the Stage 1.5.
Stage 1.5: It contains the file system drivers, which allows it to load Stage 2 directly from any known location.
Stage 2: Loads the configuration file that contains all of the user interface and options that are displayed on the screen.
The advantage of this Stage architecture is that it allows GRUB to be large enough to allow for fairly more complex and configurable options as compared to other bootloaders.
Now that you have a fairly reasonable idea of how GRUB works, lets tweak it according to our needs and customize GRUB2 in Ubuntu.
GRUB2 stores it’s main configuration in the /boot/grub/grub.cfg file. However, we need not edit it in any way, as we will see that it automatically gets updated. The user’s settings are stored in /etc/default/grub file. We will be editing this file to change the GRUB’s settings. Other scripts are located in /etc/grub.d/ directory.
Editing the file
First we need to install the gksu program, if not already installed. Open the terminal by pressing Ctrl+Alt+T, and type the following command
sudo apt-get install gksu
Enter the password and press “y” or “Y” when prompted to.
Open the configuration file by installing the following command:
gksu gedit /etc/default/grub
Enter the password when prompted to and the configuration file will open up in the editor.
Choosing a background image:
By default GRUB uses a monochrome look. You can add a line in then like
to specify the image file to be used by GRUB in the background.
There is however a number of restrictions on the file type and format, so you can download splash images by typing the following command in the terminal
sudo apt-get install grub2-splashimages
Once installed, the images are located in the /usr/share/images/grub folder.
Change the Default OS
You can change the default OS, by modifying the GRUB_DEFAULT= line.Use GRUB_DEFAULT=0 uses the first entry as default, change it 1 to use the second entry as the default OS, change it to 2 for second entry and so forth.
If you want to be more specific, you can type the label, for e.g.
GRUB_DEFAULT=”Windows 7 (loader)”
Change the GRUB timeout
You can change the GRUB timeout by changing the GRUB_TIMEOUT=10 line and enter the time in seconds. For e.g.
Update the changes
Type the following command to update your changes.
Restart your computer to see the changes take effect !!