How to extract a .dmg file in Linux?
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.
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.
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.
#!/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