Saturday 19 February 2011

Boot a Real Mac OS-X Partition under Linux and VirtualBox

This should be easy, but Apple make it hard.

I have a MacBook Pro. I have OS-X Leopard 10.5.2 installed as well as Ubuntu 10.10 linux.

I wanted to get my OS-X partition to run as a virtual machine.

After many false starts I got something to work.



First, the specs.
Hardware: MacBook Pro 4,1, early 2008, 2.4GHz, 200GB, 15"
http://en.wikipedia.org/wiki/MacBook_Pro
Host OS: Ubuntu 10.10
VM Manager: VirtualBox 3.2.8 OSE r64453
Guest OS: OS-X 10.5.2 Leopard (I don't bother to update it as I don't use it much and it have virtually nothing installed)
Overview

1. Get VirtualBox to list the physical partition in the Virtual Media Manager.
2. Setup the VM
3. Tweak it.
3. Run it.

1. Setup Disk Image

Please proceed at your own risk. Only do this if you have backed-up your disk partitions (with Time Machine for example, but don't forget about your linux partition) or your don't care about any data on your disk.

I used this information to create my VMM vmdk file.
http://ejs.seniejitrakai.net/2010/11/01/running-virtualbox-guests-from-physical-drive/
In my case, my hard drive is /dev/sda under linux.



phil@max:~$ VBoxManage internalcommands listpartitions -rawdisk /dev/sda

Oracle VM VirtualBox Command Line Management Interface Version 3.2.8_OSE(C) 2005-2010 Oracle CorporationAll rights reserved.
Number  Type   StartCHS       EndCHS      Size (MiB)  Start (Sect)1       0xee  1023/254/63  1023/254/63           200            12       0xaf  1023/254/63  1023/254/63        119102       4096404       0x83  1023/254/63  1023/254/63         11444    2443309763       0xaf  1023/254/63  1023/254/63         23167    343011768


The OS-X partition in my case is number 3. It is about 23GB.

Then I made the vmdk file like this:

phil@max:~$ VBoxManage internalcommands createrawvmdk -filename /home/phil/.VirtualBox/HardDisks/example.vmdk -rawdisk /dev/sda -partitions 3 -register 
Oracle VM VirtualBox Command Line Management Interface Version 3.2.8_OSE(C) 2005-2010 Oracle CorporationAll rights reserved.
RAW host disk access VMDK file /home/phil/.VirtualBox/HardDisks/example.vmdk created successfully.

This made this file - yours will be different, but it should have the same structure:

# Disk DescriptorFileversion=1CID=279c9811parentCID=ffffffffcreateType="partitionedDevice"
# Extent descriptionRW 1 FLAT "example-pt.vmdk" 0RW 409639 ZERO RW 243921336 ZERO RW 23437500 ZERO RW 75243292 ZERO RW 47448016 FLAT "/dev/sda" 343011768RW 262184 ZERO 
# The disk Data Base #DDB
ddb.virtualHWVersion = "4"ddb.adapterType="ide"ddb.geometry.cylinders="16383"ddb.geometry.heads="16"ddb.geometry.sectors="63"ddb.uuid.image="99ca08b3-6d2e-4ed4-8790-2430cfe5a57a"ddb.uuid.parent="00000000-0000-0000-0000-000000000000"ddb.uuid.modification="00000000-0000-0000-0000-000000000000"ddb.uuid.parentmodification="00000000-0000-0000-0000-000000000000"

Now if you run Virtual Media Manager, you should now see a new hard drive entry for your physical partition.


That wasn't that hard, thanks to Sun/Innotek for making this easy.

2. Setup VM.

The key fields are these:
OS Type = Mac OS X
Use an existing hard disk - the one I created above: example.vmdk
The rest are the current defaults (which I will list below).
I also enabled 3D acceleration, but I can pick either.
Too easy, right?

3. Tweak VM

Apple OS-X checks to see if a special key is in a chip. VMs don't currently emulate this chip with the key, so you need to get the key off your machine and add it manually to the VirtualBox XML file that describes the VM.

The key is really a plea from Apple to not steal their OS. Here is their EULA for 10.5.

http://images.apple.com/legal/sla/docs/macosx105.pdf

It contains this clause:

A. Single Use. This License allows you to install, use and run one (1) copy of the Apple Software on a single Apple-labeled computer at a time. You agree not to install, use
or run the Apple Software on any non-Apple-labeled computer, or to enable others to do so. This License does not allow the Apple Software to exist on more than one
computer at a time, and you may not make the Apple Software available over a network where it could be used by multiple computers at the same time. 

I think this complies: One licensed and installed copy of OS-X on an Apple-labeled computer. I can't run it twice because that would do bad things to the file system.

So, I'll continue...

In my case the XML file is /home/phil/.VirtualBox/Machines/example/example.xml

This is what it might look like:


<?xml version="1.0"?>
<VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.11-linux">
  <Machine uuid="{0db68b53-a452-40bd-bb83-ad8952411320}" name="example" OSType="MacOS" snapshotFolder="Snapshots" lastStateChange="2011-02-19T08:34:33Z">
    <MediaRegistry>
      <HardDisks/>
      <DVDImages/>
      <FloppyImages/>
    </MediaRegistry>
    <Hardware version="2">
      <CPU count="1" hotplug="false">
        <HardwareVirtEx enabled="true" exclusive="true"/>
        <HardwareVirtExNestedPaging enabled="true"/>
        <HardwareVirtExVPID enabled="true"/>
        <PAE enabled="true"/>
        <HardwareVirtExLargePages enabled="false"/>
        <HardwareVirtForce enabled="false"/>
      </CPU>
      <Memory RAMSize="1024" PageFusion="false"/>
      <Firmware type="EFI"/>
      <HID Pointing="USBTablet" Keyboard="USBKeyboard"/>
      <HPET enabled="true"/>
      <Chipset type="ICH9"/>
--- SNIP --- 


  </Machine>
</VirtualBox>

As you can see, the whole configuration of a VM is, more-or-less, understandable.

But wait! To do the next bit, you have to run the VM once. Until you do this scary thing, the XML file is missing bits that make the next part easier.

So, start the VM. When you see lots of text you can close the window and shutdown the VM.


This is all safe it seems.

My example VM XML file now looked like this - the highlighted bits are what we want to see:


<?xml version="1.0"?>
<VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.11-linux">
  <Machine uuid="{57d6a1c9-833f-4fb7-b765-f4c37793bc56}" name="example" OSType="MacOS" snapshotFolder="Snapshots" lastStateChange="2011-02-19T08:27:47Z">
    <MediaRegistry>
      <HardDisks/>
      <DVDImages/>
      <FloppyImages/>
    </MediaRegistry>
    <ExtraData>
      <ExtraDataItem name="GUI/LastCloseAction" value="powerOff"/>
      <ExtraDataItem name="GUI/LastGuestSizeHint" value="1024,768"/>
      <ExtraDataItem name="GUI/LastNormalWindowPosition" value="400,61,1024,815"/>
      <ExtraDataItem name="GUI/LastWindowPostion" value="37,53,1024,815"/>
      <ExtraDataItem name="GUI/MiniToolBarAlignment" value="bottom"/>
      <ExtraDataItem name="GUI/SaveMountedAtRuntime" value="yes"/>
      <ExtraDataItem name="GUI/ShowMiniToolBar" value="yes"/>
    </ExtraData>
--- SNIP --- 
  </Machine>
</VirtualBox>

To tweak it, I followed these instructions:
http://www.takwing.idv.hk/tech/virtual/vb320_macvm/page3.html

Modify your VM's xml file by adding the following line to the section:

<ExtraDataItem name="VBoxInternal2/SmcDeviceKey" 
value="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"/>



Mine then looked like this:

<?xml version="1.0"?>
<VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.11-linux">
  <Machine uuid="{57d6a1c9-833f-4fb7-b765-f4c37793bc56}" name="example" OSType="MacOS" snapshotFolder="Snapshots" lastStateChange="2011-02-19T08:27:47Z">
    <MediaRegistry>
      <HardDisks/>
      <DVDImages/>
      <FloppyImages/>
    </MediaRegistry>
    <ExtraData>
      <ExtraDataItem name="GUI/LastCloseAction" value="powerOff"/>
      <ExtraDataItem name="GUI/LastGuestSizeHint" value="1024,768"/>
      <ExtraDataItem name="GUI/LastNormalWindowPosition" value="400,61,1024,815"/>
      <ExtraDataItem name="GUI/LastWindowPostion" value="37,53,1024,815"/>
      <ExtraDataItem name="GUI/MiniToolBarAlignment" value="bottom"/>
      <ExtraDataItem name="GUI/SaveMountedAtRuntime" value="yes"/>
      <ExtraDataItem name="GUI/ShowMiniToolBar" value="yes"/>
      <ExtraDataItem name="VBoxInternal2/SmcDeviceKey" value="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"/>
    </ExtraData>
--- SNIP --- 
  </Machine>
</VirtualBox>    

4. Run it.

That's it.

Let me know if it worked for you, and if you have a different hardware, host, guest configuration.

If it didn't work, then I probably can't help - but you you want me to explain anything that I did in more detail then please ask.

BTW, if this kills you disk, damages your data, or generally make your life a misery then you will recall that I warned you, right?

No comments:

Post a Comment

Please use family friendly language.