Sunday, 24 February 2013

Installing Ubuntu on Retina Macbook Pro


There is an update to this post that shows a simpler and more maintainable approach to the installation.

Installing Ubuntu on a Mac tends to be a little trickier than installing on a PC as Macs use EFI instead of BIOS. Now, with the introduction of Apple's Retina Macbook Pro screens we have an additional complication. However, Canonical and the Ubuntu community have been investing some time in getting the Retina Macbooks to play nice with Ubuntu 13.04, so I decided to get the latest, bleeding edge version. The great thing is that there has been an effort to keep the trunk version stable, so I've that getting the pre-release version of Ubuntu 13.04 to be a great solution.

If you search the Internet for information about running Ubuntu on the Retina Macbook Pro, you'll find tales of issues with the screen resolution (running at 2880x1880 with tiny icons and text), and driver issues with WiFi and sound. Well, I'm pleased to say, that Ubuntu 13.04 (with the 3.8.0-6 kernel) resolves these issues. There are some extra steps to take during the installation process, but these are related to EFI rather than Ubuntu itself. This guide is a walkthrough of the steps that I took to partition Macbook Pro hard drive and to install a dual-boot system: Mac OS X 10.8 and Ubuntu 13.04 (pre-release).

Partition the Hard Drive

This step is nice and easy on the Mac. Just launch Disk Utility, click on the laptop's hard drive and click on the Partition tab. From there the Mac OS X partition can be resized. Disk Utility allows you to create a new partition with the extra space, but I just left it as Free Space, so that it would be created by the Ubuntu installer.

Create the Ubuntu USB Installer

The latest stable release of Ubuntu is available at http://www.ubuntu.com/download, but I wanted pre-release version, which is at http://cdimage.ubuntu.com/daily-live/current/. You'll need the 64-bit Mac (AMD64) desktop image.

Instructions for creating a bootable USB stick are provided http://www.ubuntu.com/download/help/create-a-usb-stick-on-mac-osx, you'll just need to remember to use the latest ISO that was downloaded above.

Install an EFI Boot Manager: Refind

Previously, I've used Refit as a boot manager and boot loader for Ubuntu on a Mac, but that doesn't seem to be maintained any more. So, for the Retina Macbook Pro I've switched to Refind, which is just a Boot Manager. We'll then be loading Ubuntu using EFI instead of Grub, which means we can leave the old world of BIOS behind. See the Refind website for more information about boot managers and loaders, EFI and Grub.

Download the binary Refind zip file from http://www.rodsbooks.com/refind/getting.html and unzip it by double-clicking the file in the Mac OS X Finder. You'll want to check out the Refind installation instructions, but I chose the simplest option of installing Refind in the Mac OS X partition. There are other possibilities, but this seemed the easiest for me to manage - especially if something went wrong.

The installation needs to be done in the Terminal, by running the install.sh script:
 cd ~/Downloads/refind-bin-0.6.7  
 ./install.sh  

The script will prompt for your password so it can run with administrator privileges using sudo. Once the script has run, Refind is installed and you can see the configuration files at /EFI/refind.

You'll need to reboot a couple of times before you can see the Refind menu appearing. We'll need to configure Refind later.

Installing Ubuntu

The main challenge I hit during the installation process is that we need to copy the Ubuntu kernel file and RAM disk image over to the Mac OS X partition. However, though you can see the Mac OS X partition from Ubuntu, it is read-only. So, we'll need a method of copying the files over once Ubuntu has been installed.

One method is to upload the files to another server when you are booted into Ubuntu - which means that you need a network connection running. On the Retina Macbook Pro, there is no built-in Ethernet, so you're only option is to use WiFi. However, when booted off the USB stick the Macbook's WiFi does not work without extra drivers. So the option is to use an external WiFi card that does work from the installer (I used an Edimax EW-7811UN Nano Adapter), use an external USB drive, or an Apple Thunderbolt Ethernet Adapter (untested). However, given that Ubuntu 13.04 is still in development, you may find that WiFi works for you when you boot from the USB stick.

Connect your bootable USB drive into the Macbook Pro and reboot - you should see the USB stick as an option in the Refind boot menu, so boot from that. In the Ubuntu installer, select the Try Ubuntu option and it will take you to the Ubuntu desktop at a resolution of 2880x1800 - you may need a magnifying glass handy to read the text. That said, it does look beautiful!

By default, Ubuntu has 'touch to click' enabled for the trackpad by default, which I found difficult work with. So the first thing I did was to turn that off in the Mouse and Trackpad area of System Settings. Next, it's work changing the screen resolution to something more usable - I selected 1680x1050 (16:10). After that, if you are using WiFi, then you'll need to connect to the network.

Install Ubuntu

You're now ready to install Ubuntu. We want to do this without installing the Grub boot-loader, which would put us back into the old-world BIOS mode. To install without Grub, run the following in a terminal:
 ubiquity -b  
This will launch the installer and you can follow the instructions to install Ubuntu on the free space that we created earlier, alongside Mac OS X. At the end of the installation, make sure that you choose the option to Continue to try Ubuntu, as there is some more work to do here.

Copy the Kernel and RAM Disk Image Files

The next step is to copy the kernel file and the RAM disk image to your external server or flash drive. The files that you need are in /boot and will be called something like vmlinuz-3.8.0-6-generic and initrd.img-3.8.0-6-generic. If you have your Internet connection working, the simplest option is to upload the files to Ubuntu One, DropBox or Google Drive.

Make a Note of the UUID

You'll need to know the UUID of the partition that you have just installed Ubuntu on. You can see this in the Nautilus File Manager window when you select the Ubuntu partition (in the title bar). Or, you can see it by running:
 sudo blkid /dev/sda5  

You'll need to replace sda5 with the partition that you used. The UUID will be a long list of characters like 27c9a93d-6cc8-2395-9a97-d105353e5c07 - we'll need this for the Refind configuration file.

Once you are done, you can reboot into Mac OS X. You'll notice that the Ubuntu partition is not showing up in Refind as yet - that's what we need to fix next.

Configure Refind

We need to configure Refind so that it sees that Ubuntu partition and has all the correct details so it can boot from it. The Refind configuration is in /EFI, which will need root access to be able to update the details. I found that TextWrangler is a great option for editing config file as it allows you to authenticate to update the files. Make sure that you download TextWrangler from the Barebones site as the version in the Apple App Store does not have this facility.

Copy the Kernel and RAM Disk Image Files

The first step is to create a new folder in the EFI config area that will hold the Ubuntu kernel and disk image: /EFI/ubuntu. You'll need to copy the Ubuntu kernel and RAM disk image files into the new folder from the server or flash drive that you used earlier.

Configuration File Changes

It's worth checking the Refind site for more details about the configuration file changes, as there are a lot more options than I will cover. The main configuration file is /EFI/refind/refind.conf. We need to set up a configuration section for Ubuntu, so edit the file and add the following section:
1:  menuentry Linux {  
2:       icon EFI/refind/icons/os_ubuntu.icns  
3:       volume 5:  
4:       loader EFI/ubuntu/vmlinuz-3.8.0-6-generic  
5:       initrd EFI/ubuntu/initrd.img-3.8.0-6-generic  
6:       options "ro root=UUID=27c9a93d-6cc8-2395-9a97-d105353e5c07"  
7:       #disabled  
8:  }  
Note that there is a menuentry Linux section already in the file, and I have just edited that section. Some of the key points to note:

  • Line 2: the icon that will be displayed on the boot manager screen. In this case, I'm using the Ubuntu logo instead of Tux.
  • Line 3: you can find the volume by running diskutil list.
  • Lines 4-5: the paths to the kernel and RAM disk image.
  • Line 6: the UUID of the Ubuntu partition that you made a note of earlier.
  • Line 7: make sure that you comment out or remove the disabled line, otherwise it will not show up in the boot menu.
That's it. If you want to make the boot screen a it prettier, you can copy a PNG or BMP image file to /EFI and add an extra line to the configuration file:
banner /EFI/MilkyWay.png 

Reboot Into Ubuntu

Once you reboot you should see the Ubuntu icon in the Refind boot menu, and it should start up. When  it does, you'll see Ubuntu in its 2880x1800 pixel glory. So once you changed the resolution to a reasonable setting, you should find Ubuntu running beautifully:

  • The WiFi adapter works out of the box.
  • The sound card works.
  • The web cam works.

In fact, I've been using Ubuntu on the Retina Macbook Pro as my main work machine for a week now and I've not found anything that does not work.