I created a custom, generalized (using Sysprep), Windows 11 image from an Azure hosted VM and stored it in a custom Azure Compute image gallery.
c:\Windows\system32\sysprep\sysprep.exe /quiet /generalize /oobe /quit
It works when I use the custom gallery image to create Azure hosted VMs with 4 cores and 16GB RAM (Standard_D4s_v5).
It DOES NOT work when I try to use it in Hyper-V on my local system with the same cores and RAM.
I download the custom image from the gallery using the method described here.
$version = Get-AzGalleryImageVersion -ResourceGroupName $ResourceGroupName `
-GalleryName $GalleryName -GalleryDefinitionName $GalleryDefinitionName `
-Name $GalleryImageVersionName -ErrorAction Stop;
$diskConfig = New-AzDiskConfig -Location $Location -CreateOption FromImage `
-GalleryImageReference @{ Id = $version.Id };
$diskName = Split-Path -Path $version.StorageProfile.Source.Id -Leaf;
$disk = New-AzDisk -ResourceGroupName $ResourceGroupName -DiskName $diskName `
-Disk $diskConfig -ErrorAction Stop;
$diskAccess = Grant-AzDiskAccess -ResourceGroupName $disk.ResourceGroupName `
-DiskName $disk.Name -Access Read `
-DurationInSecond (New-TimeSpan -Minutes 60).TotalSeconds -ErrorAction Stop;
$vhdPath = "c:\downloads\$diskName.vhd";
Get-AzStorageBlobContent -Uri $diskAccess.AccessSAS -Destination $vhdPath `
-ErrorAction Stop;
Once that downloads I set up a VM locally with the code below.
$vm = New-VM -Name "TestVM" -VHDPath $vhdPath -MemoryStartupBytes 16GB `
-ErrorAction Stop;
$vm = $vM | Set-VM -ProcessorCount 4 -AutomaticCheckpointsEnabled $false `
-CheckpointType Standard -PassThru -ErrorAction Stop;
$vm | Start-VM -ErrorAction Stop;
It says it starts but when I connect to it using the Hyper-V Virtual Machine Connection window all it shows is a blank screen with a flashing cursor.
Evidence leads me to believe that this is not a graphics card issue (which other stack overflow articles address):
- If I let it run for a few minutes and try to do a shutdown the operation fails with a "The device is not ready for use" error.
- I've tried this on two different hosts and see the same thing.
- Both of the hosts I've tried it on I can successfully run an image I created using Disk2VHD.
Note: I have also used the /mode:vm argument in the SysPrep command but it had no effect on the outcome.
Any ideas on how to get this to work?
The key to resolving this was understanding two things:
The following produces a running Win-11 VM: