GRUB by definition is Grand Unified Boot Loader. It is a part of program either stored in GPT or MBR depending on the boot set-up of the computer.
List of contents:
- What is GRUB?
- Where is GRUB located?
- Grub functionality
- Various commands in GRUB
- Operating systems that can be booted using GRUB
- GRUB tips
- Grub Rescue windows 10 (no such partition error)
To understand GRUB better let’s first understand what is a boot sector?
A boot sector is generally the first sector of the hard drive that is accessed when the computer is turned on. When the computer boots up the MBR or GPT correspondingly are accessed to load the kernel files or OS files to execute and run the Operating system. These files include the drivers of various hardware components embedded on the mother board which collectively give the desired end result of a user.
What is GRUB?
Grub is a piece of software that exists in the MBR or GPT. Broadly speaking, GRUB allows a user to opt between multiple Operating systems that are installed on one or more drives existing on the computer. There are two types of grand unified boot loaders namely GRUB version 1 and GRUB version 2.
GRUB version 1 is also called the legacy GRUB. The latest version of GRUB that is GRUB version 2 is designed for UEFI based systems. The functionality of each Version is discussed in the later subsections.
Where is Grub located in the boot sector?
Depending upon the boot sector that is either the master boot record or the GUID partition table the physical allocation of the GRUB changes:
Figure1: Location of grub in MBR and GPT (image source: Wikipedia)
boot.img has the exact size of 446 bytes and is written to the MBR (sector 0). core.img is written to the empty sectors between the MBR and the first partition, if available (for legacy reasons the first partition starts at sector 63 instead of sector 1, but this is not mandatory). The /boot/grub directory can be located on a distinct partition, or on the root partition as shown in the picture above.
How does GRUB function?
To understand the functionality of GRUB better we first define a set of terminology:
boot.img: To simply present a boot.img is the disk image containing utilities, Operating system, kernel files, diagnostics and various other drivers for the hardware to initiate.
core.img: It is the default RAW disk image loaded on the hard disk by the manufacturer.
File system: File system defines the organization of files and their format. It takes care of the addressing of the data onto a physical sector. Ex: NTFS, FAT, Ex-FAT, HFS etc.
The functionality of GRUB can be classified into three stages:
- Stage 1: In the primary stage of GRUB the boot.img which may be located at either Master Boot Record (MBR) or GUID partition table (GPT) or alternatively in any of the VBR (Volume Boot Record). At this stage GRUB directs the next stage using an address of the kernel files of various Operating systems. During the installation time GRUB is configured to load the first sector of the core.img.
- Stage 1.5: In this stage the core.img which is by definition saved in the storage space that exists between MBR and the first partition. The first partition of the hard drive is marked at 63rd sector of the hard drive leaving the first 62 sectors to be free of any file system or partition. After the execution the core.img will load the file needed for configuration with various other modules like file system drivers acquired from boot.img. Finally the 2nd stage is loaded after the file path(/boot/grub) specification is provided.
- Stage 2: In this final stage a Text-based User Interface is displayed which will enable the user to select between the Operating systems. You can specify a default Operating system to load after a user define timeout. In the TUI a selection of commands can be entered as listed below.
VARIOUS COMMANDS IN GRUB:
Although there are a long list of Command line based commands available in GRUB, we primarily focus on the commands that are specific to the OS selection menu in this article. The five major menu GRUB commands are listed as follows:
Press “c” once the operation system selection is displayed to open command prompt
I. timeout: When used, this command shall acknowledge the computer to wait for a specified time in seconds before the default entry is loaded. Example: timeout sec
II. hiddenmenu: This command can be used to hide the menu. Once this command is used you no longer will have menu displayed. The default boot entry is used after the specified timeout is expired. Example: hiddenmenu
III. title: Use this command to set a new entry in the menu with a designated name. Usually this is done after installing a new secondary Operating system on the computer. Example: title name
IV. default: this command will let you specify a default Operating system to load if the any item in the menu is not selected within the predefined timeout. Example: default num, the “num” here is the number of the OS partition as displayed in the menu listed.
V. fallback: fallback is a very important command when it comes to any errors in the boot sector of primary/default OS. Hence if the default entry fails to load-up, the secondary option specified as a fallback will load making it a redundant OS. Example: fallback num, the “num” here is the number of the of the secondary boot file as displayed in the menu listed.
Note: It is to be noted that all the commands are cases sensitive. If any line in the terminal is followed by a “#” it is to be considered as a comment rather than a command.
What Operating systems can be booted using GRUB?
The various Operating systems that can be booted using grub are as follows:
- Solaris 9
- Solaris 10
Tips to know before installation of GRUB:
Tip1: To be at a safer side it is always recommended to have a Linux based OS installation after the Windows based installations. This is because the when Windows is installed after the Linux OS, The MBR preinstalled during Linux installation is replaced by a newer MBR of windows consequentially overwriting the space in older MBR allocated for GRUB. Hence the unknown file system error comes up.
Tip2: To have a boot as fast as possible without waiting for the timeout after grub menu has loaded, you can use the command etc/default/grub/GRUB_FORCE_HIDDEN_MENU="true". This command will only bring up the Operating system menu if you press and hold the shift key during grub startup.
How to recover data after grub rescue error?
We know now that with the help of grub a computer having a single hard disk can have multiple partitions with multiple Operating systems.
When you change the alignment of partition in one Operating system it might affect the partitioning on the other. This is because the Operating system might use a single physical drive and hence it might overlap with other partitions. Reinstallation of the OS is also one of the causes of the GRUB rescue error. This problem is most common for the computers installed with Windows 10.
At this stage the computer while booting up fails to recognize the Operating system and hence you won’t be able to access the lost partition in Windows 10. The recommended resolution is recover lost data and repair the Operating system.
Also many a times we would want to dispose one of the Operating systems that exist on the SSD or hard disk to make some free space. But this will delete the GRUB partition existing on the boot sector which will lead to no such partition error as shown below.
The best way to confront this problem is to recover the partition without losing data. This can be achieved with the help of an advanced data recovery tool.
Once the data has been recovered you can then rebuild MBR using bootable media like DVD or USB drive. If you are using an external solid state drive as your boot drive there are various SSD data recovery techniques that are implemented to recover lost data on the Operating system.