Skip to content

Instantly share code, notes, and snippets.

@thecloudtaylor
Last active October 10, 2023 19:18
Show Gist options
  • Save thecloudtaylor/c6b551f24c198ebdaba6d8eca429bae8 to your computer and use it in GitHub Desktop.
Save thecloudtaylor/c6b551f24c198ebdaba6d8eca429bae8 to your computer and use it in GitHub Desktop.
Notes For Testing Annual Channel

Creating the VHD

Best run in an Azure VM so your not having to download/upload large files (WS2022 seems to be fine)

Download the Annual Channel ISO

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

Optional - If you need OpenSSH

There are a few approaches to accomplish this - to reduce more downloads I'm copying the FOD files into the VHD.

  1. Mount the corresponding "Microsoft Server Language and Optional Features Preview" ISO
  2. Copy out the FOD Files "mkdir c:\temp\OpenSSHFOD", "copy E:\LanguagesAndOptionalFeatures\OpenSSH-* c:\temp\OpenSSHFOD"

Download Convert-Windows Image

https://raw.githubusercontent.com/x0nn/Convert-WindowsImage/main/Convert-WindowsImage.ps1

Hack a few lines...

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

Run Convert-WindowsImage

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.

Create Azure Blob Store and SIG

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.

Params

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

1) Create RG

az group create --name $resourceGroup --location $location

2) Create Storage Account

az storage account create \
    --name $storageAccountName \
    --resource-group $resourceGroup \
    --location $location \
    --sku Standard_LRS \
    --encryption-services blob

3) Create container (note you need to update the scope)

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>"

4) Create a storage container

az storage container create \
    --account-name $storageAccountName \
    --name $storageContainer \
    --auth-mode login

5) Upload the VHD to the container (Update the file names as needed)

Two approaches the first is slower...

Option 1:

az storage blob upload \
    --account-name $storageAccountName \
    --container-name $storageContainer \
    --name 23H2_25951.vhd \
    --file 23H2_25951.vhd \
    --auth-mode login

Option 2:

  1. Download and extract azcopy.exe. https://aka.ms/downloadazcopy-v10-windows
  2. Login azcopy login
  3. Upload azcopy copy 23H2_25951.vhd https://<$storageAccountName>.blob.core.windows.net/<$storageContainer>/23H2_25951.vhd

6) Create the SIG

az sig create --resource-group $resourceGroup --gallery-name $galleryName

7) Create an Image Definition

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

8) Create an Image (update the VHD URI and Verions number)

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

Adding an new OS version

This assumes you have already created a SIG and have created a new VHD.

1) Upload the new VHD to the Blob store

az storage blob upload \
    --account-name $storageAccountName \
    --container-name $storageContainer \
    --name 23H2_XXXXX.vhd \
    --file 23H2_XXXXX.vhd \
    --auth-mode login

2) Create an New Image Definition

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

3) Create an Image (update the VHD URI and Verions number)

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment