Hi all,
My home lab previously consisted of Windows servers, 2012 R2 and 2016, running Hyper-V. I had many guest VMs running that were Gen 2 VMs (aka UEFI with GPT disk partition/layout). After finally starting to tinker with Proxmox when 5.0 came out, I've decided to convert the whole thing to a Proxmox cluster. The only roadblock was converting the existing VMs and getting them running on Proxmox. I've searched on and off for quite a while for a complete guide to converting these VMs that A) actually worked and B) was fairly simple to do. I have not found such a guide anywhere, but piecing together steps from other guides that worked on the individual problems and steps of the conversion, I wrote a complete guide that will get your VMs converted fairly quickly and easily with almost no 3rd party tools involved and almost all of the process happens on the Proxmox host instead of on the Hyper-V host.
Tested with:
references/credits:
https://www.servethehome.com/converting-a-hyper-v-vhdx-for-use-with-kvm-or-proxmox-ve/
http://www.firewing1.com/blog/2012/...-layout-without-data-loss-and-gigabyte-hybrid
http://domyeung.blogspot.com/2015/08/converting-hyper-v-guest-to-linux-kvm.html
forum user: aderumier
My home lab previously consisted of Windows servers, 2012 R2 and 2016, running Hyper-V. I had many guest VMs running that were Gen 2 VMs (aka UEFI with GPT disk partition/layout). After finally starting to tinker with Proxmox when 5.0 came out, I've decided to convert the whole thing to a Proxmox cluster. The only roadblock was converting the existing VMs and getting them running on Proxmox. I've searched on and off for quite a while for a complete guide to converting these VMs that A) actually worked and B) was fairly simple to do. I have not found such a guide anywhere, but piecing together steps from other guides that worked on the individual problems and steps of the conversion, I wrote a complete guide that will get your VMs converted fairly quickly and easily with almost no 3rd party tools involved and almost all of the process happens on the Proxmox host instead of on the Hyper-V host.
Tested with:
- Proxmox 5.1-41
- Hyper-V host - Server 2016
- Gen 2 VMs running:
- Server 2012 R2
- Win10
- Server 2016
- Linux live CD with gdisk - knoppix is fine
- Windows install media 10/2016 will work for 2012
- Document critical settings such as NIC configuration that will be lost by migrating to a new hypervisor, local administrator account, etc
- Export the Hyper-V VM (got to get the VHD/VHDX disk files)
- On the hyper-v host, use the export function to create clean copies of the VHDs of the VM.
- Export allows you to leave the VM in place with any snapshots or Hyper-v Replica intact pending confirmation of conversion success
- Copy the VHD/VHDX file(s) to the proxmox host
- Do this however you want
- Check the integrity of the files:
- qemu-img check -r all disk1.vhdx
- Create a target VM on the proxmox host
- Create this VM so that the specs match as closely as possible to your source Hyper-V VM
- Cores/ram/etc
- Make note of the disk file name
- Example: vm-521-disk-1.qcow2
- Only create a single disk in this target VM, even if your source has more than one. To get the VM booting, we will focus only on the primary/OS disk of the source VM. We're going to be modifying partition tables, no need to risk the other disks. They can/will be copied over later
- Remove the empty disk that is created by the wizard
- Create this VM so that the specs match as closely as possible to your source Hyper-V VM
- Import and convert the vhd/vhdx
- Proxmox 5.0 includes a command that allows importing and converting a foreign disk image to a VM with one command
- qm importdisk <vmid> <source> <storage> [OPTIONS]
- <vmid> is the (unique) ID of the VM.
- <source> is the path to the disk image to import
- <storage> is the target Proxmox storage pool ID
- [OPTIONS] includes --format <qcow2 | raw | vmdk>
- This is where you specify the format the imported disk will become
- The command for our example would be:
- qm importdisk 521 disk1.vhdx pvedata --format qcow2
- This will import the vhdx to the pvedata Proxmox datastore, convert it to qcow2 format in the process, and add it to the configuration of VM 521 as an unused disk
- Configure the disk on the VM
- In the Hardware tab of the VM, you will see the imported disk at the bottom as unused disk 0
- Double click on the disk, or click on it and hit the edit button, in the Add: Unused Disk window:
- Set the Bus/Device to IDE 0
- Cache can be left default - If you're on a ZFS filesystem, you likely need to change this to Write through
- Other options can be set as desired
- In the Options tab of the VM, ensure your Boot Order and other settings are set appropriately
- Ex boot order would be ide0, CD-ROM, Network
- I also enable Qemu agent as I install that later as well
- OPTIONAL - snapshot the VM. If you're not familiar with the steps being done below, it may be beneficial to snapshot the VM at this point. This will allow you to roll back any incorrect changes made in the steps below and try again without waiting to re-import the disk
- Configure the VM to boot with the linux live cd/dvd and start it up
- I use knoppix as it already has gdisk as part of the DVD image and it boots into a gui
- Convert the GPT partition layout to MBR
- This will use the gdisk command
- Inside the VM, open a terminal and enter the following commands:
- OPTIONAL - take a backup of the GPT partition table:
- gdisk -b sda-preconvert.gpt /dev/sda
- gdisk /dev/sda
- Your command prompt will enter gdisk and it will look like:
- Command (? for help):
- Your command prompt will enter gdisk and it will look like:
- Press r and enter - this takes you to the recovery menu
- Press g and enter - this converts the partition table from GPT to MBR
- OPTIONAL - press p and enter to preview the new MBR partition table
- If your source disk had more than 4 partitions, this conversions gets tricky, more steps are needed that are out of scope here: http://www.rodsbooks.com/gdisk/mbr2gpt.html#gpt2mbr
- Press w and enter to write the changes
- OPTIONAL - take a backup of the GPT partition table:
- Fixing Windows boot from this converted disk. At this point you have a disk with your Windows OS, but it still won't boot in this condition. The next steps will walk you through repairing the Windows boot function
- Remove the linux live CD image, and load the Windows install disk image
- Reboot the VM
- Start the Windows Install wizard, but instead of choosing 'Install Now', choose 'Repair your computer'
- Click on the Troubleshooting option and open the command prompt
- Enter the following command:
- diskpart
- The next steps can vary, but the simple goal is to use the diskpart tool to mark the partition that holds your C drive as active, and to ensure it is labeled as C
- list disk
- You should only have the single disk - disk 0
- select disk 0
- list volume
- You likely have one or more other volumes/partitions, such as a the normal Windows Recovery partition
- Usually the largest volume on the disk is the one that should be your C drive - in this example, that will be volume 3
- If it is already assigned the letter C, move on to marking it as active
- If another volume, such as a recovery partition has been assigned C, we need to fix that
- Issue these commands to remove the drive letter from a volume
- select volume 2
- remove letter=c
- Do the same for other volumes that aren't supposed to have drive letters
- Then assign the C drive letter to the large volume
- select volume 3
- assign letter=c
- Mark your C drive as active
- select volume 3
- active
- Exit diskpart
- exit
- list disk
- The next steps will rebuild the BCD store and other critical boot files and settings. Type the following commands:
- bootrec /rebuildbcd
- This command will scan the disk to locate your windows install and build the BCD store to boot that install
- bcdboot C:\windows
- Replace c:\windows with the path to your windows install on the disk if it's different
- This command ensures that needed boot files are in place on this partition
- bootrec /fixmbr
- This command writes a master boot record compatible with Windows
- bootrec /fixboot
- This command writes a new boot sector that is compatible with Windows
- bootrec /rebuildbcd
- Power down the VM, remove the Windows installer image, and test booting the VM normally. At this point it should boot and be able to login.
- Install the required drivers for any new hypervisor based hardware inside the VM, such as the NIC or balloon drivers
- OPTIONAL - Convert the IDE controller to Virtio SCSI for better performance
- Windows does not have a driver for this natively installed, so there are a few simple steps to install the driver and prepare the Windows install to boot from a virtio SCSI disk
- Remove any snapshots at this point as editing the VM hardware can cause them to become invalid and require editing the VM config file to manually remove after the fact if they're not removed first
- Add a new, empty disk to the VM using the desired controller
- In the VM, install the correct driver for the newly added controller and verify you can access the new empty disk.
- Shutdown the VM
- Detach/delete the new empty disk
- Detach, but don't delete, your OS disk
- Reattach the OS disk, but choose the new controller type and configuration you want for the disk
- Boot the VM
- Add any other disks that were converted from the source VM. To do this:
- Shutdown the VM
- Remove any snapshots at this point as editing the VM hardware can cause them to become invalid and require editing the VM config file to manually remove after the fact if they're not removed first
- Add new/empty disks to the VM to match the needed number of disks from the source VM
- Repeat the steps from section 6 to copy the converted disks over these new/empty disks
- Boot the VM
- No partition conversion is necessary for your non-OS disks as Windows can read them fine as is
references/credits:
https://www.servethehome.com/converting-a-hyper-v-vhdx-for-use-with-kvm-or-proxmox-ve/
http://www.firewing1.com/blog/2012/...-layout-without-data-loss-and-gigabyte-hybrid
http://domyeung.blogspot.com/2015/08/converting-hyper-v-guest-to-linux-kvm.html
forum user: aderumier
Last edited: