How to mount big .dmg in small HD? I have a 120 GB .dmg where I would like to study one directory. However, my Mac's HD is much smaller. I get a warning you cannot mount the directory.  

I used the command to create the image

sudo dd if=/dev/sda of=/media/ubuntu/ntfsDisc/sda.hfs.dmg bs=512 status=progress




How can you mount/read some content of a big .dmg image in small HD?
The command sudo dd if=/dev/sda of=/media/ubuntu/ntfsDisc/sda.hfs.dmg doesn't create a mountable dmg file!

Your "sda" - which is the complete /dev/disk0 translated to OS X naming conventions - probably contains several partition tables (1st and 2nd GUIDpt/MBR), free space and several file systems on the different partitions (sda1-sda4?).

So sda.hfs.dmg neither contains a valid file system (parts of the file could be extracted to contain one though) nor does it behave like a typical dmg. Instead it's a raw (data) file. 



Example: Whenever I have to backup a rescue thumb drive containing OS X (or save the content because I need the thumb drive for other purposes) I execute:

dd if=/dev/disk4 of=/Users/user/backup/OSXRescue.raw bs=1m


Besides the main partition this "raw" file also contains 3 partition tables (1st and 2nd GUIDpt/MBR), some "unallocated" space, an EFI and a Recovery HD partition. The file has the same size as the thumb drive and but is not mountable because it doesn't contain a real and consistent file system as expected by diskutil or hdiutil.

To restore this OSXRescue.raw to the same thumb drive I have to execute

dd if=/Users/user/backup/OSXRescue.raw of=/dev/disk4 bs=1m


This should restore an exact copy of the content of the rescue thumb drive (even the remnants of deleted files which don't occur in the file system(s) of the original thumb drive).

I may also use another drive (with at least the same size as the original thumb drive) to restore the full content of the rescue thumb drive to it. The result is fully bootable. The previous content of the external drive will be overwritten though!



To rescue your .tex file you have to dd the "raw" file to a real hard drive. This will restore the original partitions and you should be able to modify the wrong partition type of partition 2 (diskXs2), then mount the HFS+ partition and examine it with a data recovery tool.

You may be able to mount the HFS+ part of the raw file in OS X similar to this Linux how-to with on-board tools or after installing additional tools (probably with Homebrew). I didn't test this though.