Linux on early Intel Macs

Guide to all obsticles you must overcome to get Linux running on early Intel Macs.

Installing Linux on a Mac from the early Intel era might seem trivial. I mean, it's a 64-bit x86 machine, should be just a regular install, right? Wrong. It's never that simple with Apple computers.

You see, this specific line of Macs from 2006 has a fun quirk. They utilize a 32-bit implementation of the UEFI firmware, which is quite unusal nowadays. That by itself wouldn't be too much of a problem, most Linux distros support booting on 32-bit EFI, it's the non-standard nature of it that makes this difficult.

Yes, it's Apple, so propriatery or non-standard is kind of their thing. Although, in their defense, in 2006 most x86 PCs were still using BIOS, since UEFI wasn't really a thing. Apple was one of the first computer manufacturers to jump on this UEFI train, so it's not too surprising their implementation might not be the most up-to-date with today's standards.

That won't stop us though. Instead of dealing with some obsure version of early UEFI firmware, we can instead utilize the built-in BIOS mode, which was intended to run Windows on your Mac in conjunction with the Bootcamp software. But, since most Linux distributions also support BIOS booting, we can take advantage of this mode for our install. Before we beign though, let's make sure you have the appropriate hardware.

Requirements

You will need a functional Mac with a 32-bit EFI system. This guide has only been tested on an iMac 5,1, however, there is technically no reason it shouldn't work on other Macs with a 32-bit EFI. If you're unsure whether your machine's EFI system is 32 or 64-bit, just look up its model number. This guide is only appropriate for 32-bit EFI Macs, as a 64-bit EFI Mac can already install Linux like any other PC with no special steps required.

It is also recommended to have a basic level of Linux knowledge, such as how to partition a drive or install a bootloader.

With that out of the way, we can begin!

Hybrid MBR

As you might know, macOS is an operating system that utilizes UEFI to boot. Windows on the other hand is strictly a BIOS system, at least at the time Apple introduced their first Intel Macs. That means macOS needs the hard drive of the machine to be formated as GPT, while Windows needs MBR. So, how did they get both operating systems installed on the same drive with both of them booting properly? Even with this special legacy BIOS mode I talked about earlier, the drive would still need to be formated as MBR for Windows, which would screw up macOS.

Apple took advantage of something called a hybrid MBR. As far as you should be concerned, it's a GPT formatted disk with an MBR header shoved at the beggining. You might think this corrupts the partition table, but it seems the creators of GPT accounted for this, as the beggining of a GPT drive has a blank space left for, you guessed it, an MBR header. So, this way Apple achieved booting both Windows and macOS from the same drive. Windows just thinks it's an MBR disk, so it looks into the space where it would (and it does) find the MBR header, and macOS treats it as a normal GPT disk, ignoring the MBR weirdness.

What does this mean for us? Well, when Windows installs on the disk, it writes an entry to the MBR table with the 0x07 label. The Mac firmware detects this, and presents Windows as a bootable option in the boot picker. But, it doesn't really know what it's booting, it only checks for the flag. If we install Linux and somehow write an entry to the MBR table with the same 0x07 flag, we can trick it into booting Linux! And that's exactly what we need to do. We need to Install linux in BIOS mode, and write that special entry into the MBR table.

Installation Medium

As I mentioned before, the Mac’s non-standard EFI implementation isn’t very good at booting Linux. This of course applies to the installation medium as well. To get Linux installed, you will (for most distributions) need to boot from the medium in BIOS mode. Unfortunately, there isn’t any option in the firmware or key combination you can press to force booting in BIOS mode. Macs from this era can boot in this mode only from the internal hard drive or the CD ROM drive. When booting from a CD (or a DVD I guess), BIOS mode is actually the only mode it can boot in. To make this easier to understand, I made this handy little table:

BIOS UEFI
CD ROM X
Internal drive X X
USB drive X

Here, you can see which mode is available on which medium. As far as I know, Gentoo is the only distro that can successfully boot from a USB drive, though nothing stops you from trying others, you might just get lucky.

Making a Bootable CD

If the USB option doesn’t work for you, which it most likely doesn’t, you will need to do the physical CD method. Even more annoyingly, you cannot just use any standard Linux ISO and burn it to a CD. Most of these ISOs include the ability to boot both on BIOS and EFI systems, which conveniently messes with firmware on these Macs, not allowing them to boot properly. You will first need to make a small modification to the ISO of your choice. Don’t worry, it's not difficult to do so, there is a C program that does it for you.

I will not cover how to do this in my guide, since there already is an amazing guide on this topic. You can either download an ISO directly from their list of pre-modified ones, or jump to the "Mod an ISO yourself with the modding program" section to modify one yourself.

After obtaining a modified ISO, burn it to a CD, stick it in your Mac's CD dirve, and we can move on to setting up the hard drive.

Partitioning the Drive

We need to set up our drive for BIOS booting. Formating the disk as MBR won't work, because the firmware doesn't know what to do with MBR disks. Instead, we can format it as GPT, and utilize the hybrid MBR concept I mentioned above. To do this, the drive must contain a special BIOS boot partition alongside your standard Linux partitions (root, swap). Here is an example layout:

No. Type Mount Point Size File System
1 BIOS boot none 1 GB none
2 root / 250 GB ext4
3 swap none 4 GB swap

You can of course create as many partitions as you want with whatever sizes and file systems you prefer, but make sure to include the BIOS boot partition, ideally at the beginning of the drive. This partition must not contain any file system, and a size of 1 GB is more than enough. GRUB will save its boot image there.

With that done, you can proceed with installing the distribution of your choice.

Making Linux Bootable

This section will focus on actually making our Linux install bootable. It assumes you have already completed all necessary steps for a functional system, except configuring the bootloader.

When installing GRUB, make sure to install it in BIOS mode by running this command:

# Replace X with your appropriate drive letter.
grub-install --target=i386-pc /dev/sdX

Then generate the GRUB configuration file:

grub-mkconfig -o /boot/grub/grub.cfg

Next, we will have to alter the MBR table. We can do that by first creating a MBR header on our GPT formatted disk. A tool called GPT fdisk will help with that. Install it using the package manager on your chosen Linux distribution. Then run it with this command:

gdisk /dev/sdX

You will see the following output:

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Here, you can see that our MBR mode is set to protective. We need to change it to hybrid and add an entry for our BIOS boot partition. You can print the current partition table by typing p. If you created the BIOS partition at the beggining of the drive, it will have the number 1 in the list.

Next, you will want to type the following series of commands:

The following prompt will appear:

Type from one to three GPT partition numbers, separated by spaces, to be added to the hybrid MBR, in sequence:

Type the number of the BIOS partition, in our case 1. If you also have a macOS partition on the drive that you would like to make bootable, intput its number as well. The next prompt will look like this:

Place EFI GPT (0xEE) partition first in MBR (good for GRUB)? (Y/N):

Decline by typing n. Now, gdisk will ask for HEX codes to assign to our partitions. Answer the prompts as you see below:

For the BIOS boot partition:

Creating entry for GPT partition #1 (MBR partition #1)
Enter an MBR hex code (default AF): 07
Set the bootable flag? (Y/N): y

For a macOS partition (if you have one):

Creating entry for GPT partition #2 (MBR partition #1)
Enter an MBR hex code (default AF): af
Set the bootable flag? (Y/N): n

The HEX code tells the firmware what OS is installed on a specific partition. We marked the BIOS partition with 0x07 to trick the firmware into thinking it's Windows, which enables it to boot in BIOS mode. A macOS partition is marked with 0xAF, with the bootable flag intentionally set to no, because we don't want macOS booting in BIOS mode.

If the program also asks about unused partition spaces, answer accordingly:

Unused partition space(s) found. Use one to protect more partitions? (Y/N): y
Note: Default is 0xEE, but this may confuse Mac OS X.
Enter an MBR hex code (default EE): 0a

Finally, type w to save your changes. This will write the MBR table in that blank space GPT has left for us.

And that's it! If you have done everything correctly, you should have a functional (and more importantly bootable) Linux installation on your hard drive. Try rebooting your system and holding down the ALT key (OPTION on Apple keyboards) during startup to enter the boot menu. You should see an option called Windows in the list. Choose it to boot into your Linux install.

Troubleshooting

If you don't see the Windows option in the boot menu, something must have gone wrong during the gdisk part. Boot back into Linux using your installation medium, then run gdisk again. Make sure the MBR is reporting as hybrid when it initially launches. If this isn't the case, repeat the steps in the "Making Linux Bootable" section.

If that isn't the problem, you can try the following steps to diagnose what's wrong:

If one of those is wrong:

Then try repeating the steps in "Making Linux Bootable". This should hopefully fix any errors you might have made initially.

Conclusion

Being able to run the most up-to-date software on a computer from 2006 is truly a spectacle, and only possible with Linux! Yes, your machine is probably still too slow to do anything more extensive, but at least it's not entirely useless. I hope you found this guide useful, and that it helped you get Linux running on these things. If you have any suggestions regarding this article or anything else, email me at wonderdingus@protonmail.com.

Thanks for reading!