How To: Run Windows 7 (Bootcamp) in VirtualBox

Bootcamp is great and all, but… the fact that we have to reboot is not !

Sometimes you want to do a little task that really has to be run on Windows or there’s no alternative software for Mac, but you don’t want to reboot into Bootcamp to do it. And you want to keep Bootcamp, since it lets you run Windows to its potential. Well, VirtualBox can certainly help you ! It’s a great piece of freeware that I recently fell in love with.

It lets you startup Windows 7 that you have on Bootcamp as a virtual machine (VM) relatively easy. So the data stays in sync whether you boot up from Bootcamp or VBox inside Mac OS (since it’s really the same installation). Instead of creating a virtual hard disk file like normal virtual machine, it uses a small special file that essential let the VM access the real physical disk.

Step-by-step guide:

  1. Install VirtualBox in Mac OS X.
  2. Create New Virtual Machine, follow the step until you have to select Virtual Hard Disk, leave it like that. The steps are,
    • Name your VM, select Windows 7, click Continue (I name mine “Bootcamp”)
    • Allocate Memory (Ram) for the VM (essentially, you should give at least 1 GB, 1024 MB), press Continue
    • Virtual Hard Disk, leave it like that for now, don’t close it or anything, we’ll do something else before continue.
      .
  3. Open Finder, go to Home Directory, look for folder named “VirtualBox VMs”, make sure it contains your VM folder (mine is Bootcamp).
  4. Open Terminal (Applications > Utilities > Terminal) and type these commands,
    • diskutil list

      press Enter/Return, then look under “/dev/disk0″ find the partition number associate with your VM (Bootcamp). It should be 4.

    • diskutil unmount /dev/disk0s4

      If your number from previous command is not 4, replace it N with yours, in disk0sN. (Do the same in the next command)

    • sudo chmod 777 /dev/disk0s4
    • sudo vboxmanage internalcommands listpartitions -rawdisk /dev/disk0

      Type it all in one line, and press Enter/Return

      • Type your Admin password (should be your own password). Nothing will show while you’re typing the password, and it’s normal, keep typing and make sure you type correctly. Then press Enter.
      • It will show a Partitions List. This time you’ll not see their names. So make your paritition 4 (or whatever yours is) is the Bootcamp partition. (Compare the size)
        .
    • cd VirtualBox VMs/Bootcamp/

      Type cd, space, then Virt and press tab, Terminal will automatically complete the folder name for you. Type Bootcamp (VM name) and press Enter.

    • sudo vboxmanage internalcommands createrawvmdk -rawdisk /dev/disk0 -filename "win7.vmdk" -partitions 4

      Type it all in one line, and press Enter/Return

      • If the process is successful. It will show “RAW host disk access VMDK file win7.vmdk created successfully.”
      • Go back to Finder, look inside Bootcamp Folder (or your VM folder) that win7.vmdk and win7-pt.vmdk are there.
        .
    • sudo chown (username) win7*.vmdk
      • Replace (username) with your Account name (If you’re not sure, type whoami in Terminal and press Enter).
      • Press Enter and type your password.
        .
  5. Go back to VirtualBox. Select Use existing hard disk and click yellow folder on the right side to find and select the created win7.vmdk, and click Continue.
  6. VirtualBox will present you a Summary page, click Done.
  7. Open up Settings of the created VM, configure the settings to your liking.
    • Network: you should select Bridge Adaptor, and the network interface you use to connect to the Internet.
    • Shared Folders: select a folder, so you can share files between Mac and Windows while running the VM. Don’t forget to tick Auto-mount.
      .
  8. Start up the VM.
    • Install Guest Additions (Select from Menu Bar in Mac while running the VM) Device > Install Guest Additions, then in Windows 7, a virtual CD will be there. Install and restart the VM.
    • After restart, if the Shared Folder does not show up in Computer, click Map network drive in Toolbar and look for your Shared Folder and tick Reconnect at login.
    • If you use VBox’s Seamless Mode, it’ll be like Windows app is running on Mac natively (of course not truly natively), pretty cool.
      .
  9. Back to Mac OS, this is what you need to know.
    • Before starting up Bootcamp in VM, you’ll always have to unmount Bootcamp partition first. Also you have to grant permission to access the data on the disk. (2nd and 3rd Termianl commands in step 4)
    • If you want this to happen automatically after you login to Mac account, open up Terminal and follow the steps,

        1. sudo nano /etc/rc.local
        2. Type your password, Enter. Teminal will show a relatively blank page.
        3. Type these lines in (change N number in /dev/disk0sN to match your Bootcamp disk)
          # grant VBox permissions to Bootcamp
          sudo chmod 777 /dev/disk0s4
          diskutil unmount /dev/disk0s4
        4. Press Control+O , and Enter to save chanegs.
        5. Press Control+X to exit.
          .
  10. End of Story :cool:
:grin:
Note: I did this long time ago, and followed various tutorials, which I didn’t keep the links. So the credit goes to people out there who originally wrote the tutorials, and you can also check out VirtualBox Manual section 9 for more technical details.

About Dekpient

A crazy kid who never wants to grow up.

5 thoughts on “How To: Run Windows 7 (Bootcamp) in VirtualBox

  1. [...] How To: Run Windows 7 (Bootcamp) in VirtualBox (kindlevsmac.wordpress.com) [...]

  2. [...] my previous post on how to run Bootcamp in VirtualBox, I just realize I forget to mention this launching tip, so here it [...]

  3. Raja says:

    Under VirtualBix the newly created vmdk file win7.vmdk shows up as the full size of my Mac HD rather than the size of the bootcamp partition. That made me nervous, so did not go ahead. Am I doing something wrong or is this correct?

    • Dekpient says:

      This might answer your questions (let me know if I get it right).
      First, win7.vmdk file size should be under 1KB, that’s very small (as it actually kinda point to the actual bootcamp partition).
      And second, make sure you got #4 right, when you “createrawvmdk” you should specify the bootcamp partition number at the end, so it only represents the bootcamp partition, not the whole disk.

      cheers!

Share your thoughts !! :D

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s