32

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.

1
  • 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
    Commented Aug 17, 2015 at 4:25

3 Answers 3

51

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.

2
  • 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
    Commented Sep 14, 2018 at 11:43
  • I get Open ERROR: Can not open the file as [Dmg] archive.
    – Geremia
    Commented Jan 7 at 22:58
1

Sometimes 7z do not work correctly.

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

1

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.

#!/bin/bash
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"
fi
exit 0

You must log in to answer this question.

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