|
Size: 16282
Comment: 0.14
|
Size: 16289
Comment: link
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 8: | Line 8: |
| * [[WikiPedia:chain loading]] by first loading [[rEFIt]] (in EFI), then using the BIOS version of GRUB 2 ([[DebianPkg:grub-pc]]) to load Linux (or Windows). | * [[WikiPedia:chain loading]] by first loading [[#rEFIt|rEFIt]] (in EFI), then using the BIOS version of GRUB 2 ([[DebianPkg:grub-pc]]) to load Linux (or Windows). |
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:
chain loading by first loading rEFIt (in EFI), then using the BIOS version of GRUB 2 (grub-pc) to load Linux (or Windows).
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, likely in squeeze, it will generally be best to use:
a single stage boot, with the EFI version of GRUB 2 (grub-efi).
This is similar to rEFIt + GRUB 2 (BIOS version), but somewhat simpler. Currently there are limitations in the EFI version of GRUB 2 which need addressing, but longer-term this should be an acceptable solution.
In the past, (etch?), pratice 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 support Intel Macs.
Any OS can be selected as default if you use GRUB 2 in EFI, or rEFIt then the BIOS version of GRUB 2 (so long as Linux is the first non-Mac partition).
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 another (working) computer available is cautious, as in case of difficulty it allows you to research the problem without needing to use (and reboot) the partly-broken 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
The old world is dying away, and the new world struggles to come forth: now is the time of monsters. (Antonio Gramsci)
The reason for the complexity in Intel Mac booting is the transition from the BIOS firmware (booting) system to the EFI system, both at the level of operating systems and at the level of boot loaders:
Mac Books use EFI to boot, and Mac OS X can be booted by EFI, but:
- GRUB Legacy (prior to GRUB 2) could not be booted from EFI, and
- booting directly from GRUB 2 in EFI (rather than chain loading via rEFIt in EFI, then GRUB 2 (BIOS version) in ), and
- Windows prior to 2008 (Windows Server 2008, Windows Vista Service Pack 1) did not support loading via EFI, and thus need to be chain loaded via BIOS.
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.
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:
- use the built-in boot loader (hold “Option” on start up)
- boot directly to CD (hold “C” on start up)
- restore original firmware (erase settings and upgrades), in dire situations
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:
- partitions in hybrid GPT/MBR (as is done by Boot Camp), with a GPT partition, the Mac OS X partition, the Debian Linux partition, and (optionally) a Windows partition,
- boots via rEFIt in EFI, then GRUB 2 (BIOS version) on the Linux partition.
The other boot options, in order of complexity:
- elilo (EFI LILO) in EFI, booting to Debian only
- 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, and GRUB 2 is in Linux – which must be the first non-Mac OS X partition (i.e., the third partition, /dev/sda3, following the EFI partition in sda1, and the Mac OS X partition in sda2) – one can set the default by:
- To default to Mac OS X, do nothing – it is the default
To default to Linux or Windows (or other), set the legacyfirst option in refit.config, which changes the default to the first non-Mac OS X partition, and then set the default via GRUB 2.
Note that to default boot into Windows by this method, you triple-chain: first rEFIt, which loads GRUB 2 on the Linux partition, which then loads Windows on the Windows partition.
Installing
See: ?Debian Install Tutorial for MacBook
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:
gptsync command on Linux
menu from rEFIt boot loader
Upgrading
Switching from LILO to GRUB
If you wish to switch from lilo to GRUB (BIOS version), while still using rEFIt in EFI:
First, please read and understand some basics at: Debian Reference: 3.3. Stage 2: the boot loader.
Second, make rescue media (a rescue CD) using grub-rescue-pc, or some Live CD/DVD, such as Knoppix, and test it.
Third, check which partition Linux is on, either using gparted in Debian or the disc tool in Mac OS X. It is probably /dev/sda3 (third partition ‘3’ on primary drive ‘a’), assuming you’re also booting into Mac OS X (EFI is partition 1, Mac OS X is partition 2), but please check.
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 GRUB 2.
Testing Live CD/DVD
To test your Live CD/DVD:
- boot with it (via rEFIt or by holding ‘C’ during boot)
- mount your Linux partition via
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 # 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
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
/GRUB Legacy – out of date, but kept for reference
