Just Code it!

Update: Written for OSX El Capitan. Works for macOS Sierra as well.

While VirtualBox is a great product easy to use to create Virtual Machines and configure in few minutes, trying to create a Virtual Machine with a OSX system could be very tricky.

With this guide I will explain a procedure you can follow if you want to install a Mac OS X system on VirtualBox, running on Max OS X as well.

I wanted to describe this because the information available are often confused, missing and too many times they require the download of extra software or installer (generally to avoid the very common issue where the UEFI Interactive Shell is displayed or the text “Fatal: no bootable medium found! System Halted”, that you can see if you selected EFI support for your Virtual Machine).

If you find this useful or interesting please share and comment for more to come!

Time to start!

Create ISO from installer

The very first thing to do is to download the OS X Installer.

I wrote a dedicated post for this and you can find it here:

Create Mac OS X Installer USB Disk

Time to do some magic!

As it stand the installer will not work on the Virtual Machine (and you will experience the error I mentioned at the start of the article).

What we’ll need to do is manipulate the installer disk in order to make it ready for our Virtual Machine to understand.

I will put the whole list of commands at the end of this article, but I will explain every line to make it clear what’s going on.

We’ll make heavy use of the “hdiutil” tool.

It is a command used to manipulate disk images and you can find detailed about this command here:



1. Attach the installer image

First thing we need to do is attaching the image of the installer (that we downloaded) as a device. Effectively simulating a device (the installation disk in this case) attached to our mac.

We achieve this using the “hdiutil” command: “attach“.

The disk we want to attach is contained in the app you downloaded from the App Store: “/Applications/Install OS X El Capitan.app

Inside its content: “/Contents/SharedSupport/InstallESD.dmg

(So essentially in: “/Applications/Install OS X El Capitan.app/Contents/SharedSupport/InstallESD.dmg“)

We’ll then proceed to attach this disk image and at the same time:

  • We’ll tell the system to hide the content of this disk from Finder with: “-nobrowse
  • We’ll no verify the image (with the checksums): “-noverify
  • and we’ll instruct it to mount it in a location where we will then intend to access its content. Let’s choose: “/Volumes/esd

That’s the full command:

2. Create new image

We want now to create a new image.

For this we’ll use the “hdiutil” command: “create”

  • We give the image an output file: “-o Installer.cdr
  • I’ll set the size to 7.5GB (you can increase it if you’ll need to): “-size 7.5g
  • Then we specify the layout of the image. We’ll use “SPUD“, that from the documentation: “SPUD causes a DDM and an Apple Partition Scheme partition map with a single entry to be written.”
  • For the filesystem (of the image) we’ll use the standard HFS+J: “-fs HFS+J

3. Attach the new disk image

We now attach the newly created disk image (still empty) to another volume. The command is conceptually identical to what we did before with “InstallESD.dmg”, but this time we attach the disk we just created “OSXInstaller.cdr.dmg”:

4. Copy the System Installer to the new disk image

The real installer is inside the disk image “BaseSystem.dmg” contained in “InstallESD.dmg” (that we attached to the volume “/Volumes/esd/“).

What we need to do is copy the content of this disk image (so the content of “BaseSystem.dmg”) into the root of our new installer disk (that we attached to “/Volumes/iso/“).

For this we use now the command “asr” that copies disk images into volumes and we just tell it to restore the image from “/Volumes/esd/BaseSystem.dmg” into “/Volumes/iso“.

The other options are to avoid verification and to skip the prompting of confirmation to continue (essentially to avoid to answer “yes” to the erase disk confirmation).

Note: the “-erase” option is now mandatory (or “asr” will refuse to run with the error: “File copy is not supported anymore.  Use the –erase flag.”).

This is the full command:

At the end of this passage the finder window pointing to our new “restored” disk (“Volumes/OS X Base System/“) should automatically popup:

and you can see that it is now mounted and available from the main finder as well:


5. Remove broken link

If you look inside “Volumes/OS X Base System/System/Installation/” you will see that there is a file “Packages” that is actually a link.

If you check where it’s pointing at (with “ls -l /Volumes/OS\ X\ Base\ System/System/Installation/Packages“), you will see that it points to:

/Volumes/OS X Base System/System/Installation/Packages -> /System/Installation/PackagesLink

That doesn’t exist.

In order to fix this we need to remove this link and put the real file in there.

We can remove it simply with:

6. Put back what the link was pointing to

Now it’s just a question to replace the link we just removed with the a real folder physically containing the files.

This is the folder “Packages” in the disk “InstallESD.dmg” (that we mounted in “/Volumes/esd/“).

Let’s copy it, preserving the property of the files (mode,ownership,timestamps) with the parameter “-p” and copying the directories recursively “-r“:

At the end of this the “Pakages” folder should be back in place (but for real this time, not anymore as a link) in the disk we are manually creating (the folder will be therefore in “/Volumes/OS\ X\ Base\ System/System/Installation/Packages“).

7. Copy the remaining missing files

If you look again in the original InstallESD disk, you can see other files in the root:

Ignore the two AppleDiagnostic files (we don’t care about these).

We need to copy the two BaseSystem files in the root of our disk:

8. Detach the volumes

We can now detach the source disk (“/Applications/Install OS X El Capitan.app/Contents/SharedSupport/InstallESD.dmg“) that we mounted in “/Volumes/esd“:

And the one we created (from “/Volumes/esd/BaseSystem.dmg“) and found in “Volumes/OS X Base System/“:

9. Create ISO disk

To use the installer in VirtualBox we need to convert our disk to iso, otherwise you would receive an “VERR_NOT_SUPPORTED” error.

To convert our dmg disk in iso we’ll use again the “hdiutil” tool with the command “convert“:

The format we’ll use is: “UDTO – DVD/CD-R master for export”:

The generated file will contain the extra extension “cdr” that we need to remove if we want to see the disk from VirtualBox in order to select it later on.

We can get rid of it simply renaming the file with “mv“:

you can get rid of OSXInstaller.cdr.dmg at any point now (thanks to Brian for noticing this missing detail in a comment).

10. Done – Summary of the commands

The image is ready to use in VirtualBox. It’s name is now: “OSXInstaller.iso

This is the summary of the commands we run to create it for an easy reference:

Create the Virtual Machine

Open now VirtualBox (you can download it there: “https://www.virtualbox.org/“). I’m using version 5.0.20.

1. Creation

Proceed creating a new Virtual Machine. You can do this by clicking the blue icon (“new”) at the top:

Give a name. If you name it something like “OSX” VirtualBox will automatically select the type of Virtual Machine you want to create (“Mac OSX”):

Click “Continue” and select then the memory size in the next screen. I pick 4096MB:

Create a virtual hard disk:

Select the default VDI (VirtualBox Disk Image) disk type:

Go ahead and pick (if you want) Dynamically allocated:

Select then the file location (the name really) and size (I will create a 40GB HD):

At this point the creation procedure will complete and you should be able to locate your newly created Virtual Machine:

2. Configuration

Select it and click on the “Settings” button:

Select the “Display” section (subsection “Screen”) and fix the amount of Video Memory if it is something like 1MB or 8MB. Move it to the max 128MB:

Enter then the “Storage” section and select the “Empty” disk. Click the CD icon on the right and pick the “Choose Virtual Optical Disk File…” from the menu that will pop-up:

Locate and select the iso we created in the previous chapter (“OSXInstaller.iso“):

At this point press “OK” and we are ready!

Install OSX on the VM

We can now start the real OSX installation procedure!

1. Start the VM

Time to run our Virtual Machine for the first time! Click on the green “Start” arrow:

It should now start and you should see the console printing out a lot of data… wait patiently:

… and more…

Finally start the installation procedure selecting your language:

Click “Continue: on the next screen:

2. Create an HDD partition

To install the system we need to create an Hard Disk first. As you can see in the following image in fact the only visible drive is the CD with the installer:

This video will show how to create the disk and start the installation process that I will describe step by step immediately after:

To create it run the tool “Disk Utility” that you can find in the top menu under “Utilities”:

Select the Hard Disk on the left side (without any partition at the moment) and click “Erase”:

In the new window that will pop-up set a name (I named it “HDD”) and click the “Erase” button:

Wait for the procedure to complete and click “Done”:

You can the close Disk Utility:

3. Install OSX!

And you’ll have your new HDD ready to select and click “Continue” to finally start the installation procedure:

Time to wait…

4. Restart the VM

At the end of the installation the system will shut down.

At this point we can remove the installation disk from our virtual drive.

Go in Settings, Storage and then select the “OSXInstaller.iso” drive. Click on the disk icon at the right of “Optical Drive” and this time select “Remove Disk from Virtual Drive”:

The drive should now be empty again:

You can now run again the Virtual Machine and this time the second part of the OSX installation procedure should kick in:

Go ahead and complete the installation.

This video shows this procedure:

At the end you should finally be able to boot into your brand new freshly installed OSX Virtual Machine! :)


That’s all!

comment and share if this helped you or if you have any questions! :)


This post is actually part of a more specific article I wrote that explains how to install OSX on a Virtual Machine in VirtualBox. You can find this other article here:
Install OS X on VirtualBox (on OS X)

This guide will show how to create an installer of your OSX system. Once done, you will be able to use it if you want for example wipe your current system and start fresh with a brand new OSX Installation, or proceed and use it to install it on a VM as I mentioned before.

I will show how to download the latest version of OSX (El Capitan at the time of this article) or an older one you previously owned (Yosemite for example).

Download the latest OS X Version (El Capitan)

To download it, you can pass through a web browser going there:

and clicking then “View in Mac App Store”:

To select then “Launch Application” and land in the App page on the App Store:

Or open directly the App Store on your mac:

and search for “El Capitan”:

Despite how you reach this stage, you will have then click on the App or just select “download” and…

… wait and wait…

Once the download is complete you can see the installer in the Application folder:

Prepare the USB

In order to create the installer you need to insert a USB stick (I will use a 16GB drive).

It is not strictly required to wipe the whole content of the USB drive but it is something I prefer to do anyway… and it takes really few seconds to do so (feel free to skip this section if you really want to).

Open “Disk Utility“.

You can find this app in the Applications/Utilities folder:

Or use Spotlight search (that you can open with CMD⌘ + SPACE) and start typing “Disk Utility”:

Once started, locate your drive on the left side (it should be easy to identify in the “External” section).

Select it and click the “Erase”:

At this point give the drive a label (it will not really matter if you are going to create an installer because it will be automatically changed later on), select the Format “OS X Extended (Journaled)” and “GUID Partition Map” for the Scheme:

Click “Erase” and wait for the operation to complete. Then click “Done”:

Time to create the installer.

Create a Bootable USB Installer

We need now to put the installer on this USB drive and make it bootable.

Open the Terminal window.

You can find it again in the Applications/Utilities folder or as usual with Spotlight (CMD⌘ + SPACE) search for “Terminal”:

NOTE: Assuming you named the USB drive “OSX”, the volume will be in “/Volume/OSX“. If you gave it a different name you will need to change the following command in order to point it to the correct location of your volume.

Type the following command:

Type your password (you will require root privileges), type “Y” when required to confirm your action and wait for the configuration to complete… it could take some time, so be patient (I’m talking even over 30 mins!):

Note that this procedure will erase the content of the USB and change its label to “Install OS X El Capitan“.


Install OSX!

You can now restart your computer. Make sure you keep the key ALT⌥ pressed while the mac is booting up!

Doing so you should see a startup selection screen similar to this one:

where you can select your newly created installer USB and follow the installation procedure.

Enjoy :)

Download a previous OS X Version (Yosemite)

If you want to download a previous version of OS X you will soon notice that it will not be available on the App Store for download.

There is still a way though if you already purchased it in the past.

To access it open the App Store, and click the “Purchased” section:

Scan through your list and locate Yosemite:

Click the “Download” button and confirm your intention to Apple clicking “Continue” on the popup:

Wait then for the download to complete:

At the end of the download:

you could receive another message from Apple that just says that this is an old version of the OS. Just ignore it:

The installer will be placed in the “Applications” folder:

You can now proceed with the same procedure described above for El Capitan if you want to create a USB Installer.

That’s all!

Once again, please share and comment if you found this article interesting or useful.



Comment or Leave a Message

Please Comment or Leave a Message if this is what you are looking for or if you have any question/comment/suggestion/request.

Install Eclipse
First of all download Eclipse from the official website:
Download IDE for Java developers (for example) or the one for C/C++ developer. I’ll download the first for this guide.

Unzip the package in your preferred folder.

Now you can start Eclipse. It will ask you for the workspace folder. You can leave the default.

NOTE: If it doesn’t start after setting launcher options then MOVE eclipse in another folder, maybe without any space within the path name.

Install Java SDK
Download the Java SDK (JDK):
I got the “jdk-6u24-windows-i586.exe” installer.

Install it. Easy :).

Install OpenGL Libraries for Java (Mac and Windows)
I use JOGL for this.
It is maintained by jogamp, there: http://jogamp.org/jogl/www/
Download JOGL from: http://jogamp.org/deployment/webstart/archive/
For Windows I Downloaded: jogl-2.0-b23-20110303-windows-i586.7z (http://jogamp.org/deployment/webstart/archive/jogl-2.0-b23-20110303-windows-i586.7z). For Mac I got the “jogl-2.0-pre-20101104-macosx-universal” package.
Extract it in a reasonable place, maybe in a subfolder named “jogl-2.0″… something like “C:libjogl-2.0” (or equivalent in Mac).

Now we have to bind it with Eclipse IDE. I will explain only the minimum amount of work to do for this (just to have it working) because I know that the first thing that someone wants is have t working and looking into the detail later, when we are already happy that it works! :)
Open Eclipse Preferences (e.g. “Windows->Preferences” in Windows Helios or “Eclipse->Preferences” in Mac Galileo).
In the form open:
Java->Build Path->User Libraries
Click the “New…” button and in the dialog type something sensible in the library name box. Something such as “jogl-2.0”:

Select the newly created entry and click on the “Add JARs…” button. Browse where the jogl package has been extracted and enter in the jar folder. Once in the folder you need to select just those files:

  • gluegen-rt.jar
  • jogl.all.jar
  • nativewindow.all.jar
  • newat.all.jar

Once this is done, you have to set the lib folder for each one of those. Just expand each entry, select the Native library location field, click “Edit…” and browse until you reach the lib folder of the same extracted jogl package:

Repeat this for each entry.

In order to use it in your (any) Java project, go into the project’s properties page (right click on the project in the Project Explorer window and select “Properties”).
In the properties page open the “Java Build Path” page, then select the “Libraries” tab and click the “Add Library…” button. In the selection window select “User Library“:

Click “Next” and select our jogl-2.0 library”

And click “Finish

If everything is done correctly, this should be the final result:

Once this is done you are ready to write and run OpenGL Java apps.

Install CDT Plugin for Eclipse (for C/C++ projects)
Go in:
Help->Install New Software…

From the list select the CDT repository for helios, or add it if it is not there: http://download.eclipse.org/tools/cdt/releases/helios
and select the CDT Main Features:

Then just follow the installation flow (Next, Next, Accept License Agreement, etc)

Restart Eclipse when asked

You can show the icon for quick access clicking on the Open Perspective button or accessing it from the menu Window->Open Perspective. Select “Other…” and select the C/C++ perspective:

Now both Java anc C/C++ perspectives will be available with one click:

Install the C/C++ compiler (Windows)
I use MiniGW to build the project. You can take it from there: http://www.mingw.org/
Install it in an easy-to-reach folder. “C:MiniGW” is perfect for this.
I Install only the C++ Compiler, MSYS Basic System and the MiniGW Developer Toolkit:

Once finished I like to add “C:\MinGW\bin” and “C:\MinGW\msys\1.0\bin” to the path:

This should be enough to meke Eclipse Happy to build our C/C++ projects.

When building C/C++ projects in Windows I use the MiniGW/CDT Toolchain, while In Mac I use MacOSX/GNU.
To set this in Windows, Open Project Preferences and then “C/C++ Build->Tool Chain Editor“. Here select MiniGW GCC, CDT Internal Builder.

In Mac, Open Project Preferencesand then “C/C++ Build->Tool Chain Editor“. Here select MacOSX GCC, GNU Make Builder.

Set OpenGL for C++ (Windows)
Before starting, just remember to edit (almost) always the settings for both configuration (Debug and Release) at the same time. This can save some time and problems when switching configuration.
To build OpenGL applications in C/C++ you generally need (at least) gl.h and glu.h headers, glu32 and opengl32 libraries (lib and dll).
Those headers can come with Windows SDK installation and for example you can find them there: “C:Program FilesMicrosoft SDKsWindowsv7.0AIncludeGL” and “C:Program FilesMicrosoft SDKsWindowsv7.0ALib”, while the runtime dlls should already be in the WindowsSystem32 (or equivalent) folder.
You can find the headers in the “C:MinGWincludeGL” folder as well and I have those one set in my environment.
To set the necessary paths open the Project properties, and select “C/C++ General->Paths and Symbols“.
In the “Include tab you can set useful path for headers and in the “Libraries” tab you can do the same for lib files.
To set Includes, select “GNU C/C++” language (if you are building a C++ project) and add all the paths needed.
In my case I have those set:

Remember to set those values for both Debug and Release configurations.

You can do the same for the Libs:

…and Lib Paths (that you generally need if you are using custom libs):

Note that if you installed MiniGW then the libraries files needed to build the solution are already picked up from there. In the specific they are “libglu32.a” and “libopengl32.a” in “C:MinGWlib” in my case. So you have just to tell Eclipse that you want to use them, as we already did just above, and don’t worry about the libraries paths.

When you run it, you will instead need the DLLs, but as already mentioned they will be already in the WindowsSystem32 folder.

Another thing to note is that some settings are available and configurable through different menus… this can be confusing at first, but doing just few experiments can help in acquiring more confidence when touching those settings. One example of this is the setting we just done, the one related to setting headers and libraries folders. In fact, instead of setting them in the way I described, you can set them always using the Project Properties page, but using the “C/C++ Build->Settings” page. The picture shows the Linker Libraries settings in this section (the same set previously through the other menu):

Installing GLUT for C++ (Windows)
If you are serious about doing something with OpenGL, you will probably need to download another piece of software that simplifies the development of a multi-platform window system independent app.
You can find them there: http://www.opengl.org/resources/libraries/glut/
The latest version (quite old as well) is the 3.7, but I worked with the 3.6 and it does the job.
Just grab a version and unzip it a good place. You can use the previously created “C:lib” folder if you prefer.
To build and run your app you need just few files:

  • glut.h
  • glut.lib
  • glut32.lib
  • glut.dll
  • glut32.dll

I suggest to organise them distributing them in good named folders:

Once this is done, just update the headers and libraries paths to use it.
NOTE: Remember to put the DLL into your app executable folder or in a system folder (WindowsSystem32).

Set OpenGL and GLUT for C++ (Mac)
Setting OpenGL on the Mac is somehow easier from one point of view, but I think that it is trickier to discover how to set-up initially.
It is easier because you should already have all you need (headers and libraries) in your OS.
You can find them in “/System/Library/Frameworks/OpenGL.frameworks/“. So, nothing really to do here.

The nice thing here is that GLUT as well comes with the system, and you should find it in “/System/Library/Frameworks/GLUT.frameworks/” :):

In order to set-up them in Eclipse, open the project properties and go in:
C/C++ Build->Settings->MacOSX C++ Linker->Miscellaneous” and write this in the Linker flags text box:
-framework GLUT -framework openGL -framework Cocoa“. This is the tricky step to find initially I recon.

… and you are ready to go!

Bonus – Install Subversive Plugin for Eclipse
Install SVN if you need one.
As already done for CDT use:
Help->Install New Software…
To install Subversive select the Helios entry and Install the option that you prefer. I selected just the Team Provider and Revision Graph options:

Restart Eclipse

When you will use it the first time it will present the Subversive Connector Discovery form. I select the SVN Kit 1.3.5 options:

I hope that this helped you sorting out some of part of all the settings and the nitty-gritty details that must be addressed in order to successfully build OpenGL applications in Windows or Mac, using Java or C++. In my experience those are often that sort of things that sometime can become frustrating problems when you need to spend hours or days trying to figure out what is missing.

If this helped you or you find this interesting or if you have some tips to share, please leave a comment and link to this page so that other people can benefit from it.