%3CLINGO-SUB%20id%3D%22lingo-sub-1658889%22%20slang%3D%22en-US%22%3EUpload%20Custom%20Windows%20Hyper-V%20Image%20for%20Gen%202%20VM%20in%20Azure%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1658889%22%20slang%3D%22en-US%22%3E%3CH2%20id%3D%22toc-hId--1268455791%22%20id%3D%22toc-hId--1268455761%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId-1219057042%22%20id%3D%22toc-hId-1219057072%22%3EIntroduction%3C%2FH2%3E%0A%3CP%3EThis%20is%20Andrew%20Coughlin%20and%20I%20am%20a%20Customer%20Engineer%20at%20Microsoft%20focusing%20on%20Azure%20IaaS.%20In%20this%20blog%20I%20will%20focus%20on%20how%20to%20upload%20a%20custom%20windows%20Hyper-V%20image%20for%20generation%202%20virtual%20machines%20in%20Azure.%20Support%20for%20generation%202%20virtual%20machines%20in%20Azure%20was%20released%20on%20November%204%2C%202019%2C%20these%20systems%20use%20UEFI%20boot%2C%20SCSI%2C%20supported%20on%20VMs%20that%20support%20premium%20storage%20compared%20to%20generation%201%20which%20use%20PCAT%20boot%2C%20IDE%20and%20are%20available%20on%20all%20VM%20sizes.%20%26nbsp%3BGeneration%202%20VMs%20provide%20for%20OS%20disk%20size%20greater%20than%202TB%20in%20size%20and%20build%20larger%20VMs%2C%20up%20to%2012TBs.%20To%20get%20additional%20information%20about%20generation%202%20virtual%20machines%20in%20Azure%20please%20visit%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fupdates%2Fazure-generation-2-virtual-machines-vms-are-now-generally-available%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ethis%20post%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20have%20ever%20uploaded%20a%20custom%20image%20in%20Azure%20in%20the%20past%20you%20will%20notice%20the%20process%20is%20very%20similar.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--588397421%22%20id%3D%22toc-hId--588397391%22%3EPrerequisites%3C%2FH2%3E%0A%3CUL%3E%0A%3CLI%3EReview%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fvirtual-machines%2Fwindows%2Fgeneration-2%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ESupport%20for%20generation%202%20VMs%20on%20Azure%3C%2FA%3E.%3C%2FLI%3E%0A%3CLI%3EInstall%20Azure%20PowerShell%20as%20documented%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fazure%2Finstall-az-ps%3Fview%3Dazps-4.5.0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%3C%2FLI%3E%0A%3CLI%3ECreate%20Hyper-V%20Gen%202%20machine%20to%20be%20used%20as%20the%20image.%3C%2FLI%3E%0A%3CLI%3EPrepare%20your%20Windows%20Hyper-V%20image%20is%20documented%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fvirtual-machines%2Fwindows%2Fprepare-for-upload-vhd-image%3Ftoc%3D%2Fazure%2Fvirtual-machines%2Fwindows%2Ftoc.json%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%3C%2FLI%3E%0A%3CLI%3EConvert%20VHDX%20to%20VHD%20as%20documented%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fvirtual-machines%2Fwindows%2Fprepare-for-upload-vhd-image%23use-hyper-v-manager-to-convert-the-disk%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%3C%2FLI%3E%0A%3CLI%3EDownload%20and%20Install%20azcopy%20as%20documented%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fstorage%2Fcommon%2Fstorage-use-azcopy-v10%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%3C%2FLI%3E%0A%3CLI%3ESign%20in%20with%20Azure%20as%20documented%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fazure%2Fauthenticate-azureps%3Fview%3Dazps-4.5.0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%3C%2FLI%3E%0A%3CLI%3ESelect%20Azure%20subscription%20to%20upload%20image%20as%20documented%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fservicemanagement%2Fazure.service%2Fselect-azuresubscription%3Fview%3Dazuresmps-4.0.0%23examples%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1899115412%22%20id%3D%22toc-hId-1899115442%22%3EUpload%20Hyper-V%20Image%20to%20Managed%20Disk%3C%2FH2%3E%0A%3CP%3EFirst%20you%20want%20to%20determine%20which%20resource%20group%20the%20image%20will%20reside%20in%20or%20if%20you%20will%20create%20a%20new%20resource%20group.%20As%20a%20reminder%20a%20resource%20group%20is%20a%20container%20that%20holds%20related%20solutions%3A%20virtual%20machines%2C%20storage%20accounts%2C%20disks%20virtual%20networks%2C%20etc.%20for%20your%20Azure%20solutions.%20A%20resource%20group%20can%20include%20all%20resources%20for%20your%20solutions%20or%20only%20those%20resources%20that%20you%20want%20to%20be%20managed%20together.%20For%20documentation%20on%20how%20to%20create%20a%20new%20resource%20group%2C%20this%20can%20be%20found%20on%20this%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-resource-manager%2Fmanagement%2Fmanage-resource-groups-portal%23create-resource-groups%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Epage%3C%2FA%3E.%20In%20this%20example%20I%E2%80%99m%20going%20to%20use%20the%20resource%20group%20called%20%E2%80%9Crg-images%E2%80%9D.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22AndrewCoughlin_0-1599851626911.png%22%20style%3D%22width%3A%20881px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F217815i1E57C16F1545AC32%2Fimage-dimensions%2F881x326%3Fv%3D1.0%22%20width%3D%22881%22%20height%3D%22326%22%20title%3D%22AndrewCoughlin_0-1599851626911.png%22%20alt%3D%22AndrewCoughlin_0-1599851626911.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFirst%2C%20we%20need%20to%20open%20an%20elevated%20PowerShell%20command%20prompt.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22AndrewCoughlin_1-1599851626922.png%22%20style%3D%22width%3A%20300px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F217816iB3414E4C590D78B8%2Fimage-dimensions%2F300x316%3Fv%3D1.0%22%20width%3D%22300%22%20height%3D%22316%22%20title%3D%22AndrewCoughlin_1-1599851626922.png%22%20alt%3D%22AndrewCoughlin_1-1599851626922.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENext%2C%20we%20will%20set%20some%20variables%20as%20we%20will%20need%20these%20throughout%20the%20process%2C%20in%20this%20example.%20We%20are%20going%20to%20be%20creating%20this%20image%20in%20Central%20US%2C%20with%20the%20image%20name%20W2K19-Image-V2%2C%20in%20the%20resource%20group%20called%20rg-images%2C%20with%20a%20disk%20image%20called%20W2K19-Image-V2.%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%24location%20%3D%20'Central%20US'%3C%2FLI%3E%0A%3CLI%3E%24imageName%20%3D%20'W2K19-Image-V2'%3C%2FLI%3E%0A%3CLI%3E%24rgName%20%3D%20'rg-images'%3C%2FLI%3E%0A%3CLI%3E%24diskname%20%3D%20'W2K19-Image-V2'%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22AndrewCoughlin_2-1599851626929.png%22%20style%3D%22width%3A%20489px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F217814i947DF8D31F8DBAB0%2Fimage-dimensions%2F489x91%3Fv%3D1.0%22%20width%3D%22489%22%20height%3D%2291%22%20title%3D%22AndrewCoughlin_2-1599851626929.png%22%20alt%3D%22AndrewCoughlin_2-1599851626929.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENext%2C%20we%20want%20to%20create%20an%20empty%20managed%20disk%2C%20you%20will%20type%20the%20following%20commands%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24vhdSizeBytes%20%3D%20(Get-Item%20%22%3CFULL%20file%3D%22%22%20path%3D%22%22%3E%22).length%0A%0A%24diskconfig%20%3D%20New-AzDiskConfig%20-SkuName%20'Standard_LRS'%20-OsType%20'Windows'%20-UploadSizeInBytes%20%24vhdSizeBytes%20-Location%20%24location%20-CreateOption%20'Upload'%0A%0ANew-AzDisk%20-ResourceGroupName%20%24rgName%26nbsp%3B%20-DiskName%20%24diskname%20-Disk%20%24diskconfig%3C%2FFULL%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22AndrewCoughlin_3-1599851626952.png%22%20style%3D%22width%3A%20729px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F217817i11F2CFF73ED1132F%2Fimage-dimensions%2F729x331%3Fv%3D1.0%22%20width%3D%22729%22%20height%3D%22331%22%20title%3D%22AndrewCoughlin_3-1599851626952.png%22%20alt%3D%22AndrewCoughlin_3-1599851626952.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENOTE%3A%3C%2FSTRONG%3E%20You%20can%20replace%20the%20Standard_LRS%2C%20with%20Premium_LRS%20or%20StandardSSD_LRS.%26nbsp%3B%20At%20the%20writing%20of%20this%20blog%20Ultra%20disks%20are%20currently%20not%20supported.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENext%2C%20we%20need%20to%20confirm%20the%20disk%20status%20is%20equal%20to%20%E2%80%9CReadyToUpload%E2%80%9D%2C%20you%20will%20type%20the%20following%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24disk%20%3D%20Get-AzDisk%20-ResourceGroupName%20%24rgName%20-DiskName%20%24diskname%0A%0A%24disk.DiskState%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22AndrewCoughlin_4-1599851626954.png%22%20style%3D%22width%3A%20712px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F217818i2D9DA82B98D82286%2Fimage-dimensions%2F712x127%3Fv%3D1.0%22%20width%3D%22712%22%20height%3D%22127%22%20title%3D%22AndrewCoughlin_4-1599851626954.png%22%20alt%3D%22AndrewCoughlin_4-1599851626954.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENOTE%3A%3C%2FSTRONG%3E%20The%20disk%20status%20must%20be%20set%20to%20%E2%80%9CReadyToUpload%E2%80%9D%2C%20if%20it%20is%20not%20you%20need%20to%20check%20what%20was%20typed%20in%20the%20%E2%80%9CNew-AzDiskConfig%E2%80%9D%20command.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20we%20want%20to%20create%20the%20writable%20shared%20access%20signature%20(SAS)%20for%20the%20managed%20disk%20we%20just%20created.%26nbsp%3B%20Then%20we%20will%20get%20the%20disk%20status%20and%20make%20sure%20it%20is%20equal%20to%20%E2%80%9CActiveUpload%E2%80%9D%2C%20to%20do%20this%20you%20will%20type%20the%20following%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24diskSas%20%3D%20Grant-AzDiskAccess%20-ResourceGroupName%20%24rgName%20-DiskName%20%24diskname%20-DurationInSecond%2086400%20-Access%20'Write'%0A%0A%24disk%20%3D%20Get-AzDisk%20-ResourceGroupName%20%24rgName%20-DiskName%20%24diskname%0A%0A%24disk.DiskState%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22AndrewCoughlin_5-1599851626956.png%22%20style%3D%22width%3A%20683px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F217819i155DC167CC682000%2Fimage-dimensions%2F683x86%3Fv%3D1.0%22%20width%3D%22683%22%20height%3D%2286%22%20title%3D%22AndrewCoughlin_5-1599851626956.png%22%20alt%3D%22AndrewCoughlin_5-1599851626956.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20we%20are%20ready%20to%20upload%20our%20disk%20to%20Azure%2C%20to%20do%20this%20you%20will%20type%20the%20following%20and%20wait%20for%20the%20process%20to%20complete%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3Ecd%20%3CLOCATION%20of%3D%22%22%20azcopy%3D%22%22%3E%0A%0A.%5Cazcopy.exe%20copy%20%22%3CLOCATION%20of%3D%22%22%20vhd%3D%22%22%3E%22%20%24diskSas.AccessSAS%20--blob-type%20PageBlob%3C%2FLOCATION%3E%3C%2FLOCATION%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22AndrewCoughlin_6-1599851626969.png%22%20style%3D%22width%3A%20717px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F217821i9A74BA3740C5EA24%2Fimage-dimensions%2F717x129%3Fv%3D1.0%22%20width%3D%22717%22%20height%3D%22129%22%20title%3D%22AndrewCoughlin_6-1599851626969.png%22%20alt%3D%22AndrewCoughlin_6-1599851626969.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhen%20the%20upload%20is%20completed%20you%20will%20get%20the%20following%20results%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22AndrewCoughlin_7-1599851626986.png%22%20style%3D%22width%3A%20727px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F217822iD3FFA727E77D08D6%2Fimage-dimensions%2F727x260%3Fv%3D1.0%22%20width%3D%22727%22%20height%3D%22260%22%20title%3D%22AndrewCoughlin_7-1599851626986.png%22%20alt%3D%22AndrewCoughlin_7-1599851626986.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAfter%20the%20upload%20has%20completed%2C%20you%20will%20revoke%20access%20from%20the%20disk%20as%20this%20is%20not%20needed%2C%20you%20will%20type%20the%20following%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3ERevoke-AzDiskAccess%20-ResourceGroupName%20%24rgName%20-DiskName%20%24diskname%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22AndrewCoughlin_8-1599851626993.png%22%20style%3D%22width%3A%20723px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F217820i76330C5AB2D809A2%2Fimage-dimensions%2F723x138%3Fv%3D1.0%22%20width%3D%22723%22%20height%3D%22138%22%20title%3D%22AndrewCoughlin_8-1599851626993.png%22%20alt%3D%22AndrewCoughlin_8-1599851626993.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-91660949%22%20id%3D%22toc-hId-91660979%22%3ECreate%20Image%20from%20Managed%20Disk%3C%2FH2%3E%0A%3CP%3EWe%20now%20have%20the%20managed%20disk%20uploaded%20to%20the%20cloud.%26nbsp%3B%20The%20next%20step%20is%20to%20create%20an%20image%20from%20that%20managed%20disk.%26nbsp%3B%20When%20the%20image%20is%20created%2C%20we%20want%20to%20make%20sure%20to%20specify%20this%20image%20will%20be%20a%20V2%20image.%26nbsp%3B%20To%20do%20this%20you%20will%20type%20the%20following%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24imageConfig%20%3D%20New-AzImageConfig%20-Location%20%24location%20-HypervGeneration%20V2%0A%0A%24imageConfig%20%3D%20Set-AzImageOsDisk%20-Image%20%24imageConfig%20-OsState%20Generalized%20-OsType%20Windows%20-ManagedDiskId%20%24disk.Id%0A%0A%24image%20%3D%20New-AzImage%20-ImageName%20%24imageName%20-ResourceGroupName%20%24rgName%20-Image%20%24imageConfig%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22AndrewCoughlin_9-1599851627014.png%22%20style%3D%22width%3A%20720px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F217823iA91E9A3FF02784E8%2Fimage-dimensions%2F720x117%3Fv%3D1.0%22%20width%3D%22720%22%20height%3D%22117%22%20title%3D%22AndrewCoughlin_9-1599851627014.png%22%20alt%3D%22AndrewCoughlin_9-1599851627014.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EVerify%20in%20the%20portal%20that%20our%20image%20is%20now%20created%20from%20our%20managed%20disk.%26nbsp%3B%20We%20can%20now%20start%20provisioning%20generation%202%20virtual%20machines%20with%20this%20image.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22AndrewCoughlin_10-1599851627021.png%22%20style%3D%22width%3A%20728px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F217824i78D6F3C5488CBF00%2Fimage-dimensions%2F728x302%3Fv%3D1.0%22%20width%3D%22728%22%20height%3D%22302%22%20title%3D%22AndrewCoughlin_10-1599851627021.png%22%20alt%3D%22AndrewCoughlin_10-1599851627021.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1715793514%22%20id%3D%22toc-hId--1715793484%22%3EConclusion%3C%2FH2%3E%0A%3CP%3EThere%20you%20have%20it%2C%20we%20have%20just%20uploaded%20a%20custom%20windows%20image%20and%20now%20we%20can%20use%20that%20image%20to%20deploy%20generation%202%20virtual%20machines%20in%20your%20Azure%20environment.%26nbsp%3B%20Thank%20you%20for%20taking%20the%20time%20to%20read%20this%20blog%2C%20I%20hope%20this%20helps%20you%20and%20see%20you%20next%20time.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%221%202%203%204%205%206%207%22%3E%3CSTRONG%3EDisclaimer%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%221%202%203%204%205%206%207%22%3EThe%20sample%20scripts%20are%20not%20supported%20under%20any%20Microsoft%20standard%20support%20program%20or%20service.%20The%20sample%20scripts%20are%20provided%20AS%20IS%20without%20warranty%20of%20any%20kind.%20Microsoft%20further%20disclaims%20all%20implied%20warranties%20including%2C%20without%20limitation%2C%20any%20implied%20warranties%20of%20merchantability%20or%20of%20fitness%20for%20a%20particular%20purpose.%20The%20entire%20risk%20arising%20out%20of%20the%20use%20or%20performance%20of%20the%20sample%20scripts%20and%20documentation%20remains%20with%20you.%20In%20no%20event%20shall%20Microsoft%2C%20its%20authors%2C%20or%20anyone%20else%20involved%20in%20the%20creation%2C%20production%2C%20or%20delivery%20of%20the%20scripts%20be%20liable%20for%20any%20damages%20whatsoever%20(including%2C%20without%20limitation%2C%20damages%20for%20loss%20of%20business%20profits%2C%20business%20interruption%2C%20loss%20of%20business%20information%2C%20or%20other%20pecuniary%20loss)%20arising%20out%20of%20the%20use%20of%20or%20inability%20to%20use%20the%20sample%20scripts%20or%20documentation%2C%20even%20if%20Microsoft%20has%20been%20advised%20of%20the%20possibility%20of%20such%20damages.%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1658889%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20this%20blog%20I%20will%20focus%20on%20how%20to%20upload%20a%20custom%20windows%20Hyper-V%20image%20for%20generation%202%20virtual%20machines%20in%20Azure.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Gen2Image.png%22%20style%3D%22width%3A%20691px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F217811i3EB8563D94E62456%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Gen2Image.png%22%20alt%3D%22Gen2Image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1658889%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAndrewCoughlin%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

 

Introduction

This is Andrew Coughlin and I am a Customer Engineer at Microsoft focusing on Azure IaaS. In this blog I will focus on how to upload a custom windows Hyper-V image for generation 2 virtual machines in Azure. Support for generation 2 virtual machines in Azure was released on November 4, 2019, these systems use UEFI boot, SCSI, supported on VMs that support premium storage compared to generation 1 which use PCAT boot, IDE and are available on all VM sizes.  Generation 2 VMs provide for OS disk size greater than 2TB in size and build larger VMs, up to 12TBs. To get additional information about generation 2 virtual machines in Azure please visit this post.

 

If you have ever uploaded a custom image in Azure in the past you will notice the process is very similar.

 

Prerequisites

  • Review the Support for generation 2 VMs on Azure.
  • Install Azure PowerShell as documented here.
  • Create Hyper-V Gen 2 machine to be used as the image.
  • Prepare your Windows Hyper-V image is documented here.
  • Convert VHDX to VHD as documented here.
  • Download and Install azcopy as documented here.
  • Sign in with Azure as documented here.
  • Select Azure subscription to upload image as documented here.

 

Upload Hyper-V Image to Managed Disk

First you want to determine which resource group the image will reside in or if you will create a new resource group. As a reminder a resource group is a container that holds related solutions: virtual machines, storage accounts, disks virtual networks, etc. for your Azure solutions. A resource group can include all resources for your solutions or only those resources that you want to be managed together. For documentation on how to create a new resource group, this can be found on this page. In this example I’m going to use the resource group called “rg-images”.

 

AndrewCoughlin_0-1599851626911.png

 

First, we need to open an elevated PowerShell command prompt.

 

AndrewCoughlin_1-1599851626922.png

 

Next, we will set some variables as we will need these throughout the process, in this example. We are going to be creating this image in Central US, with the image name W2K19-Image-V2, in the resource group called rg-images, with a disk image called W2K19-Image-V2.

  • $location = 'Central US'
  • $imageName = 'W2K19-Image-V2'
  • $rgName = 'rg-images'
  • $diskname = 'W2K19-Image-V2'

 

AndrewCoughlin_2-1599851626929.png

 

Next, we want to create an empty managed disk, you will type the following commands:

 

 

$vhdSizeBytes = (Get-Item "<full File Path>").length

$diskconfig = New-AzDiskConfig -SkuName 'Standard_LRS' -OsType 'Windows' -UploadSizeInBytes $vhdSizeBytes -Location $location -CreateOption 'Upload'

New-AzDisk -ResourceGroupName $rgName  -DiskName $diskname -Disk $diskconfig

 

 

AndrewCoughlin_3-1599851626952.png

 

NOTE: You can replace the Standard_LRS, with Premium_LRS or StandardSSD_LRS.  At the writing of this blog Ultra disks are currently not supported.

 

Next, we need to confirm the disk status is equal to “ReadyToUpload”, you will type the following:

 

 

$disk = Get-AzDisk -ResourceGroupName $rgName -DiskName $diskname

$disk.DiskState

 

 

AndrewCoughlin_4-1599851626954.png

 

NOTE: The disk status must be set to “ReadyToUpload”, if it is not you need to check what was typed in the “New-AzDiskConfig” command.

 

Now we want to create the writable shared access signature (SAS) for the managed disk we just created.  Then we will get the disk status and make sure it is equal to “ActiveUpload”, to do this you will type the following:

 

 

$diskSas = Grant-AzDiskAccess -ResourceGroupName $rgName -DiskName $diskname -DurationInSecond 86400 -Access 'Write'

$disk = Get-AzDisk -ResourceGroupName $rgName -DiskName $diskname

$disk.DiskState

 

 

AndrewCoughlin_5-1599851626956.png

 

Now we are ready to upload our disk to Azure, to do this you will type the following and wait for the process to complete:

 

 

cd <location of Azcopy>

.\azcopy.exe copy "<location of vhd>" $diskSas.AccessSAS --blob-type PageBlob

 

 

AndrewCoughlin_6-1599851626969.png

 

When the upload is completed you will get the following results:

 

AndrewCoughlin_7-1599851626986.png

 

After the upload has completed, you will revoke access from the disk as this is not needed, you will type the following:

 

 

Revoke-AzDiskAccess -ResourceGroupName $rgName -DiskName $diskname

 

 

AndrewCoughlin_8-1599851626993.png

Create Image from Managed Disk

We now have the managed disk uploaded to the cloud.  The next step is to create an image from that managed disk.  When the image is created, we want to make sure to specify this image will be a V2 image.  To do this you will type the following:

 

 

$imageConfig = New-AzImageConfig -Location $location -HypervGeneration V2

$imageConfig = Set-AzImageOsDisk -Image $imageConfig -OsState Generalized -OsType Windows -ManagedDiskId $disk.Id

$image = New-AzImage -ImageName $imageName -ResourceGroupName $rgName -Image $imageConfig

 

 

AndrewCoughlin_9-1599851627014.png

 

Verify in the portal that our image is now created from our managed disk.  We can now start provisioning generation 2 virtual machines with this image.

 

AndrewCoughlin_10-1599851627021.png

 

Conclusion

There you have it, we have just uploaded a custom windows image and now we can use that image to deploy generation 2 virtual machines in your Azure environment.  Thank you for taking the time to read this blog, I hope this helps you and see you next time.

 

Disclaimer

The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.