96

I've got a .dmg file, and I can't figure out how to open it. How can I open it?

9 Answers 9

76

To extract it, it is much easier to use 7zip:

7z x file.dmg
3
  • 7
    Thanks, 7z did the job, whereas dmg2img complained about a corrupted dmg image.
    – rinni
    Jun 30, 2014 at 12:42
  • 5
    Note that 7z works only for unencrypted dmg images
    – vog
    Dec 23, 2016 at 18:19
  • 2
    This just created a file called 0.unknown partition for me. Jan 10, 2018 at 15:13
65

Install dmg2img.

Next, read the package information page and the manual page to see if it is useful to you.

The application seems to convert .dmg to a file that can be mounted using the mount command:

dmg2img file.dmg imagefile.img

From your Wikipedia article, the next command seems to be available to do that:

sudo mount -o loop -t hfsplus imagefile.img /mnt

In this way, the file imagefile.img is a result from dmg2iso and the contents will be available at /mnt. If the hfsplus type is not detected, you might need to load the kernel module for it:

sudo modprobe hfsplus

When done, you can unmount it by running:

sudo umount /mnt
8
  • 2
    This will not work if the dmg file has 10.6+ compressed files in it.
    – Dave
    Oct 23, 2013 at 20:14
  • 11
    I get this error - mount: wrong fs type, bad option, bad superblock on /dev/loop0
    – tuxdna
    Feb 5, 2014 at 10:40
  • 3
    @tuxdna Do you really have a HFS image? Check the output of file file.dmg. You can also try 7z l file.dmg to list the contents.
    – Lekensteyn
    Feb 5, 2014 at 10:55
  • 1
    I am using dmg2img v1.6.2. I ran dmg2img on mysql-5.5.28-osx10.6-x86_64.dmg which created mysql-5.5.28-osx10.6-x86_64.img, but it doesn't mount.
    – tuxdna
    Feb 5, 2014 at 10:57
  • @Lekensteyn Thanks! Now it works. Check my answer below.
    – tuxdna
    Feb 5, 2014 at 11:12
33

This works for me:

  • Extract using 7z x
  • Locate the hfs partition file
  • Mount it to a directory

Extract using 7z x

root # aptitude install p7zip-full
root # 7z x ../mysql-5.5.28-osx10.6-x86_64.dmg 

7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=en_IN,Utf16=on,HugeFiles=on,4 CPUs)

Processing archive: ../mysql-5.5.28-osx10.6-x86_64.dmg

Extracting  0.MBR
Extracting  1.Primary GPT Header
Extracting  2.Primary GPT Table
Extracting  3.free
Extracting  4.hfs
Extracting  5.free
Extracting  6.Backup GPT Table
Extracting  7.Backup GPT Header

Everything is Ok

Files: 8
Size:       125475840
Compressed: 117543935
root # ls
0.MBR  1.Primary GPT Header  2.Primary GPT Table  3.free  4.hfs  5.free  6.Backup GPT Table  7.Backup GPT Header

Locate the hfs partition ( here it is 4.hfs file ):

root # ls -l
total 122548
-rw-r--r-- 1 root root       512 Feb  5 16:06 0.MBR
-rw-r--r-- 1 root root       512 Feb  5 16:06 1.Primary GPT Header
-rw-r--r-- 1 root root     16384 Feb  5 16:06 2.Primary GPT Table
-rw-r--r-- 1 root root      3072 Feb  5 16:06 3.free
-rw-r--r-- 1 root root 125435904 Feb  5 16:06 4.hfs
-rw-r--r-- 1 root root      2560 Feb  5 16:06 5.free
-rw-r--r-- 1 root root     16384 Feb  5 16:06 6.Backup GPT Table
-rw-r--r-- 1 root root       512 Feb  5 16:06 7.Backup GPT Header

Mount it to folder:

root # mkdir t
root # mount -oloop 4.hfs t
root # cd t/
root # ls
mysql-5.5.28-osx10.6-x86_64.pkg  MySQL.prefPane  MySQLStartupItem.pkg  ReadMe.txt
1
  • You can specify the single file you want to extract: 7z x ../mysql-5.5.28-osx10.6-x86_64.dmg 4.hfs
    – Lekensteyn
    Feb 5, 2014 at 15:56
8

If you succeed with the instructions from Lekensteyn and binfalse more power to you. If you are getting

$ lsmod | grep hfs
hfs                    54782  0 
hfsplus                84912  0
$ sudo mount -o loop,ro -t hfsplus imagefile.img /mnt
mount: wrong fs type, bad option, bad superblock on /dev/loop0,

Right now Ubuntu only comes with dmg2img version 1.6.2 and version 1.6.4 sometimes makes a difference. Also you can extract specific partitions from a dmg and only some of them are hfs+

$ dmg2img -l file.dmg
partition 0: Protective Master Boot Record (MBR : 0)
partition 1: GPT Header (Primary GPT Header : 1)
partition 2: GPT Partition Data (Primary GPT Table : 2)
partition 3:  (Apple_Free : 3)
partition 4: disk image (Apple_HFS : 4)
partition 5:  (Apple_Free : 5)
partition 6: GPT Partition Data (Backup GPT Table : 6)
partition 7: GPT Header (Backup GPT Header : 7)
$ dmg2img -p 4 file.dmg imagefile.img
  • Current Ubuntu versions come with 1.6.5 as of version 14.04
4

When using dmg2img file.dmg imagefile.img on linux if you get ERROR: Inflation failed message, just install 7zip as

sudo aptitude install p7zip-full

and issue the following command on terminal

7z x your_file.dmg
  • find the InstallMacOSX.pkg/InstallESD.dmg
  • issue the command dmg2img InstallESD.dmg imagefile.img on the terminal.

Now you can mount imagefile.img with

modprobe hfsplus

and then

mount -t hfsplus -o loop mountain.img /mnt
4

In the case of some .dmgs, you can neither 7z x them, nor mount the result of dmg2img.

In that case, the .img resulting from dmg2img your.dmg new.img can have its paritions extracted with 7z x:

$ 7z x factor-macosx-x86-64-0.98.dmg
[...]
Extracting archive: factor-macosx-x86-64-0.98.dmg
ERROR: factor-macosx-x86-64-0.98.dmg
factor-macosx-x86-64-0.98.dmg
Open ERROR: Can not open the file as [Dmg] archive

$ dmg2img factor-macosx-x86-64-0.98.dmg factor.img
[...]
factor-macosx-x86-64-0.98.dmg --> factor.img
[...]
Archive successfully decompressed as factor.img

$ sudo mount -o loop -t hfsplus factor.img /mnt
mount: /mnt: wrong fs type, bad option, bad superblock on /dev/loop5, missing codepage or helper program, or other error.

$ 7z x factor.img 

[...]
Extracting archive: factor.img
[...]
Everything is Ok                                

Folders: 2717
Files: 10266
Size:       176431113
Compressed: 264214528

$ ls -lah factor factor/factor/
factor:
total 24K
drwx------  6 cat cat 4.0K Jul 30  2018  .
drwxr-xr-x 21 cat cat 4.0K Feb 19 16:28  ..
drwx------  8 cat cat 4.0K Jul 30  2018  factor
drwx------  2 cat cat 4.0K Jul 30  2018 '[HFS+ Private Data]'
drwx------  2 cat cat 4.0K Jul 30  2018 '.HFS+ Private Directory Data'$'\r'
drwx------  2 cat cat 4.0K Jul 30  2018  .Trashes

factor/factor/:
total 97M
drwx------   8 cat cat 4.0K Jul 30  2018 .
drwx------   6 cat cat 4.0K Jul 30  2018 ..
drwx------ 163 cat cat 4.0K Jul 30  2018 basis
drwx------  45 cat cat 4.0K Jul 30  2018 core
-rw-r--r--   1 cat cat  702 Jul 30  2018 .dir-locals.el
drwx------ 288 cat cat  12K Jul 30  2018 extra
-rw-r--r--   1 cat cat   32 Jul 30  2018 factor
drwx------   3 cat cat 4.0K Jul 30  2018 Factor.app
-rw-r--r--   1 cat cat  97M Jul 30  2018 factor.image
-rw-r--r--   1 cat cat   40 Jul 30  2018 .gitattributes
-rw-r--r--   1 cat cat   43 Jul 30  2018 git-id
-rw-r--r--   1 cat cat 366K Jul 30  2018 libfactor.dylib
-rw-r--r--   1 cat cat  16K Jul 30  2018 libfactor-ffi-test.dylib
-rw-r--r--   1 cat cat 1.3K Jul 30  2018 LICENSE.txt
drwx------   9 cat cat 4.0K Jul 30  2018 misc
-rw-r--r--   1 cat cat 4.6K Jul 30  2018 README.md
-rw-r--r--   1 cat cat 3.6K Jul 30  2018 .travis.yml
drwx------   2 cat cat 4.0K Jul 30  2018 work

Success!

3
  • Multiple answers suggest directly using 7z on the dmg file. Why convert it then?
    – Olorin
    Feb 19, 2019 at 4:18
  • 2
    @Olorin this is for when 7z x your.dmg fails with Can't open as archive: 1, and when dmg2img's output won't be accepted by mount either. I'll clarify
    – cat
    Feb 19, 2019 at 21:24
  • 1
    I was facing same problem but this answer helped my situation.
    – kamae
    May 7, 2020 at 10:39
3

First of all install DMG2IMG. Now you can convert it to IMG:

dmg2img your.dmg new.img 

The IMG can be mounted with:

sudo modprobe hfsplus
sudo mount -t hfsplus -o loop new.img /mnt

And take a look at /mnt

1

following the answer of @aman and @tuxdna, because dmg2img doesn't seem to work on compressed dmg images.

so i made a bash script (tested on ubuntu 14.10) to automatize the process of :

  • extracting with 7z in a temp folder
  • looking for which partition to mount
  • copy the hfs/hfsplus folder/partition somewhere else
  • delete the temp folder
  • mount the partition

find it here: https://github.com/aurelien-rainone/scripts/blob/master/mountdmg.sh

example of use:

panty@Computerino:[~/scripts]: mountdmg.sh -t hfsplus -d /mnt ~/Downloads/cutecom-ng.dmg 

7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,2 CPUs)

Processing archive: /home/panty/Downloads/cutecom-ng.dmg

Extracting  0.MBR
Extracting  1.Primary GPT Header
Extracting  2.Primary GPT Table
Extracting  3.free
Extracting  4.hfs
Extracting  5.free
Extracting  6.Backup GPT Table
Extracting  7.Backup GPT Header

Everything is Ok

Files: 8
Size:       33549312
Compressed: 10059312
mountdmg.sh: successfully mounted 4.hfs on /dev/loop0
mountdmg.sh: run sudo umount /dev/loop0 when finished
0

The instructions in some of the posts to this topic only work on older versions of 7z.

If you want to extract JUST the 4.hfs file from a .dmg file (i.e: just one level deep) and are using a newer version of 7-zip then you need to use different parameters:

In 7-Zip [64] 9.20 you can use this command:

7z x file.dmg 4.hfs

In 7-Zip [64] 16.02 you need to use this command:

7z x -t* file.dmg 4.hfs

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .