Skip to main content

Working with .dmg files

A .dmg file is a disk image file. It is used to create a disk image of a Mac.

Creating a .dmg file

The following command is used to create a .dmg file.

hdiutil create -srcfolder [path to folder] -volname [volume name] -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW [path to .dmg file]

To create a blank .dmg file, you can use the following command.

hdiutil create -size [size in MB] -volname [volume name] -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW [path to .dmg file]

The -fs HFS+ argument is used to create a HFS+ file system. The -fsargs argument is used to specify the file system arguments. The -c argument is used to specify the number of clusters. The -a argument is used to specify the number of sectors per cluster. The -e argument is used to specify the number of sectors per extent.

The -format UDRW argument is used to create a read-write disk image.

Mounting a .dmg file

hdiutil attach [path to .dmg file]

Creating a password protected .dmg file

You can password protect a .dmg file using 256-bit AES encryption. The following command is used to create a password protected .dmg file.

hdiutil create -srcfolder [path to folder] -volname [volume name] -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW -encryption AES-256 [path to .dmg file]