6

I know this may stem from a fundamental misunderstanding of the way disk images are intended to work, but even when full permissions are granted on a .dmg file, I am unable to add or remove files on the mounted disk image. Is there any way (natively or via a 3rd-party tool) to do this?

I know that when a disk image is mounted, a checksum verification is done, so I'm guessing that because modifying the image at all would destroy the checksum, this is inherently not allowed, but I'm wondering if there's a utility that could re-image the disk with a subset of its contents, perhaps recalculating the checksum in the process.

NOTE: Copying all the contents over, deleting, and then re-imaging is not a plausible option, due to the size of the image and the fact that it already fills most of the available space of the external drive on which it resides.

1
  • 1
    If you can't delete something it's probably because the .dmg file is read-only. In at Terminal, hdiutil imageinfo filename and look at the output for: Format: UDRO Commented Feb 18, 2016 at 23:11

2 Answers 2

8

You can edit, add, and remove files on a Disk Image if it is formatted to be readable and writable, which is set at the creation of the Disk Image.

This is a different concept than file permissions: File permissions allow you to read, i.e. mount, an entire Disk Image, or delete it in entirety (as a Disk Image itself is a single large file). How the Disk Image was formatted sets the rules for if you can only read (or both read and write) files within the Disk Image.

To natively create a readable and writable copy of a Disk Image, you can use the hdiutil of macOS via Terminal.app like this:

hdiutil convert -format UDRW -o ReadableAndWritableCopy.dmg ReadOnlyOriginal.dmg

You can then edit what is in the ReadableAndWriteableCopy.dmg Disk Image and create another copy with your edits that is read-only (like the original was) like this:

hdiutil convert -format UDRO -o ReadOnlyCopy.dmg ReadableAndWriteableCopy.dmg

1
  • 4
    When converting back to a read-only copy, I recommend using hdiutil convert -format UDBZ ... to enable bzip2 compression on the disk image. I was confused why my slightly edited copy of a read-only .dmg was so much larger then the original, and I eventually figured out that UDRO doesn't use any compression.
    – Chris
    Commented Jul 7, 2021 at 2:01
2

A disk image is designated as read-only or read-write when it is created. Simply changing the permissions on the DMG file will have no effect.

Here is one purported solution that I have not tried myself, that uses the hdiutil convert command to make a disk image writable, and hdiutil resize to add extra space if required for any additional content.

2
  • Is this safe or does Apple expect them to be readonly?
    – Pacerier
    Commented Feb 22, 2018 at 0:13
  • @Pacerier it is irrelevant. While your DMG is mounted, your data has vulnerability level X. This X is the same if you write files in DMG and re-encrypt it and if you only read files by decrypting using the same key that you enter once in both cases. Keep in mind that while disk is mounted, readonly or not, it can be accessed by any software like normal folder. The only risk with writable DMGs i see is that they potentially can get corrupted in rare cases.
    – Croll
    Commented Nov 16, 2018 at 0:02

You must log in to answer this question.

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