Fixing Linux boot problems with GRUB

If problems in the Linux boot process occur when GRUB is loaded find out how to figure out what went wrong using two options. You can re-install GRUB using grub-install and start your computer, or manually load GRUB through the GRUB command interface.

In the previous two parts of this series (Recovering Linux using Knoppix and Troubleshooting Linux boot problems), you have acquired some background knowledge that will help you fix Linux boot problems. Here, you'll read what you can do when your computer doesn't boot because of an error in the bootloader GRUB.

To start Linux, you need GRUB. But you may encounter a problem with GRUB that prevents your computer from booting properly. You will know this has occured because one of the following symptoms will be present:

  • GRUB is completely wiped and you see nothing but a blinking cursor when your server boots.
  • GRUB generates a generic GRUB error message
  • GRUB indicates that it cannot find a file it needs.

If you are having GRUB problems, there are two approaches to fix them. You can re-install GRUB and you can try to start your computer by manually entering GRUB in the command line. Let's start by looking how you can re-install GRUB. After that, you'll read how to manually load GRUB if you encounter a GRUB error.

Reinstalling GRUB
If you have a serious problem with the MBR on your computer, it can happen that you only see a blinking cursor at the moment your computer boots. If you have a serious problem with the MBR it is unlikely you have GRUB, therefore, you don't see a GRUB error message. Basically, in that situation it is impossible to boot your computer, so you need a rescue-CD to start it. You can use Knoppix to boot your computer.

Make sure that everything on your hard disk is mounted as described in the article mentioned before, enter a chroot environment and next use the grub-install command to install GRUB again. In case you want to install GRUB in the MBR and the hard disk is addressed by the device file /dev/sda, you would use the command grub-install /dev/sda. This command reads the GRUB configuration file (/boot/grub/menu.lst on most distributions) and based on that, writes the new GRUB bootloader to the MBR. Here is what you will see when using grub-install to re-install GRUB:

root@Knoppix:/# grub-install /dev/sda You shouldn't call/sbin/grub-install.
Please call /usr/sbin/grub-install instead! Searching for GRUB installation
directory ... found: /boot/grub Installation finished. No error reported. This
is the contents of the device map /boot/grub/device.map. Check if this is
correct or not. If any of the lines is incorrect, fix it and re-run the script
'grub-insteall'. (hd0) /dev/sda

Booting manually with GRUB
It's not always necessary to re-install GRUB. If the GRUB code still exists, but due to an issue in the GRUB configuration file you are unable to boot anymore, you can try to reboot manually. This is the best approach if GRUB gives an error message and stops. By entering all GRUB commands manually, you can see exactly where the problem occurs and that helps you in fixing the problem. In the next procedure, you can read how to manually load the GRUB configuration.

  1. To enter the GRUB boot menu, watch carefully what your computer is doing when it boots. In most cases, it shows you have to press the Escape key at the moment GRUB is processed. This brings you to the GRUB command line. Alternatively, you can boot from a rescue CD and enter the command grub to open the GRUB command line interface. Here is an example of this interface.


    Click on image for larger version
    From the GRUB command line interface, it's easy to troubleshoot GRUB.

  2. Fortunately, the GRUB shell offers you help, so that it's not strictly necessary to remember all the right commands. To get an overview of all commands that are available, just type the help command.


    Click on image for larger version
    Type "help" to get an overview of all available commands.

  3. Loading GRUB manually requires entering all of the commands from the /boot/grub/menu.lst file manually. The best approach to do this is to look at the current contents of the menu.lst. You can do that from the GRUB shell by entering the command cat /boot/grub/menu.lst. Somewhere in this file (which may contain lots of comments) you will read what your computer needs to boot.


    Click on image for larger version
    Make sure that you enter the correct commands, display the contents of the menu.lst file to get a good example.

  4. With the example on your computer's monitor, you can manually enter all the GRUB lines. That means that you have to enter the root, kernel and initrd lines. The following three lines give an example of what this could look like:
    root (hd0,0) kernel /boot/vmlinuz-2.6.24-16-server root=/dev/sda2 ro
    splash initrd /boot/initrd-2.6.24-16-server
  5. After entering these commands, your computer awaits further instructions. Basically, that means you have to enter the boot command now. By entering this command, the boot process starts. Monitor it carefully to make sure that there are no errors when booting. As your server refused to boot normally, there are chances that it will give you an error as well if you manually enter the lines from the menu.lst. If it does, make sure to find the error and try booting again, until it works out well.

At the very first stage in the boot procedure, GRUB is loaded. Things can go wrong at that stage, especially if there is an error in the MBR, in the GRUB configuration file itself, or in one of the files that is loaded by GRUB. If that happens, you can enter all the GRUB commands manually to find out what's wrong. If that doesn't work, you can also choose to reinstall GRUB.

ABOUT THE AUTHOR: Sander van Vugt is an author and independent technical trainer, specializing in Linux since 1994. Vugt is also a technical consultant for high-availability (HA) clustering and performance optimization, as well as an expert on SLED 10 administration.
 

This was first published in July 2009

Dig deeper on Linux management and configuration

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchDataCenter

SearchServerVirtualization

SearchCloudComputing

SearchEnterpriseDesktop

Close