😀

Azure の CentOS を Rocky Linux にマイグレーションしてみた

に公開

背景と目的

CentOS 8 のサポート終了に向けて、既存の CentOS 8 を簡単に Rocky Linux へマイグレーション出来るのか試してみました。

前提条件

コマンドの実施環境は、Mac + Azure CLI です。

zsh
% sw_vers
ProductName:    macOS
ProductVersion: 11.4
BuildVersion:   20F71

% az version
{
  "azure-cli": "2.26.0",
  "azure-cli-core": "2.26.0",
  "azure-cli-telemetry": "1.0.6",
  "extensions": {}
}

実施内容

zsh
# 環境変数を設定します
region=japaneast
prefix=mnrcentos

# VM のパスワードを生成します
vmpass=$(openssl rand -base64 16)
echo $vmpass

# リソースグループを作成します
az group create \
  --name ${prefix}-rg \
  --location $region

# VM イメージを探します(現時点は OpenLogic が提供している CentOS 8.4 が見当たらなかったので 8.3 にしました)
az vm image list \
  --offer centos \
  --publisher openlogic \
  --sku 8_3 \
  --all \
  --output table

Offer    Publisher    Sku       Urn                                       Version
-------  -----------  --------  ----------------------------------------  --------------
CentOS   OpenLogic    8_3       OpenLogic:CentOS:8_3:8.3.2020120900       8.3.2020120900
CentOS   OpenLogic    8_3       OpenLogic:CentOS:8_3:8.3.2021020400       8.3.2021020400
CentOS   OpenLogic    8_3-gen2  OpenLogic:CentOS:8_3-gen2:8.3.2020120901  8.3.2020120901
CentOS   OpenLogic    8_3-gen2  OpenLogic:CentOS:8_3-gen2:8.3.2021020401  8.3.2021020401

# VM を作成します
az vm create \
  --resource-group ${prefix}-rg \
  --name ${prefix}-vm \
  --os-disk-name ${prefix}-vmOSDisk \
  --image OpenLogic:CentOS:8_3:8.3.2021020400 \
  --admin-username azureuser \
  --admin-password $vmpass \
  --size Standard_A2_v2 \
  --nsg-rule NONE \
  --storage-sku Standard_LRS

# 自動生成された NSG を見つけます
nsg=$(az network nsg list \
  --resource-group ${prefix}-rg \
  --query "[].name" \
  --out tsv)

# NSG に自身のパブリック IP から SSH 接続出来るようにします
az network nsg rule create \
    --resource-group ${prefix}-rg \
    --name Allow-SSH \
    --nsg-name $nsg \
    --priority 100 \
    --source-address-prefixes $(curl -s inet-ip.info) \
    --destination-port-ranges 22 \
    --access Allow \
    --protocol Tcp

# VM に SSH 接続します
ssh azureuser@$(az vm show \
  --resource-group ${prefix}-rg \
  --name ${prefix}-vm \
  --show-detail \
  --query publicIps \
  --output tsv)

実施結果

Rocky Linux へのマイグレーションは、時間がかかりますが簡単でした。

bash
$ wget https://raw.githubusercontent.com/rocky-linux/rocky-tools/main/migrate2rocky/migrate2rocky.sh

$ sudo bash ./migrate2rocky.sh -r
Preparing to migrate CentOS Linux 8 to Rocky Linux 8.

Determining repository names for CentOS Linux 8.....

Found the following repositories which map from CentOS Linux 8 to Rocky Linux 8:
CentOS Linux 8    Rocky Linux 8
appstream         appstream
baseos            baseos
extras-openlogic  extras

Getting system package names for CentOS Linux 8..........

Found the following system packages which map from CentOS Linux 8 to Rocky Linux 8:
CentOS Linux 8        Rocky Linux 8
centos-logos-ipa      rocky-logos-ipa
centos-backgrounds    rocky-backgrounds
centos-gpg-keys       rocky-gpg-keys
centos-logos          rocky-logos
centos-indexhtml      rocky-indexhtml
centos-linux-release  rocky-release
centos-logos-httpd    rocky-logos-httpd
centos-linux-repos    rocky-repos

Getting list of installed system packages.

We will replace the following CentOS Linux 8 packages with their Rocky Linux 8 equivalents
Packages to be Removed  Packages to be Installed
centos-gpg-keys         rocky-gpg-keys
centos-linux-release    rocky-release
centos-linux-repos      rocky-repos

In addition to the above the following system packages will be removed:
centos-linux-release
centos-linux-release

Getting a list of enabled modules for the system repositories.

Excluding modules:
libselinux-python:2.8

Found the following modules to re-enable at completion:
python36:3.6

Running dnf update before we attempt the migration.
Last metadata expiration check: 0:01:25 ago on Tue 13 Jul 2021 11:13:20 AM UTC.
Dependencies resolved.
======================================================================================================
 Package                        Arch    Version                             Repository            Size
======================================================================================================
Installing:
 fwupd                          x86_64  1.5.9-1.el8_4                       BaseOS-openlogic     2.8 M
     replacing  dbxtool.x86_64 8-5.el8
 kernel                         x86_64  4.18.0-305.7.1.el8_4                BaseOS-openlogic     5.9 M
 kernel-core                    x86_64  4.18.0-305.7.1.el8_4                BaseOS-openlogic      36 M
 kernel-modules                 x86_64  4.18.0-305.7.1.el8_4                BaseOS-openlogic      28 M
Upgrading:
 NetworkManager                 x86_64  1:1.30.0-9.el8_4                    BaseOS-openlogic     2.6 M
 NetworkManager-libnm           x86_64  1:1.30.0-9.el8_4                    BaseOS-openlogic     1.8 M
 NetworkManager-team            x86_64  1:1.30.0-9.el8_4                    BaseOS-openlogic     145 k

 (中略)

  yum-utils-4.0.18-4.el8.noarch                                                 
  zip-3.0-23.el8.x86_64                                                         
  zlib-1.2.11-17.el8.x86_64                                                     

Complete!

Done, please reboot your system.
A log of this installation can be found at /var/log/migrate2rocky.log

# 再起動します(マイグレーションを開始してから 37 分後です)
$ sudo reboot

# もう一度 VM に SSH 接続してから実行します
$ cat /etc/os-release 
NAME="Rocky Linux"
VERSION="8.4 (Green Obsidian)"
ID="rocky"
ID_LIKE="rhel fedora"
VERSION_ID="8.4"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Rocky Linux 8.4 (Green Obsidian)"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:rocky:rocky:8.4:GA"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
ROCKY_SUPPORT_PRODUCT="Rocky Linux"
ROCKY_SUPPORT_PRODUCT_VERSION="8"

# OpenLogic のリポジトリ情報が残っているため下記のエラーが表示されます
$ sudo dnf update
CentOS-8 - AppStream (OpenLogic)                                                                                                                                                                    13 kB/s | 249  B     00:00    
Errors during downloading metadata for repository 'AppStream-openlogic':
  - Status code: 404 for http://olcentgbl.trafficmanager.net/pub/rocky/8/AppStream/x86_64/os/repodata/repomd.xml (IP: 138.91.1.67)
Error: repo 'AppStream-openlogic' のメタデータのダウンロードに失敗しました : Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
CentOS-8 - Base (OpenLogic)                                                                                                                                                                         13 kB/s | 246  B     00:00    
Errors during downloading metadata for repository 'BaseOS-openlogic':
  - Status code: 404 for http://olcentgbl.trafficmanager.net/pub/rocky/8/BaseOS/x86_64/os/repodata/repomd.xml (IP: 138.91.1.67)
Error: repo 'BaseOS-openlogic' のメタデータのダウンロードに失敗しました : Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
CentOS-8 - Extras (OpenLogic)                                                                                                                                                                       13 kB/s | 243  B     00:00    
Errors during downloading metadata for repository 'extras-openlogic':
  - Status code: 404 for http://olcentgbl.trafficmanager.net/pub/rocky/8/extras/x86_64/repodata/repomd.xml (IP: 138.91.1.67)
Error: repo 'extras-openlogic' のメタデータのダウンロードに失敗しました : Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
リポジトリーを無視します: AppStream-openlogic, BaseOS-openlogic, extras-openlogic
メタデータの期限切れの最終確認: 0:25:01 時間前の 2021年07月13日 11時31分46秒 に実施しました。
依存関係が解決しました。
行うべきことはありません。
完了しました!

# OpenLogic のリポジトリ情報を無効にします
$ sudo mv /etc/yum.repos.d/OpenLogic.repo /etc/yum.repos.d/OpenLogic.repo.bak
$ sudo mv /etc/yum.repos.d/OpenLogicCentOS.repo /etc/yum.repos.d/OpenLogicCentOS.repo.bak

# エラーが表示されなくなりました
$ sudo dnf update
メタデータの期限切れの最終確認: 0:32:16 時間前の 2021年07月13日 11時31分46秒 に実施しました。
依存関係が解決しました。
行うべきことはありません。
完了しました!

# waagent も動いてくれています
$ ps aux | grep waagent
root         929  0.0  0.6 335816 23108 ?        Ss   11:53   0:00 /usr/bin/python3.6 -u /usr/sbin/waagent -daemon
azureus+    7534  0.0  0.0 221928  1064 pts/0    S+   12:12   0:00 grep --color=auto waagent

参考

zsh
# リソースグループを削除します
az group delete \
  --name ${prefix}-rg

How to Migrate to Rocky Linux from CentOS, Alma Linux, RHEL, or Oracle Linux

Discussion