Mac OS X running as Virtualbox guest – inside Opensolaris container.

With the release of Virtualbox 3.2 beta Mac OS X “guests” are now supported. 

The following guide will show you how to get OS X running inside virtualbox using the command line interface.  It applies to any host operating system, but in this case we’re adding an additional virtualization layer on top of opensolaris.

Officially, so as not to run afoul of the Apple EULA, if you want to run OS X as a Virtualbox Guest you need to be running Virtualbox on Apple hardware.

So, let’s imagine that instead of a nice, 64 core Intel nehalem server I actually have a Mac Pro on which I am – for the sake of argument and somewhat inexplicably – running Opensolaris.

Today we’re not only going to show you how to get Mac OS X running in Virtualbox, but also how to run it on Virtualbox running inside an Opensolaris container, or zone.  Just in case you had, for example, a need to add resource controls, or clone multiple versions of your resulting OS X virtual machine, teleport running VMs to another server…

You will need a copy of a modified version of the OS X install DVD.  If you search around you might locate something called “iDeneb_v1.6_1058_Lite_Edition.iso” which is what I used for this example.

If you don’t care about the Opensolaris container (or indeed the opernsolaris host OS) part of this tutorial, you can use the same sequence to run Mac OSX as a Virtualbox guest on any OS, provided you’ve installed the 3.2 beta version (or later).  You just need to ensure that whatever machine you’re using has a CPU that supports VMX.  Otherwise the OS X Install CD won’t load the Operating system properly.  (Other guests will be fine)

[Grab the beta here]

Click here to skip to the Mac OS X guest configuration section.

Step 1:  Create the opensolaris container

At the time of writing, I was using Opensolaris b133.  The bits I typed are in bold.

1.a.  Define a new zone.

root@nehalem:/# zonecfg -z vbox
vbox: No such zone configured
Use 'create' to begin configuring a new zone.
zonecfg:vbox> create
zonecfg:vbox> set autoboot=true

1.b.  Deciide where it will live.  In this case I chose /zones/vbox.

zonecfg:vbox> set zonepath=/zones/vbox

1.c Add some networking so that you can talk to the world. In this case I have ipmp set up for redundancy. Change to suit your actual network interface. Here, mine is ipmp0, and I’ve given it the address 1.2.3.4.

zonecfg:vbox> add net
zonecfg:vbox:net> set physical=ipmp0
zonecfg:vbox:net> set address=1.2.3.4
zonecfg:vbox:net> end

1.d.  This is the important part.  Add the two virtualbox drivers from the global zone. You can’t install devices in a container, so you need to make sure that the ones that the global zone uses are available to your container.

zonecfg:vbox> add device
zonecfg:vbox:device> set match=/dev/vboxdrv
zonecfg:vbox:device> end
zonecfg:vbox> add device
zonecfg:vbox:device> set match=/dev/vboxusbmon
zonecfg:vbox:device> end

Then all you need to do is create the zone.  This will take a few minutes.

zonecfg:vbox> commit
zonecfg:vbox> exit
root@nehalem:/# zoneadm -z vbox install
A ZFS file system has been created for this zone.
 Publisher: Using opensolaris.org (http://pkg.opensolaris.org/dev/ ).
 Publisher: Using contrib.opensolaris.org (http://pkg.opensolaris.org/contrib/).
 Image: Preparing at /zones/vbox/root.
[...]

Step 2:  Install the Virtualbox package.

This needs to be done in the global zone as well as your newly-created container.  So while our new container is installing, go ahead and grab the latest beta, and install it in the global zone:

root@nehalem:/var/tmp# pkgadd -d VirtualBox-3.2.0_BETA1-SunOS-r60785.pkg
The following packages are available:
 1  SUNWvbox     Oracle VM VirtualBox
 (i386) 3.2.0_BETA1,REV=2010.04.27.22.46.60785
Select package(s) you wish to process (or 'all' to process
all packages). (default: all) [?,??,q]:

Once that’s done and your new container is ready, boot it and you’ll need to install the exact same Virtualbox package in the container, as well as some other packages.

inside the new container:

root@vbox:/# pkg install SUNWuiu8 SUNWgccruntime
[.. output omitted ..]
root@nehalem:/var/tmp# pkgadd -d VirtualBox-3.2.0_BETA1-SunOS-r60785.pkg

At this point, we’re ready to create our Guest.  We’re going to do this using the command line interface, so this will work on any operating system.  It isn’t Solaris specific.

If you’re following along from the top, make sure you’ve logged into the Opensolaris container (use “zlogin <container>”).

You don’t need to be root.  Cut and paste the following lines, being sure to change the green parts as appropriate for your system.

[Note: Since this post was written creating a Snow Leopard capable VM is now a lot simpler.  If you have compatible hardware, you might be interested to check out this post instead. ]

VBoxManage createvm -name OSX -ostype MacOS_64 -basefolder /vbox -register
VBoxManage createhd ---filename /vbox/OSX/OSX.vmdk --size 10240
VBoxManage modifyvm OSX --cpus 8
VBoxManage modifyvm OSX --memory 8192
VBoxManage modifyvm OSX --usb on --usbehci on
VBoxManage modifyvm OSX --acpi on --ioapic on
VBoxManage storagectl OSX --name "SATA Controller" --add sata \
  --controller IntelAHCI
VBoxManage storageattach OSX --storagectl "SATA Controller" \
  --type hdd --port 0 --device 0 --medium /vbox/OSX/OSX.vmdk
VBoxManage storagectl OSX --name "IDE Controller" --add ide \
  --controller PIIX4
VBoxManage storageattach OSX --storagectl "IDE Controller" --port 0 \
 --device 1 --type dvddrive --medium /misc/iDeneb_v1.6_1058_Lite_Edition.iso

Now a well-known issue with earlier versions of Virtualbox was that if you managed to install OS X you might have the guest os complaining that no keyboard was connected.  Indeed, this is what happened to me.  In order to get a Mac OS X guest to run with a keyboard and mouse inside Virtualbox, you need to add the following lines to your configuration:

VBoxManage modifyvm OSX --mouse usb
VBoxManage modifyvm OSX --keyboard usb

Now you can go ahead and boot it up, and install Mac OS X.  You don’t need to change any package selections for the iDeneb CD.  Once you’re done just, reboot and voila!

VBoxManage startvm OSX --type vrdp

To access your OSX console, use VRDP.  Point your RDP client at the IP address you gave your container (or whatever IP address is running Virtualbox as the host if you skipped the Opensolaris part).

[ One thing worth noting - sometimes Mac OS X struggles if you give it more than 1 virtual CPU.  If this happens, set the number of CPUs to 1, and reboot and it should be fine.]

Virtualbox, iSCSI targets and teleport

Here’s a quick rundown on how to get Virtualbox running with iSCSI targets.

But first the why: why would you want to configure Virtualbox to use an iscsi target instead of a native disk image?

The answer is teleport.  Sure, you can use an NFS or CIFS share just as easily with teleport, but using iSCSI targets is just that little bit more fun.

If you’re just setting up a standalone virtualbox, stick with disk images on local filesystems.  The only reason to put your disk images on shared storage is so that teleport works.

For the uninitiated, teleporting is somewhat similar to VMWare’s “vMotion”.  It’s the term given to the process of moving the processing and networking of a virtual machine to a different physical host without any (much) interruption to the virtual host.

Unlike VMWare though, Virtualbox lets you teleport your VM to different types of machines.  That means you can teleport your VM from your linux machine to your Macbook Pro, over to your Opensolaris server and even to your Windows machine.  The only limitation seems to be that they must have the same processor family (Intel to AMD processors doesn’t appear to work… yet.)

In this example I’m using an Opensolaris server to serve iSCSI targets from my ZFS pool.  This gives me neat stuff like dedup and compression, as well as thin provisioning if I would like it.  It doesn’t matter if you’re using FreeBSD or indeed any other way of presenting iSCSI targets.

On the Opensolaris server:

  • Create a zfs volume to be your iSCSI target.  Here I have a zpool named “xpool”.# zfs create -V 20G xpool/targetThis will create a 20Gb volume.  To use thin provisioning, use the -s flag to the zfs create command)
  • Install the following packages if you haven’t already:
    SUNWiscsitu
    SUNWiscsitr
    SUNWiscsidmu
    SUNWiscsidmr
    SUNWstmf
    SUNWstmfu
  • Share the target:
    # zfs set shareiscsi=on xpool/target
    (Note: if you have more recent version of Solaris, this command may fail with “invalid property ‘shareiscsi’ “.  In that case, see this post for instructions)
  • Make note of the device’s ID:
    # iscsitadm list target
    Target: xpool/target
    iSCSI Name: iqn.1986-03.com.sun:02:74cedff0-250c-eacc-b509-bc930dc897d6
    Connections: 0

Now you can create your Virtualbox virtual machine.  I’m using the command line here.  You can repeat these steps quickly on any machine where you’d like to teleport the machine to.  Besides, who needs one of them fancy-pants GUIs, anyhow?

First – register the iSCSI target as a virtualbox disk:

# VBoxManage addiscsidisk –server 1.1.1.1 –target iqn.1986-03.com.sun:02:74cedff0-250c-eacc-b509-bc930dc897d6

Check that it worked…

# VBoxManage list hdds
Sun VirtualBox Command Line Management Interface Version 3.1.4
(C) 2005-2010 Sun Microsystems, Inc.
All rights reserved.

UUID:       dfab4e6a-4ad6-44fa-96e0-76d5504b92aa
Format:     ISCSI
Location:   1.1.1.1|iqn.1986-03.com.sun:02:74cedff0-250c-eacc-b509-bc930dc897d6
Accessible: yes
Type:       normal

Now we can go ahead and create our VM.  You can see what types of VMs your server will support with the command:

# VBoxManage list ostypes

It’s probably best to make sure that the type of server you’re going to build is supported on all the hosts you plan on teleporting it to.  It might save a bit of pain and anguish later..

This is a simple VM with an IDE controller and a single hard disk.  We attach an ISO image to the IDE controller as the second device in order to install our OS.  Later we can attach the Virtualbox additions ISO here, too.

# VBoxManage createvm –name testvm –ostype WindowsXP –basefolder /vbox –register
Sun VirtualBox Command Line Management Interface Version 3.1.4
(C) 2005-2010 Sun Microsystems, Inc.
All rights reserved.

Virtual machine ‘testvm’ is created and registered.
UUID: c8a5b6a3-6fb3-4b50-beb2-9a08e656392a
Settings file: ‘/vbox/testvm/testvm.xml’

Now we can add memory limits, disk controllers and disk devices:

# VBoxManage modifyvm testvm  –memory 1024 –cpus 4
# VBoxManage storagectl testvm –name “IDE Controller” –add ide –controller PIIX4
# VBoxManage storageattach testvm –storagectl “IDE Controller” –port 0 –device 0 –type hdd –medium dfab4e6a-4ad6-44fa-96e0-76d5504b92aa

# VBoxManage storageattach testvm –storagectl “IDE Controller” –port 0 –device 1 –type dvddrive –medium /vbox/XP.iso
# VBoxManage modifyvm testvm –nictype1 82545EM –nic1 bridged –bridgeadapter1 nge0
## !!! Adjust “nge0″ to suit your network interface name !!! ##
# VBoxManage modifyvm testvm –vrdp on

Once that’s done, boot it and connect via RDP to your host to install your operating system.

# VBoxManage startvm testvm –type vrdp

While the operating system is installing, repeat the steps on another machine, but don’t power it on.  Remember to change the “bridgeadapter” to the appropriate interface name.  (Note: You don’t need to use a NIC at all in our VM and this will still work, but what use is a VM without network access?)

Teleporting virtualbox vms

Once you’re set up, you can move VMs around like this:

1. On the host machine that you want to move the virtual machine to:  (In  this example we’ll assume our destination has IP address 1.1.1.20 and our source has IP address 1.1.1.10)

# VBoxManage modifyvm testvm –teleporter on –teleporteraddress 1.1.1.20 –teleporterport 54321

2. On the host machine, you can now power it on, and it should sit idle waiting for a teleport request to arrive from 1.1.1.10.

# VBoxManage startvm testvm –type vrdp

3. On the host machine that has the running virtual machine:

# VBoxManage controlvm testvm teleport –host 1.1.1.10 –port 54321

Once the progress bar hits 100%, you’re done!


 

Technorati Tags: , , , , ,