What is GRUB? How to Recover Lost Operating System Data after GRUB Rescue Error?

9 minutes read
Written By
Updated On

GRUB, by definition, is a Grand Unified Boot Loader. It is a part of the program, either stored in GPT or MBR, depending on the boot set-up of the computer.

List of contents:

  1. What is GRUB?
  2. Where is GRUB located?
  3. Grub functionality
  4. Various commands in GRUB
  5. Operating systems that can be booted using GRUB
  6. GRUB tips
  7. Grub Rescue Windows 10 (no such partition error)

To understand GRUB better, let’s first understand the boot sector.
A boot sector is generally the first part of the hard drive accessed when the computer is turned on. When the computer boots up, the MBR or GPT correspondingly are accessed to load the kernel or OS files to execute and run the Operating system. These files include the drivers of various hardware components embedded on the motherboard, collectively giving a user the desired result.

What is GRUB?

Grub is a piece of software that exists in the MBR or GPT. GRUB allows users to opt between multiple Operating systems installed on one or more drives existing on the computer. There are two types of grand unified boot loaders: GRUB version 1 and GRUB version 2.

GRUB version 1 is also called the legacy GRUB. The latest GRUB, 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, which is either the master boot record or the GUID partition table, the physical allocation of the GRUB changes:

Location of GRUB in MBR & GPT (source: Wikipedia)

Figure 1: 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 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 present a boot.img is the disk image containing utilities, Operating system, kernel files, diagnostics, and 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: The File System defines the organization of files and their format. It takes care of the addressing of the data in 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 may be located at either the Master Boot Record (MBR) or GUID partition table (GPT) or 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 is, by definition, saved in the storage space between MBR and the first partition. The first partition of the hard drive is marked at the 63rd sector of the hard drive, leaving the first 62 sectors 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, enabling the user to select between the Operating systems. You can specify a default Operating system to load after a user-defined timeout. In the TUI, a selection of commands can be entered as listed below.
    GRUB Main Screen

Various Commands In GRUB:

Although a long list of Command line-based commands is available in GRUB, we primarily focus on the commands 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 the 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 a menu displayed. The default boot entry is used after the specified timeout has 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 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 an imperative command regarding any errors in the boot sector of the 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 case-sensitive. If any line in the terminal is followed by a “#” it should be considered 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:

  1. Windows
  2. Linux
  3. Solaris
  4. Solaris 9
  5. Solaris 10

Tips to know before installation of GRUB:

Tip 1: To be on the safer side, it is always recommended to have a Linux-based OS installation after the Windows-based installations. This is because 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 the older MBR allocated for GRUB. Hence, the unknown file system error comes up.

Tip 2: To boot as fast as possible without waiting for the timeout after the 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 a GRUB Rescue Error?

We know now that with GRUB's help, a computer with a single hard disk can have multiple partitions with multiple Operating systems.

When you change the alignment of the partition in one Operating system, it might affect the partitioning in the other. This is because the Operating system might use a single physical drive so that 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, while booting up, it fails to recognize the Operating system; hence, you won’t be able to access the lost partition in Windows 10. The recommended resolution is to recover Windows data and repair the Operating system.

No Such Partition Error

Also, we often would want to dispose of one of the Operating systems on the SSD or hard disk to make some free space. But this will delete the GRUB partition existing on the boot sector, leading to no such partition error, as shown below.

GRUB Rescue

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 rebuild MBR using bootable media like a DVD or USB drive. If you use an external solid-state drive as your boot drive, various SSD data recovery techniques are implemented to recover lost data on the Operating system.

About the Author: John Harris

With a decade of experience in data recovery, John Harris, Senior Editor at Remo Software, is your go-to specialist. His focus includes partition management, Windows solutions, and data troubleshooting, delivering insightful content that serves both users and search engines. John's expertise shines through in illuminating blog posts, untangling data loss intricacies across diverse storage platforms.…