Skip to content

Instantly share code, notes, and snippets.

@motleytech
Created June 25, 2016 05:36
Show Gist options
  • Save motleytech/90d8bc8e16117bd99b2dab141df3eee8 to your computer and use it in GitHub Desktop.
Save motleytech/90d8bc8e16117bd99b2dab141df3eee8 to your computer and use it in GitHub Desktop.
osx vm on osx

Recently, I tried creating an OSX Virtualbox VM on my macbook. Creating a virtualbox VM should be easy, I guessed, as I am just looking to run an OSX guest on an OSX host. Not trying to create a hackintosh here.

However, it turned out to be more tricky than I anticipated. For starters, I needed a bootable iso of the OSX operating system, but Apple does not provide one anymore. So this is what I had to do...

I searched around on google and ran into many useless pages. Finally, I found one that had a useful solution.

I replicate the instructions here, in case that website goes missing.

Step by step instructions

Look for Install OSX Yosemite.app in your /Applications folder. If its already there, you can save on a large download.

Do this step only if you did not find the app file in step 1. Download the Yosemite installer app from the app store. It should be in your purchased apps if your system is already upgraded to yosemite. This is a big download - go get some coffee. Once the app is downloaded, it will attempt to start the installer. Cancel out of it. The app file is now downloaded to your /Applications folder. However, its not in the iso format that virtualbox requires.

Convert the app into an iso file by doing the following...

Copy paste the below script into a text editor and save it as a file somewhere on your system. Lets assume you saved it as convert_yosemite.sh in /tmp folder.

#!/bin/bash
# Script to create osx yosemite iso image

# Mount the installer image
hdiutil attach /Applications/Install\ OS\ X\ Yosemite.app/\
Contents/SharedSupport/InstallESD.dmg -noverify \
-nobrowse -mountpoint /Volumes/install_app

# Convert the boot image to a sparse bundle
hdiutil convert /Volumes/install_app/BaseSystem.dmg -format UDSP -o /tmp/Yosemite

# Increase the sparse bundle capacity to accommodate the packages
hdiutil resize -size 8g /tmp/Yosemite.sparseimage

# Mount the sparse bundle for package addition
hdiutil attach /tmp/Yosemite.sparseimage -noverify -nobrowse \
-mountpoint /Volumes/install_build

# Remove Package link and replace with actual files
rm /Volumes/install_build/System/Installation/Packages
cp -rp /Volumes/install_app/Packages /Volumes/install_build/System/Installation/

# Copy Base System
cp -rp /Volumes/install_app/BaseSystem.dmg /Volumes/install_build/
cp -rp /Volumes/install_app/BaseSystem.chunklist /Volumes/install_build/

# Unmount the installer image
hdiutil detach /Volumes/install_app

# Unmount the sparse bundle
hdiutil detach /Volumes/install_build

# Resize the partition in the sparse bundle to remove any free space
hdiutil resize -size `hdiutil resize -limits /tmp/Yosemite.sparseimage \
| tail -n 1 | awk '{ print $1 }'`b /tmp/Yosemite.sparseimage

# Convert the sparse bundle to ISO/CD master
hdiutil convert /tmp/Yosemite.sparseimage -format UDTO -o /tmp/Yosemite

# Remove the sparse bundle
rm /tmp/Yosemite.sparseimage

# Rename the ISO and move it to the desktop
mv /tmp/Yosemite.cdr ~/Desktop/Yosemite.iso

Start terminal and run this command cd /tmp; chmod +x convert_yosemite.sh to make the script executable. Run the script by running the command ./convert_yosemite.sh on the terminal prompt.

Once its done, you will have a Yosemite.iso file on your desktop.

That's it. You should be able to use this iso file as the bootable osx media required for the osx vm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment