Dealing with Grub

GRUB (the grand unified boot loader) is your friend if you are running linux. Once upon a time (before grub) there was something called lilo (the linux loader) but this was so long ago most people have forgotten about it. And GRUB is a major improvement in many ways.

Usually grub gets automatically installed for you, does what it is supposed to do, and requires no attention. The rest of this guide covers the cases when things go wrong.

There are millions of grub tutorials and articles on the web. There is no decent official documentation for grub, which is a shame. There is of course the texinfo stuff, but I don't know anyone who knows how to navigate through texinfo pages.
Some pretty good articles are:

grub lingo

One of the major sources of confusion when working with grub is its way of describing disks. First of all, every hard disk (whether scsi, ata, sata) is denoted by hd. Disk numbering and partition numbering always begin with zero. Here are some examples: Confused? Don't procede till you get this straight! Also note that on some machines the BIOS numbering (which is what grub cares about) can differ from the drive numbering once linux gets going. This is rare, but you have been warned. The grub find command will be your friend here.

The grub menu

Sometimes you may need to edit the file /boot/grub/grub.conf. On some systems /etc/grub.conf is a handy symbolic link to this file, but I am not sure this is a good habit to be lured into. Note that you can just edit this file and then reboot to have changes take effect, no need to reinstall grub.

Reinstalling grub

Most commonly you install grub on the MBR of your first hard drive. There can be special reasons when you may want to install grub on a disk partition instead of the MBR. I never do this. You might want to if you had some kind of boot manager already on the MBR and wanted it to pick up grub when you decided to boot linux.

The grub-install utility is the handiest way to reinstall grub. The one time I have needed to (and had success doing so) was when I was doing a dual boot install and the windows install overwrote GRUB, allowing me to boot windows, but not linux. The fix in this case went like this:

In some cases you may add the --recheck option to the grub-install line, like so: The grub-install manual page warns against this option, but many people say it has solved their problems.

The grub prompt

You can fire up an interactive grub by just typing
grub
This gives you a grub shell with lots of commands. Grub lives in its own world, which is just a little peculiar. Hard drives all get designations like (hd0) (which would be used to specify the MBR of the first drive for example). Hard drive partitions get designations like (hd0,0) (which would be used to specify sda1, often a /boot partition).

Note that sda is known to grub as hd0, sdb is known to grub as hd1. I have seen cases where the BIOS drive error (hd0, hd1) differes from the linux logical order (sda, sdb), so keep on you toes. Also note that the linux partition numbers begin with "1" (sda1, sda2) whereas the grub partition numbers begin with "0" (hd0,0), (hd0,1).

A recommended set of commands to put grub onto the MBR of a system with an sda1 /boot partition might be:

grub
find /boot/grub/stage1 (if you have no /boot)
find /grub/stage1 (if you have a /boot)
root (hd0,0)
setup (hd0)
quit
Note that when I actually tried this, it did not do all that I had hoped it would. Running grub-install did what I wanted. After doing setup, when I tried to boot the machine it would launch grub which would present me with a prompt! Then it was necessary to use the configfile command to grub to actually boot the system. Someday perhaps I will understand this.

Miscellaneous grub tips

There is a quick one line flavor of fdisk that will show you the partition structure on all of your disks:
fdisk -l
This isn't actually a grub trick, but very often you need this information when working with grub, so I present it here.

Grub has a builtin cat command, use it like:

cat (hd0,1)/etc/fstab

If your system boots, and then presents you with a grub prompt, try this:

configfile /grub/grub.conf
It worked for me. For some reason grub in this case could not find the grub menu all by itself. The fix was to boot from an install CD (or use the trick above and then use the system to patch itself) and then:
chroot /mnt/sysimage
grub-install /dev/sda

A grub case history

After doing a big Fedora Core 11 "yum update", my machine became unbootable (halting after the word GRUB). Part of the fix was:
-- boot the Fedora 11 install/rescue DVD into rescue mode.
chroot /mnt/sysimage
grub-install /dev/sda
After this, the system booted!

There is more to the story than just this though. I had set up a /boot partition, but it was just being ignored and /boot was just a directory in root. I had just one drive with /dev/sda1 being /boot and /dev/sda3 being /. The initial install worked just fine without /boot. So I moved all the stuff from /boot on /dev/sda3 onto the /boot (which I mounted on some oddball mountpoint for the purpose). Then I edited /etc/fstab to mount /dev/sda1 on /boot (after moving the old /boot directory elsewhere. This still halted at the GRUB word (so the /boot partition may have been a red herring), but after doing the above grub-install, everything worked just fine.

Good Luck!


Have any comments? Questions? Drop me a line!

Adventures in Computing / tom@mmto.org