Skip to main content

Converting a physical Windows installation into a virtual machine

Looking to run Linux on your computer but preserve the current Windows installation as a virtual machine? Trying to virtualize a Windows installation so you can transfer it to another computer?

Using these steps you are likely to be able to take your existing physical Windows partition and convert it into a working virtual machine. I did this with a Windows 7 physical image then installing Fedora 23 and using VirtualBox to run Windows 7.



Amazingly, to me at least, the process of creating the virtual disk image is performed from the running Windows system you'd like to virtualize. This is really convenient and much nicer than having to reinstall from scratch. disk2vhd is what enables you to do this on-the-fly virtual disk creation. It is created by Microsoft, so its kind of funny to use their tool to make it easy to convert a computer to Linux.

NOTE - This level of monkeying around with operating systems and file systems does not always end well. You should back up all of your data before starting, because if something goes wrong you'll likely end up reinstalling from scratch into a virtual machine and wanting to copy your data back after that process is complete.


The overall process:

  1. Create a virtual machine disk file of the physical Windows system.
  2. Store that virtual machine disk file on an external storage device temporarily
  3. Confirm that everything appears to have worked.
  4. Install Linux (this overwrites the physical Windows system)


  5. Copy back the virtual machine disk file and create a virtual machine from it
  6. Enjoy your new Linux system and the convenience of running Windows in a VM when you need it.



Step-by-step:

  1. Get a large external storage device to put the virtual machine image on. The storage should be at least as large as the one inside of your computer if you want to ensure you won't run out of space. I used a 1+TB external usb disk drive.
  2. Download disk2vhd from http://technet.microsoft.com/en-us/sysinternals/ee656415
  3. Run disk2vhd. Ensure that you've unchecked 'vhdx' unless you know that your virtualization software can support it. I don't think virtualbox can, so I unchecked that box.
  4. Wait for some time until the image is created. It took an hour or more in my case.
    • NOTE: disk2vhd will also create an image of the external USB storage that is being used to hold the primary drive image (the one with the Windows install). You may see '<computername>-0.vhd' and '<computername>-1.vhd'. The '-1.vhd' file was the one created of the backup storage. I only removed it at the very end though, because I wasn't sure at the time.
    • At this point you may notice that the virtual disk file is smaller than your physical disk. Mine was 100GB vs. the 256GB SDD that it came from, and appears to reflect only the amount of data that was present.
  5. Download and install VirtualBox.
  6. Create a virtual machine and point it at the '<computername>-0.vhd' file on the usb storage.
  7. Start up the virtual machine to test that the disk2vhd process was successful.
    1. At this point I ran into a BSOD
    2. And used these steps to resolve it by switching the storage controller to an IDE one.


  8. At this point the virtual machine started and booted the virtual disk copy of my physical install. All of my applications were present as were all of my files. This let me confirm that the disk image looked good.
  9. Power everything down and unplug the usb storage.
  10. Install Linux. (NOTE: Once you've reformatted the Windows partition you can't go back)
  11. Install VirtualBox
  12. Plug in your external storage
    • NOTE: At this point I made a copy of the .vhd file just in case I broke something. I ended up not needing it but I thought it was a good idea and worth the hour or so it took to copy the 100GB to another file on the usb storage.
  13. Create a new virtual machine, point it at the usb storage .vhd file
  14. Boot the Windows VM up (See the above step about the storage controller if you get a BSOD). At this point everything worked well for me and Windows started up normally.
  15. Install guest tools
  16. Enjoy, you've successfully transferred a physical Windows install to a virtual machine!
  17. To transfer the VM back to your internal storage:
    1. Power off the virtual machine
    2. Use VirtualBox virtual media manager to clone the virtual disk to a location on your internal hdd. At this point I also converted the file to a .vdi, the native VirtualBox format.
    3. Modify the virtual machine settings to point at this .vdi file.



This guide on lifeofageekadmin.com  provided some helpful steps that I used when figuring out how to do this.

Comments

Popular posts from this blog

Debugging an imprecise bus access fault on a Cortex-M3

This information may apply to other cortex series processors but is written from practical experience with the Cortex-M3. Imprecise bus access faults are ambiguous, as noted by the term "imprecise". Compared to precise bus errors, imprecise errors are much trickier to debug and especially so without a deep understanding of arm processors and assembly language. Imprecise and precise flags are found in the BusFault status register, a byte in the CFSR (Configurable Fault Status Register). BusFault status register bits The definition for imprecise and precise bits is: [2] IMPRECISERR Imprecise data bus error: 0 = no imprecise data bus error 1 = a data bus error has occurred, but the return address in the stack frame is not related to the instruction that caused the error. When the processor sets this bit to 1, it does not write a fault address to the BFAR. This is an asynchronous fault. Therefore, if it is detected when the priority of the current pr

Graco Swing By Me - Battery to AC wall adapter modification

If you have one of these Graco battery powered swings you are probably familiar with the cost of C batteries! The swing takes four of them and they only last a handful of days. I'm not sure if the newer models support being plugged into the wall but ours didn't. If you are a little familiar with electronics and soldering, here is a rough guide on how you can modify yours to plug in! I wasn't sure how exactly to disassemble the swing side where the batteries were. I was able to open up the clamshell a bit but throughout this mod I was unable to determine how to fully separate the pieces. I suspect that there is some kind of a slip plate on the moving arm portion. The two parts of the plastic are assembled and the moving arm portion with the slip plate is slid onto the shaft. Because of the tension in that slip plate it doesn't want to back away, and because of the mechanicals that portion of the assembly doesn't appear accessible in order to free it. I was

Memory efficient queuing of variable length elements

In embedded environments memory can be a critical driver of the design of data structures and containers. Computing resources have been expanding steadily each year but there are still a wide range of systems with far less than a megabyte of memory. On systems with tens of kilobytes of memory, structures are often designed to be compact to maximize data density. Rather than splurging on memory aligned elements that would be faster for the processor to access, a developer will typically use types with minimal sizes based on the known range of values that the element is intending to hold. Fixed sized buffers At my day job a fixed size pool of messages was implemented to hold message data. While this achieved one design goal of using statically allocated buffers, avoiding dynamic allocations that might fail at runtime, it isn't efficient if there is a wide range of message sizes. It isn't efficient because each message uses a message buffer. With small message sizes the buff