Skip to content

Instantly share code, notes, and snippets.

@webknjaz
Last active January 31, 2024 15:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webknjaz/b6405536e6d475e03f353898cd7d837f to your computer and use it in GitHub Desktop.
Save webknjaz/b6405536e6d475e03f353898cd7d837f to your computer and use it in GitHub Desktop.
$ MACOS_VM_VERSION=12.4
$ MACOS_VM_CODENAME=$(softwareupdate --list-full-installers 2>&1 | grep "Version:\s$(echo "${MACOS_VM_VERSION}" | sed 's#\.#\\.#g')[0-9.]*," | awk -F' macOS ' '{print$2}' | awk -F, '{print$1}' | uniq)
$ MACOS_VM_NAME="ansible-core-ci-template-macos-${MACOS_VM_VERSION}-playground"
$ MACOS_INSTALLER_NAME="Install macOS ${MACOS_VM_CODENAME}"
$ MACOS_INSTALLER_VOLUME_NAME="${MACOS_VM_CODENAME}"-"${MACOS_VM_VERSION}"
$ MACOS_INSTALLER_VOLUME_PATH="/Volumes/${MACOS_INSTALLER_VOLUME_NAME}"
$ MACOS_DOWNLOADED_INSTALLER_APP_PATH="/Applications/${MACOS_INSTALLER_NAME}.app"
$ MACOS_CREATEINSTALLMEDIA_BIN_PATH="${MACOS_DOWNLOADED_INSTALLER_APP_PATH}/Contents/Resources/createinstallmedia"
$ MACOS_ORIGINAL_INSTALLER_VOLUME_PATH="/Volumes/${MACOS_INSTALLER_NAME}"
$ MACOS_IMAGE_OUT_PATH=~/"${MACOS_INSTALLER_VOLUME_NAME}"
$ MACOS_DMG_IMAGE_PATH="${MACOS_IMAGE_OUT_PATH}.dmg"
$ softwareupdate --fetch-full-installer --full-installer-version "${MACOS_VM_VERSION}"
Downloading and installing 12.4 installer
SUPreferenceManager: Failed to set object of class: __NSCFString for key: LastRecommendedMajorOSBundleIdentifier with error: Error Domain=SUPreferenceManagerErrorDomain Code=1 "(null)"
SUPreferenceManager: Failed to set object of class: __NSCFString for key: LastRecommendedMajorOSBundleIdentifier with error: Error Domain=SUPreferenceManagerErrorDomain Code=1 "(null)"
Install finished successfully
$ hdiutil create -o "${MACOS_IMAGE_OUT_PATH}" -size 14000m -volname "${MACOS_INSTALLER_VOLUME_NAME}" -layout SPUD -fs HFS+J
created: ~/Monterey-12.4.dmg
$ hdiutil attach "${MACOS_DMG_IMAGE_PATH}" -noverify -mountpoint "${MACOS_INSTALLER_VOLUME_PATH}"
/dev/disk2          	Apple_partition_scheme         	
/dev/disk2s1        	Apple_partition_map            	
/dev/disk2s2        	Apple_HFS                      	/Volumes/Monterey-12.4
$ sudo "${MACOS_CREATEINSTALLMEDIA_BIN_PATH}" --volume "${MACOS_INSTALLER_VOLUME_PATH}" --nointeraction
Erasing disk: 0%... 10%... 20%... 30%... 100%
Making disk bootable...
Copying to disk: 0%... 10%... 20%... 30%... 40%... 50%... 60%... 70%... 80%... 90%... 100%
Install media now available at "/Volumes/Install macOS Monterey"
$ hdiutil detach "${MACOS_ORIGINAL_INSTALLER_VOLUME_PATH}"
"disk2" ejected.
$ prlctl create "${MACOS_VM_NAME}" -o macos
Creating the virtual machine...
Generate the VM configuration for macosx.
The VM has been successfully created.
$ prlctl set "${MACOS_VM_NAME}" --autostart off --startup-view headless --on-shutdown close --autostop stop --on-window-close keep-running --tools-autoupdate no --cpus 2 --memsize 4096 --videosize 32 --device-set net0 --type shared --auto-share-camera off --auto-share-bluetooth off --auto-share-smart-card off --device-del hdd0 --isolate-vm on
Remove the hdd0 device.

The VM has been successfully configured.
$ prlctl set "${MACOS_VM_NAME}" --device-add hdd --size 65536
Creating hdd0 (+) sata:0 image='/Users/administrator/Parallels/ansible-core-ci-template-macos-12.4-playground.pvm/harddisk1.hdd' type='expanded' 65536Mb online-compact=off

Created hdd0 (+) sata:0 image='/Users/administrator/Parallels/ansible-core-ci-template-macos-12.4-playground.pvm/harddisk1.hdd' type='expanded' 65536Mb online-compact=on


The VM has been successfully configured.
$ prlctl set "${MACOS_VM_NAME}" --device-set cdrom0 --image "${MACOS_DMG_IMAGE_PATH}" --connect
Creating cdrom0 (+) sata:1 image='/Users/administrator/Monterey-12.4.dmg'

Configured cdrom0 (+) sata:1 image='/Users/administrator/Monterey-12.4.dmg'


The VM has been successfully configured.
$ prlctl start "${MACOS_VM_NAME}"
Starting the VM...
The VM has been successfully started.

<Manual GUI OS initial install stage>

$ prlctl stop "${MACOS_VM_NAME}" && prlctl set "${MACOS_VM_NAME}" --device-del cdrom0 && prlctl start "${MACOS_VM_NAME}"
Stopping the VM...
The VM has been successfully stopped.
Remove the cdrom0 device.

The VM has been successfully configured.
Starting the VM...
The VM has been successfully started.

<Manual GUI OS post-reboot install stage>

<Within the VM (through Parallels GUI)>

$ sudo systemsetup -setremotelogin on
Password:
setremotelogin: Turning Remote Login on or off requires Full Disk Access privileges.

So we're forced to fall back to ticking the System Preferences -> Sharing -> [x] Remote Login checkbox.

<On dev machine/control node (optionally)>

$ sudo emerge -v net-misc/sshpass
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment