AstroFloyd's blog

Linux-only installation on a 2006 Macbook using rEFInd

Advertisements

While installing Linux on a blank hard-disc drive is trivial on most PCs, it turned out not to be on a 2006 Macbook Core duo. I gave up on the idea that Linux must be able to boot directly from Apple’s UEFI, and used rEFInd instead. The peculiarities of this process are described below.

The white Core duo (without the 2) 32-bit Macbook was purchased in September 2006. I booted Kubuntu from a custom-made EFI LiveUSB flash disc, installed rEFInd, which then allowed me to boot from the LiveUSB flash drive / USB pen drive / USB stick of my choice and install Linux. If I had known that installing rEFInd was inevitable, I had not gone through all the trouble of creating the first LiveUSB drive, but I would have mounted my new drive on another Linux computer and installed rEFInd that way instead (although doing this from a 64-bit system may have led to complications — I didn’t try). However, I started out under the impression that I would manage to boot Linux directly using Apple’s screwed-up UEFI system.

Overview of the steps to follow

This is a schematic overview of the main installation steps. See the next section for more detail for some of these steps.

  1. Boot your Mac, with the blank drive installed, from a (first) LiveUSB system — or mount the new drive on an existing system (this may be troublesome if it has a different bitness — I didn’t consider or try this).
  2. Create a ~50-500Mb UEFI/ESI/vfat/FAT32 partition (sdX1 – see below).
  3. Partition the rest of the disc as you wish for your Linux installation (boot, root, swap, home, etc.), or leave this until you boot from the LiveUSB/CD/DVD system you want to install your actual Linux distribution from (sdX2-sdXn).
  4. Download rEFInd and install it on the first partition (sdX1). Make the manual changes described below.
  5. Reboot your Mac (with the new drive installed) and boot from the installation (second) LiveUSB/CD/DVD system.  (Note that this would be a different flash drive than the one in the first step).
  6. Install Linux as usual, but make sure your first partition (sdX1) is not erased. It will typically be mounted on /boot/efi/. When installing a boot loader (e.g. grub), use EFI mode (despite the fact that rEFInd emulates BIOS – see below).

Steps in detail

Creating the UEFI partition

You will need a small, dedicated partition for UEFI. People recommend sizes between 20 and 500 Mb. I chose 100Mb and call the disc /dev/sdX below — make sure you replace the “X” with the proper letter for your drive. Here’s how to do it in parted (where a UEFI partition is labelled ESI (sic)), nicked from the Gentoo wiki:

# parted /dev/sdX

(parted) mkpart ESI fat32 0% 100m
(parted) mkpart primary ext4 100m 100% # (optional)
(parted) set 1 boot on
(parted) quit

# mkfs.vfat -F 32 /dev/sdX1
# mkfs.ext4 /dev/sdX2 # (optional)

The first mkpart command creates the dedicated UEFI partition, starting at the beginning of the disc and ending it 100Mb later. The second mkpart command creates a second partition for the rest of the disc (starting at 100Mb, filling up to 100%).
The two mkfs commands create the file systems on the two partitions — FAT32 for the first (UEFI, sdX1) and the default Linux ext4 filesystem on the second partition (sdX2). In principle you can leave out the second mkpart and mkfs commands here and do this when you install Linux later, or replace them with your custom commands for a different partitioning scheme. See the Gentoo wiki for more details. It is important that the sdX1 partition is kept intact when installing Linux later.

You will need to mount the UEFI partition (sdX1) in order to install rEFInd in the next step. Typically this will be done in /boot/efi/, but let’s do this in /boot/temp-efi/ in case that partition exists on your current Live system:
# mkdir /boot/temp-efi
# mount /dev/sdX1 /boot/temp-efi

Install rEFInd

The boot manager rEFInd is a still developed clone of the dead project rEFIt. I downloaded the binary zip file (v0.7.7) from this page, unzipped it and ran the installation script, after mounting my new partition /dev/sdX1 on /boot/temp-efi as described above:
# mkdir ~/rEFInd/ && cd ~/rEFInd/
# wget http://downloads.sourceforge.net/project/refind/0.7.7/refind-bin-0.7.7.zip
# unzip refind-bin-0.7.7.zip
# cd refind-bin-0.7.7/
# ./install.sh

Because of my old 32-bit Macbook, the rEFInd installer complained that:

Since my disc containing MacOSX was failing and this was to be its replacement, I simply ignored these warnings and carried on with the installation. rEFInd was nicely installed in /EFI/refind/ on the UEFI partition (sdX1, mounted on /boot/temp-efi, so in my case in /boot/temp-efi/EFI/refind/).

In order to boot this old Macbook, you need to rename the install directory from “refind” to “boot” and the efi file to “boot.efi”:
# cd /boot/temp-efi # Or wherever you mounted your UEFI partition
# mv EFI/refind/ EFI/boot/ # Rename the directory
# mv EFI/boot/refind_ia32.efi EFI/boot/boot.efi # Rename the file

In addition, you can consider editing EFI/boot/refind.conf, to set the boot delay from 20 to e.g. 3 seconds.

rEFInd should now be installed. If you mounted your disc on another system, put it back into your Macbook. Your Mac should now be able to start rEFInd and boot from a LiveUSB/CD/DVD system, from which you can install Linux on your hard drive.

Install Linux and your bootloader

I decided to install Arch Linux, so I downloaded an ISO image, copied its contents onto a USB flash drive, stuck in into the Macbook and booted from that. You can of course use your own favourite Linux flavour to do something similar. When installing, keep the following in mind:

When installing grub, I issued:
# grub-install --target=i386-efi --recheck --efi-directory=/boot/efi --bootloader-id=grub /dev/sdX

This used i386-efi mode for my old 32-bit/i386 Macbook in (U)EFI mode to install grub in /boot/efi/. This resulted in the warning/error message

EFI variables are not supported on this system

which can be ignored when using rEFInd, however fatal they sound — “They’re caused by the fact that you’re booted in BIOS mode, and they’re irrelevant because the task they’re intended to perform will be handled by rEFInd”, according to this rEFInd page (their step 26 “Type sudo grub-install”). The message doesn’t appear anymore when installing grub from my newly installed Linux system, presumably because I now truely booted in UEFI mode. See also the postscript below.

Post-installation troubleshooting

After rebooting my freshly installed Arch Linux system, the kernel with custom-made initramfs failed to recognise my disc. I didn’t copy the actual error message, but it ran something like

(PART)UUID=abc123-... not found

I think the problem was the fact that the custom initramfs image was created automatically, using an analysis of the LiveUSB system I used to install. The solution was to boot using the initramfs-fallback image (which will load about every driver the world has ever known) and as root recreate the custom initramfs image, in my case of Arch Linux by rerunning

# mkinitcpio -p linux

and reinstalling grub. After that, Arch Linux booted fine. I set the grub timeout to 2 seconds, and a reboot (shutting down and cycling through rEFInd, grub, kernel boot and starting KDE) now takes about a minute.

Postscript

While I’m writing this up, I wonder whether installing grub in UEFI mode hasn’t actually supplanted rEFInd. That would explain why booting is so fast, and why I don’t actually see rEFInd pop up anymore…

Advertisements