Thursday, October 10, 2013

How to convert or move real Windows HDD installation to Virtual Machine VM VirtualBox

I wanted to achieve this, and none of the solutions I found on the internet were suitable/easy enough for me, so I created an easier and simpler way of achieving this.

My situation was: Original laptop HDD with Windows 7 64-bit, plus SSD with Ubuntu installed.
I wanted to take the Windows install from the original HDD, and move it to a VM in my Ubuntu install/drive.
The advantages of my method are that it only requires you to have an external HDD/flash drive slightly larger than your desired VM drive size (ie. Your VM drive does NOT have to be the size of your source HDD - this is the key difference to other methods I found on the web)


1. Create Virtual Machine, creating VDI virtual drive to desired size
2. Set VM parameters for DMI bios to match real machine, as in this thread (section 1.2 only): https://forums.virtualbox.org/viewtopic.php?t=9697
3. Boot Windows on real machine, remove any unnecessary programs/files, do disk cleanup.
4. Disable hibernation (if active), system restore, and manually set pagefile to use main partition only (the one you're going to copy)
5. In Windows (using Computer Manage), resize main partition down to desired size (as in VDI) MINUS 100mb.
6. Create Windows System repair - burn to CD or DVD
7. Reboot, then run PowerDefragmenter from Windows on main partition.
8. Boot linux live CD with partimage (eg. http://www.sysresccd.org/SystemRescueCd_Homepage) on real machine.  Connect your external HDD/flash, and use partimage to copy the first two partitions to a file/s on your external HDD - One should be labelled SYSTEM and be 100mb.  The 2nd will be the main partition that you just resized down.
9. Now boot your OS that has VirtualBox on it (for me it was my Ubuntu), start Virtualbox and mount the LiveCD to the VM, so it boots into the LiveCD
10. Connect your external drive to the computer, and mount it in the VM.
ALT 10. For me my external HDD wouldn't mount in the VM, so instead I copied the partimage files to a folder in Ubuntu, and then from the VM/LiveCD I mounted the folder via Samba
11. Use Gparted to create two partitions in the VM drive - the first 100mb, and label it SYSTEM, with filesystem as NTFS.  Check the "boot" flag for this partition.  Create the 2nd partition with the remaining space on the VM drive, also NTFS.
12. Now run partimage, select the first partition (eg. sda1) and enter the image file location, and go through the restore process.  Repeat for the 2nd partition - if you have the image files split, just enter the full filename of the first file, and it will sort out the rest.
13. Cool now you have successfully copied the Windows install from the real install to the VM drive!
14. Shutdown the VM, and mount the Windows System repair disc that you created earlier and boot into this.  When I did it, "Windows installation table" didn't show me any installations - my heart sank thinking it wasn't going to work.  However I just clicked "repair errors" (can't remember exact wording) and it proceeded to do some checking/fixing.
15. Reboot without the system repair disc mounted, and voila, you should have a working Windows VM
16. Final steps for me were: install VirtualBox guest additions, use "Computer Manage" in Windows to extend the main partition to fill a few extra free MBs that were left in the VM drive.

Hope this helps someone!