As Windows administrator, you know the importance of keeping up with Windows server versions to stay supported and receive updates.
To do so, you usually have 2 options to upgrade your Windows server version:
- in-place upgrade
- deploy a new virtual machine running the targeted version and then migrate your workloads and data on this new virtual machine
Well, when running virtual machine on Azure, you only have (or had) the last option.
Good news, you can now perform in-place upgrade on virtual machine running on Azure.
But before you start preparing to perform in-place upgrade, here are few things you need know:
- in-place upgrade is possible and supported only from Windows Server 2012 R2 and Windows Server 2016 to Windows Server 2019, or Windows Server 2016 and Windows Server 2019 to Windows Server 2022
- as for any in-place upgrade, ensure you have enough disk space (https://learn.microsoft.com/en-us/windows-server/get-started/hardware-requirements#storage-controller-and-disk-space-requirements)
- the upgraded VM must be configured for volume license (KMS server activation). This is the default for any VM created in Azure but if it has been imported (with a lift and shift for example) you need to configure KMS activation (https://learn.microsoft.com/en-us/troubleshoot/azure/virtual-machines/troubleshoot-activation-problems#step-1-configure-the-appropriate-kms-client-setup-key)
- the virtual machine must use managed disks; you can migrate to managed disk by following these steps https://learn.microsoft.com/en-us/azure/virtual-machines/windows/migrate-to-managed-disks/
Now you are almost ready. The last steps are:
- confirm your running workloads/applications are compatible with the new OS version you are upgrading to
- perform a snapshot – in case you have to roll back
- prepare the upgrade disk; you will need the Azure PowerShell module (Install-Module -Name Az) – latest version 9.3.0
The in-place upgrade requires the use of an upgrade media attached to the VM as managed disk.
This media can be used on multiple VM but only one at a time.
To create the upgrade media, use the below script
# Connect to Azure and select the subscription
Connect-AzAccount
Set-AzContext –Subscription <subscription ID>
# Resource group of the source VM
$resourceGroup = “<name of the resource group where the VM is>”
# Location of the source VM
$location = “<location of the VM>”
# Zone of the source VM, if any
$zone = “”
# Disk name for the that will be created
$diskName = “<upgrade media disk name>”
# Target version for the upgrade – must be either server2022Upgrade or server2019Upgrade
$sku = “server2022Upgrade”
# Common parameters
$publisher = “MicrosoftWindowsServer”
$offer = “WindowsServerUpgrade”
$managedDiskSKU = “Standard_LRS”
# Get the latest version of the special (hidden) VM Image from the Azure Marketplace
$versions = Get-AzVMImage -PublisherName $publisher -Location $location -Offer $offer -Skus $sku | sort-object -Descending {[version] $_.Version}
$latestString = $versions[0].Version
# Get the special (hidden) VM Image from the Azure Marketplace by version – the image is used to create a disk to upgrade to the new version
$image = Get-AzVMImage -Location $location -PublisherName $publisher -Offer $offer -Skus $sku -Version $latestString
# Create Resource Group if it doesn’t exist
if (-not (Get-AzResourceGroup -Name $resourceGroup -ErrorAction SilentlyContinue))
{
New-AzResourceGroup -Name $resourceGroup -Location $location
}
# Create Managed Disk from LUN 0
if ($zone){
$diskConfig = New-AzDiskConfig -SkuName $managedDiskSKU `
-CreateOption FromImage `
-Zone $zone `
-Location $location
} else {
$diskConfig = New-AzDiskConfig -SkuName $managedDiskSKU `
-CreateOption FromImage `
-Location $location
}Set-AzDiskImageReference -Disk $diskConfig -Id $image.Id -Lun 0
New-AzDisk -ResourceGroupName $resourceGroup `
-DiskName $diskName `
-Disk $diskConfig
Then you can attach the upgrade media disk on the virtual machine; it can be done even if the VM is running.
And finally you can start the in-place upgrade process by connecting to the virtual machine and launch the command from the upgrade disk
setup.exe /auto upgrade /dynamicupdate disable
You can then select the target image
During the upgrade, the RDP session will be disconnected; you can monitor the progress using the screenshot feature available in the Boot diagnostics
Once you have completed your in-place upgrade, you can proceed to remove the snapshot and the upgrade media.