Sunday, June 5, 2011

Windows 7 on Mac OS X through Virtual Box

Using Windows 7 installed in a Bootcamp partition from Mac OS X simultaneously

This guide will help you set up access to your Windows 7 installation directly from Mac OS X. You can follow this simple guide without technical knowledge and get your Windows 7 Virtual Box, up and running without any hassle. What all you need to do is, “Follow the guide blindly”.

Software Required: Virtual Box 3.2.6 or later

Time Required: 30 mins

Things we will do in this guide:

  1. Prepare the Mac system for installation
  2. Configure Virtual Box for the first boot
  3. Install Virtual Box Guest Additions for seamless full screen usage
  4. Install Audio Drivers in Windows 7
  5. Use connected USB Devices in Windows 7
  6. Setup Shared Folder between Mac and Windows 7 and access it
  7. FAQs
    1. Virtual Box Errors
    2. Fatal: No Bootable Medium Found! System Halted.
    3. Windows “Blue Screen of Death”
  8. References

1. Prepare the Mac system for installation

Before configuring Virtual Box, we need to prepare Mac OS X to work seamlessly with Windows 7 Partition. For that, the Bootcamp drive should be unmounted every time we work with Virtual Box. Following steps will guide you to unmount the Bootcamp drive by default whenever you start your Mac OS X.

Open a Terminal window and type the following command:

$sudo vi /etc/rc.local
Password:
Enter the Admin password.

It opens rc.local file in vi editor. To make changes to the existing or newly created file, you need to type “ i “ (small i without quotes) and enter the following in two separate lines:

diskutil umount /Volumes/BOOTCAMP
sudo chmod 777 /dev/disk0s3

After that you need to press “esc” and type “ : “ (without quotes) and type “ x “ (without quotes).

Now type the following to check whether the procedure you have done is right or not:

$cat /etc/rc.local

The following output should appear:

cat command to check rc.local file
cat command to check rc.local file

Then check whether the file has appropriate permissions by typing the following:

$ls –l /etc/rc.local

The following output should appear:

ls -l command to check the file permissions
ls -l command to check the file permissions

If the permissions are not like –rw-r-r-- , then change the permissions by typing the following commands:

$sudo chown root:wheel /etc/rc.local
$sudo chmod 644 /etc/rc.local

Restart the system

The above steps will unmount the Bootcamp drive permanently. If you don’t want to unmount the Bootcamp drive permanently, you can unmount that temporarily by typing the following commands without following any of the above steps:

  1. First Eject Bootcamp drive by right clicking on the drive and clicking “Eject”
  2. Type the following to make it workable with Virtual Box:
$sudo chmod 777 /dev/disk0s3

You have successfully completed the process of configuring your Mac OS X for the installation.

2. Configure Virtual Box for the first boot

Open Terminal Window and type following command (Make sure that the command is in a single continuous line):

$sudo VBoxManage internalcommands createrawvmdk -rawdisk /dev/disk0 -filename win7raw.vmdk -partitions 3

If you are facing problems, copy and paste the command from here:

sudo VBoxManage internalcommands createrawvmdk -rawdisk /dev/disk0 -filename win7raw.vmdk -partitions 3

It will create 2 files, “win7raw.vmdk” and “win7raw-pt.vmdk” in your root directory. After the successful creation of the files, type:

$sudo chown [admin-user-name] *.vmdk

The most difficult steps of the configuration are complete.

Now, open Virtual Box.

  1. Click on “New”
  2. Click “Continue”
  3. Type the name “Windows 7” and select “Microsoft Windows” and “Windows 7” if they are not selected automatically.
  4. Set your RAM of at least 1 GB
  5. Check “Boot Hard Disk” and check “Use existing hard disk”
    1. Click on “Browse” button
    2. Click “Add”
    3. Go to your root folder and select “win7raw.vmdk” and click “Open”
    4. Click “Select”. If any errors occur, please check you have completed all the procedures specified in Step 1.
    5. Click “Continue”
    6. Click “Done”

Now, you need to attach your “Windows 7” partition to this Virtual Machine you have created.

  1. Select your “Windows 7” Virtual Machine
  2. Click on “Settings”
  3. Click on “Storage” Tab
  4. Select IDE Controller
  5. Click “Add Hard Disk” which will directly add your “win7raw.vmdk”
  6. In the “Attributes” column of “Storage” tab, set “Type” as “ICH6”
  7. Click “Ok”
Attach Disk Controller to Virtual Box
Attach Disk Controller to Virtual Box

You have successfully configured your Virtual Box with your Windows 7 Partition.

Successfully configured Virtual Box for Windows 7
Successfully configured Virtual Box for Windows 7

Click on “Start” to boot your “Windows 7” partition and allow it to install all the necessary drivers after login to your windows account.

Here, typically the window size is set to a resolution of 800x600. You can maximize your resolution by following the step 3.

3. Install Virtual Box Guest Additions for seamless full screen usage

Virtual Box Guest Additions are required for High Resolution Video Support, Time Synchronization, Seamless Windows, Shared Folders, Mouse Pointer Integration, Shared Clipboard and Automated Logons.

If you have already tried putting your virtual machine on full screen mode and didn’t get the resolution better than 800x600 or some standard resolution, here is the solution:

  1. Go to the “Applications” folder in your Mac OS X
  2. Locate Virtual Box Package
  3. Right click on the Virtual Box and click on “Show Package Contents”
  4. Browse through and locate “ContentsĂ MacOSĂ VBoxGuestAdditions.iso”

Now, start your “Windows 7” from Virtual Box

  1. Locate “Devices” in the Menu Bar of the Windows 7 Virtual Box
  2. Click on “CD/DVD Devices”
  3. You will be able to see “VBoxGuestAdditions.iso” file. If you are not able to see it, click on “More CD/DVD Images” and browse for the VBoxGuestAdditions.iso from the folder specified above.
  4. Now find the “VBoxGuestAdditions.iso” mounted as a CD in “My Computer” of Windows 7
  5. Open the drive and click on the appropriate package (32-bit and 64-bit) installer.
  6. After the installation, restart your Windows 7 System.
  7. After restart, Login to the Windows 7
  8. Now click on “Machine” on Virtual Box menu bar and select “Enter Fullscreen Mode” or press Host Key+F

:) You should be able to see your “Windows 7” running in full screen mode with maximum resolution.

4. Install Audio Drivers in Windows 7

I use a Mac Book Pro running on OS X 10.6.2. I faced problem with my audio driver. So I thought of helping the guys facing the same kind of problem with Windows Audio Drivers.

Following are the steps:

  1. Go to “Control Panel”
  2. Select “Device Manager”
  3. You can see your Audio Driver being highlighted for no drivers
  4. Right Click on it and select “Update Driver Software”
  5. Allow it search online
  6. It will automatically download the software and install it.
  7. Restart Windows 7 and you will be happy to hear the Welcome note @ Login Scree

5. Use connected USB Devices in Windows 7

If you have checked that the USB devices which you have connected to your MAC, are not accessible from Windows 7 or, if you are not able to select it from the USB Devices List (Grey Device or the device name is Grey-ed), please follow this procedure.

  1. Shut down your Windows 7 System
  2. Select Windows 7 in Virtual Box
  3. Click on “Settings”
  4. Click on “Ports” tab
  5. Check “Enable USB Controller” and “Enable USB 2.0 Controller”
  6. Click on “Add USB Filter” with all the fields set to empty. If you set all the fields empty, Windows 7 will be able to access all kind of devices, which you attach to the system.
  7. Click “Ok”
  8. Remove all the devices which you want your Windows 7 System to access
  9. Start Windows 7
  10. Make sure that your mouse is in Windows 7 Window
  11. Now attach the USB device.
  12. You can see that your USB device will be installing its drivers comfortably in the system tray.
Adding USB Filters for connecting USB Devices in Windows 7
Adding USB Filters for connecting USB Devices in Windows 7

This completes the section of installing USB Devices

6. Setup Shared Folder between Mac and Windows 7 and access it

  1. Shut down your Windows 7 System
  2. Select Windows 7 in Virtual Box
  3. Click on “Settings”
  4. Click on “Shared Folders” tab
  5. Click on “Add a New Folder Definition”
  6. Browser for the folder which you want to share
  7. It will get directly added to your Machine Folders list
Adding a Shared Folder between Mac OS X and Windows 7
Adding a Shared Folder between Mac OS X and Windows 7

You have successfully added a Shared Folder

You can access the folder by typing the following command in the "Run" dialog box:

\\vboxsvr\[folder-name]

7. FAQs

  1. Virtual Box Errors

    1. Check properly whether you have unmounted Bootcamp drive
    2. Check whether you have given proper permissions to the Disk0s3
$sudo chmod 777 /dev/disk0s3

C. Check whether you have given appropriate ownership to the *.vmdk files

$sudo chown [admin-user-name] *.vmdk

2. Fatal:No Bootable Medium Found! System Halted.

Check whether you have attached the IDE Controller Properly in the “Settings” Menu of Virtual Box

3. Windows “Blue Screen of Death

Check in “Settings” Menu of Virtual Box whether the “Attributes” column of “Storage” tab, set “Type” as “ICH6”

8. References

http://dashes.com/anil/2009/10/how-to-run-windows-7-under-mac-os-x-106-for-free.html

http://www.microsoft.com/windows/windows-7/

http://www.apple.com/macosx/

http://blog.brianguy.com/2009/11/automatically-unmount-boot-camp.html

http://bloggy.kuneri.net/2008/05/16/how-to-share-files-with-virtualbox-between-mac-and-windows/

http://forums.virtualbox.org/viewtopic.php?f=2&t=11729

http://www.virtualbox.org/ticket/495

*********End of Article**********

Excuse me for any mistakes

Thank you very much :) - Viplav (Lucky)

24 comments:

  1. Thanks Viplav for your excellent and orderly account. You guided me all the way through it. Now I'd rather NOT permanently unmount disk0s3. Instead I'd like to unmount it as necessary. What nano command should I put in then? Thank you very much for your guidance.

    ReplyDelete
  2. If you don’t want to unmount the Bootcamp drive permanently, you can unmount that temporarily by typing the following commands:

    First Eject Bootcamp drive by right clicking on the drive and clicking “Eject”

    Type the following to make it workable with Virtual Box:
    $sudo chmod 777 /dev/disk0s3

    ReplyDelete
  3. Viplav - many thanks for your quick answer. Deeply appreciated!
    I have entered the all the commands as listed, and after that, Bootcamp drive is not shown up each time after login, unless I remount it from Disk Utility.
    Is there anyway to undo this change, i.e. I only want to do the temporary unmount as you just mentioned.
    Lots of thanks again!

    ReplyDelete
  4. In the file "/etc/rc.local", check whether the comand "diskutil umount /Volumes/BOOTCAMP" is present. If it is there, delete the line. This should solve the problem.

    ReplyDelete
  5. Great job Viplav! This is really a terrific guide. I have had no joy in accomplishing this configuration, until today!

    This works so well I want to make my windows partition larger (50/50) with the Mac Partition. No resizing with boot camp, but this guide worked so well I am happy to rebuild my windows install!

    Well done.

    ReplyDelete
  6. Your guide is the most detailed instruction so far on this subject!
    I would like to add few more points:
    - Please explain a bit about some terminal commands.
    - Not everyone has windows 7 on partition 3. This is my case because I created another partition for sharing data between Mac and Win before using Virtual box. I took me a while to change your "partition 3" to my "partition 4"

    ReplyDelete
  7. Viplav, I have problem with the size of the win7raw.vmdk. It's too big so there is a warning message "Start up disk is full". How can I reduce the size of the virtual disk?
    Thank,

    ReplyDelete
  8. It is not possible to re-size a bootcamp partition.

    It sounds to me like your configuration is wrong. Most likely you have a partition and a separate vmdk.

    Back up the info you have on your "shared partition" remove all the partitions (except your mac osx), perform the bootcamp install, and then Viplav's procedure. Step 6 should circumvent your need for a "shared partition" but if you still want to make one, create it after the other steps.

    ReplyDelete
  9. i could not add "win7raw.vmdk" to the IDE controller as it caused an error
    instead, "win7raw.vmdk" automatically appeared in the SATA controller already
    but an error occured right after i start installing saying that i need to insert installation disc and restart my computer
    i complete all the previous steps without any problem though

    ReplyDelete
  10. also i'm using virtualbox 4.0.10

    ReplyDelete
  11. Johnny,

    remove the VMDK from the SATA controller, and then add it as IDE/ICH6.

    ReplyDelete
  12. Same issue.. When I try to start windows 7 I get the following.

    Failed to open a session for the virtual machine Windows 7.
    Failed to load VMMR0.r0 (VERR_SUPLIB_WORLD_WRITABLE).
    Unknown error creating VM (VERR_SUPLIB_WORLD_WRITABLE).

    ReplyDelete
  13. > $sudo chmod 777 /dev/disk0s3
    Thanks for this. Helped me with installing Windows7

    ReplyDelete
  14. Check in “Settings” Menu of Virtual Box whether the “Attributes” column of “Storage” tab, set “Type” as “ICH6”

    This did not work for me; however, I selected 'PIIX4' instead of 'ICH6' and it seemed to work fine, no blue screen of death. I am running virtualbox 4.0.12, perhaps your version and mine differ when it comes to which of those 2 should be selected. Hope this helps anyone else with this issue. Your article is otherwise fantastic!

    ReplyDelete
  15. Hello,

    I was attempting to use the above steps with Windows XP instead of Windows 7. I believe I followed all the steps but I get an error saying Windows could not start because of a disk hardware configuration problem and that it could not read from the selected boot disk. It said to check the boot path and hardware.

    Thanks

    ReplyDelete
  16. hey. after pasting “sudo VBoxManage internalcommands createrawvmdk -rawdisk /dev/disk0 -filename win7raw.vmdk -partitions 4″ i got “sudo: VBoxManage: command not found”. should i type something else to make it work or is there other way?

    Cheers guys

    I`m running Mac Os x 10.7.2, Windows 7 Home Premium 64bit

    ReplyDelete
  17. Hi,

    Thank you for these tips. I tried them and managed to see the startup logo of Windows 7. However, it does not fully starts: I get a text message saying that Windows couldn't make it (and it says maybe because of hardware or software change). It gives choices to start Windows normally again or with a recommended way. I tried both but I still get the same issue. Anyone got this issue? I'm on Mac OS X Lion 10.7.2 with a Macbook Pro bought this year.

    ReplyDelete
  18. Hi! Thanks for the guide!

    I had the same problem as Philou; fixed it by ticking the "Enable IO APIC" option in the virtualbox settings for the windows 7 system.

    Hope that helps!

    ReplyDelete
  19. When I start my Windows7 virtual box I get a missing operating system error. All works fine in bootcamp. Any suggestions appreciated

    ReplyDelete
  20. Hi SouthForty. What is most likely happening here is that you have not selected the right partition. (I had this same problem).

    Heres what you should do to fix this. Open a terminal window and type: "diskutil mount disk0s3" without the ". Below that you should get something like "Volume Recovery HD on disk0s3 mounted". If this does not contain the name of your Bootcamp partition (by default:BOOTCAMP) then this is your problem.

    To fix this, try augmenting the last number in the "disk0s3" command to "disk0s4". See if that has the name of the bootcamp partition, if not try "disk0s5" and so on...

    When you finally find the number that works for you, completely restart the tutorial, except for wherever the number "3" appears, replace it with the number you found to work.

    Hope this helps. Mobius5150.

    ReplyDelete
  21. I'm getting this error:

    user-pc:Win7iMac username$ $sudo VBoxManage internalcommands createrawvmdk -rawdisk /dev/disk0 -filename win7raw.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

    My bootcamp partition is on disk0s4

    what should I do?

    ReplyDelete
    Replies
    1. The issue was I was in the directory I had created for the new OS in the VirtualBox VMs dir. The instructions here don't tell you you have to be in your home directory to make the files.

      Also in the instructions to install the Guest Additions, they just tell you to find the .iso in the application, but don't tell you to copy it somwhere like your desktop where the Virtual Machine can find and mount it.

      But other than that, I got it going! Now to figure out 3D support

      Delete
  22. I have the win7raw.vmdk file created but when I go to load it in VirtualBox I get

    Failed to open the hard disk

    could not open the medium

    VD: error VERR_ACCESS_DENIED opening image file

    Details:

    Result Code:
    NS_ERROR_FAILURE (0x80004005)
    Component:
    Medium
    Interface:
    IMedium {aa8167ba-df72-4738-b740-9b84377ba9f1}
    Callee:
    IVirtualBox {2158464a-f706-414b-a8c4-fb589dfc6b62}


    If anyone has any tips that would be greatly appreciated.

    ReplyDelete