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.
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
Currently, there are two versions of 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.
- Use mkdir /temp to create a directory that you can use as the temporary mount point.
- Use mount /dev/sda2 /temp to mount the root file system on this directory.
- Use mount -o bind /dev /temp/dev to make the directory that contains all devices available as a subdirectory of /temp
- Use mount -t proc proc /temp/proc to mount the proc kernel interface as well.
- At this point, you can turn the /temp directory into your new root with chroot /temp.
- 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:
[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
title Red Hat Enterprise Linux (2.6.32-220.el6.x86_64)
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
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 Line, Beginning Ubuntu Server Administration and Pro Ubuntu Server Administration.