HFS

From Gentoo Wiki
Jump to:navigation Jump to:search
Resources

The Hierarchical File System, abbreviated HFS, is the native filesystem of the Apple Macintosh and its operating system up to Mac OS 8. It was the primary base filesystem of the Macintosh on the Motorola 68000 architecture. The filesystem is case-insensitive.

Its successor HFS+ became the standard base filesystem in Mac OS 8.1 on PowerPC as well as Mac OS X on PowerPC and Intel x86. However, on PowerPC-based Macs a HFS partition is still used for the bootstrap partition.

Installation

Kernel

KERNEL Enable HFS support (CONFIG_HFS_FS)
File systems  --->
   Miscellaneous Filesystems  --->
      <M> Apple Macintosh file system support
      < > Apple Extended HFS file system support
   -*- Native language support  --->
      (utf8) Default NLS Option
      <M>   Codepage macroman
      {*}   NLS UTF-8

Since HFS partitions are normally only found on Apple Partition Maps (APM), enable this partitioning scheme in the kernel:

KERNEL Enable APM support (CONFIG_MAC_PARTITION)
Enable the block layer  --->
   Partition Types  --->
      [*] Macintosh partition map support

Emerge

diskdev_cmds

The sys-fs/diskdev_cmds package is a port of HFS/HFS+ utilities from OpenDarwin, the BSD core operating system of macOS. It includes mkfs and fsck userspace utilities.

root #emerge --ask sys-fs/diskdev_cmds

The commands have names common to OpenDarwin: newfs_hfs and fsck_hfs. The package creates symlinks to mkfs.hfs and fsck.hfs. To create a new filesystem on a partition, e.g. on /dev/sda3, use:

root #newfs_hfs -h /dev/sda3
Warning
Creating a new filesystem will delete all data on the specified partition! Be very sure about the specified device file! (E.g. /dev/sda3)
Note
newfs_hfs is able to create a HFS and a HFS+ filesystem. With the option -w it can also add a HFS wrapper to a HFS+ partition. Other options include -v "Volume Label". Refer to the manpage for more information (man 8 newfs_hfs).

To use newfs_hfs to create the NewWorld Bootblock from the example below, the command would be:

root #newfs_hfs -h -v "NewWorld Bootblock" /dev/sda3

hfsutils

The sys-fs/hfsutils package traditionally provides means to access the Hierarchical File System on m68k and ppc/ppc64 Macs. The included utilities provide limited access to a filesystem on a selected partition.

root #emerge --ask sys-fs/hfsplusutils

Instead of mounting the filesystem as a subfolder under the root directory /, the various utilities of package sys-fs/hfsutils access the filesystem directly. hmount selects the partition for theese utilities and humount releases it again. The use of sys-fs/mac-fdisk is highly recommended.

root #emerge --ask sys-fs/mac-fdisk
Note
Package sys-block/parted can also create Apple Partition Map (APM) style partitions. However, it is not as verbose about partition types.
Note
The Apple Partition Map (APM) requires every block, except block 0, to be part of exactly one partition. The partition table itself is therefore also definied as one partition, /dev/sda1, and each block of free space between the actual partitions is partition type Apple_Free. For Linux filesystems, including swap, partition type Apple_UNIX_SVR2 must be used.
root #mac-fdisk -l /dev/sda
/dev/sda
        #                    type name                  length   base      ( size )  system
/dev/sda1     Apple_partition_map Apple                     63 @ 1         ( 31.5k)  Partition map
/dev/sda2              Apple_Free Extra                 262144 @ 64        (128.0M)  Free space
/dev/sda3              Apple_Boot NewWorld Bootblock   1834944 @ 262208    (896.0M)  Unknown
/dev/sda4              Apple_Free Extra                 262144 @ 2097152   (128.0M)  Free space
/dev/sda5               Apple_HFS Tiger              209715200 @ 2359296   (100.0G)  HFS
/dev/sda6              Apple_Free Extra                 262144 @ 212074496 (128.0M)  Free space
/dev/sda7               Apple_HFS Leopard            314572800 @ 212336640 (150.0G)  HFS
/dev/sda8              Apple_Free Extra                 262144 @ 526909440 (128.0M)  Free space
/dev/sda9              Apple_Boot Apple Hardware Test   100898 @ 527171584 ( 49.3M)  Unknown
/dev/sda10             Apple_Free Extra                 262144 @ 527272482 (128.0M)  Free space
/dev/sda11        Apple_UNIX_SVR2 Linux Boot           2097152 @ 527534626 (  1.0G)  Linux native
/dev/sda12             Apple_Free Extra                 262144 @ 529631778 (128.0M)  Free space
/dev/sda13        Apple_UNIX_SVR2 Gentoo Linux       134217728 @ 529893922 ( 64.0G)  Linux native
/dev/sda14             Apple_Free Extra                 262144 @ 664111650 (128.0M)  Free space
/dev/sda15        Apple_UNIX_SVR2 Debian Linux       134217728 @ 664373794 ( 64.0G)  Linux native
/dev/sda16             Apple_Free Extra                 262144 @ 798591522 (128.0M)  Free space
/dev/sda17        Apple_UNIX_SVR2 Linux Local         71216270 @ 798853666 ( 34.0G)  Linux native
/dev/sda18             Apple_Free Extra                 262144 @ 870069936 (128.0M)  Free space
/dev/sda19        Apple_UNIX_SVR2 Linux swap          67108864 @ 870332080 ( 32.0G)  Linux native
/dev/sda20             Apple_Free Extra                 262144 @ 937440944 (128.0M)  Free space

Block size=512, Number of Blocks=937703088
DeviceType=0x0, DeviceId=0x0
root #parted /dev/sda print
Model: ATA TOSHIBA-TR200 (scsi)
Disk /dev/sda: 480GB
Sector size (logical/physical): 512B/512B
Partition Table: mac
Disk Flags: 

Number  Start   End     Size    File system     Name                 Flags
 1      512B    32.8kB  32.3kB                  Apple
 3      134MB   1074MB  939MB   hfs             NewWorld Bootblock   boot
 5      1208MB  109GB   107GB   hfs+            Tiger
 7      109GB   270GB   161GB   hfs+            Leopard
 9      270GB   270GB   51.7MB  hfs+            Apple Hardware Test  boot
11      270GB   271GB   1074MB  ext2            Linux Boot
13      271GB   340GB   68.7GB  btrfs           Gentoo Linux
15      340GB   409GB   68.7GB  btrfs           Debian Linux
17      409GB   445GB   36.5GB  ext4            Linux Local
19      446GB   480GB   34.4GB  linux-swap(v1)  Linux swap
Note
On PowerPC Macs with Apple Partition Map, both HFS and HFS+ filesystems are type Apple_HFS. Special partitions, such as case-sensitive HFS+ or Software-RAID partitions, will be Apple_HFSX and are always HFS+.
Important
Some HFS+ partitions feature a HFS wrapper partition for compatibility reasons which cannot be used. If a partition of this kind is mounted as HFS, not HFS+, it contains one single file identifying it as HFS wrapper partition. Starting with Mac OS X 10.3 Panther Apple tools will no longer default to creating a wrapper partition for HFS+ volumes.
Note
The terms "partition" and "volume" are used synonymous in this context, since Mac OS calls a partition with a mountable filesystem a volume.

Select the partition with hmount:

root #hmount /dev/sda4

On the selected partition, the commands h[format|vol|fsck|ls|dir|pwd|mkdir|cd|rmdir|attrib|copy|rename|del] can be used for file and filesystem operations.

root #hls
Apple Extras     Desktop Folder   Develop
Important
Instead of the Unix "/" for directories the colon ":" has to be used. E.g. instead of /dir/to/file, on the HFS volume :dir:to:file has to be used for the provided utilities.
root #hcp /path/to/source_file_from_linux_filesystem :path:to:target_file_on_hfs_volume
root #hcp :path:to:source_file_on_hfs_volume /path/to/target_file_from_linux_filesystem

This will copy a file from the Linux filesystem to the HFS volume and vice versa. The utilities will automatically determine if the source or target is on the HFS volume or the Linux filesystem, thus the pathname should be unambiguous and use the slash "/" for Linux and the colon ":" for HFS.

The partition is released (unmounted) with the humount utility:

root #humount /dev/sda4
Note
Please refer to the manpages of each single utility for further information. (man 1 manpage, where manpage is one of: hattrib, hcd, hcopy, hdel, hdir, hformat, hfsutils, hls, hmkdir, hmount, hpwd, hrename, hrmdir, humount and hvol).

NewWorld Bootblock

A specialty of the PowerPC-based NewWorld Macs is the use of a NewWorld Bootblock for yaboot or GRUB. NewWorld Macs are PowerPC-based Macs with Open Firmware version 3.0 (OF3) or later. OF3+ will automatically look for bootable partitions, like those of the type Apple_Boot. When such a partition contains a filesystem of the type HFS, and this filesystem contains a "blessed" file (attribute ":tbxi"), this file will be selectable as a boot option from OF3+.

First, a NewWorld Bootblock has to be created using mac-fdisk:

root #mac-fdisk /dev/sda

At the interactive command prompt this partition can either be created manually e.g. by using the C command for "create new partition, specifying the partition type", or semi-automatic by using the b command for "create new 800k Apple_Bootstrap partition (used by yaboot)". Either way you should get a bootable HFS partition of either the type Apple_Boot or Apple_Bootstrap.

Assuming this partition is /dev/sda3, to bless a bootloader such as yaboot or GRUB, hattrib can be used.

root #hformat -l "NewWorld Bootblock" /dev/sda3
root #hmount /dev/sda3
root #hcopy /boot/grub/powerpc-ieee1275/core.elf :core.elf
root #hattrib -c UNIX -t tbxi :core.elf
root #hattrib -b :
root #humount /dev/sda3
Warning
Creating a new filesystem with hformat will delete all data on the specified partition! Be very sure about the specified device file! (E.g. /dev/sda3)
Important
Do not boot core.elf from /boot/grub/powerpc-ieee1275/core.elf directly, since this is only the GRUB core program without extensions such as filesystem drivers. It will not be able to access the Linux /boot directory. Use grub-mkimage to create a bootable GRUB bootloader which will be able to boot Linux and other operating systems. See here for details.
Note
sys-boot/yaboot and sys-boot/yaboot-static provide the installer ybin, which will do the above automatically on the in /etc/yaboot.conf preconfigured partition.

See also

  • HFS+ — the native filesystem of Mac OS 8.1+ and Mac OS X up to 10.12 Sierra from Apple for Mac computers.
  • Filesystem — a means to organize data to be retained after a program terminates.
  • Mount — the attaching of an additional filesystem to the currently accessible filesystem of a computer.
  • Removable media — any media that is easily removed from a system.
  • /etc/fstab — a configuration file that defines how and where the main filesystems are to be mounted, especially at boot time.


References