More often than not there wouldn't need to be a need to convert a Gen2 VM down to a Gen1 VM. The exceptions to this would be downgrading a version of Hyper-V from Windows Server 2012 to 2008 R2; the chances of this are quite remote to very unlikely these days.
The other reason could be that you can't or rather not use Azure Site Recovery service or Azure Migrate: Server Migration and prefer to manually migrate your on premise Gen2 VM's from Hype-V into Azure yourself. In either case, I have the steps needed to assist with your pursuit.
It's worth noting that Azure only supports the following:
- Fixed VHD not VHDX and/or dynamically expanding disks
- MBR (msdos) partition tables, not GPT/UEFI for the OS disk
- Essentially Gen1 Hyper-V guests
- To start, backup/clone the virtual disk and convert the existing VHDX to a VHD:
Convert-VHD –Path .\test.vhdx –DestinationPath test.vhd -VHDType Fixed
Create a Gen1 VM with a smaller, whole number fixed size whole VHD, ie: 30GB, and also attach the newly converted VHD to the new Gen1 VM.
Alternatively, in the existing Gen2 VM, shrink the OS partition to a desired size, shrink the VHDX to just accommodate the resized partition with the command below, then create a new VHD copy as a fixed size virtual disk using the command above:
Resize-VHD -Path .\test.vhdx -ToMinimumSize
Note: The above command only works with VHDX virtual disks.
- Booted into Gparted and on the smaller newly created VHD, created a MBR (msdos) partition table
- Copy both the boot (Recovery) and OS partitions to new MBR VHD (resize within Gparted if needed before copying), shutdown the VM, detaching the converted VHD and leaving the smaller newly created VHD attached
- Boot into Windows Server ISO and repair the bootloader (Recovery) partition:
Select "Repair your computer" > "Use recovery tools" > "Start Command prompt"diskpartlist diskselect disk 0list partitionselect partition 1 (or partition of the 'Windows' Partition)activeexit
- Copy the 'bootmgr' file from the root of the Windows Server DVD to the boot (Windows) partition, assuming drive letter is C:\, ie:
- Reboot from Windows Server DVD and repair the bootloader;
Select "Repair your computer" > "Use recovery tools" > "Start Command prompt"bootrec /fixmbrbootrec /fixbootbootrec /rebuildbcd
Repair the BCD file (Located under C:\Boot):cd /d <drive letter>:\EFI\Microsoft\Boot\bootrec /FixBootbcdboot c:\Windows /l en-us
- Eject the Windows Server DVD, reboot and allow Windows to run chkdsk
- Prepare the VM to be hosted by Azure, including Windows Server 2008 SP2, install all the latest Updates, and install the latest Azure VM Agent
Note: If you change the product SKU after following Step 9, ie: Evaluation to Retail, repeat Step 8 again.
- Shutdown VM, upload the OS VHD to a blob storage in the same region and resource group which you'd need to create the VM in Azure - Use AzCopy as upload as a Page Blob:
azcopy copy 'C:\Hyper-V\test1\test.vhd' 'https://bla.blob.core.windows.net/vhds/test.vhd?SASToken' --blob-type PageBlob
- Create the VM; you can convert the uploaded VHD into a Managed Disk and then create a VM. Alternatively, via create the VM from the uploaded VHD via PowerShell. Change the variables to suit your needs:
To determine the Subnet array number:$rgName = "Servers"#$subnetName = "default"$location = "East US"$vnetName = "vnet"$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgName$vnet.Subnets.Id
Change the array number, starting from 0 being the first subnet onwards.
- Ensure the VM boots. Proceed to use the Unmanaged Disk or convert, otherwise read the steps below to create a Managed Disk with a preferred naming convention.
Tip: To retain the neat OsDisk naming convention, migrate the VHD from the Storage account from Unmanaged to a Managed Disk. This will allow you to provide the VHD a preferred name, amongst defining the size and type (Standard, SSD, etc…).
- Finally, assign an static IP, include in the backup and enable disk encryption.
Note: Try resetting the TCP/IP stack if the VM NIC doesn’t initialize, run netsh int ip reset in an elevated command prompt.
Please refer to the sites below for more information: