Running Bootcamp using VirtualBox [Updated 2011-08-04 for OS X Lion]

UPDATE (2011-08-04)! If you installed OS X Lion and are having problems with “missing operating system” when you boot your virtual machine, it is because Lion installed a new recovery partition that re-arranged the partition numbering scheme. Replace any references to disk0s3 with disk0s4 and “-partitions 3″ with “-partitions 4″. That should get you up and running.

Just wanted to put all this out there so that hopefully other people can find it. I’ll need this again as a reference for when I set up my wife’s laptop as well!
Please note that anything documented here is how it worked for me on my laptop. If you have issues, look for any notes below. If you can’t find an answer, check Google. As a last-ditch effort, you can comment here, but I don’t know if I will have an answer or not. Oh, and each line in the fancy code blocks below starts with #. That way it will hopefully make it easier to read if something is word-wrapped. I forgot I had a GeSHi plug-in installed. Ignore the strikethrough stuff.

First off, get VirtualBox. As of the time of this post, the current version is 3.2.4. Install it per the instructions. The easy part is done!

Now, open Terminal. You will need to make the Bootcamp partition accessible to VirtualBox. Run the following command:

sudo chmod a+rw /dev/disk0s3

Next, we’ll need to build a VirtualBox vmdk image:

1
2
cd /path/to/wherever/you/want/to/keep/files
sudo VBoxManage internalcommands createrawvmdk -rawdisk /dev/disk0 -filename bootcamp.vmdk -partitions 3

And, finally, make the vmdk file accessible:

sudo chmod a+rw /path/to/bootcamp.vmdk

But, don’t get too excited yet. You’ll lose that whole “chmod a+rw” if you reboot. You can build an AppleScript that will do all that fancy stuff and then launch VirtualBox. Go ahead and start the AppleScript Editor and use the following code (replacing your_password_here with your password–it’s compiled, so I think it’s fairly safe):

1
2
3
do shell script "chmod a+rw /dev/disk0s3" password "your_password_here" with administrator privileges
do shell script "chmod a+rw /path/to/your/vmdks/*.vmdk" password "your_password_here" with administrator privileges
do shell script "open -a VirtualBox"

Save the AppleScript as an application. I named mine “VirtualBootcampBox”. If you want to give it an icon, you can download the applet.icns (icon borrowed from here) and copy it to the Contents/Resources directory of the application you created with AppleScript.

That should do it. Open the application that you created with AppleScript and point your new VirtualBox machine to the vmdk you created and have fun!

This entry was posted in Geek Stuff and tagged , , . Bookmark the permalink.

32 Responses to Running Bootcamp using VirtualBox [Updated 2011-08-04 for OS X Lion]

  1. Clark Gaylord says:

    Thanks for the post — very helpful.

    I was unable to do execute the createrawvmdk since the resource /dev/disk0s3 was in use:
    VBoxManage: error: VMDK: could not open raw partition file ‘/dev/disk0s3′
    VBoxManage: error: Error code VERR_RESOURCE_BUSY at /Users/vbox/tinderbox/mac-rel/src/VBox/Storage/VMDK.cpp(3764) in function int vmdkCreateRawImage(VMDKIMAGE*, VBOXHDDRAW*, uint64_t)
    VBoxManage: error: Cannot create the raw disk VMDK: VERR_RESOURCE_BUSY
    VBoxManage: error: The raw disk vmdk file was not created

    It occurred to me the issue was that my bootcamp partition was mounted. If you open a Finder window, you may see your bootcamp partition as a drive (in my case it was called BOOTCAMP). Unmounting this fixed the problem:

    $ sudo umount /Volumes/BOOTCAMP/
    $ sudo VBoxManage internalcommands createrawvmdk -rawdisk /dev/disk0 -filename /var/local/vmdk/bootcamp.vmdk -partitions 3
    RAW host disk access VMDK file /var/local/vmdk/bootcamp.vmdk created successfully.

  2. Sam B says:

    I unmounted the Bootcamp partition and followed all of your steps. It seemed to work perfectly. However, when I tried to run VirtualBox I got a windows error during bootup that says “Windows could not start because of a computer disk hardware configuration problem”. Any ideas on whats going on? This is with the Bootcamp partition still unmounted. If its mounted, I can’t even get this far.

  3. Rich says:

    I have Lion with a Bootcamp partition and XP installed. I can’t get the VBoxManage command to work:

    $ sudo chmod a+rw /dev/disk0s4

    WARNING: Improper use of the sudo command could lead to data loss
    or the deletion of important system files. Please double-check your
    typing when using sudo. Type “man sudo” for more information.

    To proceed, enter your password, or type Ctrl-C to abort.

    Password:
    $ cd /virtualdisks
    $ VBoxManage internalcommands createrawvmdk -rawdisk /dev/disk0 -filename bootcamp.vmdk -partitions 4
    VBoxManage: error: Cannot open the raw disk ‘/dev/disk0′: VERR_ACCESS_DENIED
    VBoxManage: error: The raw disk vmdk file was not created

    • Garrett says:

      My examples are using my MacBook Pro, so it’s entirely possible that your Mac may have a slightly different setup. The easiest way I know to figure out the correct partition is to launch Terminal and then type “df -h” and look for the line that has your Bootcamp partition (usually something like /Volumes/Bootcamp). The first column, Filesystem, will list the disk number and partition, /dev/disk0s4 in my case. In that case, you’ll want to replace all references of “/dev/disk0″ to whatever your device is. The “4″ is the partition number, so you’ll want to use your partition number in place of any references to the number “4″ in the examples.

      I hope this helps!

  4. This is my version of the script that seems to work for me. It seems that in this new version of the script, the author did not include the need to unmount the bootcamp partition:


    --Make the BOOTCAMP partition writeable

    do shell script "chmod a+rw /dev/disk0s4" password "your_password_here" with administrator privileges
    do shell script "chmod a+rw /path/to/your/vmdks/*.vmdk" password "your_password_here" with administrator privileges

    tell application "Finder"

    if exists "BOOTCAMP" then

    --Eject BOOTCAMP Volume if mounted

    do shell script "umount -f /Volumes/Bootcamp" with administrator privileges

    end if

    end tell

    --Launch Virtual Machine

    do shell script "vboxmanage startvm name_of_virtual_machine"

  5. dasa says:

    I.
    I get this error when i try to setup the image in VB:
    The medium ‘/Users/Black_Dasa/bootcamp.vmdk’ can’t be used as the requested device type.
    Exit Code: NS_ERROR_FAILURE (0×80004005)
    Component: Medium
    Interface: IMedium {53f9cc0c-e0fd-40a5-a404-a7a5272082cd}
    Caller: IVirtualBox {c28be65f-1a8f-43b4-81f1-eb60cb516e66}

    How can i solve?

    ps: great article.

  6. conanlive says:

    i followed the steps as shown below to do it. BUT, there is still “Window Error Recovery” when click start to run it .
    Error message:
    “Window Error Recovery
    Window failed to start. A recent hardware or software change might be the cause

    If Window files have been damaged or configured incorrectly. Startup Repair can help diagnose and fix the problem. If power was interrupted during startup, choose Start Windows Normally. (Use the arrow keys to highlight your choice.)

    Launch startup Repair(Recommend)
    Start Windows Normally
    …”

    When i click either “Launch startup Repair” or “Start Windows Normally”, it can’t work well. Anything wrong?Thx.

    i used bootcamp version 4.0.1 and VirtualBox version 4.1.0
    –>sudo umount /Volumes/BOOTCAMP
    –>sudo chmod a+rw /dev/disk0s4
    –>sudo VBoxManage internalcommands createrawvmdk -rawdisk /dev/disk0 -filename bootcamp.vmdk -partitions 4
    –>sudo chmod a+rw bootcamp.vmdk
    –> setup virtualbox with window 7 bootcamp.vmdk
    –> click start

  7. daniel says:

    @ conanlive in virtual box , when vm is turned off, press right click->settings on your win 7 vm.

    go to “storage” tab , remove the controller “controller SATA” node (which includes your bootcamp image) then add it to “controller IDE” node.

  8. conanlive says:

    I can’t usefully run Virtualbox in full-screen mode. I switched to full-screen, but the full screen consisted of the window surrounded by black space. Where i can find installation of guest additions in mac os x?

  9. Marc says:

    Hi,
    I have the same issue as conanlive, however Daniel’s solution does not fix the issue and I cannot get bootcamp W7 to boot in VBox. Same situation as conanlive, switch to IDE no help.
    Mac OS X 10.7.2, VBox 4.1.4.
    Marc

  10. JP says:

    @Marc I had the same problem as you and Daniel, I tried what Daniel suggested and it didn’t work either. Finally I played around with 2 different things.

    In settings, you have an option for the Chipset between PIIX3 and ICH9
    and in storage, on the IDE Controller, you have 3 different types.

    So in total, you have a total of 6 possible combination. Try them all and see which one works. For me, it was PIIX3 in the chipset and ICH6 in the Type for the IDE Controller.

    Hope it helps.

  11. Ben Reilly says:

    Just want to confirm that for Windows 7 (64-bit) on OS X Lion, you need to use the /dev/disk0s4 and partition 4 options, and also need to remove the SATA Controller in the VirtualBox “Storage” options. Load the vmdk into the IDE Controller instead.

    Like JP, the PIIX3 chipset and ICH6 IDE Controller worked fine for me.

    Thanks a lot for posting this. Glad to have access to my Bootcamp partition without rebooting and without having to buy VM software.

  12. Vijay-Kumar Solanki says:

    When I follow the steps, and use the 2nd AppleScript script – using 3 instead of 4 ( I’m on Snow Leopard ), I get this message from AppleScript:
    VBoxManage: error: Could not find a registered machine named ‘bootcamp.vmdk’
    VBoxManage: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBox, interface IVirtualBox, callee nsISupports
    Context: “FindMachine(Bstr(pszVM).raw(), machine.asOutParam())” at line 544 of file VBoxManageMisc.cpp

    Did I do something wrong?

    TIA – Vijay

  13. Marc says:

    @JP: Thanks a lot for your help. It worked for me with chipset PIIX3 and PIIX4.
    Great tip!
    Marc

  14. Foebu says:

    Thank you for your tips, guys. If it can help someone, my machine works with ICH9 and ICH6. ;)

  15. Bryant says:

    Hi,
    I have gone through all the steps and setup virtualbox to run my bootcamp partition. I am using Snow Leopard OSX 10.6.8. When I go to start bootcamp I get this error:
    Windows could not start because of a computer disk hardware configuration problem.
    Could not read from the selected boot disk. Check boot path and disk hardware.
    Please check the windows documentation about hardware disk configuration and your hardware reference manuals for additional information.

    I’m not exactly sure what I should do to run bootcamp.

  16. Raja says:

    I followed the instructions to create the raw partition (I run OSX Lion – so it is partition s4) and vmdk is created successfully. When I create a new VM in VB and select the bootcamp.vmdk – the disk size is shown as 698.64 GB! The bootcamp partition is only 90.81 GB. I was nervous to proceed, so cancelled out of it. Any help will be much appreciated.

  17. Barry says:

    Thanks for the instructions. I followed the modified instructions for Lion. using disk0s4 and -partitions 4. I got to the part where I attach the .vmdk file to the New virtualbox virtual image, but it says the virtual size is 465GB which is approximately the size of my HFS partition, rather than 30GB which is the size of my Bootcamp partiton. I am highly suspicious about starting this image in case it corrupts my HFS partition. Is a hugely greater reported size of partition “normal?”

  18. Martino says:

    Did anyone run into network connection issues? I tried both NAT and Bridged adapters and windows still says there is no network adapter connected?

  19. LE says:

    Hi,
    I tried all the steps but when I try to boot windows, I get the blue screen of death no matter what I do. When I chose any other controller than the ICH6, I get a BAD_POOL_CALLER. When I chose ICH6, it still crashes but it doesn’t say that. Can anybody help me?

  20. Evan says:

    Hi, I have created the bootcamp.vmdk file successfully by unmounting my XP partition beforehand, but now when I try to launch the file in VirtualBox it doesn’t run the partition and says the GUI says I still need to create one. How can I launch the .vmdk file so that XP will run?

  21. erbY988 says:

    Hi guys,
    have created successful my virtual partition to start my bootcamp-partition from OS X without restart.
    But i can’t solve the problem with the network – don’t get an internet-connection on my Win7 in VirtualBox on any network-settings in VirtualBox.
    Do someone solve this problem and is able to help me???

    Thanks for your time,
    erbY988

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>