Document how to mount disk images with the HFS+ partition at an offset

This commit is contained in:
Tor Arne Vestbø
2012-10-22 18:15:51 +02:00
parent 596f8b6c33
commit dcd99af04f

View File

@@ -56,6 +56,44 @@ You may then proceed to mount the `.dmg` file using regular means, *eg.*:
This will give you read-only access to the content of the sparse-bundle disk image.
### Mounting partitions at an offset
Some sparse-bundles may contain partition maps that `mount.hfsplus` will fail to process, for example the *GUID Partition Table* typically created for Time Machine backup volumes. This will manifest as errors such as "`wrong fs type, bad option, bad superblock on /dev/loop1`" when trying to mount the image.
The reason for this error is that the HFS+ partition lives at an offset inside the sparse-bundle, so to successfully mount the partition we need to pass this offset to the mount command. This is normally done through the `-o offset` option to mount, but in the case of HFS+ we need to also pass the partition size, otherwise the full size of the `dmg` image is used, giving errors such as "`hfs: invalid secondary volume header`" on mount.
To successfully mount the partition, first figure out the offset and size using a tool such as `parted`:
parted /mnt/bundle/sparsebundle.dmg unit B print
This will print the partition map with all units in bytes:
```
Model: (file)
Disk /mnt/bundle/sparsebundle.dmg: 1073741824000B
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 20480B 209735679B 209715200B fat32 EFI System Partition boot
2 209735680B 1073607585791B 1073397850112B hfsx disk image
```
Next, use the *start* and *size* columns from the above output to create a new loopback device:
losetup -f /mnt/bundle/sparsebundle.dmg --offset 209735680 --sizelimit 1073397850112 --show
This will print the name of the loopback device you just created.
**Note:** Passing `-o sizelimit` directly to the `mount` command instead of creating the loopback device manually does not seem to work, possibly because the `sizelimit` option is not propagated to `losetup`.
Finally, mount the loopback device (which now starts at the right offset and has the right size), using regular mount:
mount -t hfsplus /dev/loop1 /mnt/my-disk
### Reading Time Machine backups
Time Machine builds on a feature of the HFS+ filesystem called *directory hard-links*. This allows multiple snapshots of the backup set to reference the same data, without having to maintain hard-links for every file in the backup set.