How to extract content of DMG without mounting it? I want add autoupdate system to my application. It downloads DMG from website, then extract new version of application from it.
-
Your question is directing you into the wrong direction... "autoupdate" is a mechanism inherently supported by MacOS Installer (framework, and service) - and you can rely on this (make your .pkg installer update the existing installed version) rather on manually merging the contents of a volume in a .dmg and your installation on the local drive. I recommend that you consider using official installer package for "autoupdates". – Motti Shneor May 03 '22 at 12:17
3 Answers
Some .dmg
files can be extracted by using 7-zip.
$ 7z x your.dmg
$ ls
your.dmg
0.MBR
1.Primary GPT Header
2.Primary GPT Table
3.free
4.hfs
5.free
6.Backup GPT Table
7.Backup GPT Header
...and after extracted the 4.hfs
file:
$ 7z x 4.hfs
...you'll get the content of the .dmg
file.
You could also mount the .dmg
in Mac OS X using hdiutil
command (which is also used by Homebrew Cask).
Please refer to this Ask Ubuntu question for more use cases on Linux.

- 1
- 1

- 780
- 8
- 23
-
-
4@BenLeggiero Not really, install p7zip on Linux/macOS which contains the `7z` command-line application. – Mengdi Gao Sep 17 '17 at 18:09
-
Extracting dmg files with 7z seem to miss the executable bits, making extracted applications from DMGs dysfunctional. May be related: https://sourceforge.net/p/p7zip/bugs/113/ – Motin Sep 14 '18 at 11:43
-
On macOS there are two Homebrew packages that provide 7-Zip: [`p7zip`](https://formulae.brew.sh/formula/p7zip) and [`sevenzip`](https://formulae.brew.sh/formula/sevenzip). `p7zip` is a fork and `sevenzip` the original implementation. It might be of interest, that `p7zip` does not currently support APFS images, the `sevenzip` formula however does. – Stefan Schmidt Nov 08 '22 at 19:27
Dmg is just a format used for MacOS. It's a not compressed file format like zip
or tar.gz
You have several choices to mount it. Here are some options.
- Double click on it to mount it.
- Use
hdiutil attach your.dmg
to mount the dmg file. After mounting on it, operating your command line to extract the files you want out.
-
This is what I needed. Can one get the mounted path from the terminal output? – Tails Jun 18 '21 at 12:34
Doing that is working counter to the design of DMGs, so it's very painful. DMGs are designed to be mounted, that is their whole raison d'être. You would need to rely on experimental code if you wanted to do something like that. You are probably better served by using a non-DMG archive such as a zip file, or by making your automatic updating process download, mount, and unmount the DMG file you provide.

- 4,293
- 4
- 36
- 61
-
Project which you have linked is a portable solution. Mounting DMG images within OSX is easy as others answers proofed. – bluszcz Jan 24 '18 at 14:08
-
Not only that - but if your .DMG is encrypted, I don't think even "Experimental code" would work for that. – Motti Shneor May 03 '22 at 12:18