keepcalculator

06 Numbers and Powers

Create a Mac Entry in GRUB2: Dual-Boot Setup

Card No. 06·71492 · Updated · Standard formula, shown below

To create a Mac entry in GRUB2, you need to add a custom menu entry that points GRUB to the macOS bootloader (usually on a separate EFI System Partition). This is typically done by editing the /etc/grub.d/40_custom file and then running update-grub (or grub2-mkconfig on some distributions). The exact configuration depends on your disk layout and whether you’re using UEFI or legacy BIOS, but the process is straightforward once you identify the correct partition.

Background: Why GRUB2 and macOS Don’t Always Play Nice

When you install Linux alongside macOS on a Mac or a PC with a Hackintosh setup, the system typically uses UEFI firmware. macOS uses its own bootloader (bootstrap.efi) located on a hidden EFI System Partition (ESP). GRUB2, the bootloader used by most Linux distributions, can chainload this macOS bootloader, but it doesn’t automatically detect it like it does for Windows or other Linux installs. This is because macOS doesn’t follow the same boot entry conventions that GRUB’s os-prober script expects, so you must add the entry manually.

How GRUB2 Boots macOS: The Chainload Method

GRUB2 doesn’t boot macOS directly; it hands off control to Apple’s bootloader. This is called chainloading. The key is to point GRUB to the correct EFI file on the correct partition. Here’s a typical entry:

menuentry "macOS" {
    insmod part_gpt
    insmod fat
    set root='hd0,gpt1'
    chainloader /System/Library/CoreServices/boot.efi
}

In this example, hd0,gpt1 refers to the first disk, first GPT partition—usually the EFI System Partition. The chainloader command loads the boot.efi file from that partition. If you have a separate macOS recovery partition, you might need to point to a different partition or use a different path.

How to Choose the Correct Partition and Path

Before editing, you need to identify which partition holds the macOS bootloader. Use the lsblk command in Linux to list block devices and partitions. Look for a small (usually 100-200 MB) FAT32 partition with the EFI label. This is the ESP. To find the exact path, mount that partition and look for System/Library/CoreServices/boot.efi. On a typical Mac with macOS installed, the path is exactly that. On a Hackintosh, it might be in a different location, but the standard path is most common.

Here are the steps to add the entry:

  1. Open a terminal and run sudo blkid to list all partitions and their UUIDs. Note the UUID of the ESP that contains the macOS bootloader.
  2. Edit /etc/grub.d/40_custom with root privileges: sudo nano /etc/grub.d/40_custom.
  3. Add the menu entry as shown above, replacing hd0,gpt1 with your actual disk and partition numbers. You can also use the search command with the UUID for a more robust entry: search --set=root --fs-uuid YOUR_UUID.
  4. Save the file and run sudo update-grub (on Debian/Ubuntu) or sudo grub2-mkconfig -o /boot/grub2/grub.cfg (on Fedora/RHEL).
  5. Reboot and test. If it fails, you may need to adjust the partition or use a different loader path.

Common Problems and Fixes

One common issue is that the boot.efi file is not found. This usually means you pointed to the wrong partition or the path is incorrect. Double-check by mounting the ESP and verifying the file exists. Another issue is that GRUB might not have the necessary modules (like fat and part_gpt) loaded; the insmod lines in the entry handle that. If you see an error like “invalid signature,” it might be because you’re trying to boot a non-UEFI macOS installation, which is rare on modern systems.

If the entry appears but boots to a black screen, try adding set debug=all to the entry temporarily to see verbose output. Also, ensure that macOS is not using FileVault2 full-disk encryption, which requires a different boot process (you’d need to point to the recovery partition instead).

Comparison: GRUB2 vs. rEFInd vs. Apple’s Boot Manager

GRUB2 is not the only way to dual-boot. Apple’s built-in boot manager (hold Option at startup) works but requires you to press a key every time. rEFInd is a popular third-party boot manager that automatically detects macOS, Windows, and Linux, and is often easier to set up for multi-boot systems. GRUB2 is more integrated with Linux and gives you more control over kernel parameters, but it requires manual configuration for macOS. If you’re comfortable editing config files, GRUB2 is fine; if you want a graphical picker with zero configuration, rEFInd is a better choice.

Safety and Precautions

Before editing GRUB configuration, back up your current /etc/grub.d/40_custom and /boot/grub/grub.cfg. A mistake could leave your system unbootable. Always test the entry after adding it. If GRUB fails to boot, you can use a live Linux USB to chroot into your system and revert the changes. Also, be aware that macOS updates may replace the bootloader or change the partition layout, so you might need to re-add the entry after a major macOS update.

Frequently Asked Questions

Why doesn’t GRUB detect macOS automatically?

GRUB’s os-prober script is designed to find common operating systems like Windows and Linux. macOS uses a different EFI boot structure and Apple’s proprietary partition scheme, which os-prober often fails to parse. Manual configuration is the reliable way to add it.

Can I use the UUID instead of hardcoding hd0,gpt1?

Yes, using the UUID is more robust because it doesn’t depend on disk order. Replace the set root line with search --set=root --fs-uuid YOUR_UUID, where YOUR_UUID is the UUID of the ESP containing the macOS bootloader. This is recommended if you have multiple disks or if disk order changes.

What if I have a Hackintosh with Clover or OpenCore?

If you’re using a Hackintosh, you might have Clover or OpenCore installed on the ESP. In that case, you should chainload their EFI files instead of Apple’s boot.efi. For Clover, the path is usually /EFI/CLOVER/CLOVERX64.efi. For OpenCore, it’s /EFI/OC/OpenCore.efi. Adjust the chainloader line accordingly.

Do I need to disable Secure Boot?

Yes, Secure Boot must be disabled to boot macOS on most systems. GRUB2 can work with Secure Boot, but Apple’s bootloader is not signed with Microsoft’s keys, so it will be blocked. Disable Secure Boot in your UEFI firmware settings before attempting to boot macOS via GRUB.

How do I remove the macOS entry later?

Simply edit /etc/grub.d/40_custom and remove the menuentry block, then run update-grub again. The entry will disappear from the GRUB menu on the next boot.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →