# bhyve: migrate Windows 7 from physical to virtual?



## aragats (Jan 24, 2017)

Does anybody have experience with this?
If I have a physical disk with Windows 7 installed, can I just use its device node for bhyve(8)?
I understand that I'll need to install virtio-net drivers in Windows. What else? The generic VGA adapter doesn't need a driver. Windows may not like the hardware change and may ask to (re)activate.

Thanks for advises and ideas!


----------



## IPTRACE (Jan 24, 2017)

I don't have but...

Please look at the bhyve wiki on https://wiki.freebsd.org/bhyve and find the question "Can I use disk images from VirtualBox or other virtualization platforms on bhyve?".
I think you can try to convert your standard OS installation to VirtualBox https://www.virtualbox.org/wiki/Migrate_Windows then convert to bhyve image.

IMHO Windows can ask you for reactiveate. But I don't think it is a problem.


----------



## usdmatt (Jan 24, 2017)

It should be possible to point bhyve at a physical disk for the ahci-hd device. However, Windows generally refuses to boot if moved to different hardware.

The normal way around this is to run `sysprep` on the Windows machine before migrating and choosing the Generalize option. This command is designed for making a re-usable image out of a Windows install and the generalize option allows it to move to different hardware. I've not tried it but I believe people have used this for moving existing systems to new hardware.

If you don't want to risk doing any damage to the existing Windows install, it may be worth taking an image of the disk (something like `dd`, although there may be faster options), and using that. Of course if it's a big disk that could be time consuming. (If you take an image onto a ZFS system you can take a snapshot once you have the image, then if you break something just rollback in seconds  ).


----------



## tcn (Jan 24, 2017)

Hi aragats,

  I did do this; actually, I migrated Windows 7 and Windows 10.  They were coming from a another VM though but I don't really see the difference.

  One thing to make sure is that you specify the sector size of you disk for Windows 7 or it will have serious issues.  The proper sector size for Windows 7 is 512.

  I don't know if you boot your system UEFI....  It is much easier that way....  I converted my to UEFI while creating the zvol.
If you don't want to do this, I would first try to install the network drivers and set remote desktop; dump the HDD to the host's filesystem and try it out (I haven't tried this).


----------



## aragats (Jan 24, 2017)

tcn said:


> The proper sector size for Windows 7 is 512


I remember such a nuance, but what if Windows 7 is already installed on an SSD? Does it still use 512 sector size? Is there any way to check it?


----------



## tcn (Jan 24, 2017)

Be careful, logical and physical are two different things.  Check if Windows sees sectors in size of 512 (which I am sure it does) by running `fsutil fsinfo ntfsinfo c:` or whatever drive you which to check is in an elevated command prompt.  

Basically, Windows 7 will always use 512K sector size.


----------



## aragats (Jan 24, 2017)

usdmatt said:


> It should be possible to point bhyve at a physical disk for the ahci-hd device. However, Windows generally refuses to boot if moved to different hardware.


Well, if the HDD and CPU are the same it wouldn't be (very) different hardware, right?


----------



## usdmatt (Jan 24, 2017)

In my experience moving a Windows disk from one computer to another has pretty much always caused it to fail to boot. 
Many backup utilities, such as Symantec System Recovery that we use regularly, actually have an 'Allow recovery to dissimilar hardware' option specifically designed to allow the system to be restored to different hardware, or to a VM. (I'm pretty sure it just does something similar to sysprep, as you get a similar process on first boot).

This is in a physical environment of course. It may be different moving between hypervisors, especially if they are both using AHCI emulation for the disk controller. I wouldn't be surprised to see a boot error if you take a physical Windows CD and try and boot it in a hypervisor though. That said, I haven't tried it, maybe you'll be in luck if the physical machine was set to AHCI mode.


----------



## aragats (Jan 24, 2017)

It looks that the main problem here is UEFI.
bhyve(8) supports only UEFI, but Windows 7 was installed to use legacy boot (although the computer is UEFI).
Booting Windows installer CD (in bhyve) and trying to run "repair" leads to this error:
"This version ... is not compatible with the version of Windows you are trying to repair ..."


----------



## tcn (Jan 24, 2017)

You can convert a non UEFI to a UEFI system; it is tricky but I've done it.


----------



## Phishfry (Jan 25, 2017)

One Windows trick I have used involves deleting every Device Manager hardware entry in Safe Mode when migrating an install.
Especially the disk controllers and video.


----------



## aragats (Jan 25, 2017)

tcn said:


> You can convert a non UEFI to a UEFI


There is a little progress: I converted it using gptgen (following these instructions). Then I ran Windows installer and used `dispart` to perform boot repair.
Now Windows boots in bhyve(8), but crashes even in Safe mode. Will investigate further.


Phishfry said:


> deleting every Device Manager hardware entry in Safe Mode ... Especially the disk controllers and video


This may help, will try tomorrow, since have no access to the physical Windows now.


----------



## aragats (Jan 25, 2017)

usdmatt said:


> The normal way around this is to run  sysprep on the Windows machine before migrating and choosing the Generalize option.


This worked (after converting to UEFI). Thanks!
However, the drawback is the machine needs to re-join the domain after `sysprep`, which is not always easily solvable if you're not a sysadmin.


----------

