Skip to main content

Recovering from a failed iMac hard drive

Back in late December the hard drive on my iMac failed... kaput! Disk utility couldn't fix it nor could it erase the drive. It had become a paper weight. Thankfully, I had time machine running for selected files/folders on the iMac (but not the whole system), which allowed me to restore to a new computer in a timely fashion. This week I found myself wanting to reference an article on my blog site and realized it wasn't loading (it was only a local blog at this time). No problem, I went to the time machine backup and pulled the code for the site. Then I went to connect the code to the database and I realized that the databases had not been backed up! Fuck! Three years worth of blog posts down the drain!

I got to thinking, maybe I could try connecting to the drive with terminal on the old iMac. So I booted into the recovery mode partition and opened the terminal application from the Utilities menu. Then I ran the following command:

Recovering my hard drive with terminal

1. diskutil list

This gave me the list of available hard drives on the computer.

Then I tried to mount the broken hard drive with this command:

2. diskutil mount /dev/disk0

This returned the following error telling me to use:

mountDisk

So I tried this command:

3. diskutil mountDisk /dev/disk0

This command mounted the broken hard disk. So, I browsed to the MAMP Pro database location with:

4. cd /Volumes/Macintosh\ HD/Library/Application\ Support/appsolute/MAMP\ PRO/db/mysql

Sure enough the database I was in need of was available. So, I put in a thumb drive and mounted it (same method as #1 and #2 above). Then I saved the entire 'mysql' directory to the thumb drive with this command:

5. tar -zcvf /Volumes/Thumb\ Drive/mamp-databases.tar.gz ./mysql

Ten minutes later the thumb drive contained a backup of the databases from the broken computer.

Next I restored the databases into my new iMac's MAMP. Instructions for how I did this will follow soon.

The lesson:

Before giving up on your data, try connecting with the command line. It just might save your (digital) life someday.


Comments