Linux Server Diary

The trials and tribulations of a Linux newbie trying to setup a home server.

Saturday, January 05, 2008

Restore GRUB

So, I decided to mess around with some bootleg software, and it got me in trouble. My GRUB install was all screwed up, and I had to fix it.

My son had downloaded one of those cracked versions of OSX Leopard that would run on a non-MAC Intel machine. The install seemed to run OK, but it wouldn't boot. After a couple of tries, I gave up.

But there was a problem, it seems that when I reformatted a partion from FAT32 to HFS+, the Mac disk utility renumbered some of the partitions. The linux partition that was on sda7 was now called sda6. I didn't expect that to happen. Vista would boot fine, but not Mint.

I had to do a couple of things to get things back. First, I setup GRUB to look for the /boot folder in the right place. I found a page that walked me through the steps to restore GRUB. Here's a quick summary:
sudo grub
find /boot/grub/stage1
(this will return the drive name - mine is hd0,5)
root (hd?,?) (use the drive name returned in the previous step)
setup (hd0)
quit

But that's not all. Since the partitions were renamed, I had to modify the GRUB menu file to point to the right one. First, I had to boot to the live CD and mount the linux partition.
sudo mkdir /media/sda6
cd /media/sda6
sudo mount -t ext3 -o defaults /dev/sda6 /media/sda6
(use your own partition name)

Next, I edited the file /boot/grub/menu.lst to reflect the correct partition:
sudo nano boot/grub/menu.lst

In this section:
title Linux Mint
root (hd0,6)
kernel /boot/vmlinuz-2.6.22-14-generic root=/dev/sda7 ro quiet splash
initrd /boot/initrd.img-2.6.22-14-generic
boot

I changed the root to point to (hd0,5) and the kernel root path to dev/sda6. After a reboot, everything was back to normal.

Next time I'm tempted with Mac software, I hope that I'll resist.