Code Monkey home page Code Monkey logo

azure-vm-in-place-upgrade-examples's Introduction

Azure Virtual Machine In-place upgrade examples

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:

  1. In-place upgrade docs
  2. Windows Setup API options

Table of contents

Prerequisites

  1. PowerShell
  2. Azure Subscription and Azure PowerShell module installed
  3. 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:

  1. 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
  2. (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

Official way (managed disks)

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:

  1. ResourceGroup - Provide the name of the resourceGroup
  2. VmName - Provide the name of the VM to be upgraded
  3. Location - Provide the location of the Azure Resource Group
  4. DiskName - Provide the name of the disk
  5. Zone - Provide the name of zone for the source VM
  6. 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.

  1. Connect to the VM using RDP or RDP-Bastion.
  2. Determine the drive letter for the upgrade disk (typically E: or F: if there are no other data disks).
  3. Start Windows PowerShell.
  4. Change directory to the only directory on the upgrade disk.
  5. 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:

  1. IPUTenantId - tenant id
  2. IPUSubscriptionId - subscription where VM is located
  3. IPUAppId - application id
  4. IPUAppSecret - secret for the application to login
  5. 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:

  1. FileShareLocation - Azure Files share location with provided data
  2. IsoFolder - folder name where ISO file is located
  3. IsoName - name of the ISO
  4. Username - username to authenticate to Azure Files
  5. 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.

Integration with Azure Monitor to get the logs in one place

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"

Links for additional information

  1. In-place upgrade docs
  2. PowerShell
  3. Run scripts on Azure Virtual Machine with Run command
  4. Custom script extensions in Azure Virtual Machine
  5. Create snapshot of the disks
  6. Backup and restore for Managed Disks
  7. Azure Monitor HTTP Data Collector API

Contributing

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.

azure-vm-in-place-upgrade-examples's People

Contributors

bovrhovn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.