ninxsoft / mist-cli

A Mac command-line tool that automatically downloads macOS Firmwares / Installers.
MIT License
615 stars 29 forks source link

Generate bootable iso files for intel platform #53

Closed trodemaster closed 2 years ago

trodemaster commented 2 years ago

Thanks for making this RAD tool! It would be really handy for some of us virtualization users to output bootable iso files for the intel platform. Rich Trouton has implemented the functionality as a shell script and is a good reference.

https://github.com/rtrouton/create_macos_vm_install_dmg

n8felton commented 2 years ago

This was actually the genesis of my FR #50, but having the tool directly output an ISO is probably a better, or at least more wholistic, approach.

Here are some notes on what I'm doing today in case it helps.

sudo mist download 12 --image --image-name 'Install_macOS_%VERSION%-%BUILD%.dmg'

LATEST_DMG=$(find "/Users/Shared/Mist" -name "Install_macOS_*.dmg" | sort -V | tail -1); echo ${LATEST_DMG}    # /Users/Shared/Mist/Install_macOS_12.1-21C52.dmg
LATEST_NAME=${${LATEST_DMG##*/}%.*}; echo ${LATEST_NAME}                                                       # Install_macOS_12.1-21C52
INSTALL_MOUNT=$(hdiutil attach "${LATEST_DMG}" -nobrowse -plist |\
  xmllint --xpath '(//key[.="mount-point"])[last()]/following-sibling::*[1]/text()' -); echo ${INSTALL_MOUNT}  # /Volumes/Install macOS Monterey
INSTALL_APP_NAME=$(find ${INSTALL_MOUNT} -name '*OS*.app' -print -quit); echo ${INSTALL_APP_NAME}              # /Volumes/Install macOS Monterey/Install macOS Monterey.app

hdiutil create -size 14Gi -type SPARSE -fs JHFS+ -volname "${LATEST_NAME}" -layout ISOCD -ov "/private/tmp/${LATEST_NAME}.iso"
ISO_MOUNT_POINT=$(hdiutil attach "/private/tmp/${LATEST_NAME}.iso.sparseimage" -nobrowse -noverify -plist |\
  xmllint --xpath '(//key[.="mount-point"])[last()]/following-sibling::*[1]/text()' -)
sudo "${INSTALL_APP_NAME}/Contents/Resources/createinstallmedia" --volume "${ISO_MOUNT_POINT}" --nointeraction

hdiutil detach "/Volumes/Install macOS Monterey 1"
hdiutil detach "/Volumes/Shared Support"
hdiutil detach "${INSTALL_MOUNT}"
hdiutil convert "/private/tmp/${LATEST_NAME}.iso.sparseimage" -format UDTO -o "/Users/Shared/Mist/${LATEST_NAME}"
mv "/Users/Shared/Mist/${LATEST_NAME}.cdr" "/Users/Shared/Mist/${LATEST_NAME}.iso"
rm "/private/tmp/${LATEST_NAME}.iso.sparseimage"
shasum -a 256 "/Users/Shared/Mist/${LATEST_NAME}.iso" > "/Users/Shared/Mist/${LATEST_NAME}.iso.shasum"
trodemaster commented 2 years ago

I was in the process of writing something very similar. Thanks! If mist could directly output a .iso and json of metadata including a sha-256 would complete the solution.

ninxsoft commented 2 years ago

Progress 🥳

➜ ~ sudo mist download --platform intel "High Sierra" --iso
┌──────────────────┐
│ INPUT VALIDATION │
└──────────────────┘
  ├─ User is 'root'...
  ├─ Download search string will be 'High Sierra'...
  ├─ Platform will be 'intel'...
  ├─ Include betas in search results will be 'false'...
  ├─ Output directory will be '/Users/Shared/Mist'...
  ├─ Temporary directory will be '/private/tmp'...
  ├─ Force flag has not been set, existing files will not be overwritten...
  ├─ Valid download type(s) specified...
  ├─ Bootable Disk Image name will be 'Install %NAME% %VERSION%-%BUILD%.iso'...
┌────────┐
│ SEARCH │
└────────┘
  ├─ Searching for macOS download 'High Sierra'...
  ├─ Found [041-91758] macOS High Sierra 10.13.6 (17G66) [2019-10-20]
┌───────┐
│ SETUP │
└───────┘
  ├─ Creating new temporary directory '/private/tmp/041-91758'...
┌──────────┐
│ DOWNLOAD │
└──────────┘
  ├─ [ 01 / 12 ] 041-91758.English.dist........ [ 08.81 KB / 08.81 KB (100.0%) ]
  ├─ [ 02 / 12 ] AppleDiagnostics.chunklist...... [ 00.00 B / 00.00 B (100.0%) ]
  ├─ [ 03 / 12 ] AppleDiagnostics.dmg.......... [ 02.87 MB / 02.87 MB (100.0%) ]
  ├─ [ 04 / 12 ] BaseSystem.chunklist.......... [ 01.98 KB / 01.98 KB (100.0%) ]
  ├─ [ 05 / 12 ] BaseSystem.dmg.............. [ 486.28 MB / 486.28 MB (100.0%) ]
  ├─ [ 06 / 12 ] InstallAssistantAuto.pkg...... [ 11.83 MB / 11.83 MB (100.0%) ]
  ├─ [ 07 / 12 ] InstallESDDmg.chunklist....... [ 16.53 KB / 16.53 KB (100.0%) ]
  ├─ [ 08 / 12 ] InstallESDDmg.pkg............. [ 04.72 GB / 04.72 GB (100.0%) ]
  ├─ [ 09 / 12 ] InstallInfo.plist............. [ 01.58 KB / 01.58 KB (100.0%) ]
  ├─ [ 10 / 12 ] MajorOSInfo.pkg............... [ 02.52 MB / 02.52 MB (100.0%) ]
  ├─ [ 11 / 12 ] OSInstall.mpkg.............. [ 684.04 KB / 684.04 KB (100.0%) ]
  ├─ [ 12 / 12 ] RecoveryHDMetaDmg.pkg....... [ 487.84 MB / 487.84 MB (100.0%) ]
┌─────────┐
│ INSTALL │
└─────────┘
  ├─ Creating new installer '/Applications/Install macOS High Sierra.app'...
  ├─ Deleting temporary directory '/private/tmp/041-91758'...
  ├─ Created new installer '/Applications/Install macOS High Sierra.app'
┌─────────────────────┐
│ BOOTABLE DISK IMAGE │
└─────────────────────┘
  ├─ Creating new temporary directory '/private/tmp/041-91758'...
  ├─ Creating disk image '/private/tmp/041-91758/041-91758.dmg'...
  ├─ Mounting disk image at mount point '/Volumes/Install macOS High Sierra'...
  ├─ Creating install media at mount point '/Volumes/Install macOS High Sierra'...
  ├─ Unmounting disk image at mount point '/Volumes/Install macOS High Sierra'...
  ├─ Converting disk image '/private/tmp/041-91758/041-91758.cdr'...
  ├─ Moving '/private/tmp/041-91758/041-91758.cdr' to '/Users/Shared/Mist/Install macOS High Sierra 10.13.6-17G66.iso'...
  ├─ Deleting temporary directory '/private/tmp/041-91758'...
  ├─ Created bootable disk image '/Users/Shared/Mist/Install macOS High Sierra 10.13.6-17G66.iso'
┌──────────┐
│ TEARDOWN │
└──────────┘
  └─ Deleting installer '/Applications/Install macOS High Sierra.app'...

I need to test against macOS Mojave and above, but it's looking good!

ninxsoft commented 2 years ago

Successful builds of High Sierra, Mojave, Catalina, Big Sur and Monterey, in the sense that createinstallmedia did not error out.

ISO file size is determined dynamically using the following formula:

("total download size" rounded up to the nearest GB) + 1GB

Works for all builds thus far, open to suggestions 👍

Will need to verify that the .iso files actually boot, then we are good to go 🥳

trodemaster commented 2 years ago

I was able to build from main branch and built an iso for the latest 12.3 beta. Booted up and installed in VMware Fusion without issue.

ninxsoft commented 2 years ago

Thanks @trodemaster I'll increment a release build soonish, once I crush a few more issues 👍🏼