How to reinstall or recover GRUB/MBR on an Intel Mac?

I'm on a triple boot MacBook (OSX, Ubuntu, Windows). Windows started misbehaving and needed to be re-installed (as it often does). After reinstalling windows, the MBR now points to Windows directly and not GRUB.

GRUB recovery which works on most MRB Partition Table, did not on this GPT Partition table:

$ sudo grub-install --root-directory /media/ubuntu /dev/sda

Ubiquity knows how to do this correctly. Which command can I run to recover GRUB/MBR on an Intel Mac?

SOLUTION: This was not simple but I found out how to do it. Thanks to Colin Watson and to the Debian IntelMac[1] Documentation for each giving me parts of the solution.

Here is what I did:

1) Boot From LiveCD

2) Go to places and mount partition with Ubuntu

3) Press CTRL-L in nautilus or use the mount command to find out where that partition is mounted (example: /media/123)

4) Open a Terminal (Application > Accessories > Terminal)

5) Run the following commands:

$ for x in dev proc sys; do sudo mount --bind /$x /media/123/$x; done

$ sudo chroot /media/123

# dhclient

# apt-get install grub-pc os-prober gptsync

# gptsync /dev/sda # Say YES

# grub-install --force /dev/sda #Tried sda4 (the ubuntu partition) but resulted w/blink _ at boot

# update-grub

# exit

$ sudo reboot

[1] http://wiki.debian.org/IntelMac/BootLoader#Upgrading


Solution 1:

I would have simply not used grub for your windows/linux partition and gone with rEFit:

http://refit.sourceforge.net/

This would mean your windows partition would show up in a menu when first booting right next to mac osx and ubuntu.

To recover your current partition you should point the grub repair at the MBR (not GPT) and use the /boot/grub location. I don't know if you've installed the boot to sda or sda1 as the disk boot record seems more sensible in this case.

sudo grub-install --root-directory /media/ubuntu /dev/sda1