I 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
1 |
hdiutil attach -owners on /path/to/your.dmg -shadow |
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
1 2 3 |
# fill disk number at <number> hdiutil detach /dev/disk<number> |
Step 4
Converting/Writing a shadowed dmg into read-only form
1 |
hdiutil convert -format UDZO -o /path/to/new.dmg /path/to/your.dmg -shadow |
That’s it, we have successfully edited read only dmg file! 🙂