Application Migration Service (AWS MGN)で移行しながらOSのアップグレードをしてみた (WS2012R2→WS2022)

この世に存在するWindows Server 2012/R2を救いたい。さあご一緒に

こんにちは、AWS事業本部の荒平(@0Air)です。

2023年10月10日にWindows Server 2012 / 2012 R2の延長サポートが終了しました。
AWSのマーケットプレイスからも削除されています。

Windows Server 2012 / 2012 R2が眠っている環境はまだまだ少なくないのではないでしょうか。

Application Migration Service (AWS MGN)を利用すれば、AWSへの移行と同時にWindows OSのアップグレードを容易に実施することが可能です。
執筆時点では、以下のOSが対象になっています。

アップグレード元OS アップグレード先OS
Windows Server 2008 R2 Windows Server 2012 R2
Windows Server 2012 R2 Windows Server 2016
Windows Server 2012 R2 Windows Server 2019
Windows Server 2012 R2 Windows Server 2022
Windows Server 2016 Windows Server 2019
Windows Server 2016 Windows Server 2022
Windows Server 2019 Windows Server 2022

参考:

今回は、このOSアップグレード機能が統合されたAWS MGNを用いて、移行しながら、Windows Server 2012 R2からWindows Server 2022に変換してみます。

前提条件

上記のドキュメントに前提条件が記載されています。

  • TLS バージョン 1.2が利用可能であること
  • インスタンスにSSM Agentがインストールされていること
    • 但し、AWS MGNを利用する場合はSSM Agentを同時に導入することが可能です
  • AD参加マシンは、ホスト名の競合を避けるため、ADDCに接続できないサブネットを選択すること
  • 指定するサブネットは、自動割当パブリックIPv4アドレスが有効になっていること
    • S3やMicrosoftへのアウトバウンド通信が発生します
  • Systems Manager に権限を提供するIAMインスタンスプロファイルが必要
  • ブートディスクに20GBの空き容量があること
  • 次のいずれかに該当する場合は対象外
    • Windows クライアントOS (Windows10など)
    • ドメインコントローラー (ADDC)、およびクラスター
    • リモートデスクトップサービス (RDSH, RDCB, RDVH, RDWA)の機能を有する

やってみた

1. Windows Server 2012 R2の準備

検証用に移行元のマシンイメージを用意しました。
残念ながら、AWS Marketplaceからは2023/10/10までに削除されてしまっていたため、辛うじて残っていたElasticBeanstalk用のAMIを利用しました。

もちろん、Windows Server 2012 R2が既に環境上にある場合は、この手順は不要です。
新規で用意する場合は、コミュニティAMIを利用することになると思いますので、規約等注意が必要です。

ゲストOSに入り、winver を確認します。

2. IAM インスタンスプロファイルを作成する

AmazonSSMManagedInstanceCore のマネージドポリシーが付与されたIAMインスタンスプロファイルを作成します。

今回はCloudShellにコマンドを投げるとお手軽なので、以下コマンドにて作成しました。

aws iam create-role --role-name ssm-server-role --assume-role-policy-document '{"Version": "2012-10-17","Statement": [{"Effect": "Allow","Principal": {"Service": "ec2.amazonaws.com"},"Action": "sts:AssumeRole"}]}'
aws iam create-instance-profile --instance-profile-name ssm-server-role
aws iam add-role-to-instance-profile --instance-profile-name ssm-server-role --role-name ssm-server-role
aws iam attach-role-policy --role-name ssm-server-role --policy-arn arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore

後の手順のために、作成したインスタンスプロファイルのARNをコピーします。

3. 移行先サブネットの用意

任意のパブリックサブネットを用意します。
Windows upgradeのテンプレートを利用する場合は、IPv4アドレス自動割当が有効である必要があります。

4. Post-Launch-Action (起動後テンプレート)の作成

起動後テンプレートのリストから、「Windows upgrade」のカードを見つけ、「編集」ボタンをクリックします。

デフォルトでは、このカードは無効になっているため、「このアクションをアクティブ化する」にチェックを入れます。

画面下に進め、アクションパラメータを入力します。

パラメータの例を記載します。

項目 値 (例) 説明
IamInstanceProfile ssm-role-name SSMを実行するためのIAMインスタンスプロファイル名
ARNではないため注意が必要
SubnetId subnet-xxxxxxxxxxxxxxx IPv4自動割当が有効なパブリックサブネットのID
TargetWindowVersion 2022 OSバージョンをプルダウンから選択
BYOLWindowsMediaSnapshotId - BYOLインスタンスをアップグレードする場合にのみ指定
AlternativeKeyPairName - 元のインスタンスにキーペアが割り当てられていない場合に指定
KeepPreUpgradeImageBackUp True デフォルトFalseTrueに設定すると、アップグレード前のイメージが保持される
RebootInstanceBeforeTakingImage True デフォルトFalseTrueに設定すると、アップグレード前にインスタンスを再起動する
AutomationAssumeRole - SSM Automation用のIAM Role ARN

5. AWS Replication Agentのインストール

ゲストOSへ、AWS Replication Agentのインストールを行います。
IAMのアクセスキーを発行して以下コマンドを置き換えます。
AWSApplicationMigrationServiceEc2InstancePolicy権限が必要です)

.\AwsReplicationWindowsInstaller.exe --region ap-northeast-1 --aws-access-key-id {IAMアクセスキーID} --aws-secret-access-key {IAMシークレットアクセスキー} --no-prompt

以下ドキュメントにあるURLから、使用リージョンに応じたエージェントをダウンロードし、コマンドを実行します。
(東京リージョンの場合:https://aws-application-migration-service-ap-northeast-1.s3.ap-northeast-1.amazonaws.com/latest/windows/AwsReplicationWindowsInstaller.exe )

ただし、Windows Server 2008以前はレガシー用エージェントとなるため注意が必要です。

The AWS Replication Agent was successfully installed. と表示されれば、正常にレプリケーションが開始されます。

ディスク容量や通信状況に応じて所要時間は変わります。
レプリケーションが完了すれば、コンソール上でも「最初のレプリケーションが終了しました」と表示されます。
以前より分かりやすいメッセージになっていました。

6. EC2インスタンスの起動・確認

早速ですが、EC2インスタンスを起動してOSバージョンが上がっているか確認していきます。

インスタンス立ち上げ時に「起動後のアクションのステータス」に進捗が表示されます。
Windows Upgradeが有効になっている場合、かなりの時間を要します。

完了すれば、移行ダッシュボードの下の方にステータスが「成功」と表示されます。
検証では、ディスク容量100GB、Windows Server 2012R2→Windows Server 2022で1時間15分を要しました。

Upgrade済みのマシンイメージはAMIとしてリストアップされているため、これを新規インスタンスとして起動します。

同様にゲストOSに入り、 winver を叩きます。
Windows Server (R) 2022と表示され、無事アップグレードできていることが確認できました!

【参考】アプリケーション一覧

以下のコマンドにて、Windows Server 2012 R2 (移行元)とWindows Server 2022 (移行先)のインストールアプリに差が無いかを確認しました。
Microsoft Edge, SSM Agent, EC2ConfigServiceの差異がありました。
(補足: SSM AgentはAWS MGNの同様のアクションにより新しいバージョンが導入されています)

Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table -AutoSize

Windows Server 2012 R2 (移行元)

DisplayName                                                        DisplayVersion  Publisher
-----------                                                        --------------  ---------


Microsoft .NET Core Host - 2.0.9 (x86)                             16.36.26615     Microsoft Corporation
Microsoft .NET Core Runtime - 3.0.0 (x86)                          24.0.28113      Microsoft Corporation
AWS Tools for Windows                                              3.15.1583       Amazon Web Services Dev
Microsoft .NET Core Host FX Resolver - 2.1.30 (x86)                16.120.30411    Microsoft Corporation
Microsoft .NET Core 2.2.8 - Windows Server Hosting                 2.2.8.0         Microsoft Corporation
Microsoft .NET Core 2.0.9 - Windows Server Hosting                 2.0.40703.10031 Microsoft Corporation
Microsoft .NET Core SDK 3.0.100 (x64)                              3.0.100.14277   Microsoft Corporation
Microsoft .NET Core Host - 3.0.0 (x86)                             24.0.28113      Microsoft Corporation
Microsoft .NET Core Runtime - 3.0.0 (x64)                          3.0.0.28113     Microsoft Corporation
Microsoft .NET Core Runtime - 2.0.9 (x64)                          2.0.9.26615     Microsoft Corporation
Microsoft ASP.NET Core 2.0.9 Runtime Package Store (x86)           2.0.13103.0     Microsoft Corporation
Microsoft .NET Core Host - 2.1.30 (x86)                            16.120.30411    Microsoft Corporation
Microsoft .NET Core Host - 2.2.8 (x86)                             16.160.28209    Microsoft Corporation
Microsoft ASP.NET Core 2.1.30 Shared Framework (x86)               2.1.30.60071    Microsoft Corporation
.NET Core SDK 1.1.14 (x64)                                         1.1.14          Microsoft Corporation
Microsoft .NET Core Host FX Resolver - 3.0.0 (x86)                 24.0.28113      Microsoft Corporation
Microsoft ASP.NET Web Pages                                        1.0.20105.0     Microsoft Corporation
Microsoft .NET Core Runtime - 2.2.8 (x64)                          2.2.8.28209     Microsoft Corporation
Microsoft .NET Core Host FX Resolver - 2.0.9 (x86)                 16.36.26615     Microsoft Corporation
Microsoft .NET Core Runtime - 2.1.30 (x86)                         16.120.30411    Microsoft Corporation
Microsoft .NET Core Runtime - 2.2.8 (x86)                          2.2.8.28209     Microsoft Corporation
Microsoft ASP.NET Core 2.2.8 Shared Framework (x86)                2.2.8.0         Microsoft Corporation
Microsoft .NET Core Runtime - 2.2.8 (x86)                          16.160.28209    Microsoft Corporation
Microsoft .NET Core SDK 2.1.818 (x64)                              2.1.818         Microsoft Corporation
aws-cfn-bootstrap                                                  2.0.10          Amazon Web Services
Microsoft .NET Core SDK 2.2.207 (x64)                              2.2.207         Microsoft Corporation
Microsoft .NET Core 3.0.0 - Windows Server Hosting                 3.0.0.19465     Microsoft Corporation
Microsoft .NET Core 2.1.30 - Windows Server Hosting                2.1.30.60071    Microsoft Corporation
Microsoft ASP.NET Core 3.0.0 Shared Framework (x86)                3.0.0.0         Microsoft Corporation
Microsoft .NET Core 1.0.16 & 1.1.13 - Windows Server Hosting       1.1.50423.187   Microsoft Corporation
Amazon SSM Agent                                                   3.1.1045.0      Amazon Web Services
Microsoft .NET Core Runtime - 3.0.0 (x86)                          3.0.0.28113     Microsoft Corporation
Microsoft ASP.NET MVC 3                                            3.0.50813.0     Microsoft Corporation
Microsoft ASP.NET MVC 2                                            2.0.60926.0     Microsoft Corporation
Microsoft .NET Core Runtime - 2.0.9 (x86)                          2.0.9.26615     Microsoft Corporation
Microsoft .NET Core Runtime - 2.1.30 (x64)                         2.1.30.30411    Microsoft Corporation
Microsoft .NET Core Runtime - 2.1.30 (x86)                         2.1.30.30411    Microsoft Corporation
Microsoft .NET Core Host FX Resolver - 2.2.8 (x86)                 16.160.28209    Microsoft Corporation
Microsoft .NET Core Runtime - 2.0.9 (x86)                          16.36.26615     Microsoft Corporation
Microsoft Visual C++ 2015-2019 Redistributable (x64) - 14.29.30135 14.29.30135.0   Microsoft Corporation

Windows Server 2022 (移行先)

DisplayName                                                        DisplayVersion  Publisher
-----------                                                        --------------  ---------

Microsoft Edge                                                     118.0.2088.61   Microsoft Corporation
Microsoft Edge Update                                              1.3.177.11

Microsoft .NET Core Host - 2.0.9 (x86)                             16.36.26615     Microsoft Corporation
Microsoft .NET Core Runtime - 3.0.0 (x86)                          24.0.28113      Microsoft Corporation
AWS Tools for Windows                                              3.15.1583       Amazon Web Services Dev
Microsoft .NET Core Host FX Resolver - 2.1.30 (x86)                16.120.30411    Microsoft Corporation
Microsoft .NET Core 2.2.8 - Windows Server Hosting                 2.2.8.0         Microsoft Corporation
Microsoft .NET Core 2.0.9 - Windows Server Hosting                 2.0.40703.10031 Microsoft Corporation
Microsoft .NET Core SDK 3.0.100 (x64)                              3.0.100.14277   Microsoft Corporation
Microsoft .NET Core Host - 3.0.0 (x86)                             24.0.28113      Microsoft Corporation
Microsoft .NET Core Runtime - 3.0.0 (x64)                          3.0.0.28113     Microsoft Corporation
Microsoft .NET Core Runtime - 2.0.9 (x64)                          2.0.9.26615     Microsoft Corporation
Microsoft ASP.NET Core 2.0.9 Runtime Package Store (x86)           2.0.13103.0     Microsoft Corporation
Microsoft .NET Core Host - 2.1.30 (x86)                            16.120.30411    Microsoft Corporation
Microsoft .NET Core Host - 2.2.8 (x86)                             16.160.28209    Microsoft Corporation
Microsoft ASP.NET Core 2.1.30 Shared Framework (x86)               2.1.30.60071    Microsoft Corporation
.NET Core SDK 1.1.14 (x64)                                         1.1.14          Microsoft Corporation
Microsoft .NET Core Host FX Resolver - 3.0.0 (x86)                 24.0.28113      Microsoft Corporation
Microsoft ASP.NET Web Pages                                        1.0.20105.0     Microsoft Corporation
EC2ConfigService                                                   4.9.3519.0      Amazon Web Services
Microsoft .NET Core Runtime - 2.2.8 (x64)                          2.2.8.28209     Microsoft Corporation
Microsoft .NET Core Host FX Resolver - 2.0.9 (x86)                 16.36.26615     Microsoft Corporation
Microsoft .NET Core Runtime - 2.1.30 (x86)                         16.120.30411    Microsoft Corporation
Microsoft .NET Core Runtime - 2.2.8 (x86)                          2.2.8.28209     Microsoft Corporation
Microsoft ASP.NET Core 2.2.8 Shared Framework (x86)                2.2.8.0         Microsoft Corporation
Microsoft .NET Core Runtime - 2.2.8 (x86)                          16.160.28209    Microsoft Corporation
Microsoft .NET Core SDK 2.1.818 (x64)                              2.1.818         Microsoft Corporation
aws-cfn-bootstrap                                                  2.0.10          Amazon Web Services
Microsoft .NET Core SDK 2.2.207 (x64)                              2.2.207         Microsoft Corporation
Microsoft .NET Core 3.0.0 - Windows Server Hosting                 3.0.0.19465     Microsoft Corporation
Microsoft .NET Core 2.1.30 - Windows Server Hosting                2.1.30.60071    Microsoft Corporation
Microsoft ASP.NET Core 3.0.0 Shared Framework (x86)                3.0.0.0         Microsoft Corporation
Microsoft .NET Core 1.0.16 & 1.1.13 - Windows Server Hosting       1.1.50423.187   Microsoft Corporation
Amazon SSM Agent                                                   3.2.1705.0      Amazon Web Services
EC2ConfigService                                                   4.9.3519.0      Amazon Web Services
Microsoft .NET Core Runtime - 3.0.0 (x86)                          3.0.0.28113     Microsoft Corporation
Microsoft ASP.NET MVC 3                                            3.0.50813.0     Microsoft Corporation
Microsoft ASP.NET MVC 2                                            2.0.60926.0     Microsoft Corporation
Microsoft .NET Core Runtime - 2.0.9 (x86)                          2.0.9.26615     Microsoft Corporation
Microsoft .NET Core Runtime - 2.1.30 (x64)                         2.1.30.30411    Microsoft Corporation
Microsoft .NET Core Runtime - 2.1.30 (x86)                         2.1.30.30411    Microsoft Corporation
Microsoft .NET Core Host FX Resolver - 2.2.8 (x86)                 16.160.28209    Microsoft Corporation
Microsoft .NET Core Runtime - 2.0.9 (x86)                          16.36.26615     Microsoft Corporation
Microsoft Visual C++ 2015-2019 Redistributable (x64) - 14.29.30135 14.29.30135.0   Microsoft Corporation

差分

Microsoft Edge                                                     118.0.2088.61   Microsoft Corporation
Microsoft Edge Update                                              1.3.177.11
EC2ConfigService                                                   4.9.3519.0      Amazon Web Services
Amazon SSM Agent                                                   3.2.1705.0      Amazon Web Services
EC2ConfigService                                                   4.9.3519.0      Amazon Web Services

参考

今回、検証の際にはエラーが頻発していましたが、その原因はディスク容量不足でした。
もし不明なエラーで悩まれている際は、AWS MGNおよびWindows Upgradeの要件を確認してみてください。

おわりに

今回は、AWS MGNによる移行と同時に実行できるWindows Upgradeを試してみました。
動作はSystems Manager Automationと同じですが、AWS MGNに統合されている分お手軽に実施できます(SSM Agentも導入してくれる)

このエントリが誰かの助けになれば幸いです。

それでは、AWS事業本部 コンサルティング部の荒平(@0Air)がお送りしました!

参考