Skip to content

Instantly share code, notes, and snippets.

@arobb
Last active November 24, 2020 13:15
Show Gist options
  • Star 59 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save arobb/447a962af4f07ef81e79987d686275e5 to your computer and use it in GitHub Desktop.
Save arobb/447a962af4f07ef81e79987d686275e5 to your computer and use it in GitHub Desktop.
Install macOS Sierra in VirtualBox on macOS host

Step 1 (Creating a bootable macOS Sierra ISO for VirtualBox):

  1. hdiutil attach /Applications/Install\ macOS\ Sierra\ Public\ Beta.app/Contents/SharedSupport/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/install_app
  2. hdiutil create -o /tmp/Sierra.cdr -size 7316m -layout SPUD -fs HFS+J
  3. hdiutil attach /tmp/Sierra.cdr.dmg -noverify -nobrowse -mountpoint /Volumes/install_build
  4. asr restore -source /Volumes/install_app/BaseSystem.dmg -target /Volumes/install_build -noprompt -noverify -erase
  5. rm /Volumes/OS\ X\ Base\ System/System/Installation/Packages
  6. cp -rp /Volumes/install_app/Packages /Volumes/OS\ X\ Base\ System/System/Installation/
  7. cp -rp /Volumes/install_app/BaseSystem.chunklist /Volumes/OS\ X\ Base\ System/BaseSystem.chunklist
  8. cp -rp /Volumes/install_app/BaseSystem.dmg /Volumes/OS\ X\ Base\ System/BaseSystem.dmg
  9. hdiutil detach /Volumes/install_app
  10. hdiutil detach /Volumes/OS\ X\ Base\ System/
  11. hdiutil convert /tmp/Sierra.cdr.dmg -format UDTO -o /tmp/Sierra.iso
  12. mv /tmp/Sierra.iso.cdr ~/Desktop/Sierra.iso

Step 2 (Installing in VirtualBox)

This is pretty straightforward.

  1. Create a new El Capitan (there is no option for Sierra at the moment) machine. Leave everything at default
  2. Boot the virtual machine from the Sierra.iso you created, which you'll find on your desktop. I had to mash F12 while the machine was starting up and then choose 'EFI CD/DVD' in the boot manager. YMMV.
  3. The install process should be familiar to you. If not, you probably shouldn't be playing with a beta OS ;)
  4. Grab a coffee, the 15 minute estimation the installer gives you is a complete work of fiction. My install took over an hour.
  5. Once installed, reboot and complete the new user process. Skip the AppleID login bit, it'll fail on a VirtualBox.
  6. Shut down the virtual machine and quit VirtualBox.
@xy90321
Copy link

xy90321 commented Sep 24, 2017

since the official macOS app already embedded with a tool to help us make install media, there's no need to manually create install image by those cp commands.

try the commands below which I've verified on my mac and successfully create a VM on my mac host.

  1. create a blank disk image (by using the command provided in Step1.2)

hdiutil create -o /tmp/Sierra.cdr -size 7316m -layout SPUD -fs HFS+J

  1. mount the blank disk image you've created and find out the volume name (normally should be '/Volumes/untitled' )

  2. create the install media by using the official tool

sudo /Applications/Install\ macOS\ Sierra.app/Contents/Resources/createinstallmedia --volume "/Volumes/untitled" --applicationpath /Applications/Install\ macOS\ Sierra.app --nointeraction

notice: replace the content in the double quotation mark with the volume name you found in 2)

  1. unmount the disk image that mounted automatically in 3), which should be named 'Install macOS Sierra'.

  2. convert the disk image to a loadable virtual drive image (by using the command provided in Step 1.11)

hdiutil convert "/tmp/Sierra.cdr.dmg" -format UDTO -o "/tmp/Sierra.iso"

then here you go.

@sghiassy
Copy link

sghiassy commented Sep 25, 2017

Or skip all of this and do it the easy way...

  1. Install Vagrant
  2. In the cli type: vagrant init jhcook/macos-sierra; vagrant up
  3. Grab cup of ☕

P.S: Make sure you have Virtual Box Extension pack installed (link)

@darkn3rd
Copy link

It seems like you have to enable USB3 according to this ticket: https://www.virtualbox.org/ticket/16644

Anyone know how to do that through the command line with VBoxManage?

@drobtitan
Copy link

Download all Mac OS X versions from this place: https://support.apple.com/downloads/macos

@titocr
Copy link

titocr commented Jan 8, 2018

@sghiassy that is cool!

@bwgchung
Copy link

I have experienced getting stuck at the boot up process. I fixed it by setting more than one processor, 8 GB RAM and max graphic RAM.

The solution I got is to set more than one processor to the VM.

@mbigras
Copy link

mbigras commented May 25, 2018

I experienced an error while using the jhcook/macos-sierra box.

==> default: Booting VM...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["startvm", "b8a680e3-383b-44be-be74-8e914a8fb7e5", "--type", "headless"]

Stderr: VBoxManage: error: Implementation of the USB 2.0 controller not found!
VBoxManage: error: Because the USB 2.0 controller state is part of the saved VM state, the VM cannot be started. To fix this problem, either install the 'Oracle VM VirtualBox Extension Pack' or disable USB 2.0 support in the VM settings.
VBoxManage: error: Note! This error could also mean that an incompatible version of the 'Oracle VM VirtualBox Extension Pack' is installed (VERR_NOT_FOUND)
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component ConsoleWrap, interface IConsole

You can manually disable USB via VirtualBox but that customization can also be made via the Vagrantfile. Details discussed at:

jonschipp/vagrant#3 (comment)

Vagrant.configure("2") do |config|
  config.vm.box = "jhcook/macos-sierra"
  # https://github.com/jonschipp/vagrant/issues/3#issuecomment-138215720
  config.vm.provider "virtualbox" do |vb|
    vb.customize ["modifyvm", :id, "--usb", "on"]
    vb.customize ["modifyvm", :id, "--usbehci", "off"]
  end
end

@samiyuru
Copy link

If you are trying this with Catalina you can use this script to create the installer media that can be mounted directly on Virtualbox. More information can be found here.

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