Using VirtualBox to Load the Boot Camp Partition

Boot Camp is very convenient as it lets me run Windows 7 programs that I need such as Microsoft Visual Studio.  It would be even more convenient if I could open it while in OS X for the times I don’t need the best performance (as I would if were playing 3-D games for example).  There are virtual machine programs available that advertise that ability, such as Parallels but I found a post that claims to do the same using VirtualBox, which is free.  I thought I’d give it a shot.  The post is at http://phaq.phunsites.net/2011/03/05/sharing-windows-7-between-boot-camp-and-virtualbox/.  He indirectly referenced http://luckyviplav.blogspot.com/2011/06/windows-7-on-mac-os-x-through-virtual.html in his steps.

To go through the steps, I had to set up a password on my user account on the Mac.  To make the changes below, it requires you to have a password to authorize them as an administrator.  Also be aware that one thing about VirtualBox is you often have to move the mouse after clicking a button, otherwise it will often not recognize the click (at least while using a touchpad/trackpad).

The steps I took on my MacBook Pro running OS X Lion 10.7.4 were:

  1. Installed Windows 7 in Boot Camp (already done)
  2. Installed VirtualBox (current version – 4.1.18 r78361)
  3. Launched Disk Utility
  4. Highlighted the BOOTCAMP partition and clicked Info
  5. Made note of the Disk Identifier (disk0s4 – though his was disk0s3)
  6. Opened Terminal
  7. Typed pwd (print working directory) to confirm I was at my home directory (Users/USERNAME).  Note: “cd ~” will get you there if you’re not.
  8. Made directories and went to them
    1. Typed mkdir “VirtualBox VMs” (the quotes are necessary because of the space)
    2. Typed cd “VirtualBox VMs”
    3. Typed mkdir Win7onMBP
    4. Typed cd Win7onMBP
  9. Changed permissions by typing: sudo chmod 777 /dev/disk0s4 (remember his was disk0s3)
  10. Ejected the BOOTCAMP partition by highlighting it in the Finder, right-clicking on it and chose eject (This was important – it wasn’t immediately obvious that I had to eject it since he said he didn’t have to nor was it obvious how to do it)
  11. [I skipped the step he had next which makes my steps 9 and 10 automatically run upon rebooting because I can’t clone the Boot Camp partition if it’s dismounted.  I did it a different way instead and moved it to step 14.]
  12. Created the VirtualBox RAW disk files by typing: sudo VBoxManage internalcommands createrawvmdk -rawdisk /dev/disk0 -filename win7raw.vmdk -partitions 4 (his was -partitions 3 because he had disk0s3 in my step 5)
  13. Changed owners of the two files (I’m still not sure why I had to but I definitely had to) by typing: sudo chown USERNAME *.vmdk (replaced USERNAME with my real username)
  14. I made a script that makes the necessary changes mentioned in step 11.  The changes last until you reboot OS X.  I can simply double click the script (run it) before launching Virtual Box if the changes haven’t already been made. (The script how-to came from kaz-k at https://discussions.apple.com/thread/3175771)
    1. Launched TextEdit
    2. Typed the lines he had (adding sudo before chmod):
      1. #grant VirtualBox permissions to Boot Camp partition
      2. #
      3. sudo chmod 777 /dev/disk0s4
      4. diskutil unmount /Volumes/BOOTCAMP
    3. I saved it as a plain text file to the desktop and named it “Virtual Box Permissions.command” (note the file extension command instead of txt)
    4. Back in Terminal, I typed cd ~ (to get back to the home directory)
    5. Typed cd Desktop
    6. Typed chmod +x “Virtual Box Permissions.command” (to make it executable)
  15. In VirtualBox
    1. Clicked “New” and clicked “Continue”
    2. Typed Win7onMBP (Microsoft Windows and Windows 7 were automatically selected) and clicked “Continue”
    3. Set the memory size to 1024 MB (1 GB) and clicked “Continue”
    4. Pressed the “Use existing hard disk” button
    5. Clicked the picture of the folder (Choose a virtural hard disk file…)
    6. The directory Win7onMBP was already highlighted so I clicked win7raw.vmdk and clicked “Open”
    7. The window closed and I clicked “Continue” in the original window
    8. Clicked “Create”
    9. Back on the main VirtualBox screen, I clicked “Settings”
    10. [I skipped the part about changing the disk to IDE – it caused problems and ended up being unnecessary]
    11. At the top, I clicked “System”  and on the “Motherboard” tab, checked “Enable IO APIC” (This was mentioned in the comments on his site)
    12. At the top, I clicked “Display”, and changed the Video Memory from 16 MB to 128 MB (for step 21 below) and clicked “OK”
  16. Next up was to press “Start” in VirtualBox.  A message shows up about Auto capture keyboard.  It notes the host key is the left COMMAND key.  I pressed “OK”
  17. It showed a mouse pointer integration message so I clicked “OK”
  18. Windows 7 loaded like a charm.  A message popped up saying “Installing device driver software.”  It then said “Device driver software was not successfully installed.” It wanted to restart but before doing so, I set the Network Location to Home.
  19. After restarting, things seemed fine.  Device Manager showed an exclamation mark for “Base System Device” under “Other devices” but it went away later.
  20. Next up was installing Virtual Box Guest Additions.  In the VirtualBox menu at the top, I clicked Devices, then “Install Guest Additions…”
  21. An AutoPlay screen popped up in Windows 7 and I clicked “Run VBoxWindowsAdditions.exe” and installed it.  I opted to add the experimental Direct3D Support though it warned me that it required at least 128 MB of Display memory (which is why I added step 15-L above).

That’s it.  I now had the Boot Camp Windows 7 installation working in Virtual Box running in OS X.  The exclamation mark I mentioned went away after installing Additions.  When I reboot, I just need to double click the file Virtual Box Permissions.command (made in step 14), then run Virtual Box as normal.

I wouldn’t play a graphically intensive Windows game this way but for running things like Visual Studio, it’s perfect!  I can even press COMMAND-F to go full-screen.  If you’re already running Boot Camp, I highly recommend trying this VirtualBox installation out if you think it might be useful.  After all, it’s free!

A side-effect is the left Windows key no longer works.  VirtualBox is using it as its host key.  The right Windows key works fine though.  You’ll have to press the FUNCTION key in addition to the F keys for things such as ALT-F4 if you leave OS X to its default configuration for those keys.  Enjoy!