Grub2 / Troubleshooting
GRUB 2’s ability to fix boot problems is greatly improved over the original GRUB bootloader. In addition to an automatic fallback mode if booting from a menuentry in a submenu, GRUB 2 allows the user to edit its menu before the operating system is loaded. The rescue mode GRUB 2 terminal can help boot an operating system so that permanent repairs to system files can be made.
The instructions on this page are written for a fully-installed Ubuntu operating system. WUBI boot problems are not covered in detail although they are addressed in several sections.
Overview
- GRUB has failed to find even the most basic information, usually contained in the MBR or boot sector.
Each of the GRUB 2 failure modes can normally be corrected either from the GRUB 2 terminal or by using an Ubuntu LiveCD. Additionally, there are compatible 3rd party bootable "rescue" CD/USB options which may also work. If using an Ubuntu LiveCD, it is recommended, but not always necessary, to use the same version CD as the system you are trying to repair. This ensures compatability of any modules and configuration files that may be loaded while attempting to repair the system.
GRUB 2 Terminal Commands
Normal
When GRUB 2 is fully functional, the GRUB 2 terminal is accessed by pressing c. If the menu is not displayed during boot, hold down the SHIFT key until it appears. If it still does not appear, try pressing the ESC key repeatedly.
-
A few of the more important commands:
When GRUB 2 is unable to boot or display the GRUB 2 menu the system will be left at a GRUB 2 terminal if possible. If the system boots to the grub> prompt, the usual modules and commands are normally available. The user may need to manually load modules using the insmod [module] command before some commands will work.
grub rescue>
In the grub rescue mode, only a limited set of commands are available. These commands are sufficient to investigate the contents of the drives, set prefix (path to the grub folder) and root (partition), load modules and boot.
General Troubleshooting Preparation
Boot-Repair
The majority of this guide is devoted to working with the GRUB 2 terminal, which is used to enter commands to attempt to repair a broken bootloader. Boot-Repair is a GUI application which can automatically analyze boot problems and select the proper course of action to repair them. Its simple interface provides beginners as well as experienced Linux users an easy method of repairing the majority of GRUB 2 problems.
Additionally, Boot-Repair contains an automated method to run a boot info script which performs a series of tests and provides a file containing much valuable information regarding the status of the computer’s operating and boot systems. This file can be inspected by community helpers on forums or IRC channels to help diagnose boot problems.
Boot-Repair can be run from a LiveCD or an operating Linux system. To download the package run the following commands:
Visit the Boot-Repair community document for more information.
Boot-Repair is available from the Launchpad repositories and can be run from a CD or a working Linux OS.
Search & Set
A great many boot problems are due to incorrect paths to required files. The GRUB 2 terminal, in either ‘failure’ mode, provides a robust ability to search hard drive(s) and partitions and to inspect their contents.
In order to boot successfully, the root, prefix, linux and initrd variables must be correct. The user must verify the paths and names of these items. If they are incorrect, use the commands below to find and fix them. GRUB 2 variable settings can be viewed with the set command.
In the following examples, X is a hard drive number; Y is a partition number. If a command example includes either of these replace them with the appropriate value.
Rescuing a Non-booting GRUB on Linux
We’re going to learn how to fix two of the more common failures. When you boot up your system and it stops at the grub> prompt, that is the full GRUB 2 command shell. That means GRUB 2 started normally and loaded the normal.mod module (and other modules which are located in /boot/grub/[arch]/ ), but it didn't find your grub.cfg file. If you see grub rescue> that means it couldn't find normal.mod , so it probably couldn't find any of your boot files.
How does this happen? The kernel might have changed drive assignments or you moved your hard drives, you changed some partitions, or installed a new operating system and moved things around. In these scenarios your boot files are still there, but GRUB can’t find them. So you can look for your boot files at the GRUB prompt, set their locations, and then boot your system and fix your GRUB configuration.
GRUB 2 Command Shell
When you’re at the grub> prompt, you have a lot of functionality similar to any command shell such as history and tab-completion. The grub rescue> mode is more limited, with no history and no tab-completion.
There must be no spaces on either side of the equals sign. Now let’s do a little exploring. Type ls to list all partitions that GRUB sees:
What’s all this msdos stuff ? That means this system has the old-style MS-DOS partition table, rather than the shiny new Globally Unique Identifiers partition table (GPT).
If you're running GPT it will say (hd0,gpt1) .
Now let’s snoop. Use the ls command to see what files are on your system:
Hurrah, we have found the root filesystem. You can omit the msdos and gpt labels. If you leave off the slash it will print information about the partition. You can read any file on the system with the cat command:
Booting From grub>
This is how to set the boot files and boot the system from the grub> prompt. We know from running the ls command that there is a Linux root filesystem on (hd0,1) , and you can keep searching until you verify where /boot/grub is. Then run these commands, using your own root partition, kernel, and initrd image:
The first line sets the partition that the root filesystem is on.
The second line tells GRUB the location of the kernel you want to use. Start typing, /boot/vmli and then use tab-completion to fill in the rest. Type root=/dev/sdX to set the location of the root filesystem. Yes, this seems redundant, but if you leave this out you'll get a kernel panic.
How do you know the correct partition? hd0,1 = /dev/sda1. hd1,1 = /dev/sdb1. hd3,2 = /dev/sdd2. I think you can extrapolate the rest.
The third line sets the initrd file, which must be the same version number as the kernel.
The fourth line boots your system.
Booting From grub-rescue>
If you’re in the GRUB rescue shell the commands are different, and you have to load the normal.mod and linux.mod odules:
Tab-completion should start working after you load both modules.
Making Permanent Repairs
So far we have made temporary changes on the terminal, so they will work only once and when we reboot again we have to do the same thing.
To get rid of this hassle we have to make settings permanent and as now We have successfully booted your system, run these commands to fix GRUB permanently:
When you run grub-install remember you're installing it to the boot sector of your hard drive and not to a partition, so do not use a partition number like /dev/sda1 .
But It Still Doesn’t Work
If your system is so messed up that none of this works, try the Super GRUB2 live rescue disk. The official GNU GRUB Manual 2.00 should also be helpful.
If you find something wrong or have any question about the solution then comment down below, you can also contact us using contact form.
Classic SysAdmin: How to Rescue a Non-booting GRUB 2 on Linux
This is a classic article written by Carla Schroder from the Linux.com archives. For more great SysAdmin tips and techniques check out our free intro to Linux course.
Once upon a time we had legacy GRUB, the Grand Unified Linux Bootloader version 0.97. Legacy GRUB had many virtues, but it became old and its developers did yearn for more functionality, and thus did GRUB 2 come into the world.
GRUB 2 is a major rewrite with several significant differences. It boots removable media, and can be configured with an option to enter your system BIOS. It’s more complicated to configure with all kinds of scripts to wade through, and instead of having a nice fairly simple /boot/grub/menu.lst file with all configurations in one place, the default is /boot/grub/grub.cfg . Which you don’t edit directly, oh no, for this is not for mere humans to touch, but only other scripts. We lowly humans may edit /etc/default/grub , which controls mainly the appearance of the GRUB menu. We may also edit the scripts in /etc/grub.d/ . These are the scripts that boot your operating systems, control external applications such as memtest and os_prober , and theming. /boot/grub/grub.cfg is built from /etc/default/grub and /etc/grub.d/* when you run the update-grub command, which you must run every time you make changes.
The good news is that the update-grub script is reliable for finding kernels, boot files, and adding all operating systems to your GRUB boot menu, so you don’t have to do it manually.
We’re going to learn how to fix two of the more common failures. When you boot up your system and it stops at the grub> prompt, that is the full GRUB 2 command shell. That means GRUB 2 started normally and loaded the normal.mod module (and other modules which are located in /boot/grub/[arch]/ ), but it didn’t find your grub.cfg file. If you see grub rescue> that means it couldn’t find normal.mod , so it probably couldn’t find any of your boot files.
How does this happen? The kernel might have changed drive assignments or you moved your hard drives, you changed some partitions, or installed a new operating system and moved things around. In these scenarios your boot files are still there, but GRUB can’t find them. So you can look for your boot files at the GRUB prompt, set their locations, and then boot your system and fix your GRUB configuration.
GRUB 2 Command Shell
The GRUB 2 command shell is just as powerful as the shell in legacy GRUB. You can use it to discover boot images, kernels, and root filesystems. In fact, it gives you complete access to all filesystems on the local machine regardless of permissions or other protections. Which some might consider a security hole, but you know the old Unix dictum: whoever has physical access to the machine owns it.
When you’re at the grub> prompt, you have a lot of functionality similar to any command shell such as history and tab-completion. The grub rescue> mode is more limited, with no history and no tab-completion.
If you are practicing on a functioning system, press C when your GRUB boot menu appears to open the GRUB command shell. You can stop the bootup countdown by scrolling up and down your menu entries with the arrow keys. It is safe to experiment at the GRUB command line because nothing you do there is permanent. If you are already staring at the grub> or grub rescue> prompt then you’re ready to rock.
The next few commands work with both grub> and grub rescue> . The first command you should run invokes the pager, for paging long command outputs:
There must be no spaces on either side of the equals sign. Now let’s do a little exploring. Type ls to list all partitions that GRUB sees:
What’s all this msdos stuff ? That means this system has the old-style MS-DOS partition table, rather than the shiny new Globally Unique Identifiers partition table (GPT). (See Using the New GUID Partition Table in Linux (Goodbye Ancient MBR). If you’re running GPT it will say (hd0,gpt1) . Now let’s snoop. Use the ls command to see what files are on your system:
Hurrah, we have found the root filesystem. You can omit the msdos and gpt labels. If you leave off the slash it will print information about the partition. You can read any file on the system with the cat command:
Reading /etc/issue could be useful on a multi-boot system for identifying your various Linuxes.
Booting From grub>
This is how to set the boot files and boot the system from the grub> prompt. We know from running the ls command that there is a Linux root filesystem on (hd0,1) , and you can keep searching until you verify where /boot/grub is. Then run these commands, using your own root partition, kernel, and initrd image:
The first line sets the partition that the root filesystem is on. The second line tells GRUB the location of the kernel you want to use. Start typing /boot/vmli , and then use tab-completion to fill in the rest. Type root=/dev/sdX to set the location of the root filesystem. Yes, this seems redundant, but if you leave this out you’ll get a kernel panic. How do you know the correct partition? hd0,1 = /dev/sda1. hd1,1 = /dev/sdb1. hd3,2 = /dev/sdd2. I think you can extrapolate the rest.
The third line sets the initrd file, which must be the same version number as the kernel.
The fourth line boots your system.
On some Linux systems the current kernels and initrds are symlinked into the top level of the root filesystem:
So you could boot from grub> like this:
Booting From grub-rescue>
If you’re in the GRUB rescue shell the commands are different, and you have to load the normal.mod and linux.mod modules:
Tab-completion should start working after you load both modules.
Making Permanent Repairs
When you have successfully booted your system, run these commands to fix GRUB permanently:
When you run grub-install remember you’re installing it to the boot sector of your hard drive and not to a partition, so do not use a partition number like /dev/sda1 .
But It Still Doesn’t Work
If your system is so messed up that none of this works, try the Super GRUB2 live rescue disk. The official GNU GRUB Manual 2.00 should also be helpful.
Advance your career with Linux system administration skills. Check out the Essentials of System Administration course from The Linux Foundation.
How to Use Grub Rescue to Fix Linux Boot Failure
The GRUB (Grand Unified Bootloader) is a tool for booting and loading operating system kernels and the default bootloader for systems based on the Linux kernel. Although it runs first when a machine is turned on, regular users rarely see GRUB in action. It functions automatically and requires no user input.
However, when attempting to boot another operating system alongside Linux on the same machine, the other system’s bootloader may overwrite GRUB, resulting in the inability of the Linux system to boot up.
This article will show you how to fix Linux boot failure using GRUB Rescue commands and the Boot Repair tool.
- An account with sudo privileges.
- Access to the command line.
Note: The tutorial below is written for GRUB 2, the current iteration of the GRUB bootloader.
GRUB Boot Issues
The most common reason for GRUB not booting into the operating system is another OS’s bootloader overwriting GRUB boot configuration. The problem occurs during an attempt a dual boot with an existing Linux installation. Another reason is the accidental removal of GRUB configuration files.
When GRUB is not able to boot the system, the GRUB Rescue prompt appears.
The example above shows GRUB displaying the «no such partition» error before displaying the grub rescue prompt. Another common GRUB error is «unknown filesystem», followed by the same prompt.
Sometimes, the screen may show the grub prompt only.
GRUB Rescue Commands
Below is the list of the commonly used GRUB Rescue commands. Use the commands in the prompts mentioned in the previous section.
2. The ls command lists the available partitions on the disk.
The output shows the partition list.
Use the ls command to find the partition containing the boot directory.
The example shows the boot directory in the (hd0,msdos1) partition.
3. Set the boot partition as the value of the root variable. The example uses the partition named (hd0,msdos1) .
4. Load the normal boot mode.
5. Start the normal boot mode.
The normal mode enables you to issue more complex commands.
6. Load the Linux kernel using the linux command.
7. Issue the boot command.
The system now boots properly.
Via Live image
Another way to fix your GRUB boot issues is to use a Linux live image to boot from an external device.
1. Download a live Linux installer. This example uses the Ubuntu 20.04 ISO image.
2. Use a tool such as Etcher to write the Linux image to an SD card or a USB flash drive.
3. Insert the bootable device and start the computer.
4. Select Try Ubuntu on the welcome screen.
5. When the live system boots up, connect to the internet.
6. Open the terminal and type the following command to add the repository for the Boot Repair tool.
Press Enter and wait for the repository to be added.
7. Update the repositories.
8. Install the Boot Repair tool.
9. Start the Boot Repair tool via the terminal.
10. Select Recommended repair.
Wait for the tool to finish repairing the bootloader.
Note: The Boot Repair tool is available as a live image, so you can boot it from an external drive without using another live OS.
Updating GRUB config file
When the system successfully boots up, make sure the GRUB configuration is up to date.
Run this command:
Reinstalling GRUB
Follow the steps below to reinstall GRUB on your Linux system.
1. Mount the partition containing the OS installation. The example mounts the /dev/sda1 partition to the /mnt directory.
2. Bind the /dev , /dev/pts , /proc , and /sys directories to the corresponding directories in the /mnt folder.
4. Unmount the directories when the installation completes successfully.
After reading this article, you should be able to fix your Linux boot failure using GRUB Rescue or Boot Repair utilities. For another way to fix your boot-related issues, read How to Use fsck Command.