Attach a .dmg without mounting the drive that it is sitting in


I have a .dmg sitting on an external drive (which also contains other data).

The .dmg is an image of a failed drive so I can't mount it but I want to attach the .dmg without mounting the partition it is in.

Is this possible?

I ask because, if I mount the partition, attach the .dmg and then try to run TestDisk, TestDisk returns this message:

Write access for this media is not available.
TestDisk won't be able to modify it.

- No partition from this disk must be mounted:
Open the Disk Utility (In Finder -> Application -> Utility folder)
and press Unmount button for each volume from this disk

I tried what I thought would work: hdiutil attach /dev/disk2s2/cfp/disk0s2-clone.dmg it didn't, attach failed - Not a Directory

I guess a different way of asking my question is, "How can I use TestDisk on a .dmg if I can't mount the partition that the .dmg is in?"

Best Answer

If you mount a drive one of the things which happens is that the file system type gets identified so macOS afterwards knows how to access the content of the drive (and find the DMG for instance). So operating systems can't access files on a drive without mounting it first.

Your actual problem seems to come from the fact that TestDisk is a tool to recover data from physical drives. So it could be used to work with the original disk your DMG represents, but it won't be able to recover data from a DMG.