I could successfully use hdiutil
for creating a dmg file on my local El Capitan box, but it's failed with on OS X 10.9.5 of Travis CI with the error
hdiutil: create failed - error -5342
The command used to creating image is
hdiutil create -ov -size 512k -type UDIF -fs UDF "$FIXTURE_ROOT/empty.dmg"
$FIXTURE_ROOT
is a exist temp dir. You can find the very details on Travis Logs.
I often had this problem, until I learned (somewhere) that hdiutil often mis-calculates the size, and that causes it to fail. So estimate the size yourself, and double it in the -size parameter. Empty space in a dmg does not increase its size significantly.