Tip

It’s an easy fix to clean up a GRUB error on your Linux server

GRUB, the boot loader for most Linux server and desktop distributions, is one place your enterprise can't afford to have issues. When your server won’t start anything, you most likely have a GRUB error. Fortunately, it’s a simple fix to get GRUB going again.

Currently, there are two versions of

    Requires Free Membership to View

GRUB — GRUB 1 and GRUB 2 — but both essentially start a kernel that allows you to work on your Linux server. We're going to work off of enterprise Linux distributions of SUSE and Red Hat, which run GRUB 1. The steps below won't work on GRUB 2 as the code is different.

If your server powers on but doesn't boot, you probably have a GRUB error. The easiest thing to try is booting the server from a rescue disk. The installation disks for both SUSE Linux Server and Red Hat Enterprise Linux (RHEL) contain a rescue system.

Once you've booted to the rescue system, you can mount everything on your server’s hard drive. In this scenario we can use the same steps for SUSE or RHEL. The only requirement is that you know which disk contains the root file system. Here we'll assume it's on /dev/sda2.

  1. Use mkdir /temp to create a directory that you can use as the temporary mount point.
  2. Use mount /dev/sda2 /temp to mount the root file system on this directory.
  3. Use mount -o bind /dev /temp/dev to make the directory that contains all devices available as a subdirectory of /temp
  4. Use mount -t proc proc /temp/proc to mount the proc kernel interface as well.
  5. At this point, you can turn the /temp directory into your new root with chroot /temp.
  6. Now mount all remaining file systems, using mount -a.

After applying the steps described above, you can re-install GRUB. Type the grub command to open the grub> prompt. From there, type setup (hd0). This will reinstall GRUB to the master boot loader of your server.

If the setup command from the GRUB prompt fails, you can run grub-install from a shell prompt. Before using grub-install, type exit to quit the GRUBprompt, then type grub-install /dev/sda. SUSE no longer officially supports this approach, so you'll have to use grub-install.unsupported /dev/sda. Don't worry about "unsupported" in the command; it works fine anyway!

If the install fails after those approaches, you'll want to check the GRUB configuration file found in /boot/grub. On RHEL, the name of the file is grub.conf; on SUSE it's menu.lst. The contents of both files are similar, as illustrated here:

Sample grub.conf

[root@hnl ~]# cat /boot/grub/grub.conf

# grub.conf generated by anaconda

#

# You do not have to run grub after making changes to this file

# NOTE:  You have a /boot partition.  This means that

#          all kernel and initrd paths are relative to /boot/, eg.

#          root (hd0,0)

#          kernel /vmlinuz-version ro root=/dev/mapper/vg_hnl-lv_root

#          initrd /initrd-[generic-]version.img

#boot=/dev/sda

default=0

timeout=5

splashimage=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

title Red Hat Enterprise Linux (2.6.32-220.el6.x86_64)

        root (hd0,0)

        kernel /vmlinuz-2.6.32-220.el6.x86_64 ro root=/dev/mapper/vg_hnl-lv_root rd_NO_LUKS LANG=en_US.UTF-8  KEYBOARDTYPE=pc KEYTABLE=us-acentos rd_NO_MD quiet SYSFONT=latarcyrheb-sun16 rhgb crashkernel=128M rd_LVM_LV=vg_hnl/lv_swap rd_LVM_LV=vg_hnl/lv_root rd_NO_DM

        initrd /initramfs-2.6.32-220.el6.x86_64.img

[root@hnl ~]#

The most important part of the GRUB configuration file is the three lines under the line that starts with title Red Hat Enterprise Linux. First, root (hd0,0) identifies where GRUB should try to find the kernel. Since the kernel is not loaded yet, the kernel name /dev/sda1 cannot be used, and we have to use the BIOS device name (hd0,0). The second line begins with kernel / and specifies the kernel's location. It has one important argument: root=, which specifies the device containing the root file system. Finally, the initrd line identifies where the initramfs can be found. Both the kernel and initrd lines refer to a file in the / directory, the root file system that was specified on root (hd0,0).

If you encounter errors reinstalling GRUB, check that the files referred to on these lines actually exist and try again.

ABOUT THE AUTHOR: Sander van Vugt is an independent trainer and consultant living in the Netherlands. Van Vugt is an expert in Linux high availability, virtualization and performance and has completed several projects that implement all three. Sander is also a regular speaker on many Linux conferences all over the world. He is also the writer of various Linux-related books, such as Beginning the Linux Command LineBeginning Ubuntu Server Administration and Pro Ubuntu Server Administration.

This was first published in May 2012

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.