An in-place upgrade allows you to go from an older operating system to a newer one while keeping your settings, server roles, and data intact. This repository shows few examples of how to effectively perform the procedure. If you want to deep dive into how the update works on Windows Server OS, check this article here.
Before proceeding you need to read this two articles to set the base:
- In-place upgrade docs
- Windows Setup API options
- Azure Virtual Machine In-place upgrade examples
- Table of contents
- Links for additional information
- Contributing
- PowerShell
- Azure Subscription and Azure PowerShell module installed
- Owner role on the subscription
To set up the environment you need to create a resource group and a VM with the OS you want to upgrade. You can use the Azure Portal or Azure PowerShell to create the VM.
To help with the setup and install tools, go to script folder:
- Init.ps1 - creates a resource group and a VM with the OS you want to upgrade - check bicep folder for parameter files and configure parameters to be used or change the values in script
- (optional)Install-Bicep.ps - installs Bicep for ARM template deployment
In order to change the SKU of the machine to upgrade, you can find the values via the Azure Portal or via the PowerShell. More here.
# GET available SKU in West Europe
$locName = "WestEurope"
Get-AzVMImagePublisher -Location $locName | Select PublisherName
$pubName = "MicrosoftWindowsServer"
Get-AzVMImageOffer -Location $locName -PublisherName $pubName | Select Offer
$offerName = "WindowsServer"
Get-AzVMImageSku -Location $locName -PublisherName $pubName -Offer $offerName | Select Skus
To start an in-place upgrade the upgrade media must be attached to the VM as a Managed Disk. The upgrade media disk can be used to upgrade multiple VMs, but it can only be used to upgrade a single VM at a time. To upgrade multiple VMs simultaneously multiple upgrade disks must be created for each simultaneous upgrade.
To attach the disk to the machine, you can use the following script (you need to go to the script folder):
.\Create-UpgradableDisk.ps1 -ResourceGroup "InPlaceUpgradeRG" -VmName "ipu-vm-2016" -Location "westeurope" -DiskName "ipu-upgrade-disk" -Zone "" -UpgradeToWindowsServer2019
Parameters:
- ResourceGroup - Provide the name of the resourceGroup
- VmName - Provide the name of the VM to be upgraded
- Location - Provide the location of the Azure Resource Group
- DiskName - Provide the name of the disk
- Zone - Provide the name of zone for the source VM
- UpgradeToWindowsServer2019 - Provide the name of the OS to upgrade to - you can choose between 2022 or 2019
To start the upgrade, you need to have VM in running state.
- Connect to the VM using RDP or RDP-Bastion.
- Determine the drive letter for the upgrade disk (typically E: or F: if there are no other data disks).
- Start Windows PowerShell.
- Change directory to the only directory on the upgrade disk.
- Execute the following command to start the upgrade:
.\setup.exe /auto upgrade /dynamicupdate disable
Select the correct "Upgrade to" image based on the current version and configuration of the VM
Upgrade from | Upgrade to |
---|---|
Windows Server 2012 R2 (Core) | Windows Server 2019 |
Windows Server 2012 R2 | Windows Server 2019 (Desktop Experience) |
Windows Server 2016 (Core) | Windows Server 2019 -or- Windows Server 2022 |
Windows Server 2016 (Desktop Experience) | Windows Server 2019 (Desktop Experience) -or- Windows Server 2022 (Desktop Experience) |
Windows Server 2019 (Core) | Windows Server 2022 |
Windows Server 2019 (Desktop Experience) | Windows Server 2022 (Desktop Experience) |
You will need to upgrade VM to volume license (KMS server activation). Checks docs for more.
ISO with Powershell (via Azure VM Run Script Extension and either managed Azure SDK or Azure Automation or serverless aka Azure Functions)
To start an in-place upgrade you can upgrade via ISO file if ISO file enables the upgrade (check docs).
Code is written in .NET Core. You will need to have .NET installed to continue. How to do that is documented here.
Navigate to src folder and to the project folder:
Set-Location "./src/UpdateViaManagedAPI"
Run the project by executing the following command:
dotnet run
Follow the instructions on the screen or provide environment variables to login to Azure:
- IPUTenantId - tenant id
- IPUSubscriptionId - subscription where VM is located
- IPUAppId - application id
- IPUAppSecret - secret for the application to login
- vmName - name of the VM to be upgraded
If you want to use the following script to update the VM, you need to have the following environment variables set:
- FileShareLocation - Azure Files share location with provided data
- IsoFolder - folder name where ISO file is located
- IsoName - name of the ISO
- Username - username to authenticate to Azure Files
- Key - key to authenticate to Azure Files
How to pass env variables - you can check out docs for dotnet run.
If you want to automate the process, you can use PowerShell great ability to prepare the environment for you.
Get-Content $PathToENVFile | ForEach-Object {
$name, $value = $_.split('=')
Set-Content env:\$name $value
}
Prepare file (example here - rename to .env) and exclude *.env files from putting it to the repo. More here.
If you want to enable/add additional features, you can read about it more on this site:
Start-Process "https://github.com/azure-samples/azure-samples-net-management/tree/master/samples/compute/manage-virtual-machine-extension"
Remarks: If you don't want to install .NET SDK on your machine, you can use GitHub Codespaces to run the code. Check this video.
Azure Monitor enables you to monitor your workloads and add your own data to custom table in Azure Log Analytics. We can send data to REST endpoint or save it to events on the system and onboarding Azure VM to the Azure Monitoring, which will pick up the data in the system events.
Check out great article how to do that here.
Start-Process "https://learn.microsoft.com/en-us/azure/azure-monitor/logs/data-collector-api?tabs=powershell"
- In-place upgrade docs
- PowerShell
- Run scripts on Azure Virtual Machine with Run command
- Custom script extensions in Azure Virtual Machine
- Create snapshot of the disks
- Backup and restore for Managed Disks
- Azure Monitor HTTP Data Collector API
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.