2013-08-13

Mounting Mac HFS+ disk volumes as read and write on Ubuntu

I gave up trying to find a volume format for an external hard drive that has read and write capable "tri-platform" (Mac, Windows, and Linux) open-source reliable drivers.  For now, a modern volume format that works between Mac OS X 10.6 and Ubuntu 12.10 Quantal machines is good enough, and that seems to mean HFS+.

To be specific, that means volumes formatted as HFS+ (case-sensitive) without journaling on a drive that is GUID Partition Table (GPT) partitioned.  Journaled HFS+ will not be writable in Linux at all, ever, with current Linux drivers.

How do we make an un-journaled HFS+ volume writable in Ubuntu?

In Ubuntu, make sure you have hfsprogs and hfsplus installed.  A terminal command like sudo apt-get install hfsprogs should do it.  It might even already be pre-installed by Ubuntu.



Next, plugging in the drive showed me that Ubuntu enables reading from the drive automatically.  Nothing hard about it.  But it won't let me write to the drive.  It needs to be mounted as rw for that.

In the GNOME Disks utility in the Preference menu, click on the disk in question from the list on the left side of the Disks window.  It should show you the volumes on that disk on the right side now.  Click on the volume in that disk that is to be mounted as rw.  Click on the little gears "More actions..." icon underneath, then select "Edit Mount Options...".

It should currently be set to have "Automatic Mount Options" as ON.  Set it to "OFF" so that you can edit its "Mount Options" (it's the unlabelled field above the "Mount Point" field - hover your mouse over the fields to get more info).

The correct Mount Options are rw,defaults.  Note that the "x-gvfs-show" and the "x-gvfs-name" mount options do not work — including those options will make the drive fail to mount; that totally wasted a lot of my time to figure out.

The "Filesystem Type" should be set to hfsplus.

You can set the "Mount Point" to pretty much any path, but if you want it to show up automatically in the Nautilus file manager automatically, it seems you have to have it mounted in a particular place.  Namely, in /media/$username/$mountPointName where "$username" is your username, and where "$mountPointName" is what you want the volume to be named when mounted.

Wait, I still can't write to it - because the permissions are all wrong...

This small problem wasted plenty of my time too, making me think I didn't mount the volume as writable.  It is writable, but I just didn't have the permissions to.

It turns out Macs will set all files and folders on external media to an "Unknown" user (uid 99) that is treated specially.  More information at this Google Mac blog post.

It'd be nice if the driver would automatically set all files and folders to have your user and group id, but the old HFS "uid=" and "gid=" mount options are not recognized by the hfsplus drivers.

Instead, just go to the terminal and do a command like sudo chown -R $username /media/$username/$mountPointName.  Now you'll own all the files and folders on that drive.

What if my HFS+ volume is Journaled?

If you have an existing HFS+ volume that is journaled, but you need to write to it from Ubuntu Linux, then go to a Mac and disable the volume's journal by using Disk Utility.  Follow the instructions from this Ask Ubuntu answer.

What if my HFS+ volume gets corrupted?

First, hope that the corruption is small.

Second, if you have a Mac, use Disk Utility on the Mac to repair it.  I'd trust the Apple provided tools more than the Linux one in such a situation.

Lastly, if you don't have a Mac, then in Linux, run in the terminal sudo fsck.hfsplus /dev/$deviceName.  You can find the "$deviceName" from the aforementioned GNOME Disks utility.  Click on the disk in question and look under its name in the top center part of the window.

You should probably check the unjournaled HFS+ volumes using Disk Utility or fsck.hfsplus once every so often since it isn't journaled.  That used to be a pretty standard regular disk maintenance thing to do with the old HFS formatted volumes until HFS+ gave us a properly journaled file system.

6 comments:

Unknown said...

Hello, I've the same situation as you, founding about all of these mishaps.

I thought that "sudo mount -t hfsplus -o uid=99,gid=99 /dev/path /mount/path" would solve all my problems concerning the user 99, read with no restrictions and write files owned by 99.

But that, as you said, didn't happen.
chown all of the files to your linux uid would solve the problem temporally, but wouldn't that make files unmanageable when using the drive in the OSX system?

Another solution would be changing your uid in the OSX to the same uid linux uses, or the reverse of that.

Unknown said...

Hey there, I've come to the situation you've faced.

I thought that "mount -t hfsplus -o uid=99,gid=99 /dev/path /mount/path"
would solve the reading problems, and write as user 99. But that didn't quite work.

Changing the filesystem owner, it seems to me, would provide only a temporary solution, giving you total control on linux but making the drive unmanageable in OSX. Wouldn't it?

blogger said...

chown all files to your linux uid doesn't make files unmanageable when using the drive in OS X systems.

It turns out Macs treat all files and folders on external media specially. Essentially it ignores permissions on external media.

You can control that behavior on the Mac side by checking off "Ignore ownership on this volume" in the "Get Info" window of an external volume on a Mac.

What that does is it makes all newly created files/folders be owned by uid 99, which the OS X kernel essentially treats as "whoever is presently logged in". It also treats all existing files/folders as though it were owned by uid 99 on mounting the volume.

As for changing your uid in OS X to match your uid in Linux (or vice versa). I've looked into that and it seems more work than it's worth.

I guess it's worth looking into if your drive has so many files/folders that chown takes forever to execute, or if you don't have sudo'er privileges on the Linux system but you do on the Mac (OTOH, I guess you could always run chown on the Mac in advance of moving the drive to the Linux system...).

Unknown said...

Yeah, I've found out about the external drive behavior later yesterday. Didn't know it was optional though.
Sorry for the duplicate post, I thought it failed the first time.

Juan Cardelino said...

I'm using this approach to share between the three platforms (by using MacDrive in windows), and it works quite nice. however I have a recurring problem, which is that one of my drives ignores the disk label and puts the UUID as the mount point i.e. /media/juan/9921930809223
Have you faced this before?

blogger said...

Hi Juan. Are you saying on Ubuntu Linux the drive mounts with its UUID as label instead of your own custom label name?

I presume a Mac would just do the right thing :) , and I have no experience with MacDrive on Windows otherwise.

If on Ubuntu, did you remember to set the "Mount Point" to /media/$username/$mountPointName with the GNOME Disks utility?

One other thing you can try. Also in GNOME Disks utility, click on your drive (usually shown on the left side of the Disks window), then click on your volume shown (usually shown on the right side of the Disks window). Below the volume shown, there should be a gears "More actions..." button: click on that and choose "Edit Filesystem Label...".

That's the two possibilities I can think of right now. Hope that works out for you!