Often using the Graphic User Interface (GUI) offered by the Disk Utility application is more convenient than using a Command Line Interface (CLI) required by macOS commands. However, the Disk Utility application only offers a limited subset of the capabilities of various macOS commands. In your case, to resize an image you would need to use the hdiutil
command. Below is an example of the syntax.
hdiutil resize -size size_spec image
The size specifiers (size_spec
) can be the following.
-size ??b|??k|??m|??g|??t|??p|??e
Here ??
needs to be replaced by a number. The letters represent the following multipliers.
b
is bytes (not blocks) where the multiplier is 1.
k
is power of two kibibytes where the multiplier is 1024 (1 x 2^10).
m
is power of two mebibytes where the multiplier is 1048576 (1 x 2^20).
g
is power of two gibibytes where the multiplier is 1073741824 (1 x 2^30).
t
is power of two tebibytes where the multiplier is 1099511627776 (1 x 2^40).
p
is power of two pebibytes where the multiplier is 1125899906842624 (1 x 2^50).
e
is power of two exbibytes where the multiplier is 1152921504606846976 (1 x 2^60).
or
-sectors sector_count | min
Specify the number of 512-byte sectors to which the partition should be resized. If this falls outside the minimum valid value or space remaining on the underlying file system, an error will be returned and the partition will not be resized. min
automatically determines the smallest possible size.
For example, the following command could be applied to an ejected image.
hdiutil resize -size 3m sample.dmg
Afterwards, the command gpt -r show sample.dmg
could be used to verify the result. In this case, the command would produce the following output.
start size index contents
0 1 PMBR
1 1 Pri GPT header
2 32 Pri GPT table
34 6
40 6144 1 GPT part - 48465300-0000-11AA-AA11-00306543ECAC
6184 3
6187 32 Sec GPT table
6219 1 Sec GPT header
Where the partition holding the volume is shown as exactly 6144 sectors = 3 x 2^20 bytes / 512 bytes per sector.