Add/Delete/Modify files within a Disk Image (.dmg)?

Solution 1:

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

Solution 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.