Grub is a boot loader for many Linux distributions which basically tells your system where it can find installed operating system(s) on one or more hard drives. Your PC needs this information in order to boot into your Linux distro successfully.
When powering on your PC, Grub begins to look for installed operating systems. If it has trouble finding one or if it can’t load part of its config, you’ll be brought to the Grub Rescue command line interface that allows you to repair the boot loader.
In this guide, we’ll show how Grub Rescue works, along with the commands you’ll need in order to repair a broken boot loader and get back into your Linux install.
If you experience a
no such partitionerror, we have a separate guide for how to fix grub error: no such partition grub rescue
In this tutorial you will learn:
- What are the Grub files?
- How to repair Grub
- What to do if Grub is completely broken
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro using grub|
|Other||Privileged access to your Linux system as root or via the
|Conventions||# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Let’s start with developing a basic understanding of grub. The grub files on your system can be found in
/boot/grub. This directory contains the grub config file
grub.cnf along with other files that are essential for grub to find and boot into your operating system(s).
If one of these files gets deleted or otherwise edited to prevent grub from doing its job, you’ll find yourself at the grub rescue menu the next time you restart your computer. Other times, fiddling with partitions in a dual boot environment can cause similar issues. Either way, you end up needing to repair grub, which is what we’ll cover next.
How to Repair Grub
When you get to a
grub> prompt, you can use the following commands as an attempt to fix your boot loader and get booted back into your Linux distro.
- Start by doing a simple
lslisting to see what partitions are available. Depending on your configuration, you may see multiple hard drives or partitions in this listing.
grub> ls (hd0) (hd0,msdos1)
- You can see the files of any partition by using another
lscommand. This will help you indentify which partition you want to boot into.
grub> ls (hd0,msdos1)/ lost+found var/ dev/ run/ etc/ tmp/ sys/ proc/ usr/ bin boot/ home/ lib lib64 mnt/ opt/ root/ sbin srv/
- Once you have determined the correct partition, you can set it as root with the following commands. For our example, we’ll be using
(hd0,msdos1)as our root partition,
/boot/vmlinuzas our Linux kernel,
/boot/initrd.imgas our image file, and
/dev/sda1as our device name. Depending on your distribution and configuration, these values may be different for you. Use tab completion to help select the right Linux kernel and image file, and
fdisk -lcommand to get the correct device name.
grub> set root=(hd0,msdos1) grub> linux /boot/vmlinuz root=/dev/sda1 grub> initrd /boot/initrd.img
- Once you have set the root partition, Linux kernel, and initrd image file, you should be able to successfully boot into your Linux distro.
- Once loaded into your system, finish repairing Grub by remaking the config file and reinstalling Grub.
# grub-mkconfig -o /boot/grub/grub.cfg # grub-install /dev/sda # reboot
What If Grub Is Completely Broken?
If you are brought to the
grub rescue> prompt when booting your computer, you’ll need to use live media to help repair your system. Once you are booted into the live environment, open up a terminal and type the following commands.
- First, mount your partition. Use
fdisk -lif you’re not sure of the correct name.
# mount /dev/sda1 /mnt
- Chroot into the installed system in order to reconfigure grub.
# chroot /mnt
- Generate a new grub config file (on Debian based systems, an alternative to the below command is
# grub-mkconfig -o /boot/grub/grub.cfg
- Lastly, install grub onto the device, exit chroot, and reboot your system as normal.
# grub-install /dev/sda # exit # reboot
This should get your Linux install back up and running, even if grub had been completely broken or deleted from your system.
If grub doesn’t work properly, your computer doesn’t know how to load Linux. It can be really intimidating when the grub prompt loads up and none of the normal Linux commands seem to work. However, rescuing grub is pretty simple once you understand how it functions and what commands to use. The steps above should help you repair grub, whether it has just been misconfigured or requires a complete reinstallation.