Fix for 17 inch dGPU switch issue
(Tested successfully in both “early” and “late” 2011 17 inch MacBook Pro)
This guide is based on the experience of many users (including me) while trying to fix the very well known issue with AMD dGPU on 17’’ MacBook Pro from 2011 (both early and late):
Step 0) As a starting point I made a clean installation of Sierra (Version 10.12.4) — This is just a step for establishing a common middle ground and is not really needed….
0.1) To do this just download the installer from the App Store and then use “DiskMaker X” to create a bootable installation.
0.2) After the bootable image is created, proceed to turn off your computer and hold the “Alt” or “Options” Key. Select the Sierra installer and proceed with the installation (I format the HDD partition to make a clean install on it)
Note: You might need to do this on another computer. Just buy one of those cheap usb to sata connectors and use it to connect it to another Mac so you don’t risk having your installation failed because of your machine.
Step 1) Prepare a Bootable USB pendrive with a non GUI Linux (Credits to AppleMacFinder)
1.1) Download ArchLinux ISO
You need a working computer for that and a spare CD/DVD/USB drive. Download the latest Arch Linux ISO image from this page -
https://www.archlinux.org/download/ , at the time of writing it is
archlinux-2017.03.01-dual.iso . Then you could either simply burn this ISO to CD/DVD
(which later could be either inserted to MBP's SuperDrive or External DVD Drive connected to MBP by two USB cables) or create a bootable USB: use the great detailed instructions from this page,
https://wiki.archlinux.org/index.php/USB_flash_installation_media
1.2) Creating the bootable USB with the .iso:
In macOS
First, you need to identify the USB device. Open /Applications/Utilities/Terminal and list all storage devices with the command:
*) diskutil list
Your USB device will appear as something like /dev/disk2 (external, physical). Verify that this is the device you want to erase by checking its name and size and then use its identifier for the commands below instead of /dev/diskX.
A USB device is normally auto-mounted in macOS, and you have to unmount (not eject) it before block-writing to it with dd. In Terminal, do:
*) diskutil unmountDisk /dev/diskX
Now copy the ISO image file to the device. The dd command is similar to its Linux counterpart, but notice the 'r' before 'disk' for raw mode which makes the transfer much faster:
*) sudo dd if=path/to/arch.iso of=/dev/
rdiskX bs=1m
After completion, macOS may complain that "The disk you inserted was not readable by this computer". Select 'Ignore'. The USB device will be bootable.
Step 2) Boot to Linux (Credits to AppleMacFinder):
2.1) Boot to it: insert this CD/DVD/USB to Macbook Pro, hold
Option key while booting, choose "EFI boot"
(that is your bootable installation media), press "
e" key to edit the GRUB options of the
Arch Linux archiso x86_64 UEFI CD menu entry while it is selected at the main screen, add
nomodeset to the end of this line and press
Enter. If everything is done correctly, you will find yourself at the Linux console! (It takes some time so be patient and wait for the prompt)
2.2) Edit EFI vars: looks like
efivarfs filesystem is mounted by default! So you can already
cd /sys/firmware/efi/efivars and
ls to explore this directory and see if there is a
"gpu-power-prefs-..." variable
(where ... is UUID of this variable).
2.2-Case 1:
If there is such a variable, its better to remove it with
rm.
*) rm gpu-power-prefs-…
In my case the
efivarfs has been mounted by default with read/write permissions, but if you are getting the
"operation not permitted" message while attempting to
rm, it means that in your case
efivarfs has been mounted as read-only and you need to remount it with read-write permissions and try again
(credits to totoe_84 for this valuable addition) (Try this and then try to remove it):
*) cd /
*) umount /sys/firmware/efi/efivars/
*) mount -t efivarfs rw /sys/firmware/efi/efivars/
*) cd /sys/firmware/efi/efivars/
*) rm gpu-power-prefs-…
If this also fails (If you still can’t erase the file) use chattr command to disable file immutability and then erase the file:
*) chattr -i "/sys/firmware/efi/efivars/gpu-power-prefs-…”
*) cd /sys/firmware/efi/efivars/
*) rm gpu-power-prefs-…
2.2-Case 2:
The file gpu-power-prefs-… doesn’t exist well then you don’t have to delete it hahaha. (I repaired 2 17 inch models and 1 didn’t have it, so it’s fine)
2.3) Create a new gpu-power-prefs-… file (Original credit mentioned above,
https://github.com/0xbb/gpu-switch/blob/master/gpu-switch,
Credits to AppleMacFinder):
*) printf "\x07\x00\x00\x00\x01\x00\x00\x00" > /sys/firmware/efi/efivars/gpu-power-prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9
2.4) Add immutability to the gpu-power-prefs-… file (Credits to AppleMacFinder):
This chattr command is supposed to lock a file to make it accessible only by "superuser" - and so that, while booting, your EFI will have no chance to screw up your
gpu-power-prefs-... variable under any circumstances
*) chattr +i "/sys/firmware/efi/efivars/gpu-power-prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9"
2.5) Unmount efivars and reboot (Credits to AppleMacFinder):
Could not unmount efivars if you are inside this directory, so change to the root directory
*) cd /
*) umount /sys/firmware/efi/efivars/
Guarantees that your EFI variables are flushed to efivarfs filesystem, please unmount it safely before rebooting)
*) reboot
3) Eliminate AMD Kexts (Credits to newfield),
Note: You might need to do this every time you do an OS updates, since each update normally writes the AMD Kexts again.
(His words and this also happened to me!: After disabling the dGPU using Arch, normal boot would hang halfway. Although safe boot would work. I wound up having to remove all the AMD kext files in the Terminal in Recovery Console)
Trying to remove them in Single User just gave me sandbox errors. (Summary -> Don’t do it in Single User Mode the one that you boot with Cmd + S)
3.1) So what you have to do is:
If you have FileVault Unlock it first:
Unlock first.
Then Boot into Recovery (“cmd + r”, it will boot without failing, if it fails then repeat step 2 and then after that boot directly into recovery with command + R, I had to do this once because the dGPU got active again after booting into the os with AMD kexts)
*) Boot into recovery mode (Command + r)
*) Start Terminal
*) diskutil cs list (find UUID for drive)
*) diskutil coreStorage unlockVolume UUID
*) cd /Volumes/Macintosh\ HD
*) mkdir AMD_Kexts
*) mv System/Library/Extensions/AMD*.* AMD_Kexts/
*) reboot
(If you only have one storage with 1 partition just use "cd /Volumes/Macintosh\ HD" and the remaining commands after starting the terminal)
Extra STEP), if your PC is now working! Download “steveschow” branch of gfxCardStatus (gfxCardStatus v2.4.3i) or just download the app directly from:
URLS:
https://github.com/steveschow/gfxCardStatus/releases
https://github.com/steveschow/gfxCardStatus
With this application you can even prove that the dedicated GPU can't get activated. Even if you try to change the selected GPU to the dedicated one, it just won't change.
—————
The End!
AND VOILA!!! You have a working 17 inch MacBook Pro. As I said I tested this with an early 2011 and late 2011 17 inch MacBook Pro’s and both are now running (Before they were both dead)
Big thanks to AppleMacFinder, to the makers and contributors of this thread, to gfxCardStatus maker and forkers
(steveschow) and to switch-gpu makers I can’t thank you guys enough as I am so happy to bring both of this incredible machines back to life. With this post I am not trying to take any credit, but as I had 2 machines I run into different issues with both, which could be helpful to others, thats why I was inclined to make “my own” guide and share it with you.
I just created an account here to share this, Hope it helps more people!