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.

Best practice

On an Intel Mac, currently the best stable (lenny) configuration is:

This allows multi-booting to Linux, Mac OS X, and Windows, yields accelerated graphics, and does not require LILO to be run every time a kernel or init ramdisk change occurs.

In future, this may be replaced by:

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:

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.

Similarly, if the firmware is corrupt, you can restore the firmware as described at Apple support (About the Firmware Restoration CD (Intel-based Macs)) or by taking it to an Apple store, but this should not prove necessary.

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.

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:

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.

Mac firmware

You mostly needn’t concern yourself with this, except as backup.

This is sometimes upgraded, which is a reason to keep Mac OS X around; see #Upgrading EFI Firmware, below.

It is also possible to:

See:

for details on firmware hacking. These should not be necessary, but are included for reference.

rEFIt

rEFIt is an EFI bootloader, particularly for Intel Macs.

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.

See No rEFIt menu after Safe Sleep or power loss for details.

Options

There are many possible configurations, depending on whether you want to boot only Debian or wish to multi-boot, and what boot loader you use in EFI.

For concreteness and maximal compatibility, one may assume that one wishes to triple-boot to Mac OS X, Debian, and Windows (possibly non-EFI aware, e.g., prior to 2008). In that case one:

The other boot options, in order of complexity:

<!> 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:

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

Installing

Installing Grub2 has also been fine for Lenny. This is the grub-pc version which boot through rEFIt (not grub-efi). This is tested on amd64 and i386.

Lenny install CD can install GRUB as bootloader. Its dialogue can be misleading if you wish to install bootloader to MBR. You must create proper MBR/GPT hybrid. It can be done by:

Upgrading

Switching from LILO to GRUB

If you wish to switch from lilo to GRUB (BIOS version), while still using rEFIt in EFI:

Also, you will need to ensure the rEFIt is at least at version 0.9 (0.14 is preferred); previous versions don’t play nice with GNU parted and GRUB 2; see [http://refit.sourceforge.net/doc/c4s5_parted.html|rEFIt: Linux partition shows as EFI System (FAT)] for details.

Testing Live CD/DVD

To test your Live CD/DVD:

mount -o dev /mnt/sda3

…or similar (above works in Knoppix), and then chroot to it:

chroot /mnt/sda3

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.

Now for the actual installation:

gptsync /dev/sda       # sync GPT and MBR boot tables
grub-install /dev/sda3 # installs GRUB as boot-loader, assuming sda3 is the system partition
update-grub            # updates /boot/grub/grub.cfg so the GRUB menu lists possible OSes to boot

Note that:

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):

# *DO* run GRUB menu updater
postinst_hook = /usr/sbin/update-grub
postrm_hook = /usr/sbin/update-grub

# do *NOT* run LILO (using GRUB instead)
do_bootloader = no

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.

You can see the latest EFI Firmware at Apple Support here: EFI and SMC firmware updates for Intel-based Macs.

See also