Feature #375
How To Mount Apple Disk Images (DMG) in Linux
Description
Apple’s disk images represent volumes which can be divided into several partitions, typically formatted with HFS or HFS+.
These volumes can’t be read just by Apple computers but also from Windows and Linux PCs.
Arch Linux comes with native support of the Hierarchical File System (HFS) but other distributions with older kernels such as Debian don’t.
Best you check withfind /lib/modules -name "*hfs*"
if the required modules get listed. If there are none listed use your package manager to find the appropriate packages.
- Ubuntu/Debian:
aptitude search hfs
- Open Suse:
zypper search hfs
- Fedora:
yum search hfs
Worth to mention is that in Linux only uncompressed DMGs can be directly mounted. The file command will tell you the actual type of a file.
file Adium.dmg
Adium.dmg: bzip2 compressed data, block size = 100k
The above output shows us that the disk image is compressed with the bzip2 algorithm and thus we can’t mount the image directly. For an uncompressed image the output would look like
file uncompressed.dmg
uncompressed.dmg: Macintosh HFS Extended version 4 data last mounted by [...]
block size: 4096, number of blocks: 6400, free blocks: 218
Mount an uncompressed DMG¶
This uncompressed image can be mounted with:
sudo mount -t hfsplus -o loop Adium.dmg /mnt
If you get a wrong filesystem type error message such as below, inspect the kernel modules loaded.
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so
You need to load the loop and one of both, hfs or hfsplus, loaded depending on your DMG filesystem format.
sudo modprobe loop sudo modprobe hfs sudo modprobe hfsplus
Mount a compressed DMG¶
To mount compressed disk images some more effort is required because they first need to be converted to a raw image. That’s where the dmg2img tool comes into action.
sudo apt-get install dmg2img dmg2img Adium_1.5.4.dmg
dmg2img v1.6.4 (c) vu1tur (to@vu1tur.eu.org)
Adium_1.5.4.dmg --> Adium_1.5.4.img
decompressing:
opening partition 0 ... 100.00% ok
opening partition 1 ... 100.00% ok
opening partition 2 ... 100.00% okArchive successfully decompressed as Adium_1.5.4.img
Now we can mount and see what’s inside the image:
sudo mount -t hfsplus -o loop Adium_1.5.4.img /mnt ls -l /mnt
total 200
drwxr-xr-x 1 501 utmp 3 Nov 7 10:47 Adium.apprw-r--r-1 501 utmp 0 Nov 7 10:48 Applicationsrw-r--r-1 501 utmp 176566 Nov 7 10:48 Changes.txtrw-r--r-1 501 utmp 21015 Nov 7 10:48 License.txt
Be warned that some images may have big partitions as in xampp.dmg, the distributed DMG of the XAMPP project of the Apache Friends. dmg2img made a 33 GB raw image out of the original 86 MB big DMG. In the case where DMGs are used to distribute a software package which should be dragged to the /Applications
folder, their creators should consider users with limited storage regardless the write capabilities of DMGs.
It would be nice to see how big the raw image will finally become before we actually convert the DMG into a raw image. If somebody knows a tool to do so, raise your voice.