All posts

Fixing frequent, random and silent shutdowns in Macbooks


Few months ago my 15" 2014 Retina MacBookPro developed a strange problem. The symptoms were that the laptop screen will go off abruptly, the fan speeds up lot after the screen goes off and finally the laptop shutsdown. This was strange! Initially I thought it might be a battery problem but when the problem didn't go away even when the laptop is on charge, I suspected somthing might be amiss. There was nothing in the logs. The reason for shutdown has a code which corresponds to "unknown". Weird! The time at which the shutdown occurs from booting up is absolutely random, from couple of minutes to several hours. Its frustrating to recreate and its annoying to work with the laptop.

The first thing I noticed was that the issue started after I updated my OS to high sierra. It could not be a coincidence. So I started by resetting everything to factory setting from scratch. Then tried resetting PRAM and SMC. When these didn't solve the problem, I took it to an Apple store for service. This is where it got worse

The Apple "Genius" took a look at the machine and ran a full diagnostics suite. It showed that the hardware were completely alright. There is nothing wrong! Even the battery, after 4 years, was in a healthy condition. After being stumped for few minutes, the guy just gave up and told me to just replace the logic board and battery. He went on to give a quote of around £800 including labour and parts and was actually being serious! The other option was to spend a bit more to get a new laptop. The trade in value of my mac was £0! I pretty much gave up at this point and decided I am just going to get a cheap laptop and install linux on it.

I got a Lenovo Ideapad 120S for £200, installed Arch linux with i3 and moved on. Then at somepoint, I came back to the Macbook to see if I can just make some money from it by selling the parts individually. While looking things up I came across this. There was a more detailed discussion here which pointed out that the entire issue is a result of a buggy driver in High Sierre and disabling the driver entirely can fix the laptop. I tried the fix and it worked! My laptop working again and in this post I detail the fix.

The Fix

First step is to boot into "Recovery Mode". This is done by pressing Cmd key and R key together while powering on the machine. You can release both of them once the apple logo shows up.

The recovery mode looks like this.

In the recovery mode, open the "Terminal" from "Utilities" menu at the top bar.

Terminal window looks like this.

Type csrutil disable in the terminal and press "Enter" key. Terminal should display a message that the system intergrity protection has been disabled.

Now restart the machine. This time let it boot normally.

After you are logged into the machine, search and open the "Terminal" app This is done by pressing Cmd and Space Bar together, then typing terminal in the box, then pressing Enter

Usually this terminal looks exactly the same as the last terminal, but since I have customised mine, it looks different.

Now try running the command

ls /System/Library/Extensions/ | grep Thunderbolt

This should show a list of kernel extension files which are installed in the system. The buggy driver is the AppleThunderboltNHI.kext. This is the file which causes the laptop to shutdown without any warning. Its function is to manage the thunderbolt to ethernet adapter which is not as critical as a functioning laptop. So we can just disable it altogether by either deleting or moving this file to somewhere else.

Deleting this not advisable since if something goes wrong we might still need the orginal file to revert things back to normal. So we'll just rename the file with different extension so that the OS doesn't load it on boot.

Now we rename the file by running the following command

sudo mv /System/Library/Extensions/AppleThuderboltNHI.kext /System/Library/Extensions/AppleThuderboltNHI.kext.BAK

Type the password and press enter when asked. Now if you run the previous command (starting with ls) again you can see that the extension of the file has changed to .BAK. Note that we can edit this file only because we disabled the csrutil earlier. This is a system designed by Apple to protect the operating system files from being editied by the user by accident. So the next step is to enable this protection again.

We shutdown the system

Boot into the recovery mode again by pressing Cmd+R. Run the command, csrutil enable in the terminal.

Finally reboot the machine.

Voila! Your Macbook should be fixed now. The only problem now is that the thunderbolt to Ethernet adapters won't work from now on since the driver is not loaded. Apart from this, apple updates will add this file again when it finds it missing so this moving the file needs to be done after every system update.



Comments