The solution posted below is a suitable approach if the machine in question already uses a foreign boot-loader.
This has the advantage of giving 100% reliable sleep and shutdown behaviour. The disadvantage of this approach detailed below is that it uses more power overall and after the first waking from sleep the dGPU uses even more power than is good for battery life.
In any case, using an external display via Thunderbolt will be disabled as well.
Note that the solution below assumes that GRUB chainloads macOS. The solution below is not only for dual boot installation with Linux. It works perfectly well by only booting macOS from an isolated instance of GRUB. Linux is only needed to set this up, not for daily use. Ubuntu is only one of possible choices used below as a popular example.
1. Disable SIP
If you can boot into Single User Recovery Mode Command+s+r, and enter:
csrutil disable
If you can’t, create a USB stick with rEFInd as described here:
http://www.rodsbooks.com/refind/sip.html#disable_in_refind
2. Change the gpu-power-prefs
Boot into single user mode Command+s and change the
gpu-power-prefs nvram variable:
sudo nvram fa4ce28d-b62f-4c99-9cc3-6815686e30f9:gpu-power-prefs=%01%00%00%00
reboot
[This step is listed in this way in case Recovery Mode is unavailable. The command may issued there as well.]
3. Create a rescue thumb drive
In this step we will create a rescue thumb drive that you can use
every time you are having trouble booting macOS.
3.1. Download ubuntu iso
http://releases.ubuntu.com/17.10/ubuntu-17.10-desktop-amd64.iso
3.2. Mount the iso
On Windows (7 and later) or Ubuntu should be straight forward (you
just need to double click the iso). On macOS, assuming you have the
iso in the Downloads folder, run the following command on the
terminal:
hdiutil attach -nomount ~/Downloads/ubuntu-17.10-desktop-amd64.iso
Which should return something like:
/dev/disk2 Apple_partition_scheme
/dev/disk2s1 Apple_partition_map
/dev/disk2s2 Apple_HFS
Then run the following commands to mount and open the iso disk (in my
case /dev/disk2
)
mkdir /tmp/ubuntu
mount -t cd9660 /dev/disk2 /tmp/ubuntu/
open /tmp/ubuntu/
3.3. Format and copy the files
Format your thumb drive as FAT32 and name it RESCUE
, then copy the
EFI
and boot
folders from the iso to your thumb drive.
3.4. Edit the grub.cfg file
On your thumb drive, open the file at boot/grub/grub.cfg
with any
text editor and change it to:
menuentry "macOS" {
insmod hfsplus
outb 0x728 1
outb 0x710 2
outb 0x740 2
outb 0x750 0
search --no-floppy --fs-uuid --set=root <YOUR UUID>
chainloader /System/Library/CoreServices/boot.efi
}
3.5. Boot you mac with the thumb drive
Boot your mac and when you hear the chimes, press and hold Option
(alt)
and then choose your thumb drive.
Then when grub appears press c
and run the command:
ls -l
A list of partitions should appear. Take note of the UUID for your
macOS partition.
Press ESC
and then e
to edit macOS menu entry and then replace
<YOUR UUID>
with the uuid of your partition.
Press fn F10
to boot.
Your macOS should now boot normally.
3.6. Change the uuid on grub.cfg
On your thumb drive, open the file at boot/grub/grub.cfg
with any
text editor and replace <YOUR UUID>
with the uuid you got on the
step 3.5.
You can now boot from the thumb drive without having to change the
uuid every time.
4. Make it permanent
In this step we will make the macOS boot without the thumb drive.
After booting macOS with your thumb drive and with it still plugged,
open the terminal and run the following commands (I will assume your
thumb drive name is RESCUE
, if not, replace RESCUE
with your thumb
drive name):
cd /Volumes
sudo mkdir efi
sudo mount -t msdos /dev/disk0s1 /Volumes/efi
sudo mkdir /Volumes/efi/boot
sudo mkdir /Volumes/efi/EFI/grub
sudo cp -R /Volumes/RESCUE/boot/ /Volumes/efi/boot
sudo cp -R /Volumes/RESCUE/EFI/boot/ /Volumes/efi/EFI/grub
sudo bless --folder=/Volumes/efi --file=/Volumes/efi/EFI/grub/grubx64.efi --setBoot
sudo bless --mount=/Volumes/efi --file=/Volumes/efi/EFI/grub/grubx64.efi --setBoot
You are now able to boot without the thumb drive.
5. Recover when macOS updates
Everytime macOS updates, you need to bless grub again. For this, you
need to boot with your rescue thumb drive, and then on macOS terminal
run the following commands:
cd /Volumes
sudo mkdir efi
sudo mount -t msdos /dev/disk0s1 /Volumes/efi
sudo bless --folder=/Volumes/efi --file=/Volumes/efi/EFI/grub/grubx64.efi --setBoot
sudo bless --mount=/Volumes/efi --file=/Volumes/efi/EFI/grub/grubx64.efi --setBoot