Skip to content

Troubles with Grub

07/09/2011

Last week I made some extensive changes to the partitions of my Linux machine. Although most of them went with no problem, nevertheless I faced some problems when I’ve changed the size and type of my boot partition. This time the problems related to Grub.

More specifically, after I resized my boot partition, changed its filetype, copied all the original files back to their previous place, I finally updated my /etc/fstab file (I used to spread my filesystem across many partitions, now I merged most of them into a single one, the boot partition) and, of course, my /boot/grub/menu.lst file. The changes to the last file were minimal and, I dare to say, secondary, since I’ve only updated the new UUIDs of my boot partition (when a partition changes in size, its UUID also changes). Everything seemed perfectly done and I’ve expected my system to normally boot after the reset. Unfortunately…And here my problems started. All related to Grub. since during computer’s startup it showed the message:

     GRUB Loading 1.5

     GRUB Error 21

I’ve made a lot of search in Internet about the source of this problem. Yet, I’m not sure about the exact cause of the problem. I have a theory, and that’s what I’m writing here down. To verify this theory more investigation is needed.

Grub gives the user 2 options of installing it either on the MBR sector of the boot disk or at the boot sector of the installed partition. My case was simply enough, since I haven’t got installed any other OS in my system and I chose to install Grub on my MBR. Since this sector is very small in size, Grub writes only a small “bootloader” code which it names Stage 1. At that point it looks for the partition where the rest of the Grub code is installed, usually in a Linux partition.

Since I hadn’t changed the files at my boot partition, where Grub should expect to find them, why that error? Well, probably the old (installed) version of Grub had no idea of the new partition type (I changed it from ReiserFS to ext4). So, my naïve approach was to simply re-install Grub. Using a Live CD I ran Grub (with root privileges, otherwise it can’t access disks or partitions) I entered:

root (hd0,0)

where my boot partition is, i.e., where Grub should find its stage2 and configuration files, and

setup (hd0)

to install the stage1 files of Grub in the MBR of my boot disk.

All these steps sounded very logical at that time, unfortunately when Grub booted again mentioned a Load Error 2, this time. I’m not sure what has happened this time, but I noticed that Grub patches the various stage1_5 files during its installation (found at /boot/grub/ in my system). So, I took the very bravery decision to remove the old stage1_5 files and re-install Grub.

No success again, but I’ve made a huge step forward. It seems that not all of them are needed for Grub to work correctly. Accidentally, I also discovered a directory lying in my system, /usr/lib/grub/, part of Grub’s distribution, where I can find the original stage1_5 files that come with Grub (in i386-pc/ sub-directory). So, I copied these files into the /boot/grub/ directory, re-installed Grub and booted my system again.

And, voilà! Since you can read this post, it means that my system is up and running. I don’t know what’s going on with Grub. I need to study more on it (and its code, of course) to find out exactly what was the problem and the solution to it. But, this is a task for another time in the future. Till then, let me enjoy again my Linux machine…

Advertisements
Leave a Comment

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: