Dealing with a DMG file on Linux

By | October 27, 2021

I received a .dmg file from a Mac user today claiming it was a video file. It took a long while to figure out how to examine this file, so here are my notes so I don’t ever have to do it again.

Step 1: Uncompress the file

My first step was to use 7z to uncompress it, but that produced the wrong results for some reason. Use dmg2img instead.

± dmg2img ~/Downloads/file.dmg

dmg2img v1.6.5 (c) vu1tur ([email protected])

~/Downloads/file.dmg --> ~/Downloads/file.img


decompressing:
opening partition 0 ...             100.00%  ok
opening partition 1 ...             100.00%  ok
opening partition 2 ...             100.00%  ok
opening partition 3 ...             100.00%  ok
opening partition 4 ...             100.00%  ok
opening partition 5 ...             100.00%  ok
opening partition 6 ...             100.00%  ok
opening partition 7 ...             100.00%  ok

Archive successfully decompressed as ~/Downloads/file.img

Step 2: Locate the partition inside the img file

Okay. So now you have an .img file which is actually a virtual hard disk. You need to find the filesystems inside that virtual disk.

± sudo losetup --find --show ~/Downloads/file.img
/dev/loop0
± sudo partprobe -s /dev/loop9
/dev/loop0: gpt partitions 1

Step 3: Mount the partition as a filesystem

You now have two new virtual devices: /dev/loop0 and /dev/loop0p1 (from the two commands in the last step!) and you can mount them now.

± sudo mount /dev/loop0p1 /mnt
± ls /mnt
total 0
0 file.app/

Now you can do all the actions you want on the archive. Enjoy!

Step 4: Cleaning up

Once you’re done, you need to clean up the mess we just made… Make sure no applications are using the files or you’ll get errors. (Hint: use the fuser command if you need to identify processes using the files. Also remember that your shell might be blocking it if you are in the directory.)

± sudo umount /mnt/ext
± sudo losetup -d /dev/loop0

You’re done!

Leave a Reply

Your email address will not be published. Required fields are marked *