Best possible way to edit read only DMG

File: DMGI ran into a situation of editing bootable dmg for my need, I utilized the hdiutil shadow mode for my purpose and thought share best possible way to edit read only dmg with community.

What is DMG file and what’s the purpose of it?

Advantages:

  • Preserve bootable state of dmg
  • Eliminate a space required to convert read-only dmg to read-write
  • Add, edit, delete any items on dmg
  • Less time consuming as compare to other approaches

Edit Read Only DMG

Step 1

Attach read-only dmg file using hdiutil

hdiutil attach -owners on /path/to/your.dmg -shadow

Note: This command takes a while depending on dmg size.

Step 2

Modifying mounted dmg, perform add, edit or delete as per your need

Step 3

Detach mounted drive [Now it is modified one] by below command or Eject it from Finder

# fill disk number at <number>

hdiutil detach /dev/disk<number>

Step 4

Converting/Writing a shadowed dmg into read-only form

hdiutil convert -format UDZO -o /path/to/new.dmg /path/to/your.dmg -shadow

Note: This command takes a while depending on dmg size.

That’s it, we have successfully edited read only dmg file! :)