As a Mac Admin I find myself constantly spinning up a new “Fresh” VM, tinkering, and then forgetting about it. I end up with a VM Library list a mile long.
I recently discovered that UTM has a command line interface, and this inspired me to write a script to quickly clone, launch, and cleanup test VMs.
You can find the script on my personal GitHub: https://github.com/BigMacAdmin/macOS-Stuff/blob/main/SpinUpUTMVM.sh
Arguments
You can run this script with no arguments, and it will clone and start a macOS VM of the same operating system as the host. So if you’re running macOS Sonoma, you will get a Sonoma VM. The script does assume you’re following the naming convention as configured in the script.
Arguments let you choose different operating systems (macOS or Windows for now) and versions. See the help dialog by running with -h.
./SpinupVM.sh -w
will start a Windows 11 VM and ./SpinupVM.sh -v 12
will start up a macOS Monterey VM.
To cleanup all of your “disposable” VMs, run with -d or --delete
and any VM the script has created previously will be deleted (after a confirmation.)
Naming Convention
The script relies on a naming convention for “Template” VMs. TEMPLATE_macOS_14_Sonoma
or TEMPLATE_Windows_11_Pro
for example. The script will create a “disposable” VM named like this: DISPOSABLE_macOS_14_1234567
where the final number is the unix epoch time that the VM was created.
When running in Delete/Cleanup mode, any VM with a name beginning “DISPOSABLE_” will be deleted.
Additional Suggestions
Terminal requires “Automation” access for UTM, which you’ll be prompted for the first time you call the utmctl
command line tool.
There is a quirk with the UTM command-line interface (/Applications/UTM.app/Contents/MacOS/utmctl
) when called directly that causes the binary to bounce on the dock and become part of your recent items. This will not happen if you create a symbolic link to the utility. sudo ln -s /Applications/UTM.app/Contents/MacOS/utmctl /usr/local/bin/utmctl
One response to “SpinUpVM.sh – A Convenience Script to Quickly Spin Up a macOS Test VM in UTM”
If you install UTM via homebrew, the command line tool will automatically be symlinked.
LikeLike