How To Create VDI from Bootcamp Partition

Discussions related to using VirtualBox on Mac OS X hosts.
Post Reply
Doug C
Posts: 5
Joined: 13. Jun 2012, 09:05

How To Create VDI from Bootcamp Partition

Post by Doug C »

Posting here to benefit others in the community.

The attached Perl script will allow you to create a VDI file from a Boot Camp partition.

The script is offered as is but I have tested it with Windows XP and Windows 7 partitions of various sizes and formats.

The script was put together after much research and trail and error so you will probably notice unneeded portitions in it. Although it could be improved to truly optimize the partitions being copied. I did try as much as possible to mimic how Windows formats and sets up a drive in creating the VDI files.

This was built for OS X but I am sure it could be easily tweak to work on Linux.

The script has to run with sudo because the partition cannot be accessed by dd without elevated privileges or changing the file permissions.

The script has three options:

-v : verbose
-l : force it to treat the partition as a pre-Windows 2000 install. This just means that it won't add in the "unused space" for dynamic drive conversion that is normal in recent Windows installs
--noboundaryadjustment : This just tells it that within the VDI disk, the partition doesn't have to end on a cylinder boundary. Windows XP when doing installs will make the partition end on a cylinder boundary. It isn't absolutely necessary though.

I hope others find this script useful. I will try to monitor this topic in case people have questions.
Attachments
convertRawPartitionToVDI.7z
use 7zip to extract script
(36.76 KiB) Downloaded 115 times
Doug C
Posts: 5
Joined: 13. Jun 2012, 09:05

Re: How To Create VDI from Bootcamp Partition

Post by Doug C »

Opps. Jump the gun a little bit in stating this worked for Windows 7. It looked like it was working so I went ahead and posted but it is still not Windows 7 ready yet. Sorry about that. But it does work great for Windows XP.
Doug C
Posts: 5
Joined: 13. Jun 2012, 09:05

Re: How To Create VDI from Bootcamp Partition

Post by Doug C »

Okay. I have fixed the script and it now works with Windows 7.

In order to get this to work though, you will need to do the following upon attaching it to a VirtualBox machine:
  1. Use Windows 7 Recovery to repair the BCD information. This is needed because we have transitioned from using the 4th partition (most likely) on the physical disk to the 1st partition on the virtual disk.
  2. Use the following method to enable the SATA driver when Windows is loading. It appears that AHCI is not enabled when using Bootcamp on Macs and so the drive is in IDE mode. Windows 7 tries to reduce boot time by not loading all possible drivers so when we switch from using IDE on Bootcamp to SATA in the VM, it is going to have troubles. Also, the IDE driver used by Bootcamp is different from the one need by VirtualBox so just putting the disk as an IDE disk instead doesn't work. Here is what you need to do:
    1. Boot the Win7 DVD inside the VM
    2. At the first screen (Language Selection), hit Shift-F10 for a command prompt.
    3. Run Regedit.
    4. Load the system hive from the VM's disk:
    5. Click on HKEY_LOCAL_MACHINE
    6. Select File > Load Hive
    7. Select < c: > \Windows\System32\config\system (name it something like "aaaa")
    8. Expand HKEY_LOCAL_MACHINE\aaaa\ControlSet1\Services\msahci
    9. Change the data for value "Start" from "3" to "0"
    10. Expand HKEY_LOCAL_MACHINE\aaaa\ControlSet1\Services\pciide
    11. Change the data for value "Start" from "0" to "3"
    12. Click on HKEY_LOCAL_MACHINE\aaaa
    13. Select File > Unload Hive
    14. Exit regedit.
    15. Reboot the VM
Attachments
convertRawPartitionToVDI.7z
use 7zip to extract
(36.61 KiB) Downloaded 111 times
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: How To Create VDI from Bootcamp Partition

Post by mpack »

Can you clarify whether this is intended to be a one-way conversion? In other words, Win7 will ask you to reactivate, isn't that correct? And from then on you would be unable to use the bootcamp partition?
Doug C
Posts: 5
Joined: 13. Jun 2012, 09:05

Re: How To Create VDI from Bootcamp Partition

Post by Doug C »

To be honest, I don't know the answer to the question about reactivation. I am putting this together to help people in my company transition from Boot Camp to virtual machines so this is not a concern if they did have to reactivate. But I can't confirm or deny that reactivation is necessary.

If or when I run into that I can post back here.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: How To Create VDI from Bootcamp Partition

Post by mpack »

Well, the requirement to reactivate isn't really my point: my question is, are you telling people how to ruin their bootcamp partitions and not warning them!
Doug C
Posts: 5
Joined: 13. Jun 2012, 09:05

Re: How To Create VDI from Bootcamp Partition

Post by Doug C »

Not intentionally.

I don't see how it would ruin it anyway but the point of doing this is to switch from using a raw partition to a virtual image. The intent is that the user would not continue to use the Boot Camp partition. I have tested this on both a Windows Vista and Windows 7 partition now and it works fine. Since my tests our on Windows that have not been registered, it is possible that reactivation might be required but it is not immediately obvious that it is when booting into the virtual machine after conversion.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: How To Create VDI from Bootcamp Partition

Post by mpack »

Doug C wrote:I don't see how it would ruin it anyway
One the virtual image is activated they would no longer be able to use the bootcamp image: the hardware signature would no longer match the one registered on the MS server. That's fine if the intention was a one way migration - hence the need to clarify if that was the case.
Post Reply