Windows 7 Physical to Hyper-V Virtual Machine
Preface
This guide provides an important step missing from any articles I could find on converting from a Windows 7 physical machine to a Hyper-V (or other) virtual machine. Most guides cover the easy part (getting the physical computer into the hypervisor such as Hyper-V), but fail to address how to get the machine to boot when the physical machine is not using an Intel PCI IDE controller for the root (C:) hard drive.
Note: See the Note on Activation if you need the physical machine online at the same time as the virtual machine, or you do not have a retail product key.
Get the machine into the hypervisor (aka the easy part)
Because other articles cover all of these options in detail, we don’t talk much about this step in this guide.
Option 1: Use Disk2vhd
- Available from Microsoft via their documentation portal. Instructions are provided on that portal.
- Create a Generation 1 Hyper-V VM with the converted image as boot drive.
Option 2: Create a system image and restore it
This is quite straightforward, so this is just a quick list of steps.
- On the physical machine go the ‘Control Panel’
- Use the ‘Backup and Restore’ tool
- The important part here is to check the ‘Create system image’ box.
- The rest of the backup is entirely optional for this guide.
- On the machine with the hypervisor (we’re assuming Hyper-V for this guide),
create an empty virtual hard drive big enough to hold all the contents of
the system image disk. E.g.
New-VHD -Path BackupDisk.vhd -Dynamic -SourceDisk 2 -Size 1TB
in PowerShell (assuming the drive with the backup image is Number 2 in the output ofGet-Disk
. and you want the virtual size of the disk to be 1TB, but have the physical size be that of the actual data). - Create a Generation 1 Hyper-V virtual machine with an empty virtual hard drive and Windows 7 installation media attached as a CD/DVD drive.
- In the virtual machine’s settings add the backup VHD as a second IDE hard drive.
- Boot the installation media.
- Choose to repair rather than install Windows 7.
- Choose to restore from system image previously created.
- This will take some time and when done you will have a new virtual machine with the contents of the physical machine’s hard drive.
Note: Those alert among you might have noticed that the command
New-VHD -Path BackupDisk.vhd -Dynamic -SourceDisk 2 -Size 1TB
would allow
you to create the image directly from the physical machine’s hard disk if you attached
said disk as a secondary disk to the machine running the command.
Option 3: Make a block-level copy and convert raw image to VHDX
This needs knowledge of Linux system-level commands/tools or you can find a guide elsewhere.
Boot to a Linux rescue CD
Such as System Rescue
Clone the hard drive bit for bit (block-level copy)
Assuming a storage disk mounted on /mnt
and assuming the physical hard disk
is /dev/sda
:
E.g. dd if=/dev/sda of=/mnt/backup-image.img bs=1M status=progress conv=fsync
Convert the image to VHDX using qemu-img
E.g. qemu-img convert -p -f raw -O vhdx backup-image.img p2v-hd.vhdx
Create a Generation 1 Hyper-V VM
With the converted image as boot drive.
Launch VM using the image (if you are lucky)
It just works.
If the virtual machine fails to boot
This is the part no one tells you.
Using installation media (e.g. Windows 7 Installation CD)
- Create a Generation 1 Hyper-V virtual machine with the hard drive image you created as the primary hard drive.
- Boot the installation media.
- Choose to repair rather than install Windows 7.
- (Likely not needed): Check the items from Microsoft’s guide for inaccessible boot device
Ensure PCIIDE device service is set to start on boot
- Using the the above Microsoft guide for inaccessible boot device,
in the
OfflineSystemHive
and in the correct control set (this guide will showControlSet001
, see Step 10 in the guide for your case) expandServices
- Check that the
PCIIDE
key exists and that it has a value namedStart
set to0
. - If not, set the
Start
for keyPCIIDE
to0
. - If PCIIDE does not exist:
- Get
mergeide.reg
from ProxMox wiki: https://pve.proxmox.com/wiki/File:Mergeide.zip - Rename
SYSTEM
inmergeide.reg
toOfflineSystemHive
- Import
mergeide.reg
into the registry (while in repair mode on the target virtual machine) - Go to step 2
- Get
- Try rebooting the virtual machine into Windows (i.e. normal boot).
- With luck you are now in Windows 7.
Alternative
Theoretically you could enable PCIIDE using chntpw
from System Rescue
or other Linux boot disks.
Appendix A: A note on activation
- If you do not have a retail product key for Windows, or you need to keep the physical machine active in addition to the newly minted virtual machine, before you boot the virtual machine, make sure that you do not have it network connected.
- Before network connecting the virtual machine execute the command
slmgr /upk
. This removes the product key from the VM’s copy of Windows. - You will need to obtain a legal copy of a retail version of Windows (in my use case, Windows 7 Profession 32-bit). For old versions of Windows you can find legal copies on sources like eBay. Avoid sellers providing only product keys (that’s not genuine windows). If you are concerned about legalities and proof thereof, you need to purchase a new copy of the full retail Windows installation media which is sealed with the original COA sticker and product key.
- Activate Windows: TBD
Appendix B: Why
- For Hyper-V Gen 1 virtual machines the virtual machine uses a virtual Intel PCI IDE controller for the primary hard drive by default.
- If the physical machine has a different controller (different manufacturer or different technology) then, because Windows 7 minimizes the number of active device drivers after installation, the driver for the Hyper-V controller is not active and the primary hard drive is not accessible to Windows. Consequently the boot fails.
- If you use a SCSI controller for a Gen 1 machine, use a Gen 2 machine, or are using another hypervisor which is not using PCIIDE emulated controller then these instructions will need to be modified to activate the controller in use. If you need to install a driver that can be done as well, but is more involved1.
You could likely boot to repair mode and use the
DISM /image:<c-drive> /Add-Driver <driver>.inf
command in order to add the driver. If you do this and write guide about it, please let me know and I will link to it. ↩︎