Recover Damaged Mac HFS+ disk with Linux

A friend of mine recently set me a challenge to recover 2TB of photo files from a Mac external drive that had failed. Fortunately, it was the USB to SATA converter that failed, so I could extract the bare drive from the case and access it using a SATA docking station.

Problem 1 – Accessing HFS+ disks in Linux

I then hit the problem that the drive used the Mac HFS+ format, which is not very Linux friendly! A search of the web revealed a useful HFS+ utility names hfsprogs. To install this plus the very useful gnome disk utility called Disks, use the following:

sudo apt-get install hfsprogs gnome-disk-utility

With the utilities installed, I could use the Disks GUI to get the /dev/sd details of the drive in question and then use the hfsprogs check disk utility to see if the disk was ok. The command for that is:

sudo fsck.hfsplus -f /dev/sdxx

Problem 2 – Fixing HFS+ disk errors in Linux

The disk check reported errors with an isolated sibling when running the catalog check. I then used the catalog rebuild option to correct that:

sudo fsck.hfsplus -r /dev/sdxx

In the above commands, sdxx is the partition in question and will typically be something like:  /dev/sdb1. You can get the details for the target disk by running the Disks GUI utility.

Problem 3 – Getting r/w access to the HFS+ disk

With the catalogue repaired I discovered that I had permission problems when trying to recover the now visible files! The solution was to use the hfsplus utility to remount the drive with read and write forced to a new mount point. Here’s how to do that:

1 — First unmount the drive: sudo umount /dev/sdxx

2 — Next, create a new mount point folder: sudo mkdir /media/your user name/folder name. For my system, that would be sudo mkdir /media/mike/recovery

3 — Now we can remount the drive to the new mount point with HFS+ read/write permissions using the following:

sudo mount -t hfsplus -o force,rw /dev/sdxx  /media/your user name/folder name. For my system that looks like:

sudo mount -t hfsplus -o force,rw /dev/sdc2 /media/mike/RECOVER

Problem 4 – Adding a 2nd HFS+ disk to take the recovered files

Just to add to the fun, my friend wanted me to copy the recovered files from the failed drive to another Mac disk that was also HFS+ formatted! The solution was to mount the second drive using the process I described in Problem 3 above.

Problem 5 – Copying files from HFS+ to HFS+ disks

Despite mounting the drives as in Problems 3 and 4 above, I was still unable to use drag-and-drop to copy some files due to permission problems. The solution was to use the command line rsync tool to manage the copy. This method is reasonably quick and ensures the best utilisation of space on the target disk. To copy the directory structure as well as the permissions you need to use the -a (archive) option. If you’re not worried about preserving permissions, use the -r option (recursive) instead. There is also an option to show progress which is useful when you’re moving lots of data. To show progress and –progress to the command. Here’s the command: rsync -a –progress disk and directory 1 disk and directory 2

Here’s a real example for my system: rsync -a –progress /media/mike/RECOVER /media/mike/SAFE/RECOVER

Note: In the final couple of commands I used the path name for the mount point and not the device (/dev/sdxx). If your path names include spaces you just have to enclose that name in single quotes. So, for a drive called My Disk on my system, the location would be:

/media/mike/’My Disk’

Please let me know if you find this useful :-))



No comments yet.

Leave a Reply

Powered by WordPress. Designed by WooThemes