How to run OSX in a VM on VirtualBox

osx_linux

Would it not be great to be able to run OSX on a virtual machine? Now you can*! All you need is a disk image of the retail DVD of “Apple Mac OSX Snow Leopard 10.6” and you can install it inside VirtualBox. Alternatively if you have a Mac (or know somebody who does) you can create a bootable image of (the free) “Apple Mac OSX Yosemite 10.10” and install that version. Instructions below.

Apple Mac OSX Snow Leopard 10.6

You need:

  1. VirtualBox 4
  2. ISO of retail DVD for “Apple Mac OSX Snow Leopard 10.6” (buy here)
  3. Follow instructions carefully

Open VirtualBox and create a virtual machine named “osx”. Then close the entire VirtualBox application and go to the command line. Run:

VBoxManage modifyvm osx --cpus 1
VBoxManage modifyvm osx --vram 128
VBoxManage setextradata osx VBoxInternal2/EfiGopMode 5
VBoxManage setextradata osx "VBoxInternal2/SmcDeviceKey" "ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"

Open VirtualBox again and start the virtual machine. Mount “Apple Mac OSX 10.6 Snow Leopard Retail.iso” and install. After installation (30 minutes) the system will reboot and it is ready for use.

Apple Mac OSX Yosemite 10.10

You need:

  1. VirtualBox 4
  2. Bootable image of “Apple Mac OSX Yosemite 10.10” (using “iesd”)
  3. Follow instructions carefully

The latest version of Apple’s OSX can also be run under VirtualBox. Download it for free from the “Apple App Store”. You do need a Mac with a valid Apple-id for this. Make sure you have the “XCode Command-Line tools” installed on this Mac. Then run the following commands to convert the download into a bootable disk image:

gem install iesd
iesd -i /Applications/Install\ OS\ X\ Yosemite.app -o Desktop/yosemite.dmg -t BaseSystem

Move “yosemite.dmg” to your Virtualbox environment and use it instead of the Snow Leopard DVD image. Note that this image does support multiple CPUs, so this will allow you to speed things up.

*) Known issues

Here are the issues on the various platforms:

  • OSX 10.6 [Linux] can only be used with a single CPU
  • OSX 10.6 [Linux] sound is not working properly
  • OSX 10.10 [Linux] cannot login on Linux
  • OSX 10.10 [Linux] graphics are very slow
  • OSX 10.10 [Linux] sound is not working

Note that Apple only allows and supports running OSX in a VM on OSX. As you can see I only tested on Ubuntu 14.04 as a host (which is not supported). Let me know whether or not the above instructions work for you (on Windows or OSX).

Conclusion

It is not working very well (out-of-the-box), but it does work a little. Enough to get you started. With some serious tinkering you may even fix it to an acceptable level. If you do, please let me know!

Links

  1. http://virtualbox-snow-leopard.blogspot.de/
  2. http://engineering.bittorrent.com/2014/07/16/how-to-guide-for-mavericks-vm-on-mavericks/
  3. http://kernelpanik.net/running-mac-osx-yosemite-on-kvm-hypervisor/
  4. http://www.virtualbox.org/manual/ch08.html
Share

VM template creation with oz-install

When you’re managing your infrastructure in the Cloud and are not satisfied with the pre-built VM templates, you will have to create your own templates. Creating templates by hand, especially when you update them regularly, is a very tedious and error prone task that should be avoided.

There are quite some tools around to help automating this process. For example, one could combine the virt-install tool with tools from the libguestfs project or use the scripts from the ubuntu-vm-builder project. One of the benefits of oz-install is its extensive OS support (it even supports creating Windows templates). In this post I will show you how to create a basic Ubuntu template with oz-install.

To efficiently build VM templates, your build machine requires a processor with virtualization extensions. With a recent Linux kernel version you could virtualize these extensions, but that will definitely slow down the whole process.

Package dependencies

To build the oz-install package, your have to make sure the following packages are installed on your system:

  • debhelper (>= 8.0.0)
  • python-all (>= 2.6.6-3)
  • build-essential
  • git-core (if you are fetching the source via Git)

dpkg-buildpackage will complain when these packages are missing.

There are several run-time dependencies, but these will be installed automatically by dpkg when installing oz-install.

Building the package

Building oz-install is not very difficult. The following steps are confirmed to work on Ubuntu 12.04, but will probably work on most Debian based Linux systems.

  1. Fetch the latest source from GitHub:
    mkdir ~/oz
    cd ~/oz
    git clone https://github.com/clalancette/oz.git oz-git
    
  2. Build the deb with dpkg-buildpackage:
    cd ~/oz/oz-git
    dpkg-buildpackage -us -uc
    
  3. Now you can install the package you built:
    cd ~/oz
    dpkg -i oz_*_all.deb
    

Creating your first (simple) template

After installing the package, you can use the following configuration files to create a basic Ubuntu 12.04 template. Feel free to experiment with the various configuration options or supported operating systems (invoke oz-install without any options to view the supported operating systems).

Apart from OS installation, you can add customization options to the template definition file. This feature can be used to run shell commands on the template after it is installed. oz-customize will start the template and use SSH to connect to the machine and run the shell commands.

  1. Create your template definition file with your favourite editor (~/oz/my-template.tdl):
    <template>
      <name>my-template</name>
      <description>My first oz template</description>
      <disk>
        <size>5</size>
      </disk>
      <os>
       <name>Ubuntu</name>
       <version>12.04</version>
       <arch>x86_64</arch>
       <install type='url'>
         <url>http://mirror.nl.leaseweb.net/ubuntu/dists/precise/main/installer-amd64/current/images/netboot</url>
       </install>
       <rootpw>securepassword-oLklpFb8</rootpw>
      </os>
      <commands>
        <command name='hostname'>
          echo 'my-template' > /etc/hostname
        </command>
      </commands>
    </template>
    
  2. Create your preseed file with your favorite editor (~/oz/my-template.preseed):
    d-i debian-installer/locale string en_US.UTF-8
    d-i console-setup/ask_detect boolean false
    d-i console-setup/layoutcode string us
    
    d-i netcfg/choose_interface select auto
    d-i netcfg/get_hostname string unassigned-hostname
    d-i netcfg/get_domain string unassigned-domain
    d-i netcfg/wireless_wep string
    
    d-i clock-setup/utc boolean true
    d-i time/zone string US/Eastern
    
    d-i partman-auto/method string regular
    d-i partman-auto/choose_recipe select home
    d-i partman/confirm_write_new_label boolean true
    d-i partman/choose_partition select finish
    d-i partman/confirm boolean true
    d-i partman/confirm_nooverwrite boolean true
    
    d-i passwd/root-login boolean true
    d-i passwd/make-user boolean false
    d-i passwd/root-password password %ROOTPW%
    d-i passwd/root-password-again password %ROOTPW%
    
    tasksel tasksel/first multiselect standard
    d-i pkgsel/include/install-recommends boolean true
    d-i pkgsel/include string openssh-server python-software-properties wget whois curl acpid
    
    d-i grub-installer/only_debian boolean true
    d-i grub-installer/with_other_os boolean true
    
    d-i apt-setup/security_host string
    base-config apt-setup/security-updates boolean false
    
    ubiquity ubiquity/summary note
    ubiquity ubiquity/reboot boolean true
    
    d-i finish-install/reboot_in_progress note
    
    d-i mirror/country string manual
    d-i mirror/http/hostname string mirror.nl.leaseweb.net
    d-i mirror/http/directory string /ubuntu
    
  3. Run oz-install with customize options:
    cd ~/oz
    oz-install -b virtio -n virtio -p -u\
      -x ~/oz/my-template.xml \
      -a ~/oz/my-template.preseed \
      ~/oz/my-template.tdl
    
  4. (optional) Monitor the installation with virt-viewer:
    virt-viewer my-template
    
  5. (optional) Import the template in libvirt and start it:
    virsh define ~/oz/my-template.xml
    virsh start my-template
    

Take this as an example and start experimenting with all the options available. After playing around with oz-install you should be able to create a structured template creation workflow. When you combine this with a set of custom scripts,
you can integrate the flow with, for example, jenkins to easily add new or updated templates to your virtualization or cloud platform in a modular way.

Share