OK, so I think I’m on the right track. This sudden shutdown is likely due to bad memory. There is nearly 32GB of memory in the iMac 2009 and it is third party, so could be bad. But figuring out how to diagnose it more a riddle. The main problem is that hitting the D key during reboot does not bring up the Diagnostic nor does holding the Option-D key.
The history of this tool is that it sort of works but it doesn’t function properly on older hardware with newer MacOS.
So what’s a person to do, well someone has gone through the trouble of finding the links for all the old AHTs, then you just burn a USB key and it works. Basically what happens is that if you clean install your old computer, the old AHTs are not kept of course, so now you have to download them. Newer Macs will actually download the AHT over the Internet, but the 2009 iMac doesn’t do that.
Note that even if you get this installed, MacRumors says the memory tests are really not that good, so you need to download memtest86. The free version seems right for most uses. That thing isn’t big on documentation, but you get a .tar file that you untarnished and you will see a README and a IMG file, but basically they are to use diskutil list to figure out what the actual disk number of the USB is and then do

diskutil unmountDisk <dev>
sudo dd if=<memtest.img> of=<dev>

Also with Sierra MacOS, you can’t even install them into the operating system (as that’s a security issue), so the preferred way is to now burn a USB key with the proper AHTs. Duplicating the answers, you figure out your actual model with it’s suffix

sysctl hw.model | awk '{ print $2 }'
ioreg -l | awk -F\" '/board-id/ { print $4 }'

Naturally (as luck is going to have it), the precise model I need is iMac11,1-F2268DAE but this doesn’t appear on the list but is in a package called iMac10,1 that tries to install it into the system folder.
First get a USB Key and make sure it uses GUID Partition and OS X Extended file system. Then copy all of the files and sudo bless the USB so it will boot. Assuming your USB key is at /Volumes/USB Key then you would do:

cp -r /Volumes/AHT/System /Volumes/USBstick/
sudo bless --folder /Volumes/USBstick/ --file /Volumes/USBstick/System/Library/CoreServices/.diagnostics/diags.efi --label AHT

I’m Rich & Co.

Welcome to Tongfamily, our cozy corner of the internet dedicated to all things technology and interesting. Here, we invite you to join us on a journey of tips, tricks, and traps. Let’s get geeky!

Let’s connect