Automate Building Jamf Compatible macOS 10.13+ Virtual Machines

cainehorr
Contributor III

I've read many posts and blogs on how to build Jamf Compatible macOS 10.13+ Virtual Machines.

After much reading, I cobbled together a script that soon became a workflow and has since become a mainstay in my toolkit.

Before I continue, here are three sites from which I pieced together my workflow:

What I'm about to present to you isn't exactly groundbreaking, but it IS handy.

So here's what you're going to need (you should start downloading now)...

#!/bin/bash

#
# createVMDK.sh
#
# DESCRIPTION
# Creates custom vmdk file with a serial number and Apple hardware type
# for use with a Mobile Device Management platform (ie Jamf).
#
# CHANGE CONTROL LOG
#   2018-09-07 - Caine Hörr
#       Version 2.0
#       Added environmentSettings sub-section
#       Added vfuseCheck with installer routine
#   2018-07-23 - Caine Hörr
#       Version 1.0
#       Initial script creation
#

environmentSettings(){
    # USER EDITABLE VARIABLES
    virtualMachineName="Jamf_Compatible_Virtual_Machine"      # Name of Virtual Machine as known to Vmware Fusion
    virtualMachineHardwareType="MacBookPro14,2"                   # Apple Macintosh hardware type
    virtualMachineSerialNumber="random"                           # "random" creates a random serial number, otherwise type in your own (needed for DEP testing)
    bootableDMG=osx_updated_180820-10.13.6-17G65.apfs.dmg       # Bootable macOS DMG as created by AutoDMG
    vfusePKG=vfuse-2.0.6.pkg                                    # vfuse PKG installer

    # DO NOT MODIFY BELOW THIS LINE
    currentDirectoryPath=`pwd`
    inputDMGpath=${currentDirectoryPath}/${bootableDMG}
    vfusePath=`which vfuse`
    dateTimeStamp=`date "+%Y-%m-%d_%H-%M-%S"`
}

main(){
    RunAsRoot
    environmentSettings
    vfuseCheck
    inputDMGpath
    configureVirtualMachine
}

RunAsRoot(){
    # Check for admin/root permissions
    if [ "$(id -u)" != "0" ]; then
        echo "ERROR: Script must be run as root, or have root privileges (ie. sudo)." 1>&2
        exit 1
    else
        echo "Running as root..."
    fi
}

vfuseCheck(){
    if [ "${vfusePath}" = "" ]; then    
        echo "vfuse not found. Installing..."
        sudo installer -pkg ${currentDirectoryPath}/${vfusePKG} -target /
        vfusePath=`which vfuse`
        echo "vfuse installed in" ${vfusePath}
        vfuseVersion=`vfuse --version`
        echo "vfuse" ${vfuseVersion} "installed"
    else
        echo "Found ${vfusePath}"
        vfuseVersion=`vfuse --version`
        echo "vfuse" ${vfuseVersion} "installed"
    fi
}

inputDMGpath(){
    if [ ! -f "${inputDMGpath}" ]; then   
        echo "${inputDMGpath} not found."
        exit 1
    else
        echo "Found ${inputDMGpath}"
    fi
}

configureVirtualMachine(){
    echo "Configuring Jamf compatible Virtual Machine"
    sudo ${vfusePath} -i ${inputDMGpath} -o ${currentDirectoryPath}/ -s ${virtualMachineSerialNumber} --hw-model ${virtualMachineHardwareType} -n "${virtualMachineName}-${dateTimeStamp}"
}

main

exit 0

SAVE A COPY OF THE SCRIPT
You're going to need a copy of the script. Here's how you can do that.

01.) Copy & Paste from this page into your favorite plain text editor
01A.) You will need to update the macOS DMG and vfuse variables accordingly.
02.) Save as "createVMDK.sh" - make sure you save in plain text format
03.) Launch /Applications/Utilities/Terminal.app
04.) Navigate to the folder where you saved the createVMDK.sh script
05.) Type in the following:

chmod 755 createVMDK.sh

06.) Press enter - this will make the script executable

SETTING UP THE ENVIRONMENT
Once you've gathered everything you need, here's how to get things set up so you can be productive...

01.) Create a folder on your Desktop called "JamfCompatibleVM"
02.) Copy/Move the vfuse.pkg into the JamfCompatibleVM folder
03.) Copy/Move the aforementioned script into the JamfCompatibleVM folder
04.) Double-Click the AutoDMG.dmg that you downloaded and copy AutoDMG.app into /Applications
05.) Run /Applications/AutoDMG.app
06.) Drag your copy of Install macOS High Sierra.app into AutoDMG.app
07.) Click the "Build" button
08.) Save the AutoDMG output file to the JamfCompatibleVM folder
09.) Go get a beverage. Take a bathroom break. Make a phone call. Whatever. This process takes awhile.
10.) When everything is done, you will have a shiny, new file named something similar to "osx_updated_180820-10.13.6-17G65.apfs.dmg" in your JamfCompatibleVM folder
11.) Update the createVMDK.sh script with the name of this file.

CREATING A JAMF COMPATIBLE macOS 10.13+ VIRTUAL MACHINE
Now that everything is in place, you're ready to roll out as many Jamf Compatible macOS 10.13+ Virtual Machines as you like!

Here's how...

  1. )Launch /Applications/Utilities/Terminal.app 02.) Type in the following commands
cd $HOME/Desktop/JamfCompatibleVM
sudo ./createVMDK.sh

03.) Press enter, sit back, and watch the blinkin' lights.

FYI - If you don't already have a copy of vfuse installed, the script will take care of the for you

When it's all done, you will have a never before booted VMDK (Vmware Fusion Compatible Virtual Machine).

Because each VMDK file has a date and time stamp appended to the file name and the serial number's are randomized, you can create an entire fleet of Jamf Compatible macOS 10.13+ Virtual Machines. Perfect for testing in your Jamf Dev environment, handing out to engineers and developers, or whatever needs you may have.

APPLE DEP COMPATIBILITY
So you need a VM to test DEP? No problem!

01.) Grab your nearest DEP enrolled Mac that's still in a box (or wherever) - just so long as it's not currently enrolled in Jamf
02.) Edit the "environmentSettings" sub-routine within the script. Specifically the following:
03.) Change "virtualMachineHardwareType" from "MacBookPro14,2" to whatever Macintosh Hardware Type your physical hardware might be
04.) Change "virtualMachineSerialNumber" from "random" to the same serial number as the physical hardware in your possession
05.) Save the script
06.) Run the script
07.) You now have a VMDK file that will masquerade as a DEP enabled device. Great for testing your DEP workflows with Jamf. Aren't Vmware Fusion snapshots handy?

COMING SOON - MAYBE...
Right now, this is version 2 of my script. I don't have much time to work on it. It gets the job done and it serves my purposes. Hopefully it will serve you well too.

In the future, I'm hoping to wrap it in a platypus wrapper so it becomes an "app" that I can double-click on. Using some cocoa-dialogue magic, I can then input information such as "random" or an actual "serial number", "machine hardware type", etc.

I'm also thinking of how I can have it auto-download the freshest version of vfuse, autodmg, and macOS. If I could automate that as well, that's be gravy!

Anyway - no promises on pie-in-the-sky ideas... but you never know.

If you have any ideas, tips, tricks, hacks, etc - pass em along!

Kind regards,

Caine Hörr

A reboot a day keeps the admin away!

5 REPLIES 5

Kristopher
New Contributor III

Issue resolved.

cainehorr
Contributor III

@Kristopher - Which "issue"?

Kind regards,

Caine Hörr

A reboot a day keeps the admin away!

jklinkowsky
New Contributor

I am getting permission denied when running the shell script ./createVMDK.sh

mlitton
New Contributor II

Do you have an update that supports Catalina?

jefff
Contributor II