Skip to content

Instantly share code, notes, and snippets.

@onuralp
Last active January 6, 2024 16:48
Show Gist options
  • Save onuralp/18936148497253f2a43bd14148a811ca to your computer and use it in GitHub Desktop.
Save onuralp/18936148497253f2a43bd14148a811ca to your computer and use it in GitHub Desktop.
Rescue your data from a corrupted hard drive on macOS

Recover files from corrupted external hard drive on MacOS

The error:

macOS can't repair the disk BLA
You can still open or copy files on the disk, but you can’t save changes to files on the disk. Back up the disk and reformat it as soon as you can.

The solution:

Basically, you copy everything to somewhere safe but the corrupted files.

You can skip step 1 and 2 to copy files directly from the corrupted hard drive to another drive. But it is a best practice to get an image of that drive first. This will help you to recover files from the corrupted drive in case of any further failure.

1. Copy Disk Image to a healthy disk

1.1 Install DDRescue

brew install ddrescue

1.2 Find the disk name

Get the Identifier of the corrupted drive using the following command: I.e. disk2s1

diskutil list

1.3 Copy the disk image

Replace disk2s2 with the identifier of your corrupted drive.

sudo /usr/local/bin/ddrescue -v -n -c 4096 /dev/disk2s2 Rescue.dmg Rescue.log

2. Mount the disk image via Disk Utility App

Open Disk Utility App and select the disk image file Rescue.dmg. Click on Mount button.

3. Copy the files from mounted disk to somewhere safe

ls /Volumes/ to get the name of the mounted disk. I.e. Rescue

Replace DISKNAME with the name of the mounted disk.

cp -Rfp "/Volumes/DISKNAME" ~/Desktop/Recovered

4. Verify the files and Unmount the disk image

Verify the files and unmount the disk image.

5. Delete the disk image

Delete the disk image file Rescue.dmg and Rescue.log file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment