Linux-only installation on a 2006 Macbook using rEFInd

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:

  • A 32-bit PC with EFI shouldn’t exist
  • If this is a Mac, then I should install rEFInd from MacOS

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:

  • Keep the first partition (sdX1) of your hard disc intact — repartitioning or reformatting this part of your disc will erase rEFInd.
  • When installing a boot loader (e.g. grub), use (U)EFI rather than BIOS mode, despite the fact that rEFInd is a BIOS emulator.

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
This entry was posted in All, Software and tagged , , , , , , , , , . Bookmark the permalink.

17 Responses to Linux-only installation on a 2006 Macbook using rEFInd

  1. Pingback: Boot Linux from a USB flash drive on a Macbook | AstroFloyd's blog

  2. Guy Stalnaker says:

    Astrofloyd – I’m trying to do what you describe. It has been unsuccessful thus far. I’m hoping you can answer a few questions about what you’ve done some of which puzzles me.

    I get the two partitions /dev/sda1 and /dev/sda2 (kubuntu install to go here). How does grub, installed in /dev/sda2 in /boot/efi/EFI/grub (if I’m reading your steps correctly) know about the efi boot partition /dev/sda1 your process first creates? And how does the boot process figure out how to shift from /dev/sda1 to /dev/sda2 to find the kernal to load it from /boot/eft/blah?

    Right now my MacBook has the /dev/sda1 boot partition with the rEFInd stuff in it and /dev/sda2 is where the kubuntu install went (which proves that rEFInd was installed right at least once so I could boot to the kubuntu LiveCD to do that install.

    But (of course) …

    – The kubuntu 13.10 install fails when it tries to do the boot config. Errors out and dies a sad death.
    – I tried using the LiveCD to open a terminal and use chroot magic to mount /dev/sda2 and do the grub-install, but that also errors with either a “cannot find kubuntu” or “source directly not found” error (error changes depending on whether, for funzies, I run grub-install from the kubuntu LiveCD terminal or the chroot terminal).
    – Current state is that rEFInd correctly indicates a linux system on a partition when I boot the MacBook, the boot process immediately halts without error, it just freezes, when I select that linux system.

    • AstroFloyd says:

      When booting, your Mac looks for media (flash drives, hard discs, dvds, …) with an EFI partition and loads rEFInd or similar when it finds it. In step 1), this is the EFI partition on the flash drive selected for that purpose. In step 5), this should be your otherwise blank hard disc that provides rEFInd. In parted, I issued “set 1 boot on” which sets the bootable flag for that disc (/dev/sdX) – this may be needed for the Mac to even consider looking there for an EFI partition.

      Once rEFInd is loaded, it looks for bootable media and tries to find e.g. grub. In step 1) both are on the first flash drive, while in step 5) rEFInd is on your hard disc while grub is on the second (installation of choice) flash drive.

      After step 6) you want to be able to boot without a flash drive, hence grub must be installed on /dev/sdXi (where i may be 1 to put rEFInd, which was already there, and grub together) as well.

      I haven’t got the mac at hand, but I think I installed grub in the same partition as rEFInd (both in /boot/efi on sdX1). The flag –efi-directory=/boot/efi in the grub-install command (where I forgot to add the device /dev/sdX, I just noticed) provides this information to grub. If I remember correctly, this tells grub where EFI sits and will install grub there (in some subdirectory) as well. Once grub is installed, grub.conf (or similar) should contain the information on where the kernel can be found and what the root of your operating system is, e.g. on the system I’m typing this from:

      root (hd0,0)  # Partition where the kernel image is located: boot partition = /dev/sda1 = hd0,0
      kernel /boot/kernel-3.6.... root=/dev/sda3 
      

      i.e. /boot is on /dev/sda1 (hd0,0) and / is on /dev/sda3 (sda2 is swap here).

      In which step do you run into problems – is that step 6)? If I understand correctly, you have EFI on /dev/sda1 and Kubuntu on /dev/sda2, including grub? In order for it to work, I suppose both partitions must have their bootable flag set. Also, did I make it clear enough in the text that the flash drive in step 1) is a different one than in step 5)?

      PS:
      Note that in step 1), I actually booted a Kubuntu Live ISO just to provide a system to allow me to install rEFInd. I didn’t try to install Kubuntu from there since I fancied a different flavour, but is this what you did, or is it something to consider (and skip steps 2)-5) completely)?

      PS2:
      Note that the grub-install command is one of a list of operations to perform to install Arch Linux, including the installation of a kernel and grub, and issuing the grub-mkconfig command.

      • Guy Stalnaker says:

        AstroFloyd,

        Thank you for your kind and detailed reply. I appreciate, truly, the time you took to write it.

        I have a working laptop with Kubuntu 13.10 installed. I’m fairly certain this is true partly due to the work I did following your guide, though, as you know from my post, there were problems. As you surmise, I did try to install Kubuntu from the USB drive. I used your process to create the EFI partition and install rEFInd. On reboot rEFInd appeared and offered me the option to boot from the USB stick, which was the Kubuntu 13.04 LiveCD. I installed Kubuntu from there. It is that install process that failed three times at the boot loader configuration step. Interestingly, on reboot rEFInd showed what seemed to be an installed kernel to boot but selecting it froze the boot process.

        That’s when I tried using a terminal session to mount chroot and manually install grub. Nothing doing and thus my post here to which you have graciously responded. I later powered down the laptop and left it alone for a day or so. The next time I powered it on the USB drive was no longer recognized as bootable. The next day I created a Kubuntu 13.04 LiveCD on DVD media. When I booted to it directly bypassing any other method I again did an install. But this time I noticed something new I’d not noticed on the previous install attempts: the partition process, in manual mode, allows one to select what a given partition is used for. There is an option for EFI partition!! When I selected that for the /dev/sda1 partition and attempted to continue, the installer complained that I’d not created a “grubbios” (or “biosgrub”) partition and that that I’d need one. I wiped out the swap partition, created a new 10 Mb partition for this and used the remainder for swap.

        The installation proceeded without error and the laptop rebooted successfully and rEFInd shows as expected. I now have a running kubuntu install which I’ve since upgraded to 13.10. I see rEFInd when I start up the MacBook and it shows a “Boot from HD” option what has worked through multiple boots.

        It seems that enough folks have wanted to do this that the kubuntu installer now has checks to determine if EFI is in use (or it could be that enough new computers now use EFI that it was necessary that the kubuntu folks include it). I think I still needed that separate EFI partition, which your process gave me though the kubuntu install process provides a means to get it in manual partition mode. Not sure if the kubuntu install process adds something like rEFInd to replace the MacOS boot loader. But your guide was my introduction to EFI about which I knew nothing whatever, so at the least I thank you for that 🙂

        I have a working laptop (that’s not too bad given its age and hardware) and thus far everything just works (sound, touchpad, etc.).

        Best regards,

        Guy

      • AstroFloyd says:

        Cool – I’m glad it worked out in the end. And thanks for the feedback; it may be useful to others.

  3. the says:

    Holy crap. Thank you. Worked 100%.There is so little info out there about installing linux to the first macbook (or maybe it’s just hard to find,) thank you for this.

  4. AstroFloyd says:

    There is a lot of detailed information on UEFI available on Rod Smith’s website:

    http://www.rodsbooks.com/efi-bootloaders/

  5. Chris Po says:

    I’m not sure what I’m doing wrong. I create the stick and when I boot the stick, I wind up at a grub> prompt. I’m pretty sure I’ve followed the directions to a T, using the 64-bit boot efi, fat32 partition, single GPT partition. I’ve tried a number of ISOs including the Kubuntu version you mentioned above.

  6. Tommy says:

    I got this to work with Mint 17.2 as the USB stick boot image on a 2007 2,1 dual core 2 with a new SSD drive. I had to name the efi file bootIA32.efi, boot.efi did not work. Booting from that I installed on a 100MB partition per instructions, then installed Mint directly from the booted USB. Works great.

  7. Tommy says:

    How did power management work out for you? I have not tweaked any settings yet and my battery is old. Just curious if you have any hints.

  8. John says:

    Would this work out for a 2006 Mac Pro??

  9. JeffC says:

    Thanks AstroFloyd and I am going to try your guide. Can your MacBook in Arch linux suspend when the lid is closed? Does hibernation work for your machine as well? I have tried Debian/Ubuntu and there is no way to get the machine suspended when the lid is closed.

    • AstroFloyd says:

      Yes, the Macbook suspends to RAM when ordered to (in KDE/plasma) or when the lid is closed. Newer kernels don’t behave well though – I think I use a v3 kernel, though I’m travelling at the moment and don’t have access to it. I’ve never tried to figure out why, though (or because) with the older kernel, live is good 🙂

  10. I thought this might be of interest to you and anyone else who lands on this page.
    I have a White 13″ MacBook from 2007. Core 2 Duo 1.8Ghz, 2Gb RAM. It was running 10.5.8, but could no longer be upgraded. I had been using it just for web browsing, and photo management on the go. All my other computers are Linux OpenSuse or Lubuntu. I now have a ChromeCast and the MacBook would not work with this, so I looked into replacing OS X with Lubuntu. After 2 days of research and experimentation I found your blog. However none of your info about installing rEFind did any good.
    I had already established that it had to be 32bit, and had been using a PartedMagic USB stick, which automatically offered EFI boot, as a Live OS to do the partitioning and housekeeping. So I used PartedMagic to clear the disk, changed the partition table to MSDOS and then went ahead and installed Lubuntu 16.10 32bit in exactly the same way I would have on any other Intel based PC. A 15Gb partition for /, 2Gb for Swap, and the remainder for /home. Set the bootloader to install on the MBR and left it to run. After it finished, it rebooted, and everything, including the WiFi, worked out of the box. Ran a system upgrade to 17.04 and all was still OK.
    There are still some minor issues with shortcut keys and the keyboard layout. The symbols on the @ & ” keys are the “wrong” way round, despite being a UK version the keyboard layout seems to be the same as the US version. Since I can touch-type this is not an issue. Also the shortcuts on the function keys don’t all work correctly, but can be setup in the preferences.
    To conclude, your instructions are vital if you are setting up to dual-boot, but in looks as if Ubuntu will now install on old Intel Mac hardware on a bare drive, as long as the partition table is set to MSDOS. I now have a slightly battered 10 year old MacBook running the latest version of Lubuntu, with all the latest web and office tools.

Leave a Reply to Guy Stalnaker Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s