LoginSignup
1
0

More than 1 year has passed since last update.

Azure上のWindowsサーバをインプレースアップグレードする

Posted at

はじめに

Azure VMのWindowsサーバが簡単にインプレースアップグレード出来るようになっていましたので試してみます。
OSのバージョンによっては最新(2022)にするまでに2回実施する必要があるようです。

アップグレード用ディスクの作成

今回はWIndows Server 2016からWindows Server 2022にアップグレードします。

Azure Powershellでアップグレード用のディスクを作成します。
この段階ではまだOSにログインする必要はありません。
Microsoftのドキュメントで提供されているコードのパラメータを変更します。

#
# Customer specific parameters 

# Resource group of the source VM
$resourceGroup = "tamura-rg"

# Location of the source VM
$location = "Japaneast"

# Zone of the source VM, if any
$zone = "" 

# Disk name for the that will be created
$diskName = "WindowsServer2022UpgradeDisk"

# 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

ディスクが作成されました。

アップグレード前確認

前提条件としてKMSサーバと通信出来る必要があります。
VMはAzureマーケットプレイスのOSイメージから作成しているので通信出来るようになっていますが、
念のため確認します。

アップグレード前のOS。

アップグレード実行

アップグレード用のディスクをVMにアタッチします。

OSにRDPでログインし、Powershellでアップグレードのsetupを実行します。

セットアップ画面が起動しますのでアップグレード先を選択します。

アップグレードが始まりました。

RDPのセッションが切断されたらAzure Portalのブート診断から進捗を確認できます。
ブート診断を設定していない場合は設定変更してください。

アップグレードが完了したようで起動しました。
25分くらい掛かったでしょうか。

アップグレード確認

Azure Portal上でWindows Server 2022に変わっていました。

OS上でもアップグレードが確認出来ました。

終わりに

とても簡単にアップグレード出来ました。
EOL対応等に良いですね。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0