How to create a bootable macOS ISO for virtualization

Purpose

If your are a developer, system administrator or enthusiast, you will soon find advantages to virtualizing an instance of the macOS. For developers you will want to maintain the integrity of your host OS for your normal business tasks, but will need to setup an environment for developing and testing. If you are a system administrator you probably wish to build a virtual macOS server. The standard way to install a desired OS into a virtual environment is by using a bootable ISO of that OS. Apple does not provide an ISO for their current macOS, but they do provide a macOS installer application. These instructions will show you how to build a bootable macOS ISO from Apple’s macOS installer application.

Prerequisites

The latest version of macOS installer application for your desired OS, which currently can be download from Apple’s App Store.

Solution

macOS Sierra

    1. At the Finder from the File menu select New Finder Window
    2. Navigate to Applications > Utilities and double-click on Terminal
    3. In the Terminal type the following commands:
      1. hdiutil attach /Applications/Install macOS Sierra.app/Contents/SharedSupport/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/OS X Install ESD
      2. hdiutil create -o ~/Desktop/macOS_10.12.2 -size 8192m -type SPARSE -fs HFS+J -layout SPUD (x represents the version number i.e. 10.12.2)
      3. hdiutil attach ~/Desktop/macOS_10.12.2.sparseimage -noverify -nobrowse -mountpoint /Volumes/macOS_10.12.2
      4. asr restore -source /Volumes/OS X Install ESD/BaseSystem.dmg -target /Volumes/macOS_10.12.2 -erase -noprompt -noverify
      5. At this point a Finder window will pop-up, so click on its red close button. In the Terminal continue typing:
      6. rm /Volumes/OS X Base System/System/Installation/Packages
      7. cp -rp /Volumes/OS X Install ESD/Packages /Volumes/OS X Base System/System/Installation/
      8. cp -rp /Volumes/OS X Install ESD/BaseSystem.* /Volumes/OS X Base System/
      9. hdiutil detach /Volumes/OS X Install ESD
      10. hdiutil detach /Volumes/OS X Base System
      11. hdiutil resize -size `hdiutil resize -limits ~/Desktop/macOS_10.12.2.sparseimage | tail -n 1 | awk ‘{ print $1 }’`b ~/Desktop/macOS_10.12.2.sparseimage
      12. hdiutil convert ~/Desktop/macOS_10.12.2.sparseimage -format UDTO -o ~/Desktop/macOS_10.12.2
      13. mv ~/Desktop/macOS_10.12.2.cdr ~/Desktop/macOS_10.12.2.iso
      14. rm ~/Desktop/macOS_10.12.2.sparseimage

Solution

macOS Mojave

    1. hdiutil attach /Applications/Install macOS Mojave.app/Contents/SharedSupport/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/InstallESD
    2. hdiutil create -o ~/Desktop/macOS_10.14 -size 8192m -type SPARSE -fs HFS+J -layout SPUD (x represents the version number i.e. 10.12.2)
    3. hdiutil attach ~/Desktop/macOS_10.14.sparseimage -noverify -nobrowse -mountpoint /Volumes/macOS_10.14
    4. asr restore -source /Applications/Install macOS Mojave.app/Contents/SharedSupport/BaseSystem.dmg -target /Volumes/macOS_10.14 -erase -noprompt -noverify
    5. At this point a Finder window will pop-up, so click on its red close button. In the Terminal continue typing:
    6. rm /Volumes/OS X Base System/System/Installation/Packages
    7. cp -rp /Volumes/InstallESD/Packages /Volumes/OS X Base System/System/Installation/
    8. cp -rp /Applications/Install macOS Mojave.app/Contents/SharedSupport/BaseSystem.* /Volumes/OS X Base System/
    9. hdiutil detach /Volumes/InstallESD
    10. hdiutil detach /Volumes/OS X Base System
    11. hdiutil resize -size `hdiutil resize -limits ~/Desktop/macOS_10.14.sparseimage | tail -n 1 | awk ‘{ print $1 }’`b ~/Desktop/macOS_10.14.sparseimage
    12. hdiutil convert ~/Desktop/macOS_10.14.sparseimage -format UDTO -o ~/Desktop/macOS_10.14
    13. mv ~/Desktop/macOS_10.14.cdr ~/Desktop/macOS_10.14.iso
    14. rm ~/Desktop/macOS_10.14.sparseimage