Wednesday, April 28, 2010

Windows on Intel Mac and AHCI mode

My configuration:
single internal hard drive in iMac with a single NTFS partition. This is BIOS identifier (hd0,1). In linux, this will be SATA device /dev/sda. The SATA controller is from ICH8M and has PCI identifier 8086:2828. Please change these references to your system configuration.
Don't worry, I still have OS X on an external FW800 drive but that's not relevant here.

First of all, I tried loading Windows 7 on my Intel Mac and then came to a few conclusions:
  • BIOS mode boot has the negative side-effect that it disables AHCI mode in the SATA controller. This leads to degraded performance of hard drive access.
  • EFI mode boot of Windows 7 requires EFI 2.0 which isn't included in the firmware.
  • Macs don't like to boot from external devices. Windows doesn't like to be installed on external drives.
So I swapped my OS X drive with Windows drive in the process of undusting my iMac. It now can boot both OSes.
This post is all about getting the SATA controller back into AHCI mode after the compatibility layer in the intel Mac changed it. AHCI gives NCQ and might be somewhat faster so I really wanted to try that after my younger brother nagged me about it during our dayly Mac-vs-PC argues.

I can talk about what I did wrong during those attempts but I will try to keep it short:
  • Start regedit and locate the following key: HKLM\System\CurrentControlSet\Services\msahci
    Change the "Start" value to "0". This will make Windows attempt to load the AHCI driver stack when it boots.
  • Download a Linux live-CD with GRUB 1.98. (others might indicate 0.xx as grub and 1.xx as grub2). I decided on the latest Ubuntu live-CD. Older versions just won't do unless you want ugly patches. You want to have the setpci grub module.
  • Download the "Rapid Storage Technology" manager software (includes the driver) and the "RST Driver Files for F6 Install" from the Intel website.
    In my case the latest version for x64 Windows was iata96enu.exe and
    The manager software will not install yet but you have to install at least the driver by unpacking it and force a device installation:
    Go to Device Manager, select Serial ATA Storage Controller, Update driver software, Browse, Pick from list, Have disk, Ignore the warning. This should be ok since the next time you'll boot Windows, the device will be different anyway.
  • Boot the Linux CD :-)
    Hold option key when booting the Mac to see it as a boot option. Load the System until you can start a terminal. Get root access:
    sudo -i
  • Because it booted from CD, it doesn't know much about the hard drive. Therefore create a device map file that maps (hd0) to /dev/sda.
    vi /boot/grub/
    If you know some linux, you know what I mean.
  • Mount your Windows partition in Linux.
    mkdir /mnt/win
    ntfs-3g /dev/sda1 /mnt/win
  • Install grub to the MBR and copy the data files too.
    grub-install --no-floppy --modules=ntfs --root-directory=/mnt/win /dev/sda
    This should report no error.
  • If you already had a Boot directory on your Windows partition (most likely), you'll now have two boot directories (-.-); Fix it by moving the contents.
    mv /mnt/win/boot/grub /mnt/win/Boot

    rmdir /mnt/win/boot
  • reboot
    reboot (duh)
  • At the grub prompt you should now be able to try some commands.
    setpci -d 8086:2828 90.b=40
    lspci (should now show 2829 instead of 2828)
    root (hd0,1)
    chainloader +1
  • If Windows now boots, it should be in AHCI mode and hopefully go ask for the drivers.
    You can install the RST manager or just check the Device Manager to see if it's working as intended.
  • You can create a C:\Boot\grub\grub.cfg file to automate the booting process. (Note: 'Manual editing of /boot/grub/grub.cfg is not encouraged')
    set timeout=10
    set default=0
    menuentry "Windows 7 with AHCI" {
    setpci -d 8086:2828 90.b=40
    set root=(hd0,1)
    chainloader +1
  • PS: If somehow Windows booting was not working in the first place or you don't want any of this anymore, you can use the Windows 7 DVD. Some recovery commands you then can use:
    bootrec /FixBoot

    bootrec /RebuildBcd

    bootrec /FixMbr
    (should erase grub again but I don't know why you would want that)
I this I have all my notes into this post and hope that besides me remembering how to do it, also will help you and other Mac fans :P


Anonymous said...

I dual-boot Linux and Mac OS on a MacBook. Just got an SSD and needed to enable AHCI on Linux as well.

I was already running grub2, so all I did was add "setpci -d 8086:2??? 90.b=40" to my grub.cfg (just before the "set root ..." line).

Works perfectly. Thanks for the tip.

will said...

I never been PC guy, i got my 1st Mac Back in mid 90's. I only use Windows for misc stuff and in past i've just used Paralle or Vmware. I'm just getting into mobile development and updated my Mac Pro G5 Quad -Duo INTELL model 4.1 please not: I UPDATED GRAPHIC"S CARD ATI Radeon HD 4870 1024MB. this isn't 512 card apple sells, I found it on eBay and It came with pre-install drivers and i was told i would not have to worry with flashing card or anything else. Works great and i haven't had any problems in OSX, PC, or LINUX. I added RAID which uses all 4 internal Bays & eSTATA card for external drives. I'm using the one internal eSTAT on board for OSX Raid BOOT Drive, whch is partition 3 way's. 1. OSX 10.6.4 2. OSX 10.6.5 Xcode 3. OSX Home Directory. eSTATA card has 2 ports 1. port is used with OSX RAID BOOT. Here's where i need the HELP. 2nd port i want to use for Windows 7 & Ubuntu 10.10 which will be release in few weeks. eSTATA card only boots Windows in AHCI mode. I follow this: ... ode-t3159/ which work. I'm using 64Bit Kernal to boot all OS's, I tweak OSX in terminal to always boot 64. The probel is that I"m unable to install BOOTCAMP DRIVERS!!! Bootcamp drivers will not work eSTAT drives. i've tried different formats with setting up drives. At 1st i wasn't going to to do OSX RAID Boot, i had it as triple boot on 1 drive which i have down to science with refit on normal SATA drive. Since BOOTCAMP drivers didn't work i figure why not. So i figure to put Windows & Ubuntu on same drive. I have formated as Master Boot record, windows 7 1st partiton. DOesn't matter how i install Bootcamp Drivers, i've tried install from OSX DVD and i pull 64 bit off install them seperatly. After i reboot Windows Kernal CRash with in 3 mins of logging in. Only way to boot is in safe mode. Can some body help me install BOOTCAMP drivers from APPLE OSX DVD. Also i'm unable to update to the Intell AHCI driver, i have to use the Generic Microsft driver.

Unknown said...

discussion on insanelymac

Marctraider said...

How wude.

Marctraider said...

Never the less, very intriguing and interesting method of enabling AHCI for Bootcamp users. I'm definately going to try this. Stupid Apple doesn't care about bootcamp :(

Unknown said...

does this method corrupt bootcamp control panel or sleep ?
thanks .

Marctraider said...

I believe it did, after sleep from S3 the Bios emulation layer seems to be re-initialized and the PCI registers will be reset. Causing a system wide hang.

dacomputernerd said...


Using this to triple boot OSX Lion, Win7 w/AHCI, and Ubuntu 12.01.

The interesting thing, is that Ubuntu isn't on the OSX+Windows boot drive.

It's on a secondary drive mounted in the optical bay.

I did this by partitioning the second disk as MBR, and installing GRUB2 into the disk's MBR.

To use either windows or linux, rEFInd boots GURB2, which then boots the OS.

Also, I can confirm this method doesn't corrupt bootcamp control panel.

Double-G said...

Normally when enabling AHCI for Windows 7 x64 or Windows 8.1 x64 on an iMac 2011 (I did it using patchcode.bin) the AHCI-stuff works but the system can no longer wake up from sleep-mode properly.

Does this also happen with the method mentioned here?
Do you know any fix for the AHCI-sleep-problem?

Double-G said...

Normally when enabling AHCI for Windows 7 x64 or Windows 8.1 x64 on an iMac 2011 (I did it using patchcode.bin) the AHCI-stuff works but the system can no longer wake up from sleep-mode properly.

Does this also happen with the method mentioned here?
Do you know any fix for the AHCI-sleep-problem?