Reading a macOS (HFS+) Hard Disk on Linux

Occasionally we need to read external hard drives on our Ubuntu Linux servers. Some of our clients are heavy macOS users, so it’s not uncommon for us to see hard disks that are HFS+ formatted. Another name for HFS+ is Mac OS Extended.

To be clear, this isn’t an ideal situation. In many cases, it would be easier to format the hard disk as ExFAT (for large files) or FAT32 when cross platform use is desirable, but that doesn’t help when you receive a disk full of important data. If you’re working using a drive, rather than merely transfering it, ExFAT may not be the best idea because it’s unjournalled and so you’re losing some protection against data loss.

If you’re using external hard disks to collaborate within the same office, then you should consider transferring files over your network (wired ethernet or fast WiFi) using a protocol like Samba. Ideally, you’ll use a server, with a journalled filesystem (e.g. ZFS), which you’ll then provide to your desktops and laptops via Samba or NFS.

Basic Mounting

  1. Ensure you have hfsplus installed: sudo apt install hfsplus
  2. Find the block device for the volume, you can list all connected disks by running sudo fdisk -l, you’re looking for the ones with the type Apple HFS/HFS+. For the purposes of this guide, we’ll assume it’s /dev/sdd2 (but yours could be completely different).
  3. Make sure you have a mount point: sudo mkdir /media/myhfsdrive
  4. Mount the device: sudo mount -t hfsplus /dev/sdd2 /media/myhfsdrive

At this point, you’ll be able to read the device at /media/myhfsdrive.

The problem you may run into though is that the ownership/permissions of the device may prevent you from reading all of your files (depending on how the permissions on the disk have been set). This isn’t an issue if you only need to to access it as root, but we generally need to access it as a non-root user. Since it’s a read only mount, we can’t and don’t want to fix the permissions with chown/chmod.

Using a Bind Mount to Change Ownership

This is where BindFS comes in. It allow you to bind mount another path, but with different ownership (it can also do stuff with permissions). BindFS is an incredibly useful tool for all sorts of situations where you want to provide a modified view of a directory that you either can’t change the permissions of or where it would be a pain to achieve the effect you want with standard Linux permissions.

Here we use bindfs’s mirror function, which allows one or more users to see anything in that mount as if they were the owner of it.

  1. Ensure you have bindfs installed: sudo apt install bindfs
  2. Make sure you’ve completed all of the basic mounting steps.
  3. Make sure you have a mount point: sudo mkdir /media/myhfsdrive-mirrored
  4. Make the bind mount: sudo bindfs --mirror=alice,bob /media/myhfsdrive /media/myhfsdrive-mirrored

Now if Alice or Bob looks in /media/myhfsdrive-mirror, they’ll appear to be the owner and be able to read it as if they are.

Unmounting

You can unmount this like you would anything else:

  1. sudo umount /media/myhfsdrive-mirrored
  2. sudo umount /media/myhfsdrive

Why Can’t I Write?

While Linux can read HFS+, it can’t write to it in journalled mode (which is the norm on macOS for good reason) because there is no support for this within the kernel. I think this is unlikely to change soon.

If you need write support, then you really need to start from scratch with the drive formatted with HFS+ without journalling, but at that point, why bother with HFS+ at all, just use ExFAT for maximum compatibility across operating systems.

There is a paid, proprietary product available from Paragon Software that claims to be able to fully read/write HFS+. I’ve not tried it.

Performance

BindFS uses FUSE, which can sometimes be a performance concern. However, I’ve not experienced any problems with performance. It’s hard to compare the performance in a repeatable way in this scenario, but my experiments measuring the speed with dd and our anecdotal experience is that BindFS doesn’t have a noticeable impact on performance. Bear in mind that this is running on server hardware (processor is Intel Xeon E3-1225 v5).