Hfsplus

HFS+, HFS Plus, or Mac OS Extended are names for a file system developed by Apple Computer to replace their Hierarchical File System (HFS). In addition to being the default file system on modern Apple computers, HFS+ is one of two formats, FAT being the other, that are supported by the iPod hard-disk based music player. Unlike FAT, HFS+ supports UNIX style file permissions, which makes it useful under linux. As Apple Computer's devices and systems become increasingly ubiquitous, it becomes important that Linux fully support this format. The following series of steps help add and use HFS+ capability and tools.

An interesting part of this HOWTO is patching Apple's utilities to work under Linux. Apple's utilities include mkfs.hfsplus and fsck.hfsplus. So creating and repairing HFS+ partitions in Linux is possible.

The above tools are not to be confused with the these system tools ie. hpmount, hpfsck contained in the gentoo package sys-fs/hfsplusutils.

These utilities have not been updated since 2002, and are in the historical folder at penguinppc. They do not operate or mount newer hfsplus partitions, but are unfortunately the only hfsplus support included on a gentoo PPC livecd. Like the preceding example some distributions sadly omit hfsplus kernel support.

The Linux kernel does not support writing to HFS+ journals, writing to a hfsplus partition is recommended only after you have disabled your journal; however, linux, as of version 2.6.16, supports case-sensitivity (also known as HFSX) (commit). iPod nanos, for example, may come with journalized hfsplus from the factory; to mount read/write under Linux simply disable journaling under OSX.

Disable Journaling
To disable journaling under Mac OS X, open the Terminal.app in the Applications/Utilities folder and type the following command:

sudo diskutil disableJournal /Volumes/TheVolumeName

where "TheVolumeName" refers to the name of the volume you wish to disable the journal on. You can re-enable journaling using the Disk Utility program in the Applications/Utilities folder.

Adding HFS+ Kernel Support
The first step is to add kernel support for HFS+-type filesystems. Please use linux 2.6, since 2.4 requires patching. This patch can be obtained from an SourceForge project called linux-hfsplus. The following steps assume use of a 2.6 kernel. First open the kernel configuration:

Now enable HFS+ support. You can choose to enable the filesystems as modules, in which case you should not forget to modprobe them after rebooting.

Save, exit, recompile, install and reboot into your new kernel.

Testing Kernel Support
Once the HFS+ support has been added to the kernel the filesystem can be mounted and manipulated by the operating system. The following command will query kernel for HFS+ support; it should return hfs and hfsplus.

Note that you may need to modprobe the hfs and hfsplus modules if you compiled them as modules.

Manually reading from and writing to an iPod
The file contains a listing of all partitions currently present on the system. The fourth generation Apple formatted iPods have three partitions, hence three partitions show up when you connect a fourth-generation iPod. The first partition is a partition map, the second is a firmware partition, and the third is a HFS+ partition. In the following case, the iPod is located at sda.

major minor #blocks  name 3    0   48122708 hda 3    1   47070418 hda1 3    2    1052257 hda2 8   48   39063023 sda 8   49         31 sda1 8   50      32768 sda2 8   51   39030224 sda3

You can now simply mount your partition of choice.

Compiling Apple's Filesystem Tools
A package of tools for modifying and viewing HFS+ partitions has been created. You can find it in sys-fs/diskdev_cmds. If you are interested in fiddling around with HFS+-partitions, you can try this package. Please note that you may be left with broken hardware.

The diskdev_cmds package, including most Darwin kernel code it was ported from, is under the Apple Public Source License. The patches themselves are licensed under the GPL; however, their use may fall under restrictions from the APSL.

Creating HFS+ Filesystems with mkfs.hfsplus
Once installed, you can use these tools to, for example, create partitions. It also includes a filesystem repair utility.

mkfs.hfsplus can be used to initialize/format/create the filesystem.

Mounting HFS+ partitions
Some HFS+ filesystems are wrapped inside of an HFS file system in order to display an error message on a Macintosh that does not support HFS+ and provide boot support. If the partition is wrapped inside of HFS partition, a special filesystem type option will be required to mount the drive. This command will show a common way to mount both wrapped and unwrapped hfsplus partitions.

Hfsplus partitions which are journalized (read-only)

iPod management
Various programs made to manage iPod content exist, one of which is gtkpod.

Additional Information Links

 * http://ipodlinux.org/Installation_from_Linux_Hfsplus
 * http://developer.apple.com/technotes/tn/tn1150.html
 * http://sourceforge.net/projects/linux-hfsplus
 * http://www.ardistech.com/hfsplus
 * http://bugs.gentoo.org/show_bug.cgi?id=46342
 * http://www.plop.at/en/hfsprescue.html