Wednesday, October 10, 2007

grub got your goat?

GParted decided to balls up before finishing a move and resize job where I wanted to decrease my oversized swap partition from about 4 gigs down to 1.2 gigs and increase the size of the partition I used for storing big media files (immediately next on the disk).

So I was left with a slightly knacked partition table and decided to burn a proper GParted livecd which also contained a program called Testdisk. This was able to rebuild the partition table (although it disturbingly seemed to think the drive had 16 heads every time I loaded it, and complained that either this setting was wrong or the disk layout was crazy until I changed it to 255... every time), but at some point I managed to overwrite the MBR as well by picking the wrong option.

Attempts to reconstruct the GRUB bootloader's MBR claimed success, but actually trying to boot from the hard disk resulted in just a cursor flashing indefinitely. No message from GRUB, even.

Eventually, I found that the instructions I'd been following didn't tell me enough and that making the bootloader was a bit more involved than just:
"root (hd0, 1)
setup (hd0)",
and certainly more difficult than just running "grub-install /dev/hda2", which wasn't at all happy.

In the end, I started copying an entry from my boot partition's old GRUB menu.lst and replacing the now-inaccurate drive references:

The final sequence of commands to fix the thing was something like this:

root@gparted:~# grub
[ Minimal BASH-like line editing is supported. For
the first word, TAB lists possible command
completions. Anywhere else TAB lists the possible
completions of a device/filename. ]

grub> root (hd0,1)
grub> kernel /boot/vmlinuz-2.6.20-16-386 root=/dev/hda2 ro quiet splash
grub> initrd /boot/initrd.img-2.6.20-16-386
GRUB Error 16: Inconsistent filesystem structure
grub> setup (hd0)
[snip a few lines of blah followed by "success"!]
grub> quit

root@gparted:~# reboot

The "error 16" line when I tried to set up the initrd threw me, but after running e2fsck on the partition at least twice I decided it was just GRUB being a bollox and went ahead with it. GRUB's own filesystem mini-tests suggested things were okay anyway. So after rebooting everything was ok.... although once I logged in, I ran a command called "update-grub" which may be Ubuntu-specific. This seems to have incorrectly specified the root partition, but we'll see...

So anyway, try that more verbose tactic before executing GRUB's setup command, if you run into a similar problem.


  1. Get a Macbook with OS X! Can't go wrong!


  2. Hey Cormac (Redmond?), I've got an order in through DCU to get a sexy Macbook with 2 gigs of RAM... in fact, that reminds me to check if they've moved their arses on it yet!
    Can't wait...


  3. Yeah, it's me! Glad to hear you're getting one. I just got one too - was converted by guys in work.

  4. How's it working out for ya? I've only really used my sister's Macbook, and that for about 5 mins... are they usable?

    It took a minute to figure out how to get a terminal, and then I was like "eh.. okay, where am I now?"