As a Linux user, I need to get the content of a .dmg (Mac OSX disk image) file which contains an application installer.

I tried dmg2dir (which requires dmg2img) which created an .img file but nothing else.

$ sudo dmg2dir jdk-8u51-macosx-x64.dmg
==> Routines successfully accomplished. Ready! 
==> Prepare loop device... 
==> Mount block device... 
Error looking up object for device /dev/disk/by-label/JDK\x208\x20Update\x2051 INTENSO openSUSE\x20Live\x20CD\x20GNOME dump
Variable is empty.

I just need the files from the .dmg file unpacked, I don't want to mount it.

In case you're curious, I need this to create a portable development environment to be used at workshops on computers that can't be prepared upfront.

  • 2
    It is a disk image. Unless someone has gone to all the work (which I guess 7z did) to write file system readers into their program, the easiest way is to use the Linux kernel filesystem modules to read the data. Which means mounting it.
    – Zan Lynx
    Aug 17, 2015 at 4:25

4 Answers 4


Just use 7z x.

In the case of for example Sublime text, 7z x "Sublime Text 2.0.2.dmg" will be enough to extract all the files.

In other cases, like for example the JDK, you have to deal with some kind of matryoshka.

$ 7z x jdk-8u51-macosx-x64.dmg
$ cd JDK 8 Update 51/
$ 7z x JDK 8 Update 51.pkg
$ 7z x Payload~

But eventually you will get a folder containing the files you're looking for.

  • Extracting dmg files with 7z seem to miss the executable bits, making extracted applications from DMGs dysfunctional. May be related: sourceforge.net/p/p7zip/bugs/113
    – Motin
    Sep 14, 2018 at 11:43

Sometimes 7z do not work correctly.

Use https://sourceforge.net/projects/catacombae/files/HFSExplorer/0.23.1/ for that cases


On the Mac, if the dmg is an image of a directory containing all the files, then make a tgz of the directory instead of a dmg, and migrate it.

if [ -d "$1" ]; then  # $1 is the directory name
tar -cf "$1.tar" "$1" || exit  # First, create a tar-file
gzip -n -S .gz "$1.tar"  # Then ,gzip it to compress it.
mv "$1.tar.gz" "$1.tgz"  # Then rename it ti a .tgz
echo "Created $PWD/$1.tgz"
else echo "Not a directory"
exit 0

I tryed all the above with this DMG: https://github.com/libsdl-org/SDL/releases/download/release-2.26.0/SDL2-2.26.0.dmg and nothing work

  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Nov 27, 2022 at 16:48
  • I also came here trying to extract SDL2. Turns out you need the official 7-zip, not the p7zip port.
    – kvance
    Dec 7, 2022 at 2:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.