EFI-Booting Ubuntu on a Mac
Last Web page update: 5/17/2011
I'm a technical writer and consultant specializing in Linux
technologies. This Web page is provided free of charge and with no annoying
outside ads; however, I did take time to prepare it, and Web hosting does
cost money. If you find this Web page useful, please consider making a
small donation to help keep this site up and running. Thanks!
| Donate $1.00 |
Donate $2.50 |
Donate $5.00 |
Donate $10.00 |
|
|
|
|
|
Note: I wrote this page when Ubuntu 10.10 was current. Since
then, Ubuntu 11.04 has been released with improved support for installing
directly to EFI-based computers. (Sadly, the 32-bit disc images I've seen
lack this support, which leaves owners of older Intel-based Macs out in the
cold.) This new EFI support has the potential to greatly simplify a
straight-up GPT/EFI configuration. I've upgraded my 10.10 installation to
11.04 using the update procedure in the Ubuntu 10.10 system, so I haven't
installed 11.04 directly on my Mac using the 11.04 installer.
Unfortunately, I've seen one report of
an EFI boot damaging a Mac's firmware. As of 5/17/2011, it's unclear to me
what the cause of this problem is and what steps can be taken to minimize
the risk.
The Problem
When installing Ubuntu Linux on an Intel-based Macintosh, most people
follow any of several guides available on the Internet, such as this
Ubuntu document. Most of these guides, however, rely on features of
the Macintosh that are intended to enable it to boot Windows. In
particular, these guides typically end up creating a configuration that
boots Linux using BIOS emulation on the Mac. In this mode, the Mac
sets up a Basic Input Output System (BIOS) layer that the OS can use,
rather than rely on the Extensible Firmware Interface (EFI) that OS X uses
to run on the computer. BIOS emulation is expedient, and it's the only way
that Windows can boot directly on a Mac, but it's got several
drawbacks:
- Longer boot times—BIOS emulation is widely regarded as
slowing the boot process. I've not tested this effect myself, so I'm
not sure how significant it is.
- Reduced graphics card flexibility—On some models with
multiple graphics chipsets, you can't select which chipset to use in
BIOS mode, but you can in EFI mode. My own Mac isn't one of the
affected models, so I can't comment further on this issue.
- Use of a hybrid MBR—Intel-based Macs use the GUID Partition
Table (GPT) rather than the more common Master Boot
Record (MBR) partitioning system. Windows, however, can't boot from
GPT disks on BIOS-based computers (which it thinks a Mac is thanks to
Apple's BIOS emulation). Therefore, Apple uses an ugly and dangerous
hack known as a hybrid MBR, in
which a GPT data structure known as the protective MBR is
altered to make the disk look like an MBR disk to Windows. The trouble
is that hybrid MBRs frequently cause problems. In fact, even the Ubuntu
installer often gets it wrong; it tries to be helpful by creating a
hybrid MBR, but depending on your partition layout, it can create a
partition table that the popular libparted-based partitioning tools
won't touch.
As far as I can tell, BIOS emulation mode only works when a hybrid MBR
is present on the hard disk or when a BIOS-bootable optical disk is
inserted in the optical drive. Thus, you can't use BIOS emulation mode with
a conventional GPT disk unless you plan to use a bootable optical disc to
boot Linux.
Ubuntu can use the BIOS emulation and hybrid MBR that enable Windows to
boot on Macs, but it doesn't need to! If you don't use these
features, you won't see their problems. Hybrid MBRs, in particular, are a
Bad Idea (with a capital B and a capital I). I've seen numerous problems
reported at the Ubuntu Forums related
to Ubuntu installations on Macs with hybrid MBRs, and more problems with
similar configurations elsewhere. See my hybrid MBR Web page
for a technical description of what they are and what can go wrong with
them. In short, they can get out of sync, cause confusion about which
partition is which, and become damaged in frustrating ways. Whenever I
think I've heard of every possible problem with hybrid MBRs, I stumble
across a new one. You're better off without one, if that's
possible—and it is, if you dual-boot OS X and Linux but not
Windows.
The trouble is that Ubuntu doesn't (yet) support installing to a Mac in
EFI mode. Therefore, to rid your computer of the dangerous hybrid MBR,
you'll need to jump through some hoops. (An alternative to all of this is
to run Ubuntu in a virtual environment, such as VirtualBox. This can be a good
solution in some cases, but it doesn't give Linux direct access to the
hardware and you'll lose some speed.)
Some Caveats
Although my opinion is that Intel-based Macs are best booted using EFI
and a GPT with a protective MBR rather than a hybrid MBR, there are
drawbacks to doing it this way. These include:
- No Windows—As noted earlier, Windows relies heavily on
BIOS emulation to boot on a Mac; therefore, if you want to triple-boot
OS X, Linux, and Windows, you'll need a hybrid MBR to boot Windows.
(You might, however, consider dual-booting OS X and Linux and run
Windows in a virtual machine such as VirtualBox. This will eliminate
the need for BIOS emulation and hybrid MBRs.) In theory, you could
triple-boot with a hybrid MBR but still use EFI mode to boot Linux.
I've not tested this, and the benefits are greatly reduced since you've
still got the hybrid MBR on your hard disk.
- Poor nVidia driver support—The biggest caveat to booting
Linux in EFI mode on Macs is that some Linux video drivers,
particularly for nVidia chipsets, don't work well when you boot in EFI
mode. Thus, if you've got a Mac with an nVidia video chipset, you'll
need to use the less capable fbdev drivers rather than the faster
nVidia drivers. My own first-generation Intel Mac Mini uses an Intel
video chipset and is not affected by this problem, so it doesn't bother
me, but it could be a deal-breaker for you. If you know of a solution
to this problem, please feel free to e-mail me.
- Missing hardware features—I've seen reports that Linux
features such as screen brightness control and suspend/resume may not
work correctly when booting using EFI. I don't use such features, so I
can't comment personally.
- Virtual terminals—I've seen reports that text-mode virtual
terminals don't work from an EFI boot; however, this limitation doesn't
apply to my computer. Perhaps it interacts with the video chipset,
framebuffer driver use, kernel version, or some other variable.
- OS architecture limitations—Older Intel-based Macs, such
as my Mac Mini, use 32-bit CPUs and EFIs. Newer models come with 64-bit
CPUs and EFIs. If you try to run a 32-bit distribution on a 64-bit EFI,
you may not have access to EFI Runtime Services. This can reportedly
limit some features, but I'm a bit unclear about the details. In my
opinion, it's best to stick with 64-bit distributions on 64-bit
hardware even on BIOS-based computers, so I don't see this as a big
problem.
If you're running Fedora, Mandriva, OpenSUSE, Gentoo, Debian, or most
other Linux distributions, the procedure I'm about to describe will
probably work; however, I've not tested it with any of these distributions
and some details may differ. Most notably, you may need to track down a
suitable version of GRUB 2 (with EFI support). On the other hand, it's
possible that your preferred distribution already supports direct EFI
installation, in which case the problem of installing to a Mac in EFI mode
may not exist. Check your distribution's documentation to be sure.
I've tested this procedure only on my first-generation Intel-based Mac
Mini. This computer uses a 32-bit CPU and 32-bit EFI, so I've tested only
the 32-bit version of Ubuntu. It's possible that the 64-bit version has
different requirements, or you may need to do things differently on newer
64-bit Macs. You can check which type of EFI you've got with the following
command, typed in an OS X Terminal:
$ ioreg -l -p IODeviceTree | grep firmware-abi
The result should include the string EFI32 or EFI64;
the meaning of each should be obvious.
Prerequisites
Before proceeding, you'll need to download a few items:
- Ubuntu Linux—You can obtain Ubuntu from its main Web site. The Web site
describes the 32-bit version as "recommended," but lacks such a
description for the 64-bit version. Don't worry, though; the 64-bit
version works fine for almost everything. I recommend using it if
you've got a 64-bit EFI, as described earlier. (Note that the string
AMD64 appears in many places in reference to the 64-bit version
of Ubuntu, but this version works fine on Intel's x86-64 CPUs;
the AMD64 string is used simply because AMD invented the
architecture.) I used a desktop version of Ubuntu 10.10 as a reference
for this Web page, but the basic procedures should be similar for the
server or alternate installer, as well as for Ubuntu variants such as
Kubuntu and Edubuntu. Burn the disc and check that it includes
directories called boot, install, isolinux,
and so on.
- GPT fdisk (gdisk)—Go to the GPT fdisk Sourceforge
download page and download the Mac
(gdisk-version.pkg) package. I recommend you also
download the Debian GNU/Linux package
(gdisk_version-1_i386.deb or
gdisk_version-1_amd64.deb, depending on which version
of Ubuntu you use) for future use, although you won't need the Linux
version for this procedure. Install the Mac version in OS X and place
the Linux version on a shared-data partition or a removable disk so you
can read it from Ubuntu.
- Super GRUB 2 Disk—Download this handy CD image from its home page. Be sure to get
Super GRUB 2 Disk, not Super GRUB Disk. (If you're installing a
non-Ubuntu distribution or an older Ubuntu version, though, you might
need Super GRUB Disk.) Burn the disc image like you burned the Ubuntu
install disc image.
- rEFIt—This is a popular Mac boot selector. It won't
directly boot a Linux kernel, but it's part of the boot process as
described on this Web page. Download the Mac disk image from its Web page. Note that there's
a rEFIt package for Ubuntu, but this package doesn't install
automatically and it includes no utilities to help you install it, so
you're better off installing it from OS X. You don't need to burn the
disk image to a CD-R; you'll be installing the software directly from
the disk image.
With these items in hand, you can proceed with installing Ubuntu, and
then fix it up so that it doesn't use a hybrid MBR.
Installing Ubuntu
If you've already got a working dual-boot configuration with OS X and
Ubuntu, you can skip this section and jump ahead to "Fixing the Installation." You may be able to skip some
of the steps in that section, too, such as rEFIt installation.
To install Ubuntu Linux 10.10 on an Intel-based Mac, follow these
directions:
- If necessary, install Mac OS X.
- Boot into Mac OS X.
- If necessary, using OS X's Disk Utility, adjust the sizes of your
partitions, making room for Linux. Note that resizing partitions is
inherently dangerous, so back up your data before beginning! You may
also want to create a FAT or unjournaled HFS+ ("Mac OS
Extended") shared-data partition. The result might look like the below
(the Linux partition in this screen shot could as easily be blank
space; I've created it here mainly to show you where Linux will
reside).
- If you haven't done so already, install the OS X version of GPT fdisk
(gdisk).
- Open a Terminal program.
- In the Terminal program, type sudo gdisk /dev/disk0
(change /dev/disk0 to /dev/disk1 or above if your
computer has multiple hard disks and the one on which you want to
install Ubuntu isn't /dev/disk0).
- In gdisk, type p to display your partition table.
Verify that it's the same one shown by Disk Utility. (Note that
Disk Utility hides the EFI System Partition, which is normally the
first partition on the disk.)
- If you created a Linux partition, type d in
gdisk to delete it. Enter its number when prompted. (If you
created multiple partitions for Linux with the intention of using them
as you created them, you can skip this step.)
- In gdisk, type n to create a new partition.
Give it a number of 99, hit the Enter key to use the default starting
sector (the program may tell you it's changed the sector value, but you
can ignore this message), +128M as the ending sector,
and a hex code of ef02. This creates a BIOS Boot
Partition of 128 MiB at the start of the largest block of free space on
the disk. This partition will be used by the initial Ubuntu GRUB
installation, but you can and should delete it once you've got native
EFI booting working. 128 MiB is actually much bigger than is required
for this purpose, but OS X likes to see gaps between partitions when it
installs or upgrades the OS, so when you eventually delete this
partition, it will leave the type of gap that OS X likes to see. (If
you created all your Linux partitions in OS X's Disk Utility, you can
put the BIOS Boot Partition in one of the gaps that Disk Utility
leaves, but you may need to accept a default value or use
+1M rather than enter +128M as the end
value.) Type p again to see the results; they should
look something like this (although I've got two OS X partitions):
- In gdisk, type w to save your changes. When
asked, type y to confirm this choice.
- Insert your Ubuntu installation CD or DVD in the computer's drive.
- Restart your Mac and hold down the Option key (Alt if you're using a PC
keyboard) as it restarts to get the Mac's OS selection screen.
- Pick the Ubuntu install disc from the options. (It will be mis-labelled
as "Windows.") The Ubuntu installer will start up.
- When the appropriate screen comes up, select Install Ubuntu
and proceed with a normal Ubuntu installation, except as noted in the
next few steps....
- When the Allocate Drive Space dialog appears, select "Specify
partitions manually (advanced)."
- You will initially see a partitioning screen with your original OS X
partitions, a biosgrub partition (what Ubuntu's partitioner
calls the BIOS Boot Partition), and free space at the end of the disk.
Select the free space and click Add to begin adding partitions....
- Create partitions for your Ubuntu installation in the free space near
the end of the disk. (If you did this in OS X's Disk Utility, you
should modify each partition by selecting it and clicking Change,
then clicking the Format option and setting an appropriate filesystem
and mount point.) I recommend creating the following partitions:
- /boot—200 MiB, ext2fs. This partition
probably isn't strictly necessary, but I had some notions for
unusual last-resort boot methods that would have made it helpful
(I didn't need these methods). This guide assumes the creation of a
separate /boot partition, so for simplicity's sake in
following this guide, you should probably create it.
- / (root)—5–20 GiB, ext4fs or your preferred
Linux filesystem. This partition is absolutely vital. If you choose
not to create a separate /home partition, make it suitably
larger.
- swap—1–2 times your system's RAM size.
- /home—The rest of your available disk space, in
ext4fs or your preferred Linux filesystem. You can merge this with
the root (/) partition if you're short on space or plan to
store little in the way of Ubuntu-specific files. Having a separate
/home partition simplifies OS re-installations and some
types of upgrades, though.
When you're done, you'll see your new partitions displayed....
- Be sure that the "Device for boot loader installation" option is set to
/dev/sda (it will include a complete name for your hard
disk—I used VirtualBox to collect the last few screen shots, but
yours will show a real disk model number).
- Click Install Now. The installation will proceed as on a PC. You can
find generic installation guides online, such as this one
at the Ubuntu site.
When the installation finishes, the computer will reboot—straight
into Mac OS X! (See the below note if it doesn't boot, though.) You must
now proceed with fixing it up in various ways....
Fixing the Installation
Note: If by chance your computer won't boot, try booting the
Ubuntu installer but click Try Ubuntu to run it in its live CD mode. Then
install the Ubuntu version of GPT fdisk and run steps 1–7 below in
the Ubuntu live CD. (Use /dev/sda rather than /dev/disk0;
Linux and OS X use different disk identifiers.) With any luck, OS X will
start up again, and you can proceed with step #8.
If you've followed the directions, your computer should now be booted
into OS X, looking very much like it did before. Ubuntu is
installed, however, and your disk has a hybrid MBR. You must now take steps
to return the hybrid MBR to a safer protective MBR, as the GPT standard
requires, and to set up a boot loader that enables you to select which OS
to boot when the computer powers up. To do so, follow these steps:
- In OS X, launch a Terminal.
- Type sudo gdisk /dev/disk0 (changing the disk
identifier as necessary). If at any point in the next few steps
something seems wrong, type q to exit without saving
your changes.
- In gdisk, type x. The command prompt will
change to read Expert command (? for help):.
- In gdisk, type o. This command displays the
contents of the hybrid MBR, which will probably consist of four
partitions, one of which is of type 0xEE. The Ubuntu installer created
a hybrid MBR (if one wasn't already present) in an attempt to be
helpful. Sometimes it will be corrupt even by hybrid MBR standards: It
will contain two 0xEE partitions, one of which overlaps other
partitions!
- In gdisk, type n. The program won't seem to
do anything; it will just show you another command prompt.
- In gdisk, type o again. The MBR contents
should be different from before; there should just be one partition, of
type 0xEE. This is a standards-compliant protective MBR.
- In gdisk, type w to save your changes.
- Open the rEFIt image file you downloaded earlier.
- Double-click the rEFIt.mpkg file to install rEFIt. Follow the prompts to
install rEFIt.
- Reboot. If the rEFIt menu doesn't appear, reboot again. If it still
doesn't appear, you'll have to debug your rEFIt installation; consult
its Web page for
suggestions. If the rEFIt menu does appear, it may have a Linux item,
but it won't work (at least, it didn't for me, but there's no reason
you can't try it). A successful rEFIt boot looks something like this,
although this screen shot is from a completed installation; you won't
see the highlighted EFI item on the left of the top row at this point.
Also, my system has two OS X installations; yours might have just one
(or three, or some other number).
- Insert the Super GRUB 2 Disk into the computer's DVD drive.
- Restart your Mac by selecting the reboot item (the up arrow on the
right of the bottom row of icons).
- When the rEFIt menu appears, you'll see two Linux items, one for a hard
disk boot and the other for a CD boot. Select the latter. (If that
doesn't work, reboot and try again with the disk option; they seem to
sometimes get mixed up.)
- After a while, a GRUB 2 menu should appear. Pick the "Detect any GRUB 2
installation (even if MBR is overwritten)" option from the menu. Note:
On my system, if I leave this menu up for more than two or three
seconds, it hangs at this point. If yours is the same, you'll need to
act quickly!
- A new menu should appear listing the GRUB 2 installations it could
locate. On my system, this consisted of a grand total of one
installation, so there's no ambiguity: Select it!
- At this point, a normal Ubuntu GRUB 2 menu should appear, enabling you
to boot Ubuntu as you would on a PC. (The screen will go completely
black for part of the boot process. Don't worry; this is normal.)
- When the login screen appears, log into your Ubuntu installation.
- Select Applications -> Accessories -> Terminal from the GNOME
menu.
- Type sudo apt-get install grub-efi. This replaces the
BIOS version of GRUB that the Ubuntu installer installed with an
EFI-based version of GRUB. In fact, there are two different EFI-enabled
versions of GRUB: grub-efi-ia32 and grub-efi-amd64.
Which is used depends on the architecture of the firmware, so if you're
running a 32-bit version of Ubuntu on a recent 64-bit OS X firmware,
you may need to explicitly install grub-efi-amd64.
- Type sudo grub-mkimage -O i386-efi -o grub.efi -p "(hd0,5)/grub"
part_gpt hfsplus fat ext2 normal chain boot configfile linux multiboot
xnu xnu_uuid jpeg png tga search loadenv font. Change
(hd0,5)/grub to the correct path to your /boot/grub
directory, in GRUB's nomenclature. This example corresponds to a
/boot partition on /dev/sda5, so change the partition
number accordingly. If you don't use a separate /boot
partition, substitute (hd0,n)/boot/grub, where
n is your Linux root partition's number. If your
platform is AMD64, use -O x86_64-efi rather than -O
i386-efi. Watch those underscores and dashes! If you used a Linux
filesystem other than ext2/3/4 for the Linux /boot partition
(or for the Linux root partition if you don't have a separate
/boot partition), you'll need to add GRUB's support module for
that filesystem to the long list at the end of the
grub-mkimage command.
- Type sudo mount /dev/sda1 /mnt to mount the EFI System
Partition at /mnt. (Change /dev/sda1 if your EFI
System Partition has an unusual partition number.) You can use
gdisk to check the EFI System Partition's number, if you like.
- Type sudo mkdir /mnt/EFI/BOOT/.
- Type sudo cp grub.efi /mnt/EFI/BOOT/.
At this point, if you did everything exactly correctly, you should be
able to boot Ubuntu in EFI mode—but not quite in the obvious way. The
Linux item in the rEFIt menu remains useless. Instead, you should see a new
EFI item in the menu, which loads the grub.efi file you created in
the preceding procedure. (See the earlier rEFIt screen shot.) This launches
GRUB, from which you can launch Linux.
The OS X and memory test options in GRUB are useless, although they work
from a BIOS boot—apparently they rely on GRUB modules that aren't
available when booted in this way, and so far I've been unsuccessful in
including them in the grub.efi file. This is no great loss, since
you can boot OS X just fine from rEFIt.
If you want to boot more quickly into Linux, you can change the
GRUB_TIMEOUT value in /etc/default/grub; however,
reducing this value will make it harder to select alternate kernels or
recovery options. If you make such a change, type
update-grub afterwards to change the
/boot/grub/grub.cfg file, which GRUB reads at boot time.
Once you're satisfied with your ability to boot and use both Linux and
OS X, you should delete the BIOS Boot Partition from your hard disk. It's
no longer needed, but OS X may want free space where it resides in the
future. You can use GParted, parted, gdisk, or any other
partitioning tool to delete this partition.
One caution: The rEFIt menu includes a "partitioning tool." As near as I
can tell, this is nothing more than the gptsync utility, which is
used to create a hybrid MBR. Don't use it! Although you'll still be
able to boot afterwards, one of the big advantages of this boot method is
that you eliminate the ugly and dangerous hybrid MBR, so why resurrect it?
You can remove this option from the menu by editing the
/efi/refit/refit.conf file in OS X and adding the following
line:
hideui tools
Unfortunately, using this option also hides the icon to launch an EFI
shell.
Going Further
It's possible to set the system up to use GRUB directly, without the
intervention of rEFIt; however, I stumbled across this configuration early
in my experimentation and now I can't seem to re-create it, so I can't tell
you how I got it! Sorry! It's not a great loss, though, since this
configuration was unstable—OS X kept resetting it, which is what led
me to install rEFIt. Also, booting OS X from GRUB produced a black screen
until OS X appears, which was a minor annoyance. (OS X did boot from
this early configuration of mine—another detail that's lost.)
You can consult the UEFIBooting page to
learn about more options for GRUB on a Mac. Some of that page's
instructions didn't work for me, though; presumably they're either specific
to particular Mac models or the page is dated.
I hope you've found this Web page informative. I realize the procedures
outlined here are complex, but in my opinion, it's worth getting rid of the
flaky and dangerous hybrid MBR even if doing so requires investing the
effort described here.
References
The following sites have additional information that you might find
useful:
If you have problems with or comments about this web page, please
e-mail me at
rodsmith@rodsbooks.com. Thanks.
Return to my main Web page.