VirtualBox and Bootcamp

Discussions related to using VirtualBox on Mac OS X hosts.
Post Reply
mpetroo
Posts: 21
Joined: 26. Jan 2010, 03:20
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows 7, 8
Location: St. Petersburg, Russia

VirtualBox and Bootcamp

Post by mpetroo »

The idea was to run Windows 7 Professional as natively by using Apple BootCamp, as the same installation by using virtual hardware in Mac OS X and avoid Windows re-activation during both the methods. I'd like to represent here my experience in this problem and mention that it works in my case. If you like, you can find step-by-step instructions below.

The starting point is that we have two operating systems, Mac OS X 10.6 and Windows 7 Professional installed properly according to Apple recommendations through the Boot Camp technology. In my case, Windows has been successfully activated with the native hardware (as I remember, before I installed Boot Camp drivers). I have also VirtualBox 4.0.4 installed in Mac OS X host as well. So, the first step is the creation of the new virtual machine named BootCamp in my case (create without any disks) and the creation of the disk image to run Boot Camp partition. It can be done with the following commands

Code: Select all

sudo diskutil unmount /dev/disk0s3
sudo VBoxManage internalcommands createrawvmdk -filename /DefaultMachineFolder/BootCamp/BootCamp.vmdk -rawdisk /dev/disk0 -partitions 3
In this step, we have unmounted BootCamp partition, and created two images, BootCamp.vmdk and Bootcamp-pt.vmdk, located in the folder with your future BootCamp virtual machine (hereafter, correct the /DefaultMachineFolder with your location, see VirtualBox Preferences to find the right path). Second step is to correct the raw vmdk file to avoid booting the HFS+ and other volumes. For this reason, I'm trying to find the ID's of the following partitions

Code: Select all

cd /DefaultMachineFolder/BootCamp
file BootCamp-pt.vmdk
From the output one can easily find the ID of unfavoured partitions. In my case the ID's were partition 1: ID=0xee (EFI partition) and partition 2: ID=0xaf (Mac OS X partition). These ID's should be replaced with 0x2d. For this reason, one can analyze the hex-dump of the file

Code: Select all

hexdump BootCamp-pt.vmdk
and find the strings

Code: Select all

00001c0 ff ff ee fe ff ff 01 00 00 00 27 40 06 00 00 fe
00001d0 ff ff af fe ff ff 28 40 06 00 00 00 20 19 80 fe
From this analysis, one can find the byte positions of 'ee' and 'af' ID's. They are 0x1c0+0x2 and 0x1d0+0x2, respectively. The decimal numbers for these positions are 450 and 466, respectively. Use calculator to transfer. After that, we have to replace these bytes with '2d'.

Code: Select all

sudo echo -en "\x2d" | dd of=BootCamp-pt.vmdk bs=1 count=1 seek=450 conv=notrunc 
sudo echo -en "\x2d" | dd of=BootCamp-pt.vmdk bs=1 count=1 seek=466 conv=notrunc 
Next step is to become the owner of the vmdk files created.

Code: Select all

sudo chown username BootCamp.vmdk 
sudo chown username BootCamp-pt.vmdk
sudo chgrp staff BootCamp.vmdk
sudo chgrp staff BootCamp-pt.vmdk
To run the BootCamp partition as non-root, one have also to change the permissions for the raw disk. Be careful with this step. My choice is

Code: Select all

sudo chgrp admin /dev/disk0s3 
sudo chmod 660 /dev/disk0s3 
Note, the last procedure should be repeated each time after rebooting the Mac OS X. I recommend to write the launch daemons, if you like.

This is sufficient to run Windows in the newly created virtual machine. I recommend to configure it, so that it has ICH6 IDE controller and attached BootCamp.vmdk. I also recommend for the first run to create the empty SATA controller to allow Windows to install the proper software for it. Windows should launch properly in this step but you probably lose your activation. The reason is that the native hardware is in drastic contrast to the virtual machine. So, if you reboot your computer back to BootCamp, it should be activated.

Last step is to collect the information about the native hardware, which Windows determines. I recommend to run dmidecode utility in Windows Power Shell to collect it. All you need is to write into the peace of paper the BIOS and System info according to 9.11 paragraph of the VirtualBox Manual and, after that, to write this information to the BootCamp virtual machine properties. After that, the reconnection of BootCamp.vmdk to the SATA interface allows one to reflect the hard disk vendor information (see 9.7.2 of the VirtualBox Manual for details). The information on native hard drive can be found in 'About This Mac'. The correct data allows Windows to run properly avoiding the re-activation process, at least if you allow VirtualBox to run as many processor cores as at the native running, in my case.

Finally, I hope that future releases of VirtualBox will allow users to run BootCamp partition in more user-frendly way. At least, it should allow to run it without changing the permissions for running the device. I think, the best way is to ask user for the sudo password before starting the virtual machine. I also would like to see automatic unmounting the BootCamp disk before running the virtual machine and automatic mounting after shutdown. I believe, the described procedure can be coded easily and hope to see the official BootCamp support very soon. :)
jarre
Posts: 13
Joined: 17. Jul 2007, 21:18
Location: switzerland

Re: VirtualBox and Bootcamp

Post by jarre »

Yea its a shame no Bootcamp support here in VB ! The others VM Commercials have BC Support easy thake the existing Partion ! And this support is not NEW ! The support BC a long time !!!!
And it still boot native !

SO Sleep well in Peace VB ! The others are Ligthyears ahead !

Greetz
Jarre
mpetroo
Posts: 21
Joined: 26. Jan 2010, 03:20
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows 7, 8
Location: St. Petersburg, Russia

Re: VirtualBox and Bootcamp

Post by mpetroo »

The concurrent commercial products does not have one feature, I mean they are all requiring additional Windows activation as they do not emulate DMI Bios and DMI System information of real hardware. That is the great concurrent advantage of VirtualBox. What would be sufficient at this step is only the possibility to run a virtual machine with sudo option avoiding the shamanism with required changing the permissions for running the physical partition. Another feature would be great to see in guest additions is the possibility to select what services and programs should run when booting as VM, e.g., bootcamp and other Apple services that require original hardware should be switched off in this case and, on the contrary, should be switched on when booting from native hardware. I have noticed that every time when the VM starts, the bootcamp process waste approximately 20% of the CPU usage for firs several minutes. At the same time it does not appear when booting from native hardware.
Post Reply