How to Use GRUB Rescue

Techwalla may earn compensation through affiliate links in this story.
How to Use GRUB Rescue
Image Credit: agrobacter/E+/GettyImages

For Windows and Mac users, startup is a pretty simple thing. You turn your computer on, it loads up Windows or OSX, and you get down to doing what you do. Clearly, things are going on under the hood, but you don't usually need to know what they are. That's not the case for Linux users, who often install their OS alongside Windows or OSX, or may even have multiple Linux operating systems on their computer. Linux uses a bootloader called GRUB to manage and boot those operating systems, and GRUB rescue to fix problems when they occur.


So What Exactly Is a Bootloader?

Your computer goes through a series of steps when you turn it on. The first thing it does is run a few pieces of code built into chips on the computer that check to make sure all the appropriate pieces of hardware are present and in good working order. Then, it checks the computer's drives, usually starting with the main hard drive, to look for a small piece of software called a bootloader. The bootloader's job is to keep track of where your operating system is installed and to get it up and running for you.


Video of the Day

Single Boot vs. Multiboot Bootloaders

Both Windows and OSX have bootloaders, but those have a simple life because they each typically only load one operating system. The Linux bootloader needs to keep track of multiple operating systems and be able to load whichever one the user selects at any given time, so it's sometimes described as a multiboot bootloader. That's where the name comes from, in fact: It's an acronym for GRand Unified Bootloader. After you make your choice from the boot menu, GRUB loads the kernel – the core part of the OS – for whichever operating system you've chosen.


Mostly It Works, but Not Always

Ordinarily, the computer begins its boot and then pauses for a moment with the GRUB menu on the screen. If you don't do anything, your computer boots into whichever OS – usually Linux – you've chosen as your default. Alternatively, you can choose from any other operating system on the menu or revert to an older version of your main OS if necessary. Occasionally, though, your menu and OS doesn't load correctly, and you are kicked out to the GRUB rescue command prompt. You can also choose this option from the GRUB menu if you suspect your system has problems and want to try to fix them.


The GRUB Command Line

The GRUB command line looks much like the command line interface you'd see if you opened up a Terminal window on Linux or, for that matter, if you ran the command command from the Run box on your Windows menu. It's essentially a stripped-down version of the full Linux command line interface. You don't have the full set of Linux tools and programs at your disposal, but you have plenty of options for fixing some of the common problems you might encounter with your system.


A Quick Clarification About GRUB Versions

If you're having GRUB problems and you're crawling the internet in search of solutions, it's important to pay attention to the date of the advice you find. The original version of GRUB hasn't seen any development for over a decade and has mostly been replaced by a newer version. Older sites refer to the two versions as GRUB and GRUB2, while newer sites now refer to GRUB2 simply as GRUB, while the original version is legacy GRUB. Advice meant for legacy GRUB often won't work on a current system and might cause damage. This article assumes you're using GRUB2 on Ubuntu 18.04 LTS, although the information should apply to any current version of Linux.


The Priority GRUB Rescue Repair

Each one of the dozens of commands available to you in GRUB rescue is complicated and needs an article-length discussion of its own. That's a bit much for a quick read, so let's focus on its most important use: Getting your system up and running and fixing whatever went wrong in GRUB.


What Your Drives Are Called

GRUB and the Linux OS itself use different terminology for your hard drives. Ubuntu and other versions of Linux refer to the first hard drive in your system as sda, the second as sdb and so on. In GRUB rescue, GRUB refers to the first physical hard drive as hd0, the second as hd1 and so on. That becomes important in a moment.


GRUB Manual Boot

Follow these steps to restart your computer with GRUB rescue if the bootloader breaks, and Ubuntu – or your other OS of choice – won't load. There are plenty of other things you can fix, once your computer is running, but you need to get your computer working first before you can do them.


  1. Type the command ls to find out what partitions your hard drive contains. It'll show your actual hard drive first, as (hd0) or something similar, followed by a series of related numbers – (hd0, gpt1), (hd0, gpt2) and so on – which represent the partitions on your hard drive. If you have multiple operating systems, there can be a lot of those.
  2. Identify the system Ubuntu boots from by typing ls again but specifying a partition. You don't need to include the prefix for the partition, just the number, so a typical command might look like ls (hd0, 3) if you had checked the first two partitions and were now looking at the third. Keep going until you find one that contains the telltale Linux directories, such as bin/, boot/, dev/, etc/ and usr/. That's the one you need to boot from.
  3. Now that you know where the boot files are, you need to let GRUB in on the secret. If the correct partition was (hd0, 3), as in the example above, you'd type set root=(hd0, 3) at the GRUB command line and then click Enter.
  4. The files you need to boot the computer are on the boot/ directory of that partition, so start typing linux /boot/vmlinuz at the command prompt. It will auto-fill the correct version of the vmlinuz file for you with a lengthy number identifying the Linux kernel version. Select the Tab key to accept it. Before you press Enter, add the root command again, but this time instead of saying root=(hd0, 3) – which is GRUB's terminology for the third partition of the first hard drive – you type root=/dev/sda3, which, you'll remember, is how Linux itself identifies the same partition.
  5. Type initrd at the GRUB command line and again click the Tab key to accept its suggestion – it should match the kernel number from the previous command – and then Enter.
  6. Type boot at the prompt to boot your system.


If Your Prompt Says Grub Rescue>

Ordinarily, your command line prompt at this stage should read grub>, but if your system is really messed up, it might say grub rescue> instead. This means you're using a bare-bones version of the GRUB rescue shell, and you won't be able to use the Tab key to complete your commands. Instead, you'll need to find those long version numbers manually and write them down. Assuming they're on the same partition, you do it like this:

  1. Type ls (hd0, 3) /boot and look at the information on the screen. The two files you're looking for are the one starting with vmlinuz and the one starting with initrd. Write them down or snap a shot of the screen with your phone's camera so you can refer to it carefully, digit by digit.
  2. Now type set root=(hd0, 3) and press Enter. At this point, you need to manually load two modules that would have been loaded for you if you were getting the grub> prompt. These use the insmod command, short for "install module."
  3. Type insmod normal and press Enter. Now type normal to run the module you've just installed. Finally, type insmod linux and press Enter, so you can move on to specify the boot files.
  4. Type that same linux command, but this time you'll fill it out manually from start to finish. For an Ubuntu 18.04 system on the same partition we've used as our example throughout, that might read linux /boot/vmlinuz-4.15.0-44-generic and follow it again with root=/dev/sda3 before pressing Enter.
  5. Do the same with the initrd command, also using the entire number you've written down. In the example, it would look like initrd.img-4.15.0-44-generic.
  6. Type boot and press Enter to boot your system.

Reinstalling GRUB After You've Booted

Your computer should boot up normally at this point, and you should be able to log in as you usually would. This isn't a process you want to use every day, though, so priority one is to fix GRUB properly. Click the Applications icon at the bottom of your Dash and type Terminal into the search bar. Once your Terminal window is open, type update-grub and press Enter. Several things will happen and then you'll get a message saying done and be back to the GRUB command line. Type grub-install /dev/sda, assuming your partition was on the first physical drive. GRUB is now reinstalled, and your computer should start normally when you reboot.

If You're Intimidated at This Point

The Linux community, in general, has always had a healthy DIY attitude, but if you're new to the Linux world or just want to get your computer back up and running with a minimum of fuss, you might find these manual repairs cumbersome. There are automated tools you can use instead, which don't need you to get your hands dirty playing with the actual workings of GRUB and Linux. Boot-repair is an example.

Using Boot-Repair Instead

To use boot-repair, you need the DVD or USB drive you used to install Ubuntu. If you don't have it, borrow a working computer long enough to download and burn a new copy. When you have it, put the OS into the disk drive or USB port, as needed, and reboot your computer. You might need to enter the bootup menu screen by pressing Esc or F2 as your computer boots and tell it to check the DVD drive or USB drive before trying to boot from the hard drive. Once that's done, choose Try Ubuntu from the disc's boot menu.

Downloading and Installing Boot-Repair

The disc or USB will take you to a slow but fully functional Ubuntu desktop, where you can do all the things you normally do with your computer. The boot-repair program is maintained as a personal package archive (PPA), so the first thing you need to do is add the appropriate PPA as a software source for your computer.

  1. Open a terminal window and type sudo add-apt-repository ppa:yannubuntu/boot-repair.
  2. Then type sudo apt update.
  3. Finally, type sudo apt install boot-repair to install the program.

Running Boot-Repair

To run the actual boot-repair utility, type boot-repair in the same terminal window. Boot-repair will scan your system for GRUB- and boot-related issues and then pop up a dialog box. From the box, you can choose to fiddle around with manual settings or select Recommended repair to have boot-repair fix the most common problems for you automatically. When it's done, it will usually tell you repairs have been completed and give you a link you can click to read a log file explaining everything that's been done. To finish, restart your computer, remove the boot disc when prompted, and then wait while it boots normally.