Fix Journal in an HFS+ File System

Yesterday my external Western Digital disk (which I use for Time Machine, among other things) stopped mounting automatically when I plug it in. This may *cough*definitely*cough*have something to do with me unmounting it forcefully while it was doing a backup, since I was in a hurry.

Disk Utility reported everything was OK with the disk, but it still failed to mount. Upon poking a bit deeper, I found these messages in the logs:

12/14/11 11:49:00.000 PM kernel: jnl: disk2s2: open: journal magic is bad (0x0 != 0x4a4e4c78)
12/14/11 11:49:00.000 PM kernel: hfs: late jnl init: failed to open/create the journal (retval 0).
12/14/11 11:49:00.000 PM kernel: hfs_mounthfsplus: hfs_late_journal_init returned (0)
12/14/11 11:49:00.000 PM kernel: hfs_mounthfsplus: encountered errorr (22)
12/14/11 11:49:00.000 PM kernel: hfs_mountfs: encountered failure 22 
12/14/11 11:49:00.000 PM kernel: hfs_mount: hfs_mountfs returned 22

Aha! Journal error. A bit of Google searching led me to this page, where one comment gave me the key:

root# mkdir /tmp/disk && mount_hfs -j /dev/disk2s2 /tmp/disk
root# diskutil disableJournal /tmp/disk
An error occurred journaling the file system: The underlying task reported failure on exit (-69860)
root# diskutil enableJournal /tmp/disk
Journaling was already enabled for volume Casa on disk2s2
root# diskutil unmount /tmp/disk
Volume Casa on disk2s2 unmounted

Despite the error in the “disableJournal” command, after this sequence the Finder was able to mount the disk, and things seem to be working fine. The trick in the first command is the -j option, since it allows the disk to be mounted (without journaling), so that the disableJournal/enableJournal commands can be issued.