AHCI compliance on Macs running Windows and Linux

Discussion in 'Windows 7' started by PeterHolbrook, Sep 17, 2009.

  1. PeterHolbrook

    PeterHolbrook MDL Addicted

    Aug 24, 2009
    917
    338
    30
    #1 PeterHolbrook, Sep 17, 2009
    Last edited: Sep 17, 2009
    Following the advice given by Daz, here's my report on how I managed to use AHCI on an activated copy of Windows 7. It may be used, with minor modifications, for people running Linux on Macs. It can even be used on regular PCs, provided the user knows what they are doing.
    --------------------------------------------------------------------------


    OK, after some tests I can report that AHCI awareness is perfectly achieavable on machines with that architecture (for instance, Macs) in which W7 has been installed and activated (for instance, through Daz and zsmin's loader). The credit of this procedure goes to johnsock, although, for some reason, his script didn't work in my case. This might be due to three reasons. The first one is that the hash of the MBR used by johnsock belongs to a pre-RTM version of the W7 MBR; the second one is that the hash belongs to a 32-bit MBR, whereas mine is 64-bit (supposing there's a difference); the third one is that the MBR of an activated machine is different from the one contemplated in johnsock's script.

    Be that as it may, those wishing to explore AHCI awareness in Windows and Linux can do so at their own risk. Be advised that this procedure isn't for the fainthearted, that it involves certain danger of rendering the Windows partition unbootable and that it requires certain expertise in the use of certain programs (regedit, hex editors) and command line entry. Because of the difficulty involved in MBR manipulations from the Windows side, and the certain danger that users of regular PCs might mess up their systems, part of my explanation involves instructions that can only run on a Unix operating system (such as a Mac OS X). I take no responsibility for whatever disaster the following may entail for novice users:

    1. Boot into Windows (not OS X) and browse to the Intel website. Look for the Intel Matrix Storage Drivers for Windows. In my case, the file is called IATA89ENU.exe. Download it and leave it somewhere safe; for instance, your Windows desktop. Don't bother running it; it won't work.
    2. Enter Command-r (Windows-r), type regedit and press Enter. If asked, say you want to run the registry editor as an administrator.
    3. On the left-handside pane, navigate to "HKLM\System\CurrentControlSet\Services\msahci "
    4. On the right-handside, edit the "Start" key and change the value from what it is to 0. This simply tells Windows to look for AHCI on the next reboot. It does nothing if, on the next reboot, the disks are still set to legacy mode.
    5. Close all Windows programs and reboot into Mac OS X.
    6. Open Disk Utility and locate your Windows volume. Click on the device containing that Volume and ascertain its identity (right-click on it). Let's assume that the device is called "disk1"
    7. Open a Terminal window (Applications, Utilities, Terminal).
    8. Enter sudo -s
    9. OS X will prompt you for the root password. Enter it.
    10. Remembering that any error in typing might be disastrous for you, type the following (remember to change "disk1" by whatever you found in step 6):
    11. dd if=/dev/disk1 of=~/w7.mbr bs=446 count=1
    12. For those of you who want to know, this copies the first 446 bytes of /dev/disk1 (the entire Master Boot Record) to a file ("w7.mbr") in your home folder. This serves two purposes: making it possible to restore the working MBR if something goes wrong and making the hack possible.
    13. Go to your home folder and make a copy of that file (for instance, using the Finder) onto the same folder. Rename the copy to w7AHCI.mbr
    14. Open w7AHCI.mbr with a hex editor. For instance, HexEdit for Mac OS X.
    15. Look for offset 162h. As a precaution, the next few bytes at that address are C3 49 63 76 61 6C and so on.
    16. If you know what you are doing, enter the following bytes in place of existing ones between offsets 162h and 173h: 66 B8 90 FA 00 80 BA F8 0C 66 EF B0 40 BA FC 0C EE C3
    17. The above are the "magic" bytes that will switch the drives back to AHCI mode.
    18. Now from offset 174h to offset 190h enter 00 00 00...
    19. And now we'll shorten the messages near the end of the MBR. From offset 191h to offset 1B7h, enter the following bytes: 42 61 64 20 70 61 72 74 69 74 69 6F 6E 20 74 61 62 6C 65 00 42 61 64 20 4F 53 00 4E 6F 20 4F 53 00 43 4B 4A 91 A5 AC
    20. Save the modifed file and exit the hex editor.
    21. Now for the really risky part. In Disk Utily, click on your Windows volume and, using the toolbar, unmount it! You will see your Windows disk disappears from your OS X desktop.
    22. Go to your Terminal and enter this command (any typo could be fatal; remember that, in place of "disk1", you should type whatever you found in step 6):
    dd if=~/w7AHCI.mbr of=/dev/disk1 bs=446 count=1
    23. If the operation was successful, you will see your Windows disk reappear on your OS X desktop.
    24. Now boot back into Windows. If booting is achieved, chances are you are on the right track. If not, follow the next instructions:

    ------------------------------------------------------------
    If disaster strikes, this is what you have to do:
    1. Once again, boot into Mac OS X.
    2. Open Disk Utility and locate your Windows volume. Click on the device containing that Volume and ascertain its identity (right-click on it). Let's assume that the device is called "disk2" (disk identities can change from boot to boot).
    3. Unmount that volume using Disk Utility. You'll see your Windows disk disappear from your OS X desktop.
    4. Open a Terminal window (Applications, Utilities, Terminal).
    5. Enter sudo -s
    6. OS X will prompt you for the root password. Enter it.
    7. Enter the following command (remember to replace "disk2" with whatever you found in step 2 above):
    dd if=~/w7.mbr of=/dev/disk2 bs=446 count=1
    8. If the operation was successful, you have successfully restored your original MBR and you will see your Windows disk reappear on your OS X desktop. No harm done.
    ------------------------------------------------------------

    Now, let's suppose you didn't mess up your Windows boot. Let's proceed to step 25:

    25. Windows will detect "new" hardware (your AHCI drive(s)). It will install its own AHCI driver. When that is done, you'll be asked to reboot.
    26. Reboot into Windows. If it detects new stuff, reboot once again.
    27. Now you want to install the Intel AHCI driver. Go to your desktop (or wherever you left the Intel installer) and double-click on IATA89ENU.exe (or whatever the installer is called).
    27. It will install the intel AHCI drivers and ask you to reboot. Reboot into Windows.
    28. "New" hardware will be detected once again and you are asked to reboot. Reboot.
    29. You are done. Your W7 is still activated and you have AHCI up and running.

    Users of regular PCs have a much simpler solution. Just change the Windows registry key, enable AHCI in your BIOS and, on the next reboot, Windows should detect your AHCI drives. Then follow steps 25-29 above and everything should be fine.

    --------------------------------------------------------------------
    EDIT: VERY IMPORTANT INFORMATION
    I've just verified that, however good and convenient AHCI is when running Windows on a Mac, AHCI awareness DISABLES calling the Boot Camp Control Panel. All normal Boot Camp functions can still be controlled via the keyboard, but you can't choose the Startup Disk, and neither can you choose to restart the computer in Target Disk mode. Perhaps a full uninstall of Boot Camp after AHCI activation followed by a reinstall might solve the issue with AHCI awareness. If not, this time you know it isn't Microsoft's fault, but Apple. If someone is willing to try the method above and report on the successful or unsuccessful launch of the Boot Camp Control Panel after uninstalling Boot Camp 3.0 and then reinstalling it, Mac users, me included, will be thankful.
     
  2. Barrym

    Barrym MDL Novice

    Aug 16, 2009
    32
    0
    0
     
  3. PeterHolbrook

    PeterHolbrook MDL Addicted

    Aug 24, 2009
    917
    338
    30
    From what you sent me, there seems to be something wrong in your modified MBR. Check up the file I've sent you.
     
  4. DerDirk

    DerDirk MDL Novice

    Nov 26, 2009
    1
    0
    0
    Hello,

    thank you very much for your very detailed guide to activate AHCI mode.

    Cause jonsock's script is for Intel chipsets only, I didn't try it till now.
    What do you guess? Could your way work on a MacBook Pro with nVidia MCP79 too?

    Please tell me, which strings are the important one.
    Btw I would like to activate AHCI for Windows XP, but for a test I also could install Windows 7. According to the mbr, is there a difference between the 32 or 64 bit version?

    I look forward to your answer.

    Cheers
    DerDirk
     
  5. PeterHolbrook

    PeterHolbrook MDL Addicted

    Aug 24, 2009
    917
    338
    30
    Sorry I didn't see your question before. Johnsock's code simply shortens a few messages displayed only if something goes wrong when running the MBR code. The extra space created by this shortening is used to add one single instruction: setting capable disks to AHCI mode. It should work on both 32-bit and 64-bit systems, but I guess mixing MBRs from different operating systems might be risky. If you want to modify your current MBR using Johnsock's method, go ahead, but make sure (according to my tutorial) that you modify your MBR, not somebody else's. And, above all, make sure you have a viable copy of your unmodifed MBR, just in case something goes wrong.

    In any case, as I've said before, AHCI implementation (at least with IATA89ENU) is not fully compatible with Boot Camp 2.x/3.0, since the Boot Camp panel stops being accessible. Perhaps Boot Camp 3.1 might solve that, but I wouldn't count on it.
     
  6. PeterHolbrook

    PeterHolbrook MDL Addicted

    Aug 24, 2009
    917
    338
    30
    I'm sorry to report that the newest Boot Camp update (3.1) continues to be incompatible with an AHCI-enabled MBR (meaning the Boot Camp panel can't run). The solution might be as simple as tweaking some registry key, but I have no idea which one. If anyone does, let them comment.
     
  7. PeterHolbrook

    PeterHolbrook MDL Addicted

    Aug 24, 2009
    917
    338
    30
    Apple have just released Boot Camp 3.2, but its Windows Control Panel continues to be incompatible with AHCI drives. This means that if all your bootable drives (or your only bootable drive) have been made AHCI-compatible, the Boot Camp Control Panel won't see any of them. This causes one of the tabs (actually, the one that lets you choose the startup disk) to stop working. I've come to realise there's an almost perfect "solution" for this anomaly: Simply insert a bootable CD-ROM into your DVD drive. It can be any Windows or OS X bootable disc. If you do that, the Boot Camp Control Panel will work perfectly well, with one single caveat: it won't see either your OS X disk or your Windows disk as bootable devices; just the bootable CD or DVD you've inserted. So, for now (until Apple decides to make Boot Camp fully compatible with AHCI disks), you need to do the following:
    1. If you want to restart in OS X, simply forget about the Boot Camp Control Panel. Go to the Windows Start Button and choose Restart. Should that be necessary, press Option when you hear the chimes and choose your Macintosh HD or partition.
    2. If you want to change your default startup disk, go to OS X and do it in System Preferences (however, you won't see your Windows disk if you have Snow Leopard AND the Paragon NTFS for OS X driver).
    3. If you want access to any other tabs in the Boot Camp Control Panel, insert any bootable CD, go to your System Tray, locate the Boot Camp icon, right-click on it and select Boot Camp Control Panel, which will work. Go to the tab you want and do whatever you intended to do. When you are done, you can eject the bootable CD.
     
  8. JamesRock

    JamesRock MDL Novice

    Mar 9, 2011
    1
    0
    0
    #9 JamesRock, Mar 9, 2011
    Last edited: Mar 9, 2011
    I got an imac 27" (Late 2009,i5, 2,66ghz) and a vertex II ssd with the bootcamp partition on it. I replaced my superdrive with this new ssd.
    I experienced very slow test results for my ssd under bootcamp win7 (64bit) and i got to know thats because of using ide for my ssd. I googled through the internet and finally found this guide.

    I managed to follow exactly through every single step of your tutorial, believe me, I was super cautious^^.
    I was able to modify everything correctly and i am also able to boot successfull into my win7 bootcamp system after the modification is done, (and I am sure I have overwritten the old MBR due to the msg that its wrtitten successfully through the terminal) the only problem is, win7 does not find any "new hardware". I just tried to install the latest driver from intel afterwards, but installation closes with "This computer does not meet the minimum requirements for installing this software". So everything just seems to be untouched in regard of AHCI for my ssd.
    Do you have any idea why this could be the case?

    Thanks in advance,

    James
     
  9. PeterHolbrook

    PeterHolbrook MDL Addicted

    Aug 24, 2009
    917
    338
    30
    #10 PeterHolbrook, Mar 25, 2011
    Last edited: Mar 25, 2011
    (OP)
    I don't visit this thread very often, so excuse my delay in answering. The fact that you receive such a message is an indication that, even though you have modifed your MBR, Windows is not aware of AHCI. You may have forgotten one significant step: HKLM\System\CurrentControlSet\Services\msahci\Start should be changed to 0.
     
  10. Euclid

    Euclid MDL Novice

    Jul 24, 2009
    16
    11
    0
    #11 Euclid, Apr 13, 2011
    Last edited: Apr 13, 2011
    If anyone is interested the "magic bytes" translates to:
    66 B8 90 FA 00 80 BA F8 0C 66 EF B0 40 BA FC 0C EE C3

    seg000:0162 mov eax, 8000FA90h
    seg000:0168 mov dx, 0CF8h
    seg000:016B out dx, eax
    seg000:016D mov al, 40h ; 40 = AHCI mode
    seg000:016F mov dx, 0CFCh
    seg000:0172 out dx, al

    Which is what johnsock has figured out already but I could only find when searching for the above code :)
    www!insanelymac!com/forum/index.php?showtopic=126089&st=71
     
  11. Zortrium

    Zortrium MDL Novice

    Apr 18, 2011
    1
    0
    0
    #12 Zortrium, Apr 18, 2011
    Last edited: Apr 18, 2011
    I'm getting the same behavior (everything seems fine and can reboot no problem, but no AHCI awareness), and I was very meticulous and double checked everything. My guess is that something relevant has changed since the instructions were posted -- maybe that I'm running Windows 7 SP1?

    EDIT: Actually, it's also possible that it's a hardware issue, because I've got the exact same machine as previously mentioned (2009 quad-core iMac).

    EDIT2: Okay, now I think the problem is that our machines have an NVidia chipset rather than an Intel chipset -- as far as I know, nobody has succeeded in enabling AHCI on an NVidia machine.
     
  12. PeterHolbrook

    PeterHolbrook MDL Addicted

    Aug 24, 2009
    917
    338
    30
    I wasn't aware of this issue. In any case, it seems to me the absence of an Intel chipset would certainly cause IATA*.exe not to work, but Windows should in any case use its own AHCI driver if it detects AHCI disks (which Johnsock's code enables). If Windows doesn't detect AHCI drives, there might be two problems:
    1. HKLM\System\CurrentControlSet\Services\msahci\Start is not set to 0.
    2. MBR patching was defective.

    Once Windows installs its own AHCI driver, installing the NVidia AHCI driver on top ought to be trivial.

    As for W7 SP1, I haven't noticed any changes in the MBR ever since I installed the AHCI hack.