Strange Behavior of hdiutil on macOS – Explanation

bashmacos

declare -i s=${foo}; n=${bar}; mp=${baz}; cn=${qux}; mac_adr=${quux} 
sudo hdiutil create -size ${s}b -fs JHFS+X -volname "${n}" -type SPARSEBUNDLE \
"/Volumes/${mp}/${cn}_${mac_addr}.sparsebundle" && echo "Done"

does not work, but

declare -i s=${foo}; n=${bar}; mp=${baz}; cn=${qux}; mac_adr=${quux} 
sudo hdiutil create -size ${s}b -fs JHFS+X -volname "${n}" -type SPARSEBUNDLE \
"/Volumes/${cn}_${mac_addr}.sparsebundle" &&
sudo mv -vn "/Volumes/${cn}_${mac_addr}.sparsebundle" "/Volumes/${mp}" && echo "Done"

Works correctly

What am I doing wrong?

Best Answer

The only difference I can see is that you are trying to create sparse bundle on different volumes. /Volume/test.sparsebundle will be located on your startup disk. /Volume/Data/test.sparsebundle will be located (probably) on another disk. Please try to check what kind of filesystem is on your second drive.

You can try your issue both commands with -debug option and compare result.