How do install OS X El Capitan onto a VM

Solution 1:

Preface:

This how-to targets VirtualBox because the OP uses it. I strongly recommend to purchase Parallels Desktop or VMware Fusion though. A lot of features like drag-and-drop, change the monitor resolution etc. don't work properly in VirtualBox (or I don't get it to work).


The installation of El Capitan is a dual-stage process. You first have to create a Yosemite VM and then update to El Capitan.

The script below apparently doesn't work with El Capitan. A "bootable" El Capitan iso boots to an EFI command line only. The intermediate step of creating a Yosemite.iso seems to be inevitable.

  • Download the latest VirtualBox installer, the latest Yosemite installer and the latest El Capitan installer.

  • Install VirtualBox

  • Use the following shell script to create a bootable Yosemite.iso. The script assumes that Install OS X Yosemite.app was downloaded to the folder /Applications.

     #!/bin/bash  
    
     # Create bootable Yosemite ISO
    
     # 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
    

    Copy the above lines, paste it into a new document prepare_yosemite_iso.sh on your desktop with a decent editor (below I use nano) and make it executable. In Terminal enter:

    touch ~/Desktop/prepare_yosemite_iso.sh
    nano ~/Desktop/prepare_yosemite_iso.sh #paste the content of the script here, save the file to disk with ctrl-O and quit nano with ctrl-X
    chmod +x ~/Desktop/prepare_yosemite_iso.sh
    
  • execute the script:

    ~/Desktop/prepare_yosemite_iso.sh
    

    After several minutes the iso with the name Yosemite.iso will be moved to your desktop.

  • Start VirtualBox and create a new Yosemite VM with the default settings.
  • If your Mac contains a Haswell processor you have to change the the cpuid in the VM. Enter the following in Terminal:

    VBoxManage list vms #to list all available VMs
    VBoxManage modifyvm <name_of_vm> --cpuidset 00000001 000306a9 00020800 80000201 178bfbff
    
  • Attach Yosemite.iso to the optical drive

  • Boot the VM, format the hdd, then install and configure Yosemite.
  • Copy the downloaded Install OS X El Capitan.app to the Applications folder in the VM. Use a network share on the host to accomplish that.
  • Start Install OS X El Capitan.app and update the VM to El Capitan.
  • To enable some screen resolutions shut down the VM and enter in (the host's) Terminal:

    VBoxManage setextradata <name_of_vm> VBoxInternal2/EfiGopMode N
    

    where N can be one of 0,1,2,3,4,5 referring to the 640x480, 800x600, 1024x768, 1280x1024, 1440x900, 1920x1200 screen resolution respectively

  • Do Ruby development...