Discussion: MacOS Bootcamp Partition as a VBox Guest

Discussions related to using VirtualBox on Mac OS X hosts.
JimBushWhack
Posts: 77
Joined: 1. Sep 2008, 23:07
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win XP on iMac; Win 7 on MacBook pro + bootcamp
Location: SF Bay Area; California, USA

Discussion: MacOS Bootcamp Partition as a VBox Guest

Post by JimBushWhack »

Hi, In a recent post, I suggested that it would be good to have a writeup of the subject matter so that other folks could benefit from it. One of the site moderators suggested that since I had just gone through this process, that I would be the perfect one to add such a writeup. So, I am "putting my money where my mouth is" and doing just that. In the post following post following this one, I detail how I was able to add a Bootcamp Windows 7 (and XP) partition as a VirtualBox Virtual Machine.

Site Moderators: Please review this document and and consider it for inclusion in the HowTos and Tutorials section.

Thanks,
JimBushWhack
JimBushWhack
Posts: 77
Joined: 1. Sep 2008, 23:07
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win XP on iMac; Win 7 on MacBook pro + bootcamp
Location: SF Bay Area; California, USA

Re: How to Use a MacOS Bootcamp Partition as a VirtualBox Gu

Post by JimBushWhack »

How to Use a MacOS Bootcamp Partition as a VirtualBox Guest Virtual Machine

Background:

When I first got an Intel Mac in the summer of 2008, I decided that I could finally get rid of my Gateway PC running Windows ME. Since the Intel Mac allowed me to run Windows via Bootcamp, I was able to use this to run the Windows version of Quicken, since the Mac version of Quicken was not very good. This worked well for a few months until I got tired of having to reboot the Mac to run Windows via Bootcamp. I started looking at VMWare Fusion and Parallels as a solution. Then I heard about VirtualBox. Since it was OpenSource (and free), I decided to give it a try. But I was disappointed when I tried to setup my existing Bootcamp Windows partition as a VirtualBox Virtual Machine. It did not work and the instructions in the manual were fairly complicated and involved delving into the Mac CLI, as the VBox GUI did not (and still does not) allow you to perform this setup. There are many forum threads on this subject, many of which I have contributed to. Finally in the Spring of 2011, I was finally able to setup a Windows 7 Guest virtual machine from a Bootcamp partition on my MacBook Pro. I never could get a Windows XP Bootcamp based Guest running on my iMac and finally gave up on it.

The Problem:

About a month ago, I updated both of my Macs to run the new MacOS release Lion. When I got around to trying to bring up Windows 7 via VirtualBox on my MacBook Pro, it failed miserably. The bootcamp partition had originally been setup as partition 3 on my hard disk under Snow Leopard. Upon investigation, I found that when Lion was installed, the hard disk partitioning had been shuffled and partition 3 was now the MacOS Recovery partition and the bootcamp partition had been moved to partition 4. Below is a view of the hard disk partitions, using the vboxmanage CLI command:
-----------------------
JBs-MacBook:BC7 Jim$ sudo vboxmanage internalcommands listpartitions -rawdisk /dev/disk0
Number Type StartCHS EndCHS Size (MiB) Start (Sect)
1 0xee 1023/254/63 1023/254/63 200 1
2 0xaf 1023/254/63 1023/254/63 274167 409640
3 0xab 1023/254/63 1023/254/63 619 561903832
4 0x07 1023/254/63 1023/254/63 30258 563173376
------------------------
The Solution:

After downloading and installing the 4.1.6 Mac OS version of VirtualBox and the Extension Pack (I had had problems with the 4.1.8 version before and the 4.1.10 version was not out yet), I tried using the vboxmanage createrawvmdk command to regenerate the vmdk disk description and MBR files, but found that I only had generated the disk description file and not the MBR. After adding a post to the VirtualBox on Mac OS X Hosts forum, one of the site moderators (mpack) showed me the error of my ways and that I had not invoked the createrawvmdk command with the -partitions argument which is required to generate the MBR file. After re-reading “Access to individual physical hard disk partitions” (paragraph 9.8.1.2) in the VirtualBox UserManual, I was able to setup the correct command line like so:

------------------------
JBs-MacBook:BC7 Jim$ sudo vboxmanage internalcommands createrawvmdk -rawdisk /dev/disk0 -filename BC7.vmdk -partitions 4
RAW host disk access VMDK file BC7.vmdk created successfully.
------------------------
I then set open access to these two files and dumped out the contents of the BC7-pt.vmdk (i.e. MBR) file:
------------------------
JBs-MacBook:BC7 Jim$ sudo chmod 777 BC7*
JBs-MacBook:BC7 Jim$ ls -l
total 16
-rwxrwxrwx 1 root Jim 512 Mar 13 13:40 BC7-pt.vmdk
-rwxrwxrwx 1 root Jim 638 Mar 13 13:40 BC7.vmdk

JBs-MacBook:BC7 Jim$ hexdump BC7-pt.vmdk
0000000 33 c0 8e d0 bc 00 7c fb 50 07 50 1f fc be 1b 7c
<<>>
00001c0 ff ff ee fe ff ff 01 00 00 00 27 40 06 00 00 fe Partition 1 Type 0xEE = Legacy MBR
00001d0 ff ff af fe ff ff 28 40 06 00 d8 a0 2c 19 00 fe Partition 2 Type 0xAF = Mac OS X HFS
00001e0 ff ff ab fe ff ff 00 e1 32 19 28 5f 13 00 80 fe Partition 3 Type 0xAB = Mac OS X Boot
00001f0 ff ff 07 fe ff ff 28 40 46 19 20 19 d6 03 55 aa Partition 4 Type 0x07 = Windows NT NTFS
JBs-MacBook:BC7 Jim$ sudo chmod 777 /dev/disk0s4
JBs-MacBook:BC7 Jim$
------------------------
Note the MBR partition table starting at hexadecimal address 00001c0. The 3rd hex character of each 16 byte partition table entry is the partition type. I have expanded the partition type to the right of the hexdump output.

At this point, I went back to the GUI and setup my virtual machine as follows:

1. Selected New and setup the Virtual Machine Name as BC7.
2. Operating System as Windows and version as Windows 7, since it is a 32bit version of Windows 7. For a 64bit version, select Windows 7 (64 bit).
3. Selected 1024 MB of memory. My Mac has 4 GB so, this works about right.
4. At the Virtual Hard Disk window, I check Start-up disk and select Use Existing Hard Drive. I clicked the arrow token on the right side and put the file path of the BC7.vmdk file generated above.
5. Review the summary window and hit Create. A new virtual machine named BC7 will show up on the left side of the VirtualBox window and be in the state of Powered Off.
6. Select this new virtual machine and then go to Settings. Review each setting category and use the defaults unless otherwise noted.
7. Under Storage, you will see that the Storage Tree shows that you have 2 controllers. An IDE controller with a CD/DVD drive showing empty and a SATA controller with the BC7 virtual disk under it. We need to get rid of the SATA controller and setup the IDE controller so that the BC7 virtual disk and the CD/DVD drive are both controlled by it:
a) Select the Empty CD/DVD drive and click on the delete attachment button below it (the one with an orange minus sign, second from the left).
b) Select the SATA Controller and click on remove controller button below it (the one with the orange minus sign, on the far right). This will also remove the BC7 virtual disk, but we will add it back in the next step.
c) Select the IDE Controller and click the Add Hard drive button to the far right of the IDE Controller line. This will bring up a dialog box where you may now select the path of the BC7 virtual disk once again, after clicking on choose existing disk.
d) Select the IDE Controller again and then click the Add CD/DVD button to the left of the Add Hard drive button. Click the Leave Empty button on the next dialog box.
e) Under Attributes, change the type to ICH6.
8. Complete the Virtual Machine setup with network and USB ports as needed. Also setup a Shared Folder so you can pass files back and forth between Windows and Mac OS. When Windows is up, you can assign a Drive letter to this shared folder for easy access. Then hit OK.

Before trying to start a Bootcamp Virtual Machine, open access to the Bootcamp partitions Device Special File must be set and if the Bootcamp partition is mounted on the live invocation of Mac OS, it must be unmounted. Since these are repetitive tasks, they are best done with a script. Below is a screen shot of a compiled applescript file that will perform these tasks as well as start the Virtual Machine:
Screen Shot 2012-03-24 at 1.38.51 PM.jpg
Screen Shot 2012-03-24 at 1.38.51 PM.jpg (52.46 KiB) Viewed 35937 times
Revisit Bootcamp Windows XP Virtual Machine:

Since I got my Bootcamp Windows 7 Virtual Machine running with VirtualBox, I decided to give Windows XP another shot. So, I installed VirtualBox 4.1.6 on my iMac. I then displayed the partition table and generated the vmdk description and MBR files. After this, I set open access for these files and then I used hexdump to display the contents of the partition table in the generated MBR file:
------------------------
JBs-iMac:BCXP Jim$ sudo vboxmanage internalcommands listpartitions -rawdisk /dev/disk0
Number Type StartCHS EndCHS Size (MiB) Start (Sect)
1 0xee 1023/254/63 1023/254/63 200 1
2 0xaf 1023/254/63 1023/254/63 206228 409640
3 0xab 1023/254/63 1023/254/63 619 422764800
4 0x0c 1023/254/63 1023/254/63 31427 424034344
JBs-iMac:BCXP Jim$ sudo vboxmanage internalcommands createrawvmdk -rawdisk /dev/disk0 -filename BCXP.vmdk -partitions 4
RAW host disk access VMDK file BCXP.vmdk created successfully.
JBs-iMac:BCXP Jim$ sudo chmod 777 BCXP*
JBs-iMac:BCXP Jim$ ls -l
total 16
-rwxrwxrwx 1 root Jim 512 Mar 13 14:02 BCXP-pt.vmdk
-rwxrwxrwx 1 root Jim 638 Mar 13 14:02 BCXP.vmdk

JBs-iMac:BCXP Jim$ hexdump BCXP-pt.vmdk
0000000 33 c0 8e d0 bc 00 7c fb 50 07 50 1f fc be 1b 7c
<<>>
00001c0 ff ff ee fe ff ff 01 00 00 00 27 40 06 00 00 fe Partition 1 Type 0xEE = Legacy MBR
00001d0 ff ff af fe ff ff 28 40 06 00 d8 a0 2c 19 00 fe Partition 2 Type 0xAF = Mac OS X HFS
00001e0 ff ff ab fe ff ff 00 e1 32 19 28 5f 13 00 80 fe Partition 3 Type 0xAB = Mac OS X Boot
00001f0 ff ff 0c fe ff ff 28 40 46 19 20 19 d6 03 55 aa Partition 4 Type 0x0C = Win95 FAT32
JBs-iMac:BCXP Jim$
------------------------

I went through the exercise described above of using the GUI to setup the Virtual Machine. But when I tried to start it, it would not start. I puzzled over this for a bit and then went back and re-read some of the posts associated with setting up Bootcamp Virtual Machines. I found references to setting the partition type field in each of the MBR partition table entries, except the one describing the Bootcamp partition, to an Unused type (e.g. 0x2d). I did this using the dd CLI command and then displayed the MBR partition table contents with the hexdump command once again below:

------------------------
JBs-iMac:BCXP Jim$ echo -en "\x2d" | dd of=BCXP-pt.vmdk bs=1 count=1 seek=0x1c2 conv=notrunc
1+0 records in
1+0 records out
1 bytes transferred in 0.000020 secs (49932 bytes/sec)
JBs-iMac:BCXP Jim$ echo -en "\x2d" | dd of=BCXP-pt.vmdk bs=1 count=1 seek=0x1d2 conv=notrunc
1+0 records in
1+0 records out
1 bytes transferred in 0.000021 secs (47663 bytes/sec)
JBs-iMac:BCXP Jim$ echo -en "\x2d" | dd of=BCXP-pt.vmdk bs=1 count=1 seek=0x1e2 conv=notrunc
1+0 records in
1+0 records out
1 bytes transferred in 0.000020 secs (49932 bytes/sec)
JBs-iMac:BCXP Jim$ hexdump BCXP-pt.vmdk
0000000 33 c0 8e d0 bc 00 7c fb 50 07 50 1f fc be 1b 7c
<<>>
00001c0 ff ff 2d fe ff ff 01 00 00 00 27 40 06 00 00 fe Partition 1 Type 2D = Unused
00001d0 ff ff 2d fe ff ff 28 40 06 00 d8 a0 2c 19 00 fe Partition 2 Type 2D = Unused
00001e0 ff ff 2d fe ff ff 00 e1 32 19 28 5f 13 00 80 fe Partition 3 Type 2D = Unused
00001f0 ff ff 0c fe ff ff 28 40 46 19 20 19 d6 03 55 aa Partition 4 Type 0C = Win95 FAT32
JBs-iMac:BCXP Jim$ sudo chmod 777 /dev/disk0s4
JBs-iMac:BCXP Jim$
------------------------

After patching the partition table and starting the Virtual Machine once again, everything worked fine.
dpkonofa
Posts: 1
Joined: 28. Mar 2012, 21:02

Re: How to Use a MacOS Bootcamp Partition as a VirtualBox Gu

Post by dpkonofa »

Are you still able to boot regularly at StartUp to this partition if you want to use Windows without the Mac OS running? Does something need to be done to the disk to prevent data loss on native boot to Windows as opposed to booting it in the "fake" VM?
JimBushWhack
Posts: 77
Joined: 1. Sep 2008, 23:07
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win XP on iMac; Win 7 on MacBook pro + bootcamp
Location: SF Bay Area; California, USA

Re: How to Use a MacOS Bootcamp Partition as a VirtualBox Gu

Post by JimBushWhack »

The only problem I had on both the Windows 7 and the XP environments was that the drive letter that I assigned to the VBox shared folder was invalid when booting from the bootcamp partition. But this was non-fatal. But I just tried booting from my XP bootcamp partition and I ended up with "dueling activations". That is when I first booted from the bootcamp partition from VBox, it required me to reactivate windows once again. I did not have to supply a product code, just check the reactivate box and reactivate online. When I booted from the Win XP bootcamp partition, it also required me to reactivate windows as well. It went through ok. Then when rebooted from Mac OS X and restarted the VBox bootcamp environment, I had to reactivate again. But when I shutdown windows and then restarted via VBox, it did not require reactivation.

None of this happened with the Windows 7 bootcamp environment, which did not require reactivation in either case.
Sanjeev
Posts: 3
Joined: 6. Sep 2012, 16:43

Re: How to Use a MacOS Bootcamp Partition as a VirtualBox Gu

Post by Sanjeev »

I am grateful to my google search using "how to run windows-7 bootcamp in virtualbox" :D
After spending hours of trial & error on Apple, VirtualBox, Youtube & other forums by chance I hit correct words and first in the search list was most useful. It gave simpler and easier instructions than others. Guidance is in easy steps and it works great :D :D
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: How to Use a MacOS Bootcamp Partition as a VirtualBox Gu

Post by mpack »

I guess this tutorial has had long enough to gestate. So, I've created a copy in the "Howtos / Other Hosts" area. This topic now becomes the discussion area, since normal users can't post comments in the tutorials area.
Sanjeev
Posts: 3
Joined: 6. Sep 2012, 16:43

Re: Discussion: MacOS Bootcamp Partition as a VBox Guest

Post by Sanjeev »

I am grateful to my google search using "how to run windows-7 bootcamp in virtualbox". The website forum that I found most useful is given below and it comes up as first in google search. I found the instructions are simpler, easier and more functional than others.
https://kindlevsmac.wordpress.com/2011/ ... virtualbox
Sanjeev
Posts: 3
Joined: 6. Sep 2012, 16:43

Re: Discussion: MacOS Bootcamp Partition as a VBox Guest

Post by Sanjeev »

I am able to access & start Windows 7 on (C:) Bootcamp partition in a VirtualBox VM Guest on Mac Os X Host which is good
Problem: Guest Windows 7 on (C:) Bootcamp partition loads but not beyond 'Startup repair ' logs and System restore logs accessed though VBVmachine on Mac Os X Host :( :(

It loads shows Windows Error Recovery * launches 'Startup repair' after a wait with option 'Start Windows normally" * for 30 seconds. I can select and attempt 'Windows repair', 'System restore'. Conclusion of the results

Startup repair can not repair this computer automatically Problem detail Problem Signature says BadPatch

Windows can not repair this computer automatically. If you have recently attached a device to this computer such as a camera or portable music player, remove it and restart your computer. If you continue to see this message contact your system administrator or computer manufacturer for assistance. Root cause Error code 0x0.

I tried Startup repair, System restore though VBVmachine but without success beyond logs. Not tried System Image recovery, Command Prompt,
* Even if 'Start Windows normally' option is selected Blue screen with white text flashes for few milliseconds and goes to Windows Error Recovery screen giving options Launch Startup repair (Recommended) Or Start Windows normally:

Sequence of events
Bootcamp running appears in VirtualBox VM & allows access to Windows 7 on (C:) BOOTCAMP partition which is good
Starting Windows
Windows is loading files - Windows Error Recovery * - launches 'Startup repair'
Startup repair is checking Windows for problem

Startup repair can not repair this computer automatically
View problem detail
Problem Signature
Problem event name StartupRepair offline
Problem Signature 01: 6.1.7600.16385
Problem Signature 02: 6.1.7600.16385
Problem Signature 03: Unknown
Problem Signature 04: 21200412
Problem Signature 05: AutoFailover
Problem Signature 06: 18
Problem Signature 07: BadPatch
OS Version: 6.1.7600.2.0.0.256.1
Locale ID: 1033

Windows can not repair this computer automatically
View diagnostic and repair details
View advanced option for System recovery and support ( System recovery options: Restore & etc tried though VBVmachine No success )

View diagnostic and repair details - Diagnostic and repair details - Startup repair diagnosis and repair log:
Session details
System Disk = \ device\ Harddisk0
Windows dir = C \ Windows
AutoChk Run= 0
Number of Root causes =1

Test performed
---------------------
Updates
System disk test
Disk failure diagnosis
Disk metadata diagnosis
Target OS Test
Volume content Check
Boot manager diagnosis
System boot log diagnosis
Event log diagnosis
Internal state Check

Name: All above Test
Result: completed successfully. Error code: 0x0
Time taken: Varies 10 - 240 ms

Root cause found
Startup Repair has tried several times but still can not determine the cause of the problem

Apple Technical support suggested reinstall VirtualBox VM . I did. Problem persists.

On separate booting in to Windows 7 on (C:) Bootcamp partition is mostly fine. However in 1 out of 10 it gives options to start in safe mode, Or Start Windows normally or Launch Startup repair. I select and it can Start Windows normally most of the times

:idea: Should I try reinstalling Windows 7 on (C:) Bootcamp partition by using my original genuine Windows 7 CD? :?:
blueytoo
Posts: 13
Joined: 20. Oct 2012, 08:32

Re: Discussion: MacOS Bootcamp Partition as a VBox Guest

Post by blueytoo »

I used this guide and it mostly works fine. Needed some fiddles with VB hardware settings to get the windows repair to not happen.

<web>luckyviplav<dot>blogspot<dot>com<dot>au/2011/06/windows-7-on-mac-os-x-through-virtual<dot>html

more stuff here
<web>phaq<dot>phunsites<dot>net/2011/03/05/sharing-windows-7-between-boot-camp-and-virtualbox/

Just having trouble with the bootcampcontrolpanel under VB. Partial fix here:
<web>apple<dot>stackexchange<dot>com/questions/59048/macbook-pro-retina-and-windows-8/59132#59132

Anyone have any ideas why the boot camp control panel has different settings available in bootcamp vs under VB?

(Oh how I hate that I can't post URLs yet)

PS Setting guest to use more than one processor will kill USB support. Bug #7462.
----
MBP 17" early 2011 2.3GHz; MacOS 10.6.8 Server (64bit); Windows7 (64bit); VB 4.2.18; BootCamp 3.3
phophollety
Posts: 3
Joined: 22. May 2013, 18:31

Re: Discussion: MacOS Bootcamp Partition as a VBox Guest

Post by phophollety »

Hello,

I've been having the very same problem, I'm running Mac OSX 10.8.2 and VB 4.2.12 r84980.

I've installed WIN7 as bootcamp partition, it works fine.

I've created the raw partition and add as a VM. But when launched I got this screen:

Image

If I try to recover or boot normally it just reboot and I get the same screen.

If I boot natively the Win 7 I need to repair to make it work.

Anyone can help?
JimBushWhack
Posts: 77
Joined: 1. Sep 2008, 23:07
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win XP on iMac; Win 7 on MacBook pro + bootcamp
Location: SF Bay Area; California, USA

Re: Discussion: MacOS Bootcamp Partition as a VBox Guest

Post by JimBushWhack »

Sorry, I no longer own the laptop with the BootCamp version of Windows 7 on it. When I got my new MacBook Pro, I ended up just building a regular VBox Virtual Machine for Windows 7, since I rarely use windows any longer.

But, I do recall some issues I had originally with the BootCamp/VBox setup that may be the root problem here. Thinking back, I setup my BootCamp version of Windows 7 using the 64 Bit version of Windows 7. This came up with no problems. But when I tried to setup a VBox virtual machine against this BootCamp partition, I could not get Windows to boot correctly through the VM scaffolding. I think (but I am not sure) I got the same "Window Failed to Start" screen as shown in blueytoo's discussion entry.

I subsequently scrapped the Windows 7 BootCamp/VBox setup. I then rebuilt a BootCamp setup using the 32 Bit version of Windows 7, since the package I bought had both 64 and 32 bit versions. After successfully setting up the BootCamp version, I setup the VBox scaffolding as described in the tutorial. This all came up with no problems.

So, this may (or may not) be your problem. I don't have time right now, but maybe in a week or so, I will try setting up a 64Bit BootCamp version of Windows 7 on my new laptop and then use the tutorial and see if I can duplicate the problem. If so, I will let you know, unless someone has confirmed my theory before then.
phophollety
Posts: 3
Joined: 22. May 2013, 18:31

Re: Discussion: MacOS Bootcamp Partition as a VBox Guest

Post by phophollety »

I'm running the WIN 7 64 in bootcamp, I was able to make it boot via virtual box, I just add as preferences in processor tab:

"Enable IO APIC" and worked...
JimBushWhack
Posts: 77
Joined: 1. Sep 2008, 23:07
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win XP on iMac; Win 7 on MacBook pro + bootcamp
Location: SF Bay Area; California, USA

Re: Discussion: MacOS Bootcamp Partition as a VBox Guest

Post by JimBushWhack »

I have setup another 64 Bit Windows 7 Bootcamp partition (40 GB) on my circa 2012 MacBook Pro running Mountain Lion (10.8.3) and setup Windows 7 such that it came up fine from the BootCamp partition. I just tried setting up the VBox (2.2.12) scaffolding as described in my tutorial. I duplicated the problem above with the "Windows Failed to Start" screen as shown above. I tried turning on the "Enable IO APIC" preference. But that had no effect. Perhaps phophoilety could show us his entire configuration? Also, would the other folks who exhibited this problem chime in and tell us if they were running with a 64 bit Windows 7 system and if the "Enable IO APIC" preference change allowed their setup to work or not?
ChipMcK
Volunteer
Posts: 1095
Joined: 20. May 2009, 02:17
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Windows, OSX
Location: U S of A

Re: Discussion: MacOS Bootcamp Partition as a VBox Guest

Post by ChipMcK »

You did note that the raw image is IDE, not lsilogic (scsi) and not buslogic (scsi)
phophollety
Posts: 3
Joined: 22. May 2013, 18:31

Re: Discussion: MacOS Bootcamp Partition as a VBox Guest

Post by phophollety »

ChipMcK wrote:You did note that the raw image is IDE, not lsilogic (scsi) and not buslogic (scsi)

Thats right, also the controller is running as IDE ICH6
Post Reply