This page covers Intel-based Macs – all models since 2006, including MacBooks and ?MacBook Pros

The most delicate part of installing operating systems, other than drive partitioning (which can destroy data), is configuring the boot loader, which can render your system unbootable. Best practice on ?IntelMacs has been changing with improved development of GRUB and supporting software.

This page only covers changing boot loaders, and does not cover the far more dangerous process of partitioning. For partitioning Intel Macs, see ?IntelMac/Partitioning.

This is similar to rEFIt + GRUB 2 (BIOS version), but somewhat simpler. Currently there are limitations in Linux and X.org which need addressing (their video drivers need BIOS to initial video hardware for acceleration), but longer-term this should be an acceptable solution.

In the past, (etch?), practice was:

chain loading by first loading rEFIt (in EFI), then using LILO.

This worked, but had the usual limitations of LILO (system wouldn’t boot if forgot to run lilo after kernel changes, etc.), and was necessary because GRUB Legacy does not (easily) support Intel Macs.

Any OS can be selected as default if you use rEFIt (version 0.14+) then the BIOS version of GRUB 2, or just GRUB 2 in EFI.

Preliminaries

First, make a rescue CD/DVD, or get a Live DVD (or Live CD, or Live USB) and test it by booting with it. If rEFIt is properly configured, you will be able to boot from discs or USB drives from the rEFIt screen. Alternatively, holding the Option key during boot should start the Apple Startup Manager, while holding the ‘C’ key during boot should boot to CD (or DVD) – these should work even if rEFIt is broken.

Having a separate working computer available is wise, in case of difficulty it allows you to research the problem without needing to reboot the non-working computer.

Worst case

Likely worst case – assuming you do not change partitions, which can destroy data – is to render the hard drive unbootable, requiring the use of a boot CD/DVD.

Booting from a CD/DVD should always work (assuming firmware is ok: you do not need to change firmware in any way to install Debian or change the boot loader), but in worst case scenario, you can always remove the hard drive, connect it to another computer (such as in a USB hard drive enclosure), and fix it there.

This is mentioned simply to alleviate fears – if you’re only changing boot loaders, not booting from hard drive (and requiring rescue CD/DVD) is likely the worst case.

Overview

Complexity in Intel Mac booting is due to the transition from BIOS firmware to the EFI system.

Mac Books now use EFI to boot

GRUB Legacy (prior to GRUB 2) cannot boot from EFI

In parallel with this is the transition from the BIOS system of partitioning (MBR) to the EFI system of partitioning (GPT). During this transition you’ll want to use a GPT/MBR hybrid system, but these are potentially very painful. Notably, the GPT and MBR partition tables can get out of sync, so after using non-GPT aware partitioning tools, you must use gptsync (either in Mac OS X or Debian) to sync the partition information. In squeeze, gdisk is a GPT-aware fdisk, but in lenny, you’ll need to use gptsync in addition to fdisk, and gptsync is useful if you’ve used Mac OS X partitioning.

Components

There are 3 components in the boot process, as described here:

Mac firmware

rEFIt (EFI bootloader) – chooses partition

GRUB (BIOS bootloader) – boots Debian

In general, once set up, you will not need to touch the firmware or rEFIt, but you can safely upgrade these without harm, and they will not touch your Linux partition.

rEFIt

rEFIt can be installed via Mac OS X, which is the easiest way to use it. There is also refit, which is a re-packaging that has licensing that is conformant to Debian Free Software standards (rEFIt itself does not). The Debian package is not necessary to use rEFIt, and requires manual installation in Mac OS X, but it may prove useful.

rEFIt 0.14 (2010 March) has some useful enhancements, notably more configurable default boot, and detection of GRUB 2, so it is a recommended upgrade.

A subtlety is that the Mac firmware (specifically the PRAM (Programmable RAM), which stores variables) stores which partition to boot, which it calls “blessing”. Mac OS X is in the second partition, while rEFIt is installed in the first (EFI boot) partition (it also has files in the OS X partition, but copies these to the EFI boot partition). Blessing is done so the Mac will use rEFIt (or other EFI-capable bootloader) to boot.

A sub-subtlety is that when returning from Safe Sleep, Macs will boot – which should always be the Mac partition, not rEFIt, but due to a bug they may boot into the “blessed” partition, rather than into Mac. Thus rEFIt includes a program “rEFItBlesser” which blesses the Mac partition on startup, then blesses the rEFIt partition on shutdown. Thus you may sometimes boot into OS X instead of into the rEFIt menu, particularly after installing or upgrading rEFIt or following power loss or OS X Safe Sleep. Rebooting should bless rEFIt on shutdown and thus reboot into rEFIt. On reinstall you may need to reboot twice – the first time rEFItBlesser now starts, and blesses on shutdown, the second time it boots into rEFIt.

GRUB 2 in EFI, multi-booting, but not to Windows prior to 2008, and not providing accelerated graphics

rEFIt in EFI, multi-booting, using LILO on the Linux partition to boot Debian

rEFIt in EFI, multi-booting, using GRUB 2 (BIOS version) on the Linux partition to boot Debian

Note the key distinction between installing GRUB 2 in EFI versus on the partition. Concretely, grub-install /dev/sda installs GRUB 2 to the hard drive (EFI), while grub-install /dev/sda3 (note the “3”, indicating partition) installs GRUB 2 to the partition. (Formally, when installing in the partition, GRUB is in the “Partition Boot Record” or “PBR”; see Volume boot record.)

It is also possible to multi-boot without using rEFIt (holding down the “Option” key at boot to access the built-in Mac multi-boot), but rEFIt makes matters much easier.

On top of this is the distinction between using a pure GPT system (which to the eyes of MBR has only a single partition) versus using a hybrid GPT/MBR system, which to the eyes of MBR has up to 4 primary partitions, consisting of a GPT partition, the Mac OS X partition, the Debian Linux partition, and optionally a Windows partition.

If you wish to retain OS X, which you may desire either to use OS X applications, to easily upgrade EFI firmware, or simply as a backup system, then easiest is to use Boot Camp to resize/repartition, and retain the Mac OS X partition. Alternatively, you can wipe the hard drive and use Debian only (or Debian and Windows, or other combinations).

Default OS

One can set any OS as the default, as follows:

If GRUB 2 is in EFI, one can set the default OS by configuring GRUB 2.

If rEFIt is in EFI, use rEFIt version 0.14+ and configure the refit.config file as documented there to select default system.

You can also triple-chain: first rEFIt → GRUB 2 on the Linux partition, then GRUB 2 to another OS (such as Windows).

At this point you should be booted as usual into your system, and should be able to edit files, run aptitude, etc.

Installing GRUB

Now you are ready to install the packages:

sudo aptitude install grub-pc os-prober gptsync

This is safe – it installs the packages, but does not change the boot loader.

grub-pc is GRUB 2 (BIOS version), while os-prober detects other OSes and automatically includes them in your GRUB menu (lenny version detects Windows, while squeeze version detects Windows and Mac OS X), and gptsync ensures that GPT and MBR partition information are in sync, just like it says on the tin.

grub-install will likely warn you against installing in a partition (which we need for multi-boot) and need to be run with --force

you cannot use reiserfs in your main partition (or rather, should not); this is potentially very dangerous and risks FILESYSTEM DESTRUCTION (quoting grub-install), and you are recommended to instead convert your filesystem to ext3, as per Serverfault: How to convert a reiserfs partition to ext3? (make sure to update fstab to read ext3 instead of reiserfs)

At this point GRUB should be correctly installed.

The need for gptsync to be run in Linux is as follows: for GRUB 2 to successfully load, the partition number must be 83 (Linux). However, the gptsync included in rEFIt in Mac OS X does not set this partition number, and thus will not load GRUB 2; this may be fixed in rEFIt 0.14.

You may instead be able to run grub-install "(hd0)" ((hd0) in GRUB = sda in Linux), but this may instead install GRUB to EFI. Alternatively, grub-install "(hd0,3)" ((hd0,3) in GRUB = sda3 in Linux) may work.

To ensure that the menu is correctly updated, edit /etc/kernel-img.conf to include the following lines (these were previously documented at zless /usr/share/doc/grub/README.Debian.gz):

You can test that this updates GRUB by reconfiguring your running kernel:

dpkg-reconfigure "linux-image-`uname -r`"

(BTW, the difference between GRUB and LILO is that GRUB can successfully load the kernel even if the menu hasn’t been updated, since it can read the file system, while LILO simply fails. However, this requires manually finding and entering the path to the kernel.)

If you are ready to reboot, cross your fingers, and reboot, either interactively or via the command line:

shutdown -r now

(If you find yourself here after your system failed to reboot, we are very sorry – if you can identify the problem, please correct it above.)

Upgrading EFI Firmware

Upgrading EFI Firmware (which Apple does through Software Update) does not affect boot loaders in any way, and is completely fine – rEFIt, GRUB 2, elilo, LILO, and Windows should continue to work exactly as before.

In fact, upgrading EFI Firmware may improve boot loaders – early firmwares sometimes caused problems with failing to recognize keyboards, preventing you from selecting different boot options in GRUB 2.