iMac gets stuck halfway through boot A couple of days ago my iMac (Late 2009) stopped turning on. It starts booting and the progress bar under the Apple logo goes to just under halfway before it turns off. Booting into recovery mode and trying to reinstall El Capitan doesn't work because it says the hard disk is locked. I tried running the chflags 0 and chmod to unlock it that are suggested around here from both single user mode and the recovery terminal but to no avail.

The files on the hard drive are all still there, so I tried to use cp to copy some stuff from there to USB disk, but it consistently crashes midway through the copy and goes to the "your computer has had a problem" screen. I've also tried zapping the PRAM.

Running first aid on Disk Utility from recovery mode says "file system verify or repair failed". I also tried booting in verbose mode and noticed it crashes after running fsck_hfs and fails, which I assume is what disk utility is doing behind the scenes.

Any advice on how to backup and then do a clean install or reinstall from recovery or just fix it would be very appreciated!
The symptoms you describe are indicative of a disk drive corruption.  It could be  physical (hardware) or just a file system corruption.

Recovery will require booting from a different drive so you can copy files over.  You can boot from an external USB that has a clean install of OS X (El Capitan would be the latest as your system is not capable of running Sierra) or replace the internal drive with an SSD and attempt recovery via USB.

Personally, I prefer the latter.

The full repair guide is available on ifixit.com, but here are the basic steps you need to go through

You will need the following:


New SSD Drive.  I recommend the Samsung EVO series
USB to 3.5" SATA adapter.  This is so you can access the drive for recovery
El Captian Installation Media. Note that this vintage iMac (2009 through Late 2011) will support up to High Sierra - 10.13.x
Suction Cups (for glass removal)
Torx T10 screwdriver
plastic spudger for connector removal
2.5" to 3.5" kit so the new drive will fit
External HDD for Time Machine (Optional, but highly, highly recommended)


Remove the glass.  The good news is that the glass panel is held in with magnets which you can remove with suction cups and the LCD itself is held in with 10 Torx screws.




Replace the drive. Once you have the panel removed, you will get access to the 3.5" Hard Drive (see pic below)



When you replace the drive, ensure that you replace the temperature sensor, otherwise you will end up with a fan that spins uncontrollably, and erroneous temperature readings.

Just reverse the steps to re-assemble your iMac.

Clean Install OS X. Using the boot media, do a clean installation of OS X.  Then reinstall your apps.

Begin recovery.  Using the USB to SATA adapter, hook up your old hard drive to your iMac via USB.  You should be able to mount it and cp (copy) your data off.  Once done, you can discard your drive (it's quite old and I wouldn't trust it for data storage anymore).  Take it to your local electronics recycler or sell it "as is, for parts only" on eBay; many recovery shops will take it for the PCB or server motors.  You won't get much, but it keeps it out of a landfill.

Set up Time Machine.  I can't stress this enough... having a backup besides (or in addition to) iCloud is extremely important.  Right now, you are finding out first hand how valuable a Time Machine backup can be.