GNU GRand Unified Bootloader (GRUB)


Jarret W. Buse

GNU GRand Unified Bootloader (GRUB)

When a computer system is first turned on, the system performs a Power On Self Test (POST). The POST occurs when a system is turned on from an off state. The POST is used to verify valid hardware settings, initialize Basic Input Output System (BIOS), determine memory size and test hardware. Once the POST is successfully completed, external peripherals can be initialized, such as the keyboard and mouse. Finally, control is passed to the bootloader.

The bootloader is the program which starts the installed Operating System (OS). In some cases, multiple Operating Systems can be installed and the bootloader can allow the user to select which OS to start. In this article, I will cover details about one bootloader in particular, GRUB.

GRUB is installed by a Linux system by the command: “grub-install /dev/drive”.

NOTE: The drive is the drive to which GRUB will be installed. For example, the drive could be sda. The drive sda should contain a Linux OS.

When GRUB is installed to a Linux system, it is by default placed under the /boot/ folder. To specify a different folder in the installed drive, use the “--boot-directory” parameter. For example, to place GRUB in the folder “/home/jarret/GRUB” on drive sda, use the command “grub-install –boot-directory=/home/jarret/GRUB /dev/sda”.

It can be possible to make a boot image for burning to CD or DVD or even use for booting a VirtualBox session. First, create a directory such as “grub-boot”. Make a folder within it called “boot” and within “boot” called “grub”. Any needed files other than GRUB can be placed into the “grub-boot” folder. After the folders reflect the folder and file structure you require, run the command “grub-mkrescue -o grub.iso grub-boot”. The necessary GRUB files will be placed in the folder “/grub-boot/boot/grub”.

Now, let's look over the GRUB process after the POST occurs. The GRUB bootloader is read into Random Access Memory (RAM) from the hard disk where it was installed. The bootloader itself is placed within the Master Boot Record (MBR) installed on the boot drive. Once in memory, the bootloader is executed and two tests are done. The first is to see if the /boot is above the 1024th cylinder of the hard disk. The second is to check if Large Block Access (LBA) mode is used on the drive. If either of these are true, another bootloader is used from the /boot folder. Now the bootloader loads a secondary bootloader. The secondary bootloader loads the GRUB menu if it is enabled. From the menu, a selection is made to which OS control is passed. The bootloader passes control to the select OS or kernel. Control is passed by loading the specified kernel or OS into memory and executing it.

The menu will appear if the menu is enabled. On a system with only one OS, the menu is not required and control is passed to the kernel or OS without the user requiring to make a selection.

Some Operating Systems will create a chain loading situation. In this case, the MBR points to the sector where the OS is located. So when the POST is completed, control passes from the MBR to the OS. With DOS and some Windows systems, the MBR can be overwritten causing GRUB to be bypassed completely. It is best to install DOS and Windows systems first before installing other systems which install GRUB. In this way, the MBR points to GRUB.

Another booting method for GRUB is Loopback booting. Here, GRUB can be used to boot from an ISO image located on a hard drive to CD/DVD. To perform an ISO boot, you need to run the command “sudo gedit /etc/grub.d/40_custom”.

An entry needs to be added as such:

menuentry “menu_name” {
set isofile=”path/iso_file
loopback loop (hd0,1)$isofile
linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=${isofile} quiet splash
initrd (loop)/casper/initrd.lz

Add as many “menuentry” items as needed. Once done, save the file and in a terminal run “sudo update-grub”. At this point, GRUB is updated and when the system is rebooted, the new menu should appear.

Be aware that a script called os-prober is used by GRUB to scan all hard drives for available Operating Systems to add to the GRUB menu.

GRUB also allows for the menu to be customized by configuring a background image, fonts, colors, etc. To install the grub-customizer, run the following in a terminal:

  • sudo add-apt-repository ppa:danielricht
  • sudo apt-get update
  • sudo apt-get install grub-customizer

Once installed, the command “grub-customizer” can be run from a terminal to start the customizer. Now you can modify the menus as well as the color, fonts and wallpaper of the menu.

For any system requiring a bootloader to select from multiple Operating Systems, GRUB works well and is customizable.


Members online

No members online now.

Latest posts