How I "P2V"ed a Windows 7 Home Install to Proxmox VE

Linda has an old laptop that she accidentally broke the screen on. Like, it sorta worked, but not really, and every time she opened the lid it got a little bit worse, until I said "enough is enough" and bought her a new one. It sat in a box in the closet for a few years.

I thought to myself "why not use that Windows license somewhere else?". I'm not sure why I had that thought as I probably won't use it at all - but it does come in handy to have Windows around every now and then, so why not? Trouble was, when I tried to download the Windows installation media, it refused to let me do that because my key was for an OEM install. And of course HP (the vendor) doesn't make their restore media available either, unless you want to pay them $20 - and I definitely did not want to do that.

So I made an image of the drive using a SATA-to-USB3 dock and dd, and then went about trying to get a copy of that image to boot in Proxmox VE via KVM. I ultimately was successful, and this is how.

Saving the Bits

Like I mentioned, I did this with dd. To figure out the right drive, look at the output of /var/log/syslog after you plug in the drive (or if you plugged it into a SATA port, look through dmesg after a reboot, or fdisk -l or similar). Then, once you know the right device, nab its bits with something like:

dd if=/dev/sdX of=/place/with/lots/of/space.img bs=4M

That'll make a bit-for-bit copy of that entire disk, so make sure you have plenty of room as the file will be big. That'll take some time so hopefully you're not in a rush. Monitor the status of the copy in another terminal by viewing the size of the image file.

The beauty of doing this is that you can then do all of your messing around on a copy of the drive rather than the original media itself. I recommend taking the drive out of the system now, and actually making another copy of the image you just made and working on it as it's easy to screw something up and it's sometimes easier to go back to the original bits.

Prepare Proxmox VE

In Proxmox, create a new virtual machine definition. Give it a reasonable set of resources such as CPU and memory - probably at least as much as it had on the original system - and make sure to make the disk at least the same size as the image that you just made. When prompted, I first chose the default SCSI controller - but I found that didn't work - but I did get SATA to work without any messing around, so choose that. I also went with an E1000 NIC as I knew it'd have drivers for it, and took the defaults for everything else.

Don't boot this yet though. That disk is empty.

Wedge Those Bits into Place

I use Proxmox's ZFS support which meant that I now had an empty zvol that I needed to copy the image into. Again, dd does the job.

dd if=the_image.img of=/dev/zvol/path/to/vm-100-disk-1

Here, make sure you specify the correct zvol or you might accidentally trash the disk of another VM. You can see this in the Proxmox UI. Select the VM, click on Hardware, then find the hard disk and take note of the name there as that's the zvol.

This will take a while too, but probably not nearly as long as the initial copy because hopefully the disks in your Proxmox system are much faster than what you pulled from the other one.

Make Windows Happy

This part took some messing around, so I apologize for not having good notes. I downloaded the ISO for all of the virtio drivers and guest agents, mounted that as a CDROM, and then installed all of that and then converted all of the devices to the virtio types. The biggest tricky thing here was that you have to remove your virtual hard drive, but it doesn't delete it - it merely marks it as unused. You can then edit the properties of the drive to change its type.

At one point during this part, Windows got cranky during bootup such that it was blue screening in a loop. It kicked into the HP recovery partition and helpfully offered to restore the system to factory defaults which I happily let it do - I didn't want all of the cruft from the existing install anyways - though HP did insist on still installing many gigabytes of software that I didn't want. I probably didn't need to have it do this if I had picked the right disk controller (SATA) I think I could have gotten the disk to boot, but whatever.

I then changed the graphics card to QXL which lets me use the SPICE protocol to connect to it. This is very important as without it, I could only interact with the VM using the Proxmox console via a web browser which, while functional for lightweight stuff, is not very responsive. I would have used RDP, but it's apparently not available in the Home Premium version of Windows 7. Anyways, install virt-viewer and then choosing the SPICE console from the Proxmox UI will launch right into it - and suddenly it's as responsive and usable as being at the actual console. SPICE is far from new software (I first used it probably 5 years ago?), but it still feels like it's just getting started - but that being said once you get it working it's on par with RDP for the things that I do.

At some point along the way it also accepted my Windows license key, and after installing what seemed like a million updates, installing Microsoft Security Essentials, and uninstalling all of the junk that HP loads by default, I now have a virtualized Windows 7 install - and it honestly seems a whole lot snappier than when it was running on bare metal (which in theory is what you'd expect, but it doesn't always work out that way).

Now let's see if I ever actually use it.