Best run in an Azure VM so your not having to download/upload large files (WS2022 seems to be fine)
Download annual channel ISO (goto https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewserver NOTE: if you also need OpenSSH download the corresponding "Microsoft Server Language and Optional Features Preview" ISO
There are a few approaches to accomplish this - to reduce more downloads I'm copying the FOD files into the VHD.
- Mount the corresponding "Microsoft Server Language and Optional Features Preview" ISO
- Copy out the FOD Files "mkdir c:\temp\OpenSSHFOD", "copy E:\LanguagesAndOptionalFeatures\OpenSSH-* c:\temp\OpenSSHFOD"
https://raw.githubusercontent.com/x0nn/Convert-WindowsImage/main/Convert-WindowsImage.ps1
On Win11 I had to hack line 2042, this was before I remembered I needed a fixed VHD... On testing w/fixed VHD on WS2022 I had to change another line (below)
#$windowsDrive = $(Get-Partition -Volume $windowsVolume).AccessPaths[0].substring(0,2)
$windowsDrive = ($(Get-Partition -PartitionNumber $windowsPartition.PartitionNumber -DiskNumber $windowsPartition.DiskNumber).DriveLetter + ":")
On WS2022 I didn't need the change on 2042 but I did need to have line 1881
#$newVhd = New-VHD -Path $VHDPath -SizeBytes $SizeBytes -BlockSizeBytes $BlockSizeBytes -Fixed
$newVhd = New-VHD -Path $VHDPath -SizeBytes $SizeBytes -Fixed
From the directory with Convert-WindowsImage.ps1 (c:\temp)
. .\Convert-WindowsImage.ps1
Convert-WindowsImage -SourcePath C:\temp\Windows_InsiderPreview_ServerDatacenter_Core_Annual_Edition_en-us_25951.iso -VHDFormat VHD -SizeBytes 30GB -IsFixed:$true -DiskLayout BIOS -VHDPath C:\temp\23H2_25951.vhd #-MergeFolder c:\temp\OpenSSHFOD
NOTE: if you also need OpenSSH add "-MergeFolder c:\temp\OpenSSHFOD" to above so it will copy over the fod.
Some of these steps are only needed the first time. You should be able to update/add a new image by running step 5 and 8 alone, or probably better step 5, 7 and 8 to create a new def with the new version.
location=westus2
galleryName=annualChannelGallery
resourceGroup=annualChannelVHD
imageDefinition=WS23H2_25951
publisher=Me
offer=testimage
sku=testsku
storageAccountName=taylorbtest
subscription=7b366897-7bba-4af8-a625-1d5ebb97a628
storageContainer=anchanvhd
az group create --name $resourceGroup --location $location
az storage account create \
--name $storageAccountName \
--resource-group $resourceGroup \
--location $location \
--sku Standard_LRS \
--encryption-services blob
az ad signed-in-user show --query id -o tsv | az role assignment create \
--role "Storage Blob Data Contributor" \
--assignee @- \
--scope "/subscriptions/<SUBID>/resourceGroups/<$resourceGroup>/providers/Microsoft.Storage/storageAccounts/<$storageAccountName>"
az storage container create \
--account-name $storageAccountName \
--name $storageContainer \
--auth-mode login
Two approaches the first is slower...
az storage blob upload \
--account-name $storageAccountName \
--container-name $storageContainer \
--name 23H2_25951.vhd \
--file 23H2_25951.vhd \
--auth-mode login
- Download and extract azcopy.exe. https://aka.ms/downloadazcopy-v10-windows
- Login
azcopy login
- Upload
azcopy copy 23H2_25951.vhd https://<$storageAccountName>.blob.core.windows.net/<$storageContainer>/23H2_25951.vhd
az sig create --resource-group $resourceGroup --gallery-name $galleryName
az sig image-definition create \
--resource-group $resourceGroup \
--gallery-name $galleryName \
--gallery-image-definition $imageDefinition \
--publisher $publisher \
--offer $offer \
--sku $sku \
--os-type Windows \
--os-state generalized
az sig image-version create --resource-group $resourceGroup \
--gallery-name $galleryName --gallery-image-definition $imageDefinition \
--gallery-image-version 1.0.0 \
--os-vhd-storage-account /subscriptions/<SUBID>/resourceGroups/<$resourceGroup>/providers/Microsoft.Storage/storageAccounts/<$storageAccountName> \
--os-vhd-uri https://<$storageAccountName>.blob.core.windows.net/<$storageContainer>/23H2_25951.vhd
This assumes you have already created a SIG and have created a new VHD.
az storage blob upload \
--account-name $storageAccountName \
--container-name $storageContainer \
--name 23H2_XXXXX.vhd \
--file 23H2_XXXXX.vhd \
--auth-mode login
Note that the SKU and Image Definition Name changed
sku=WS23H2_30000
imageDefinition=WS23H2_30000
az sig image-definition create \
--resource-group $resourceGroup \
--gallery-name $galleryName \
--gallery-image-definition $imageDefinition \
--publisher $publisher \
--offer $offer \
--sku $sku \
--os-type Windows \
--os-state generalized
az sig image-version create --resource-group $resourceGroup \
--gallery-name $galleryName --gallery-image-definition $imageDefinition \
--gallery-image-version 1.0.0 \
--os-vhd-storage-account /subscriptions/<SUBID>/resourceGroups/<$resourceGroup>/providers/Microsoft.Storage/storageAccounts/<$storageAccountName> \
--os-vhd-uri https://<$storageAccountName>.blob.core.windows.net/<$storageContainer>/23H2_XXXXX.vhd