Linux on Early Intel Macs
Installing Linux on an Apple computer has always required just a bit extra work in comparison to a standard x86 PC. This is especially true with Macs released right after Apple switched to Intel. In this guide, I will cover specific steps needed to get Linux running on these machines.
Requirements
You will need:
- early Intel Mac with a Core 2 Duo, such as an iMac 5,1 (a Core Duo Mac won't work because the CPU is 32-bit)
- 64-bit Linux distribution that lets you access the TTY during installation (I recommend Gentoo because of course I do)
- blank CD/DVD + a way to burn it (if you choose to install Gentoo, use a USB drive instead)
Choosing an Installation Medium
First, we need to understand the limitations of the early Intel Mac boot system. There are two "modes" in which these machines can boot:
- EFI mode (used mainly for booting macOS)
- legacy BIOS mode (for anything else)
Each of these modes can be used only on certain storage mediums, which you will need to keep in mind when choosing what to install the OS from. Here are the various storage mediums and the booting modes they support:
Storage medium | EFI | BIOS |
---|---|---|
Internal drive | ✅ | ✅ |
Optical drive | ❌ | ✅ |
External drive (USB, FireWire) | ✅ | ❌ |
Furthermore, the EFI implementation in these computers is non-standard and ancient, so your Linux distribution of choice is likely to not boot successfully in this mode. Despite that, I recommend first trying to flash your install image to a USB drive and see if it can boot in EFI mode. You might get lucky and avoid having to burn a CD.
If you discovered that your distribution indeed cannot boot from a USB drive, you will have to burn a modified ISO to a CD.
Modifing an ISO for Booting from a CD
Most Linux distributions provide so-called "hybrid ISOs". These can boot on both EFI and BIOS systems, but trigger a bug when trying to boot on an early Intel Mac, as these machines don't expect a CD to be EFI-bootable.
Upon trying to boot such disk, you will see a black screen asking you to choose from two unlabeled options. You won't be able to select anything though, because the keyboard drivers haven't been loaded yet, meaning the computer is stuck on this screen forever.
To get around this, you will need to modify the disk image to remove the hybrid ability. This is thankfully rather simple thanks to this handy program (huge thanks to this person for making it). Copy the code, paste it into a C file (I called it "isomacprog.c") and compile it with GCC or whatever C compiler. Then use the program in the following way:
./isomacprog nameoftheimage.iso
This will modify the ISO in place, so if you intend to keep the original make a copy first.
With that, you can burn the modified version onto a CD and begin the installation.
Partitioning
You will now need to partition your Mac's hard drive. Use a tool like cfdisk
to make your life easier and follow these steps:
- initialize the drive as GPT if it isn't already (this is intentional despite installing for BIOS booting)
- create a BIOS boot partition at the beginning of the drive, 1 MB in size is enough. Make sure to mark it as BIOS boot too. This partition is necessary because we are trying to boot in BIOS mode from a GPT formatted drive.
- create any additional partitions for a functional Linux setup (root, swap etc.)
Proceed by installing the operating system normally, but pause when you reach the bootloader.
Installing the Bootloader
We will be using GRUB because it is the only one I tested and it just works. Install it on your system.
Then, simply run grub-install
as if you were installing GRUB on a 32-bit machine:
grub-install --target=i386-pc /dev/sdX
Don't forget to also generate a GRUB config by running:
grub-mkconfig -o /boot/grub/grub.cfg
Creating a Hybrid MBR Entry
Even after installing GRUB, your Mac will still not be able to boot into Linux. You will need to complete one last step.
To determine whether there is an operating system the Mac can boot in BIOS mode, it looks into the MBR header of the hard drive. You might think this is impossible, because the drive is formatted as GPT, but Macs use a feature of GPT called hybrid MBR. In simple terms, there is an MBR header even on a GPT formatted drive, it's just not commonly utilized by normal computers.
You will need to create an entry in the MBR header for your Linux installation. I used a tool called gptfdisk
but it should also be possible with regular fdisk
.
Start by running 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, the MBR mode is set to protective, which is how it normally is on a freshly formatted GPT drive. We need to change it to hybrid.
Type the following series of commands:
r
to switch to recovery/transformation modeh
to create a hybrid MBR
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:
Enter the number of the BIOS boot partition, which should be 1 if you put it at the beginning of the drive. If you have a macOS partition too, input its number as well (of the HFS partition, not EFI).
Next, the program will come up with this prompt:
Place EFI GPT (0xEE) partition first in MBR (good for GRUB)? (Y/N):
Decline by typing n
.
Now you will be asked to assign HEX codes to the individual partitions you selected. This helps the computer identify what's on them.
For the BIOS boot partition, answer accordingly:
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
Assigning the hex code 0x07
to the BIOS boot partition makes the Mac recognize it as BIOS bootable. This is generally the HEX code used for marking older Windows installations, which only supported BIOS booting, but on these Macs can be used to mark anything we want to boot 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 to that hybrid MBR header, allowing the Mac to boot your Linux install.
Rebooting
Assuming you have done everything correctly, you can now reboot your machine and see a "Windows" option in the boot picker. This is your Linux install. It's marked as Windows because Windows was the only BIOS booting OS intended to run on these Macs, so it just identifies anything that's not macOS as Windows.
Choose this option to boot into your freshly installed OS.
Troubleshooting
If you don't see the Windows option in the boot menu, something must have gone wrong during the making an MBR entry 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 Creating a Hybrid MBR Entry section.
If that isn't the problem, you can try the following steps to diagnose what's wrong:
- type
x
to enter expert options - type
o
to print the MBR header - verify the BIOS boot partition is marked with
0x07
- verify the same partition is also set to bootable
If one of those is wrong:
- type
n
to delete the MBR header - type
w
to write the changes
Then try repeating the steps in Creating a Hybrid MBR Entry. This should hopefully fix any errors you might have made initially.
Conclusion
I hope this guide has given you the knowledge required to turn your ancient Mac into something useful again. These machines are a pleasure to use, and it's always great when we can breathe new life into them with a modern OS.
Additional Resources
Here are some websites that helped me get this running: