Virtual macOS on macOS Host

Six years with Mac OS X as my primary operating system (OS) has included three hardware upgrades and a couple fresh installs. The complete OS and application rebuilds were not necessitated by any particular problems. It is mostly a psychological carry over from two decades of painful Microsoft Windows upgrades. Something just feels right about a complete reinstall. Recently I've been testing automated ways of installing applications and customizing the configuration of both apps and the OS. Having a virtual machine (VM) to test with makes the process go faster, so I set out to build a macOS VM. The steps below resulted in a working macOS VM on my MacBook Pro (MBP).

A guide to installing a macOS virtual machine on a macOS host.

Prerequisites

Apple License Agreement Compliance

Before we get started I must point out that I'm not violating the Licensing Agreement nor am I suggesting anyone do so. Per Apple's Software License Agreement for OS X Yosemite you are granted a limited, non-transferable, non-exclusive license:

(iii) to install, use and run up to two (2) additional copies or instances of the Apple Software within virtual operating system environments on each Mac Computer you own or control that is
already running the Apple Software, for purposes of: (a) software development; (b) testing during
software development; (c) using OS X Server; or (d) personal, non-commercial use.

VirtualBox

This guide assumes you have VirtualBox 5.x installed on your macOS host machine.

macOS Installer

Currently, I have not had any luck getting macOS El Capitan (10.11.x) to boot in a VirtualBox VM. Most likely this is due to Apple's change from an MBR (master boot record) base system to GPT (GUID partition table). As a result I had to download Install OS X Yosemite from the Apple App Store to my MBP.

Install iESD Ruby Gem

The iESD ruby gem enables you to modify extensions, kextcache, and packages in macOS InstallESD disk image used by Mac OS X installer. It will be used to convert the Yosemite installer into a disk image format that can be used by VirtualBox.

The first step is to verify that you are running Ruby version 1.9.2 or later. Run the following command and verify the version:

ruby -v  

Next install the iESD ruby gem using the command below:

gem install iesd  

Create OS X Yosemite Bootable Image

Since the installer included with the Install OS X Yosemite app is not bootable we need to use iESD to create a bootable disk image using the command below:

iesd -i /Applications/Install\ OS\ X\ Yosemite.app -o Yosemite.dmg -t BaseSystem  

Install OS X in VirtualBox VM

Create VirtualBox VM

Follow these steps to create a new VirtualBox VM that we will install Mac OS X into:

  1. Start the VirtualBox GUI application.
  2. From the Machine menu select New.
  3. Type macOS into the Name field, select Mac OS X for the Type, select Mac OS X 10.10 Yosemite (64-bit) for the Version, and click the Continue button.
  4. The Memory Size should be at least 2048 MB. Click Continue.
  5. Select Create a virtual hard disk now and click Create.
  6. Select VDI and click Continue.
  7. Select Dynamically allocated and click Continue.
  8. Leave the File location as the default macOS value, change the size to 40.00 GB, and click Create.

Configure VirtualBox VM

Now that the VM has been created we'll need to modify a few configuration settings before booting the first time.

  1. While still in VirtualBox with the newly created macOS VM selected, click the Settings button.
  2. Select the Storage tab.
  3. Under the Storage Tree section select the Empty optical drive.
  4. Click the small CD-ROM image in the Attributes area to the right of the Optical Drive label, and select Virtual Optical Disk File....
  5. Select the Yosemite.dmg bootable image file you created earlier and click Open.
  6. Click OK to close the VM Settings window.

Boot VM and Install OS X Yosemite

It will take anywhere from 15-30 minutes to complete the steps below, including an automated reboot, at which point you should have a running Yosemite VM.

  1. While still in VirtualBox with the newly created macOS VM selected, click the Start button.
  2. It may take 1 to 2 minutes to finish booting from the disk image mounted to the optical drive but eventually you will be presented with the Welcome screen.
  3. Select your preferred language (Use English for the main language in my case) and click the arrow button to continue.
  4. Before continuing on the next screen we need to format the VirtualBox hard drive created for this VM following these steps
    • At the top of the window select Utilities > Disk Utility.
    • Select what should be the only drive listed (42.95GB VBOX HARDDI...).
    • Select the Erase tab.
    • Ensure the Format is set to Mac OS Extended (Journaled).
    • Set the Name to Macintosh HD.
    • Click the Erase button and then Erase again to begin the process.
    • After less than 30 seconds it should be done.
    • In the top, left select Disk Utility > Quit Disk Utility.
  5. Back on the OS X Installer window click the Continue button.
  6. Click Continue and then Agree if you accept the terms or Cancel if you do not.
  7. Select the recently formatted Macintosh HD drive and Continue.

Initial OS X Setup

After the installation process completes you will be presented with the steps to setup Mac OS X for the first time. I've run into issues with system hang by trying to complete the full setup process so instead I skip some sections as detailed in these steps:

  1. On the Welcome screen select your country and click Continue.
  2. Choose a keyboard layout and click Continue.
  3. Select Don't transfer any information now and click Continue.
  4. Select Don't sign in, click Continue, and then Skip to confirm.
  5. If you accept click Agree twice or go Back if you do not.
  6. Complete the information to create an initial Administrator account and click Continue.
  7. Select the settings you prefer on the Diagnostics & Usage window and click Continue.

With any luck setup will complete and you'll be presented with the Yosemite wallpaper and a running system.