VirtualBox
I recently ended up acquiring a Windows 7 Professional license. While I rarely have a need for Windows, that one rare instance is important. Many of the bank's web interfaces are tightly dependent on IE. I do have a copy of CrossOver but that doesn't help much. Most times, IE crashes when trying to render pages. Must be having some OLE dependency.
So I convinced myself to install Windows7. For my banking needs and also to catch-up on how that platform has been doing. From my limited usage, my current impression has been that Windows 7 is a great revive. [passwordless] sudo is conceptually implemented into Windows 7. I'm not sure how good that would be given that most users would have the tendency to just click on 'Yes' without paying attention to the pop-up. Anyways.....I installed Windows 7 onto one of my spare partitions to get the full experience (than doing it in a VM image).
Reboot is pain... This is what made me look at possibilities of using my installed copy of Windows 7 into a VM configuration. I've been using KVM for things here and there but its UI kept me away. Even with virt-manager's existence over a year or two, I think they still haven't reached what qemulator was early. (Just realized that qemulator now is re-branded VirtualBricks). I also had had looked at VirtualBox sometime before, so now was the right time to try it again. And it impressed..........
Requirement
- Use my installed OS Image from the physical partition
- Well integrated User Interface
Req1
VirutalBox just rocked. There's pretty decent documentation available on their website covering all aspect of the product. This blog entry is also a good starting point for Req1. To use the physical partition as the Guest Image for the VM, the following command is required.
VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk -rawdisk /dev/sda -partitions 1,2,3 -relative -register
The docs have all the details but I'll mention the noteworthy parts. This is an advanced command not available in the UI. We register our disk/partitions to the vmdk to be sued with the VM. The -partitions 1,2,3 is important. This basically defines the config as, "Attach my disk /dev/sda with partitions sda1, sda2 and sda3 to the file vmdk". This will ensure that the guest VM sees all the partitions natively. This is important because without the full disk outlook grub would go confused. Also this is important to ensure that Windows 7 senses no hardware change when switching boots in between Virtual and Native. The -register option is to set this setting permanent across reboots on the Host OS.
Windows 7 does not have Hardware Profiles anymore (or to the best of my knowledge). What that means is that Windows 7, on every switch, would assume a possible corruption and play safe by asking you to pop-in the Repaid CD. This is PITA. To overcome this pain, it is important to layout the image settings as I've mentioned above so that in either of the modes, Windows 7 feels that it is the same disk. This ends bringing a very risky situation. With Debian running: You have rw access to your 2nd and 3rd partition. And then when you fire-up the VM, if by mistake grub boots into Linux instead of Windows, kiss your data goodbye. Well, not 100% true, but don't get there.
A better workaround is this:
1) Add your disk image (that points to the physical partition) to your VM config
2) Add the gurb-rescue-cdrom.iso provided by the grub-rescue-pc package
3) Be very sure that the only bootable device selected is the CDROM device i.e. grub-rescue-cdrom.iso
Do this and there'll be no room for error. We simply bypass our native boot loader and instead boot off the grub rescue iso. Setting the correct partition persistent is left as an excercise for the reader.

Okay!! For completeness, this is how it should look.
Req 2
With Req1 achieved, I was pretty happy. But Req2 results got me impressed. For your eyes.......

A pretty neat summary of my Guest VM. You can see most of what it supports.
- USB
- PulseAudio
- Shared Folder
- SATA Controller
- VT
- 2D/3D (Experimental)

This one's a Maximized Windowed View of the Guest VM running.

But what impressed me the most is the Seamless Mode that VirtualBox provides. In the above screenshot, if you notice closely you'll realize that the desktop displayed is that of KDE's. This is very cool when I use the IE browser because IE is rendered as almost a regular native application. With Guest Tools installation, there's no Keyboard Capture/Release. Your Host's mouse is tightly integrated and will act on events when inside the Guest VM's display.
Not every thing can be described in words. You need to use it really experience its features.
An awesome product. And the best - GPL. It comes packaged in 2 editions: Proprietary (that adds proprietary plugins: iSCSI, RDP etc) and OSE Open Source Edition (which recently saw the USB feature added to it).

Comments
Good one, thanks will try it
Good one, thanks will try it out sometime and let you know how it goes.
Booting failed
Hi Raj,
I followed some other posts to you, and appreciate you posting your findings. This is great. Thanks.
And it almost worked for me. I get to the Windows splash screen. The little glowing lights fade on and start spinning. Then before the Windows logo shows up, I get the BSOD.
When I try to repair, it says:
"The boot selection failed because a required device is inaccessible."
I made sure that the devices were available per your (and other) posts and set only the CD-ROM image of Grub to be bootable.
That all seems okay, but I'm still struggling to see where I went wrong. If at all you can offer a tip for me to fix this, that would be great. I'd just LOVE to be able to not always have to boot and reboot to go between my Ubuntu and Windows7 installations.
Thanks again!
What do you mean when you say
What do you mean when you say "it almost worked"? Were you able to successuflly boot once? What is the stop error in the BSOD?
I had been facing a different challenge lately (fixed now). My problem was that in VirutalBox, the OS would boot perfect. But when I booted it native, it used to BSOD somewhere 2 minutes after login. My guess was that it must have been caused by a flaky foreign driver because the OS would boot and eventually crash (like in 2 minutes). Even if I booted in Safe Mode, it was the same problem. That gave me the impression that there were some delayed driver initializations and those, when initialized, were crashing the OS. My first suspicion was on the VirtualBox Guest Add-On driver.
I left it there because I didn't have enough time to investigate. Since the OS was only accessible through the VM, recently, I decicded to remove (de-crapify) all the add-on drivers (Intel's packages, Authentec's Packages et cetera). I removed every damn foreign package and resorted back to the native Microsoft shipped drivers. And you know what, the OS now boots perfect in both, Virutal and Native mode. It is not the Windows OS that is bad, it is the support strategy that makes it terrible. :-) This must be the very same reason why the linux kernel has a taint flag.
Microsoft should make a WHQL mode boot option. There will be many people writing crappy stuff for Windows. If Microsoft wants their OS stable, they need to go stricter on the support strategy.
Now coming back to your point. Did you install any foreign driver packages in the Windows OS? That could be the cause. Otherwise, try to see what the stop error is. On BSOD, does Windows 7 dump the memory? If yes, that dump is stored somewhere in %SYSTEM_ROOT%. I don't recollect the path. Get your hands on it and see what could be causing the trouble.
Option -register missing
Hi,
What version of VirtualBox do you have? I have 4.0.4 and the option -register is not available. Do you know to how another way to do what this option does?
Thanks,
Gilbert
Yes. The latest version
Yes. The latest version quietly dropped the -register option, for good. The mapping is still persistent even without the -register option. Just use the same command without it.
Are the partition and relative options necessary?
Hi. This is a great guide. Thanks for taking the time to type it all up.
I am about to give your method a try on my own machine, but after reading through the VirtualBox manual for more information on the raw disk commands (http://www.virtualbox.org/manual/ch09.html#rawdisk), I have one question for you...
Why did you choose to use the "partition" and "relative" options? You said, "This is important to ensure that Windows 7 senses no hardware change when switching boots in between Virtual and Native." I'm not sure if I understand the raw disk commands completely, but if the goal is to present the exact same hard drive to the native-boot OS as the virtual-boot OS, wouldn't leaving out the "partition" and "relative" commands be a better option since they will alter how the partitions are presented to the guest OS? I can understand why other guides use these commands because they are attempting to substitute another MBR in the raw disk image than occurs on the real disk, but your solution (which I like better) of booting a GRUB rescue disc image does not require faking the MBR.
Do you think these command options are actually necessary using your rescue disc method? I'm just looking to simplify the setup for my own build and to reduce any potential for problems. I don't want to have to keep running a Windows Repair or having to call MS on the phone to reactivate my Windows 7 license every time I switch booting methods.
Thanks for your input!
When you installed windows on
When you installed windows on your box, your setup was like:
/dev/sda1 - NTFS
/dev/sda2 - Linux
/dev/sda2 already had linux installed. You went ahead and did a native install of Windows on /dev/sda1. Perfect. At that time, Windows understood the partition layout that its disk had 2 partitions and it was installing on partition 1.
Now when doing the VirtualBox partition mapping, if you only export /dev/sda1, Windows senses that it is a different device than what its records say. Windows senses this as a catastropy on its way and so, to take preventive measures, asks you to instead be sure and follow the recovery method. With Windows 7, with no Hardware Profiles, this can be a PITA.
That is why we export the same disk layout through VirtualBox so that, for Windows, it remains the very same setup. That is why in this method, you don't need the hacky mbr trick. Grub ISO just helps us chainload to ntldr residing on the native disk. Since nothing has changed on the native disk layout front (thanks to VirtualBox's awesome work), Windows just boots fine.
Hope this helps
CAUTION
Be very sure to not access the Windows partition on the Linux host when VirtualBox is active.
And the other way around too.
And the other way around too. From withing VirtualBox, since it has access to the same disk, make sure it never ever boots the Linux partition. That is why I recommend to deactivate all boot devices except the Grub ISO.
Thanks for your reply. OK,
Thanks for your reply.
OK, that makes sense. So you want Windows inside of the VM to see the exact same hard drive layout as it does outside of the VM. That way, you won't trigger Windows Repair.
Given that, shouldn't I then use this command:
VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk -rawdisk /dev/sda
...then set the VM to boot only from the GRUB recovery disc image, and leave it at that?
If I follow everything you're saying, I should be able to leave out the "partition" and "relative" options that you listed above because I'm using the whole drive anyway, and I should leave out the "register" option because the latest version of VirtualBox no longer supports this option. Does that make sense?
Thank you.
Pages
Add new comment