Installation

It’s really easy to make a bootable setup-stick for Ubuntu. You just need Unebootin and the Ubuntu 14.10 Utopic Unicorn (non-mac) ISO.

You can get the ISO image here: http://www.ubuntu.com/download/desktop/thank-you/?version=14.10&architecture=amd64

There once were mac-versions of the setup ISOs. They came without the EFI booting files, so the Mac would start them in BIOS-legacy mode.

The BIOS-legacy mode is included in the Mac firmware and emulates a full BIOS, which is obviously really inefficient. The Mac would startup the EFI, then the BIOS-legacy mode, then the Linux bootloader, then Ubuntu itself. When you install Ubuntu, it will set itself up to boot in BIOS-legacy mode.

I’m a perfectionist when it comes to these things, so I really tried hard to set Ubuntu up without this BIOS emulation, and you should too.

It’s really easy to prepare an installation stick with Unebootin, so I won’t write about it.

Setting up Ubuntu

I really searched a long time to find a guide to do this and found a great one here: http://heeris.id.au/2014/ubuntu-plus-mac-pure-efi-boot/

I will try to simplify it here and explain step by step why we’re doing what.

First of all insert your boot-stick and restart your MacBook while pressing the “alt” or “option” key on your keyboard. This will hopefully (probably not on your first try) bring up the Mac’s boot menu.

Your boot menu will most likely look this one alike, but instead of the “Install OS X Mavericks”-drive there should be your Ubuntu installation stick.

Select your Ubuntu installation stick there, press Enter and the Ubuntu installer should boot up.

Another menu will show up. The Ubuntu installer’s menu. Among those options you will find “Install Ubuntu”. So go ahead and select it.

The installer will explain everything from there on. Just go ahead and set everything up to your liking. Be careful with the partitioning step though! There we need to be careful, so everything goes as planned.

You should see these partitioning options:

Guided — use entire disk

Guided — use entire disk and set up LVM

Guided — use entire disk and set up encrypted LVM

Manual

You should select “Guided — use entire disk”—again, this will erase your entire disk. We do not want LVM, as this confuses EFI later on.

The installer will present you with the partitioning it will perform. It should create three partitions: EFIboot, ext4 and swap. Be careful, that it really creates an EFIboot partition! If it doesn’t, something is going awfully wrong.

Continue with the installation and you will get an unbootable Ubuntu installation. Hooray!

Booting Ubuntu

One might say: “What’s this?! We just installed Ubuntu and it’s already broken?” Yes, but this step isn’t always necessary. You could just boot it in BIOS-legacy mode. Ewwwwwwwww!

To fix Ubuntu we need to boot the installation stick again and instead of selecting “Install Ubuntu”, this time we only need to press “c” to bring up the grub console.

The GRUB console. Isn’t it beautiful? — No.

Type “ls” to get an overview of your partition table. It should look like this:

(memdisk) (hd0) (hd0,msdos) (hd1) (hd2) (hd2,gpt3) (hd2,gpt2) (hd2,gpt1)

Cycle through the partitions with the following instruction to find your GRUB installation:

ls (hd2,gpt1)/boot/grub

You just need to modify “gptX”.

If you get this back: “error: file ‘/boot/grub’ not found.” it’s the wrong partition if you get something like: “unicode.pf2 […] grub.cfg” it’s the partition we’re searching for.

Now we need to get the UUID of the drive:

grub> ls -l (hd2,gpt2)

Partition hd2,gpt2: Filesystem type ext* [...] UUID e86c20b9-83e1-447d-a3be-d1ddaad6c4c6 - Partition start at [...]

Where “(hd2,gpt2)” is the partition you found earlier.

Note down this long string (the UUID) and be prepared to enter it again later.

Now set it as your root, so GRUB can reference it in our further instructions:

set root=(hd2,gpt2)

Now we know enough to boot into the system.

linux /boot/vmlinuz[tab].efi.signed root=UUID=[UUID]

You can press [tab] to find our which files are there, because I’m not really sure which kernel 14.10 originally uses. It’s probably 3.16.7–031607, but hey—tab completion.

Replace [UUID] with the UUID string you noted down earlier. No shortcuts, no copy&paste, no tab completion. I’m sorry, but there’s no way around typing it.

initrd /boot/initrd[tab]

The same game—tab completion. Then:

boot

And your fresh Ubuntu system should boot for the first time.

Fixing Ubuntu

Now we’re finally fixing it. Make sure, that your system is connected to the internet. In Ubuntu 14.10 Wi-Fi should already work. That’s nice. If it’s not (this was the case with older versions of Ubuntu) you need a LAN connection or copy all the Debian packages needed to install Wi-Fi drivers from another system.

(Ignore that everything still looks tiny due to the Retina display. We’re going to fix that later)

Open a terminal window by pressing “ctrl-alt-T”.

Here comes the first sudo in this guide, but it won’t be the last.

First of all we’re going to add Jason Heeris’s repository, which contains nice tools to fix the EFI boot partition:

sudo add-apt-repository ppa:detly/mactel-utils

Then we’re going to install some tools we need:

sudo apt-get update

sudo apt-get install mactel-boot hfsprogs gdisk grub-efi-amd64

Now we’re going to get the partition table (again):

mount

Somewhere in there you’ll find this line:

/dev/sda1 on /boot/efi type vfat (rw)

This is your EFI boot partition, but it’s formatted as VFAT. Unfortunately the Mac EFI firmware does not boot anything from VFAT, so we will need to reformat it. First of all we need to unmount the partition to be able to edit it:

sudo umount /dev/sda1

Note that it doesn’t have to be at “/dev/sda1” for you, even if it’s very likely.

Now let’s edit your partition table with gdisk:

sudo gdisk /dev/sda

Press “p” to print to let gdisk print the current table, which looks like this:

[...]

Number Start (sector) End (sector) Size Code Name

1 2048 194559 94.0 MiB EF00

2 194560 968574975 461.8 GiB 8300

3 968574976 976771071 3.9 GiB 8200

The first partition is the EFI boot partition. For me—in contrary to Jason’s instructions—it didn’t have the code EF00. It’s size was even larger at about 500MB. So don’t worry, you will recognise it as it is always really small and number 1. Now delete it:

Command (? for help): d

Partition number (1-3): 1

And add a new partition at its place:

Command (? for help): n

Partition number (1-128, default 1): 1

Now press enter twice to confirm the recommended size for the partition:

First sector (34-976773134, default = 2048) or {+-}size{KMGTP}:[ENTER]

Last sector (2048-194559, default = 194559) or {+-}size{KMGTP}: [ENTER]

Then enter AF00 for the filesystem code:

Current type is 'Linux filesystem'

Hex code or GUID (L to show codes, Enter = 8300): AF00

Changed type of partition to 'Apple HFS/HFS+'

Then press “w” to write the changes to your disk. Gdisk will ask for your confirmation before it proceeds. Now you’ve got a new, unformatted HFS+ EFI boot partition. Let’s format it with:

sudo mkfs.hfsplus /dev/sda1 -v Ubuntu

After that we need to update the Ubuntu filesystem table, so Ubuntu knows where to load the new /boot/efi partition from. First of all edit the /etc/fstab file:

sudoedit /etc/fstab

Search for these two lines and delete them:

# /boot/efi was on /dev/sda1 during installation

UUID=C59D-1B30 /boot/efi vfat defaults 0 1

Exit with “ctrl-x” and press “y” to save.

Now we need to replace the line you deleted with our new partition:

sudo bash -c 'echo UUID=$(blkid -o value -s UUID /dev/sda1) /boot/efi auto defaults 0 0 >> /etc/fstab'

I modified the command Jason suggests, because of a bug (?) in blkid.

Then remount the EFI boot partition:

sudo mount /boot/efi

Reinstalling GRUB

By default GRUB is installed on the system partition, but for EFI it’s on the EFI boot partition. Oops! We just formatted it. Well then let’s reinstall GRUB.

Because this process is always identical I will just write out all commands you need:

sudo mkdir -p "/boot/efi/EFI/$(lsb_release -ds)/"

sudo bash -c 'echo "This file is required for booting" > "/boot/efi/EFI/$(lsb_release -ds)/mach_kernel"'

sudo bash -c 'echo "This file is required for booting" > /boot/efi/mach_kernel'

sudo grub-install --target x86_64-efi --boot-directory=/boot --efi-directory=/boot/efi --bootloader-id="$(lsb_release -ds)"

sudo hfs-bless "/boot/efi/EFI/$(lsb_release -ds)/System/Library/CoreServices/boot.efi"

Done!

Better reboot the system to make sure it works.

Improving the EFI Boot Order

After rebooting we should improve the EFI boot order. THis can be done using the “efibootmgr” tool. If you run it, it will print something like:

BootCurrent: 0000

Timeout: 5 seconds

BootOrder: 0080

Boot0000* ubuntu

Boot0001* Ubuntu 14.10

Boot0080* Mac OS X

BootFFFF*

Then remove all entries, which names are not “Ubuntu 14.10”:

sudo efibootmgr -b 0000 -B

sudo efibootmgr -b 0000 -B

Replace the numbers with the ones you see from “efibootmgr”’s output.

Now set the default booting partition to “Ubuntu 14.10”, in this case:

sudo efibootmgr -o 0001

You should end up with an EFI boot order, that looks just like mine:

BootCurrent: 0000

Timeout: 5 seconds

BootOrder: 0001

Boot0001* Ubuntu 14.10

BootFFFF*

By the way, even if you change the timeout after a reboot it will always default to 5 seconds.

GRUB timeout

In the next steps we will update the system. This will also load the newest kernel. Unfortunately this will reconfigure GRUB, which will then set a timeout of 10. There’s no way around adding some scripts to GRUB to prevent this: