macOS installers come equipped with a script (called createinstallmedia) to create a macOS bootable USB installer drive. But sometimes it may be necessary to create a bootable ISO. The process is similar as we will use a DMG image instead of a physical drive to create the installer, which can then be converted to ISO.
Follow these steps to get the work done:
hdiutil create -o ~/Desktop/macOS.dmg -size 8500m -volname macOS -layout SPUD -fs HFS+J
hdiutil attach ~/Desktop/macOS.dmg -noverify -mountpoint /Volumes/macOS
sudo /Applications/Install macOS Catalina.app/Contents/Resources/createinstallmedia --volume /Volumes/macOS --nointeraction
I encountered an issue where if any of the steps would fail, subsequent runs of createinstallmedia would immediately fail with the following error:
Erasing Disk: 0%... 10%...
Error erasing disk error number (22, 0)
A error occurred erasing the disk.
hdiutil detach /volumes/Install macOS Mojave
hdiutil convert ~/Desktop/macOS.dmg -format UDTO -o ~/Desktop/macOS.cdr