Just Code it!
Header

Install OS X on VirtualBox (on OS X)

May 28th, 2016 | Posted by riccardotramma in Install | Mac | OS | OSX | Virtual Machine | VirtualBox

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:

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/hdiutil.1.html

http://apple.stackexchange.com/questions/198737/install-el-capitan-in-virtual-box-for-testing-purposes

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:

and:

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! :)

 

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

44 Responses

  • Wes says:

    Nicely done! I’ve seen several instructions on trying to get this to work; yours is the first that -actually- does.

    Many thanks!

  • Eddie says:

    Great write up. This guide is the only one that worked for me. Using El Cap host and guest on VirtualBox Version 5.1.4 . Nice one!

  • mbigras says:

    I was able to follow this tutorial and get El Capitan up and running with only a few snags:

    1. On Step 5 I think there is something wrong with the syntax to remove the broken link, I ended up just opening it in finder and trashed it.
    2. There’s a bit of a typo on Step 7, some of the html got stuck in the expression

    Besides that it all seems to be working so far :)

    • riccardotramma says:

      I removed the html that the editor sneakily inserted :).
      For step 5 you need to ensure that the name matches, and I know that spaces in the name could create some issues/confusion. Anyway yes, the main goal is to remove the broken link, so using finder to remove it works as well.
      I’m glad to hear that it worked for you as well.
      Thanks for the comment mbigras.

  • GM says:

    Thanks a lot! Your instructions worked fine with macOS Sierra.

  • Nick says:

    fantastic, works a treat for Sierra! So many bad guides out there!

  • Brian H says:

    This is an outstanding resource. I really like how you were able to present the information so that it is very useful for people with a wide range of technical knowledge. Novices can just follow step-by-step and likely get to a successful conclusion. Those with more technical knowledge of OS X can skim through and find the key bits of information they are missing to accomplish the task. The curious (of all types) can benefit from the concise explanations of _why_ these commands and options are being employed. (I’m thinking specifically of the “Create ISO from installer” section.)

    Needless to say, it worked beautifully for me. The only slight snag I ran into was after running the OS X install process, the VM didn’t just shut down, it restarted — without giving me a chance to “remove” the installation iso from the virtual optical drive as you describe in the next step. During the restart, my VM appeared to get stuck and I thought maybe it was trying to boot from the installer iso again. I just powered down (closed) the VM, removed the iso in the settings as you describe, and started the VM again. Success!

    Thank you for putting in the time and effort to make this guide.

    • riccardotramma says:

      Thanks Brian!
      I really appreciate your comment and feedback.
      You got exactly the reason why I write these posts, that are not only aimed at solving the problem but more importantly want to offer an opportunity to understand the concepts behind it if you are technical or simply curious (as you said).

      For the OSX version that you tried to install, was it El Capitan, Sierra or something else?

  • Christoph says:

    This is an awesome article. Very clear, very detailed, and the first one I found that actually works! (I used it to install Sierra in a VirtualBox on Sierra.) Thank you Riccardo!

  • Kent says:

    Thanks for this guide! I was really in despair after trying the guide at http://www.starkandwayne.com/blog/running-a-mac-vm-on-a-mac-using-virtualbox/ without luck on Sierra and VirtualBox 5.1 as I got the UEFI trouble you mentioned.
    One thing I ran into still, on Mac Mini 2012, was that the USB controller really have to be USB 1.1 (OHCI). Otherwise it will halt during boot sequence.

  • Himanshu says:

    Hello! Riccardotramma, I have a problem, While starting vm for very first time, it just repeats its command screen several times i mean, Its a bootloop, Please help how to fix it.

    • riccardotramma says:

      Hi Himanshu,

      check if the settings of the machines are correct. In my case I selected ICH9 Chipset, and checked the three checkboxes: “Enable I/O APIC”, “Enable EFI”, “Hardware Clock in UTC Time”. Not all of them are relevant for the issue you are describing, so I’m just mentioning it to allow you to know how my one is configured.

      I hope this helps,
      Riccardo

    • Brian H says:

      Hi Himanshu. Are you saying that when you start the VM, it reboots itself over and over, repeatedly? If so, then I guess the “command screen” you mentioned is the “verbose” text output of the OS X booting process, because VirtualBox always adds the “-v” boot argument.

      I’ve run a few different versions of OS X and VirtualBox on two machines, but haven’t seen a boot loop like that. If you could look at the last few lines of the text that is displayed on the screen during boot maybe it would help narrow down the cause. (Or, maybe not, because the last message probably tells you the last step that did complete successfully, while the real problem might be more related to the what the NEXT message would have said — but never appears!) — Brian H.

  • Brian H says:

    Hi Riccardo — I’ve come back to this excellent guide to do another install (reason given later). In the spirit of appreciation I will point out two (very minor) corrections or clarifications for any readers:

    1) In “Create ISO From Installer,” section 7, it says “Ignore the BaseSystem.chunklist file and the two AppleDiagnostic files (we don’t care about these).” But the command lines shown in the next box include
    “cp -rp /Volumes/esd/BaseSystem.chunklist /Volumes/OS\ X\ Base\ System/”
    which seems to contradict the statement to ignore that file.

    I did copy that file (as listed in the command box) and it worked fine, but I don’t know whether that file is necessary or not.

    2) At the end of the process the file “OSXInstaller.cdr.dmg” is left over, but not very useful. I believe it may be deleted anytime after the “hdiutil convert…” command.

    I used your instructions with success installing macOS 10.12.2 Sierra as the guest OS in a VirtualBox VM. My host machine is a late 2015 iMac and is running 10.11.6 El Capitan. Currently my VirtualBox is version 5.1.12, the latest right now. I installed Sierra recently because I was unable to update my working El Capitan VM with a recent security update from Apple without getting strange errors afterwards (code signing errors, Finder crashing, etc.). Previous updates had worked fine, though.

    Sierra is now running well, but once again during installation I had a little problem (as I mentioned in comments above) that others might encounter: as part of the normal OS X install procedure, the VM was automatically restarted, and it seemed to get stuck (hang, freeze) during the restart, with a black console screen and a few lines of text (I think). I waited over 30 minutes but it never proceeded.

    So I closed the VirtualBox VM window (this does an abrupt “power off” on the VM), and then started the VM again. This time it booted OK and went through the normal completion of the OS X installation and all appears fine.

    Thanks again, Riccardo, and good luck to everyone!

    Brian H.

    • riccardotramma says:

      Thanks Brian, good spotting ;). I updated the post accordingly.
      Interesting problem the code signing error during a security update. I’ll keep it in mind if I encounter anything similar.
      Once again, thanks your comments and words. Appreciated.
      Riccardo.

  • Alex says:

    Thanks a lot Riccardo for this posting, it really worked for me installing Mac OS Sierra VirtualBox on a MacBook Pro. However there seems to be a shortcoming, when switching the OSX VirtualBox to Full Screen Mode (Host+F) the window doesn’t expand all the way to the host display. I know that Virtual Box currently doesn’t support additions for MAC. Although there is a pkg file in the ISO for Additions this doesn’t seem to work, do you know any way to work around this?

    Thanks again for your posting and any hint would be appreciated

    Alex

    • Brian H says:

      Hi Alex – I’m not associated with the web page author but have some info that may help you. For a guest OS X (MacOS) in Virtualbox, you must choose one of only six possible screen resolutions that can be set in the EFI (the firmware) for the virtual machine. This is done by a Terminal command like

      ‘VBoxManage setextradata “my-vm-name” VBoxInternal2/EfiGopMode N

      …where N can be one of 0,1,2,3,4,5 referring to the 640×480, 800×600, 1024×768, 1280×1024, 1440×900, 1920×1200 screen resolution respectively.

      Perhaps none of the choices are perfect for your setup — you just have to pick the one that is “best”. If they ever create guest additions for MacOS then there could be other choices. But for now, these are the only ones that work. Here is the section of the manual that describes this better:

      https://www.virtualbox.org/manual/ch03.html#efividmode

      • Alex says:

        Hi Brian

        Your suggestion really helped. There are some warning messages during Virtual Box startup but after all seems to be fine. It’s not possible to get the same resolution as the host display but getting something close to it makes things easier.
        Thanks for your help and the time taking to reply.

        Alex

  • jose bernal says:

    Hi, I’m using MacBook Air
    I trying to Install a macOS Sierra 10.12 like Guest and macOS Sierra 10.12 like Host.
    2 Processors, 4096 for RAM, 40GB for Hard Disk
    I got this error message: Still Waiting for Root Device.

  • jose bernal says:

    Hi, I’m using MacBook Air
    I trying to Install a macOS Sierra 10.12 like Guest and macOS Sierra 10.12 like Host.
    2 Processors, 4096 for RAM, 40GB for Hard Disk
    I got this error message: Still Waiting for Root Device.
    Please tell me, possible mistakes.
    Thank you for your valuable Help

  • jose bernal says:

    Hi Ricardo!
    I found my mistake!

    I replaced your steb
    “hdiutil convert macOSInstaller.cdr.dmg -format UDTO -o macOSInstaller.iso”
    by
    “sudo hdiutil makehybrid -iso -joliet -o macOSInstallerDirectHybrid.iso macOS/macOSInstaller.cdr.dmg”
    using macOSInstallerDirectHybrid.iso for VirtualBox (and the error raise up)

    Then I follow your original step
    “hdiutil convert macOSInstaller.cdr.dmg -format UDTO -o macOSInstaller.iso”

    Later I tryed replacing the rename file
    “mv macOSInstaller.iso.cdr macOSSierraInstaller.iso”
    by
    “sudo hdiutil makehybrid -iso -joliet -o macOSInstallerExtendHybrid.iso macOSInstaller.iso.cdr”
    and the results were (similars, in other words, bad file for installation).

    Later I checked the Sizes file with “ls -al” note (the dates are different because I was confirming the results)

    -rw-r–r–@ 1 josebernal staff 8053063680 Jan 24 02:36 macOSInstaller.cdr.dmg
    -rw-r–r– 1 josebernal staff 8053063680 Jan 25 00:14 macOSInstaller.iso.cdr
    -rw-r–r– 1 josebernal staff 6178375680 Jan 25 00:56 macOSInstallerDirectHybrid.iso
    -rw-r–r– 1 josebernal staff 6178375680 Jan 25 01:09 macOSInstallerExtendHybrid.iso
    -rw-r–r– 1 josebernal staff 8053063680 Jan 24 17:53 macOSSierraInstaller.iso

    then I Compared the files to be used
    “cmp macOSSierraInstaller.iso macOSInstaller.cdr.dmg”
    and the results was are exactly files!

    Then I discover that maybe you don’t need to do
    “hdiutil convert macOSInstaller.cdr.dmg -format UDTO -o macOSInstaller.iso”
    instead do rename the original image file
    “mv macOSInstaller.cdr.dmg macOSInstaller.iso”
    or copy it
    “cp macOSInstaller.cdr.dmg macOSInstaller.iso”
    to preserve macOSInstaller.cdr.dmg file!

    Thank you!!!

  • Rafa says:

    Hi,

    I have been trying to do install a Sierra guest on top of my my Host (also a macos Sierra Macbook 12” with VirtualBox last version 5.1.14 installed) and I’m not able to start the VM intallation, it freezes during the first boot Installing the VM in the console screen.
    I don’t know why.

    Can you give me some light?

    Regards,

  • jose bernal says:

    Check if you take like base of Installation mac OS El Capitan, I recommend to you, none flavor, only use Mac OS 64 bits… https://forums.virtualbox.org/viewtopic.php?f=22&t=80719

  • Rafa says:

    Hi José,

    Ok, I’ll give it a try in one or two days and I’ll report here my findings.

    Thank you,

  • F says:

    Running VB 5.1.14 r112924 on mac OS Sierra and attempting to install a mac OS Sierra guest. I can follow all the directions up until the OS installer stops due to an “unknown error” and asks me to restart and try again (which doesn’t work). Any ideas?

  • Bimal says:

    macOS sierra dropped the support for Faxing from a USB Modem. Is it possible to extract this “Faxing Module” from an older version of OS X and then use it in macOS Sierra? Your views?

    Thanks
    Bimal

  • Jean says:

    Thank you Riccardo! I have a couple of questions. I’m new at all this and the first thing I did, as your article suggests, was to create a bootable USB drive with Sierra on it. Now, as I read through the rest of this article, I’m having difficulty understanding how that bootable drive with Sierra on it, plays into all of this. It seems all these steps are being done on my actual Hard Drive, correct? So why did I need to make the USB drive? Just to have a copy of Sierra safely somewhere?

    Thx!

  • Jean says:

    Thank you Riccardo! I have some questions as I’m new to this and a bit confused. The first thing I did was create the bootable USB drive with Sierra on it, per your instructions. Reading through the rest of this, I don’t understand how that drive plays into all of this. Or was it just to have a bootable copy of Sierra safely away somewhere? It seems the rest of these commands are being done on my actual hard drive, correct?
    Thanks in advance,
    Jean

    • riccardotramma says:

      Hi Jean!

      In this specific case you don’t really need to create a physical bootable USB. The main thing you need in order to install Sierra on a VM is only the installer app.
      So, if you were following the previous article, you can follow it until you have the app downloaded (that happens at the very start, before the section “Prepare the USB”).

      Once you have it, you can continue with this article from “Time to do some magic!”.
      In it, in fact, all the operations are performed on this file (the downloaded one, that I have in the Applications folder: “/Applications/Install OS X El Capitan.app”) that contains the image of the installer disk (“/Applications/Install OS X El Capitan.app/Contents/SharedSupport/InstallESD.dmg“)
      This file (on your mac) is the one we mount in place, simulating an inserted media (in the section “Attach the installer image”). Then everything else continues from there :).

      Thanks for the comment and let me know if this helps :).
      Riccardo

  • John Harris says:

    Thank you so much for writing this guide, it is the only one I have found that works (El Capitan VM on El Capitan host & VirtualBox 5.1). Thanks again

  • Jose Bernal says:

    Hi, I was following again for macOS Sierra 10.12.6 but Now it’s not working… for me this post works for macOS Sierra 10.12.3.

    https://www.virtualbox.org/ticket/16644..

    IOConsoleUsers: gIOScreenLockState 3, hs 0, bs 0, now 0, sm 0x0

    You know how fix it?

  • fgio51 says:

    Hi,
    Thanks for this clearly lesson.
    I did every steps to create an iso of Sierra installer, all seems working well.
    I created the VM, launched it, loaded the iso, and I get the launch screen with the message “FATAL: No bootable medium found! System halted.”
    That’s 3 days, I tried to create this VM to use software not working on High Sierra…
    Do you have any idea to solve this issue?
    Many Thanks



Leave a Reply

Your email address will not be published.