3

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?"

4
  • 1
    The error message might be misleading here. I assume you want to run TestDisk against the DMG, right? This is different from „how can I open a file from a drive without mounting the drive“ (which is what your question currently asks). Can you focus your question on what you actually want to accomplish?
    – nohillside
    Commented Mar 1, 2020 at 8:23
  • Thanks for answering @nohillside. You are correct: I'd like to run TestDisk against the .dmg but, from what I understand, the partition that the .dmg is in (or any partitions on that drive) cannot be mounted for TestDisk to be able to function.
    – tripleman
    Commented Mar 1, 2020 at 16:06
  • TestDisk complains about the DMG, not the partition it is stored on. If you can't select the unmounted DMG from within TestDisk I suspect the application is just not built for the task you want to do.
    – nohillside
    Commented Mar 1, 2020 at 16:14
  • 1
    The short answer is No. You cannot access any file on a given filesystem unless that filesystem is mounted! Commented Mar 1, 2020 at 16:15

3 Answers 3

3

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.

1
  • Thanks @nohillside. The first paragraph of your answer is, as far as I can tell, the crux of the issue and the actual answer—and I've marked it as such. But my knowledge in Terminal is limited and was hoping there was a way. For sure, TestDisk can be used to recover data from the original, failing drive. But, all the information I've gathered says that it's best to image a failing drive and attempt recovery on the image. First, because if you botch things, you can grab another image and try again, and second, it limits the strain on a failing drive.
    – tripleman
    Commented Mar 1, 2020 at 21:00
1

The reason testdisk fails is because it needs to write to the device, but your dmg is probably stored in read-only format, so it is not able to write to the virtual device that represents the dmg.

Because it's not smart enough to check if the device is a read-only media (like read-only dmg), it assumes that it cannot write to the disk because a partition is mounted. When a partition is mounted, it's locked/write protected so that you don't lose data.

To solve this, you can either "restore" the dmg to an actual physical drive then run testdisk on it, or you can mount this dmg as read-write using a shadow file. See man hdiutil for more details.

-shadow [shadowfile]
                     Use a shadow file in conjunction with the data in the pri-
                     mary image file.  This option prevents modification of the
                     original image and allows read-only images to be attached
                     read/write.  When blocks are being read from the image,
                     blocks present in the shadow file override blocks in the
                     base image.  All data written to an attached device will
                     be redirected to the shadow file.  If not specified,
                     shadowfile defaults to image.shadow. If the shadow file
                     does not exist, it is created.  hdiutil verbs taking
                     images as input accept -shadow, -cacert, and
                     -insecurehttp.

So your command would probably look something like: hdiutil attach -nomount -noverify /path/to/dmg -shadow (/path/to/shadow/file (optional))

0

Running hdiutil attach -nomount -verbose ~/Downloads/test.dmg will attach the disk but not mount it. Here is the view from Disk Utility after running the command.

enter image description here

1
  • Thanks for answering, @notkevin. That will attach the .dmg without mounting it but the important part—that the partition containing that .dmg must not be mounted. At least, that's how I interpret the warning that TestDisk shows when I try to analyse the .dmg.
    – tripleman
    Commented Mar 1, 2020 at 16:09

You must log in to answer this question.

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