How can I open a .dmg file?
Solution 1
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
Solution 2
To extract it, it is much easier to use 7zip:
7z x file.dmg
Solution 3
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
Solution 4
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
Solution 5
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
Related videos on Youtube
jrg
BY DAY: Software Developer at Upstart. BY NIGHT: I have an infrequently updated blog. FOR FUN: Camping, motorcycling, bicycling, geekin' out from time to time. In The Past: Ask Ubuntu Moderator email: james at armyofminions dot com
Updated on September 18, 2022Comments
-
jrg over 1 year
I've got a .dmg file, and I can't figure out how to open it. How can I open it?
-
HDave over 10 yearsThis will not work if the dmg file has 10.6+ compressed files in it.
-
tuxdna over 10 yearsI get this error -
mount: wrong fs type, bad option, bad superblock on /dev/loop0
-
Lekensteyn over 10 years@tuxdna Do you really have a HFS image? Check the output of
file file.dmg
. You can also try7z l file.dmg
to list the contents. -
tuxdna over 10 yearsI am using
dmg2img v1.6.2
. I ran dmg2img onmysql-5.5.28-osx10.6-x86_64.dmg
which createdmysql-5.5.28-osx10.6-x86_64.img
, but it doesn't mount. -
tuxdna over 10 years@Lekensteyn Thanks! Now it works. Check my answer below.
-
Lekensteyn over 10 yearsYou can specify the single file you want to extract:
7z x ../mysql-5.5.28-osx10.6-x86_64.dmg 4.hfs
-
rinni almost 10 yearsThanks,
7z
did the job, whereasdmg2img
complained about a corrupted dmg image. -
vog over 7 yearsNote that 7z works only for unencrypted dmg images
-
Aaron Franke over 6 yearsThis just created a file called
0.unknown partition
for me. -
Olorin about 5 yearsMultiple answers suggest directly using
7z
on the dmg file. Why convert it then? -
cat about 5 years@Olorin this is for when
7z x your.dmg
fails withCan't open as archive: 1
, and whendmg2img
's output won't be accepted bymount
either. I'll clarify -
Skylar Ittner about 5 yearsI'm getting segmentation faults when trying to use a multipart DMG.
-
Lekensteyn almost 5 yearsFor future readers, @SkylarIttner reported the issue here: github.com/Lekensteyn/dmg2img/issues/7
-
Samir Patel over 4 yearsThis utility does not support password protected .dmg files
-
kamae about 4 yearsI was facing same problem but this answer helped my situation.