Hfsplus

From Gentoo Linux Wiki
Jump to: navigation, search

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.

Contents

[edit] 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.

[edit] 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:

# cd /usr/src/linux # make menuconfig

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.

Linux Kernel Configuration: HFS+ filesystem and macintosh partition support
File systems  --->
    Miscellaneous filesystems  --->
    <*> Apple Extended HFS file system support
    <*> Apple Macintosh file system support
    Partition types  --->
    [*] Advanced partition selection
    [*]   Macintosh partition map support

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

[edit] 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.

# grep hfs /proc/filesystems

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

[edit] Manually reading from and writing to an iPod

The /proc/partitions 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.

$ cat /proc/partitions
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
Note: Under Linux the HFS/HFS+ partition map is represented as a the first partition in sdX1; on the other hand, PC BIOS/MSDOS partition maps are not included as a separate partition and are located in the first ~32KB of the raw disk device (/dev/hda or /dev/sda) This shows how Macintosh Partition maps are treated as separate partitions under Linux, by counting blocks contained within partitions.
      Macintosh disk      PC/MSDOS disk
            31 sda1             33 (hidden partition map)
+        32768 sda2       47070418 hda1
+     39030224 sda3        1052257 hda2                 
-------------------------------------------------------------
=     39063023 sda        48122708 hda

You can now simply mount your partition of choice.

# mount /dev/sda3 /mnt/ipod

[edit] 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.

Warning: It is unclear whether these tools are x86_64 compatible (previously this read as "they are not supported". See Gentoo bugzilla link at the bottom - it seems that they were fixed in the end.

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.

# emerge diskdev_cmds

[edit] 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.

# mkfs.hfsplus -v iPod /dev/sda3
Warning: At this time -J (journaled) should be avoided under Linux.
Warning: Do not use -s (case-sensitive) in kernels before 2.6.16. Also, do not use -s on an iPod as it will not always detect your music. See next section on mounting.

[edit] 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.

# mount -t hfsplus /dev/sda3 /mnt/ipod

Hfsplus partitions which are journalized (read-only)

# mount -t hfsplus -o ro /dev/sda3 /mnt/ipod

[edit] iPod management

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

[edit] Additional Information Links

Personal tools