LoginSignup
1
3

More than 1 year has passed since last update.

CentOS8.2からalmalinuxにOSアップグレードしたときに、ハマったこと

Last updated at Posted at 2022-04-20

背景

CentOS 8系がEOLを迎えたので、サポート中のOSに移行する必要があった。
移行先を、CentOSと互換性があり保証期間が長めに設定されている almalinuxと決定したため、移行作業を行った。

結論

/etc/yum.repos.d/CentOS-Stream*にファイルがある場合に、yum update を実行すると
OSがCentOS Stream 8に更新されることがある。
困る場合は、上記ファイルを除外することで、CentOS 8系の最新版(記載時点では8.5)に更新することができた。

環境

CentOS 8.2

想定していた移行手順

CentOS 8.2
↓ dnf updateにて更新
CentOS 8.5
↓ 移行シェル
almalinux

操作

最初に、システムバックアップを取得する。

事前確認
# OSバージョン確認確認
[root@test-server ~]# cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)

# dnf updateができるか確認
[root@test-server ~]# dnf update
CentOS-8 - AppStream                                                                                                                                           115  B/s |  38  B     00:00
エラー: Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

# yum でエラーが発生
# CentOS8は、サポート終了しているため。yum リポジトリのURL書き換えが必要。

# /etc/yum.repos.d/内容を確認
[root@test-server yum.repos.d]# ls -la /etc/yum.repos.d/CentOS-*
-rw-r--r--  1 root root  732  4月 19 14:10 /etc/yum.repos.d/CentOS-AppStream.repo
-rw-r--r--  1 root root  713  4月 19 14:10 /etc/yum.repos.d/CentOS-Base.repo
-rw-r--r--. 1 root root 1043  9月 16  2020 /etc/yum.repos.d/CentOS-CR.repo
-rw-r--r--. 1 root root  668  9月 16  2020 /etc/yum.repos.d/CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  743  9月 16  2020 /etc/yum.repos.d/CentOS-Devel.repo
-rw-r--r--  1 root root  757  4月 19 14:10 /etc/yum.repos.d/CentOS-Extras.repo
-rw-r--r--. 1 root root  738  9月 16  2020 /etc/yum.repos.d/CentOS-HA.repo
-rw-r--r--. 1 root root  928  9月 16  2020 /etc/yum.repos.d/CentOS-Media.repo
-rw-r--r--  1 root root  735  4月 19 14:11 /etc/yum.repos.d/CentOS-PowerTools.repo
-rw-r--r--. 1 root root 1382  9月 16  2020 /etc/yum.repos.d/CentOS-Sources.repo
-rw-r--r--  1 root root  725 12月 20  2019 /etc/yum.repos.d/CentOS-Stream-AppStream.repo
-rw-r--r--  1 root root  706 12月 20  2019 /etc/yum.repos.d/CentOS-Stream-Base.repo
-rw-r--r--  1 root root  666 12月 20  2019 /etc/yum.repos.d/CentOS-Stream-Debuginfo.repo
-rw-r--r--  1 root root  750 12月 20  2019 /etc/yum.repos.d/CentOS-Stream-Extras.repo
-rw-r--r--  1 root root  932 12月 20  2019 /etc/yum.repos.d/CentOS-Stream-Media.repo
-rw-r--r--  1 root root  730 12月 20  2019 /etc/yum.repos.d/CentOS-Stream-PowerTools.repo
-rw-r--r--  1 root root 1374 12月 20  2019 /etc/yum.repos.d/CentOS-Stream-Sources.repo
-rw-r--r--  1 root root   74 12月 20  2019 /etc/yum.repos.d/CentOS-Stream-Vault.repo
-rw-r--r--  1 root root  796 12月 20  2019 /etc/yum.repos.d/CentOS-Stream-centosplus.repo
-rw-r--r--. 1 root root   74  9月 16  2020 /etc/yum.repos.d/CentOS-Vault.repo
-rw-r--r--. 1 root root  798  9月 16  2020 /etc/yum.repos.d/CentOS-centosplus.repo
-rw-r--r--. 1 root root  338  9月 16  2020 /etc/yum.repos.d/CentOS-fasttrack.repo

# sedによる書き換えを実施。
# 他のリポジトリでもエラーが出る場合は、書き換える対象ファイルを追加してください。
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Base.repo
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-AppStream.repo
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Extras.repo
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Base.repo
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-AppStream.repo
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Extras.repo

# dnf update確認
[root@test-server ~]# dnf update
CentOS-8 - PowerTools                                                                                                                                           15 MB/s | 2.3 MB     00:00
CentOS-Stream - AppStream                                                                                                                                       16 kB/s | 4.4 kB     00:00
CentOS-Stream - AppStream                                                                                                                                       32 MB/s |  21 MB     00:00
CentOS-Stream - Base                                                                                                                                           7.3 kB/s | 3.9 kB     00:00
CentOS-Stream - Base                                                                                                                                           3.0 MB/s |  21 MB     00:06
CentOS-Stream - Extras                                                                                                                                         8.5 kB/s | 2.9 kB     00:00
CentOS-Stream - Extras                                                                                                                                          31 kB/s |  18 kB     00:00
Extra Packages for Enterprise Linux Modular 8 - x86_64                                                                                                          16 kB/s | 8.7 kB     00:00
Extra Packages for Enterprise Linux Modular 8 - x86_64                                                                                                         1.0 MB/s | 1.0 MB     00:01
Extra Packages for Enterprise Linux 8 - x86_64                                                                                                                  18 kB/s | 9.8 kB     00:00
Extra Packages for Enterprise Linux 8 - x86_64                                                                                                                 1.9 MB/s |  11 MB     00:05
依存関係が解決しました。
===============================================================================================================================================================================================
 パッケージ                                             アーキテクチャー            バージョン                                                     リポジトリー                          サイズ
===============================================================================================================================================================================================
インストール中:
 centos-stream-release                                  noarch                      8.6-1.el8                                                      Stream-BaseOS                          22 k
     置き換え  centos-release.x86_64 8.2-2.2004.0.2.el8
     置き換え  centos-release-stream.x86_64 8.1-1.1911.0.7.el8
     置き換え  centos-repos.x86_64 8.2-2.2004.0.2.el8
 kernel                                                 x86_64                      4.18.0-373.el8                                                 Stream-BaseOS                         8.0 M
 kernel-core                                            x86_64                      4.18.0-373.el8                                                 Stream-BaseOS                          39 M
 kernel-modules                                         x86_64                      4.18.0-373.el8                                                 Stream-BaseOS                          32 M
アップグレード中:
 NetworkManager                                         x86_64                      1:1.39.0-1.el8                                                 Stream-BaseOS                         2.3 M
 NetworkManager-libnm                                   x86_64                      1:1.39.0-1.el8                                                 Stream-BaseOS

(中略)

ここで注目しなければいけないのが、リポジトリが Stream-BaseOS となっている箇所。
このままdnf update続けてしまうと、CentOS Stream 8 に更新されてしまった。

この状態のまま、CentOS Stream 8 から almalinuxへの移行シェルを叩いてみたが
OSバージョンチェックでエラーとなり、実施できなかった。

[root@test-server almalinux-deploy]# bash almalinux-deploy.sh
Check root privileges                                                 OK
Detect centos version                                                 ERROR
Check EL is supported                                                 ERROR

対応

まずは、作業前の状態にOSをロールバックする。

#CentOS-Stream 系ののリポジトリファイル除外
[root@test-server ~]#mv -i /etc/yum.repos.d/CentOS-Stream* /tmp/

# dnf updateの確認
# リポジトリ欄が BaseOSに変更されているところに注目。
[root@test-server yum.repos.d]dnf update
メタデータの期限切れの最終確認: 0:03:04 時間前の 2022年04月19日 14時11分49秒 に実施しました。
依存関係が解決しました。
===============================================================================================================================================================================================
 パッケージ                                            アーキテクチャー               バージョン                                                       リポジトリー                      サイズ
===============================================================================================================================================================================================
インストール中:
 centos-linux-release                                  noarch                         8.5-1.2111.el8                                                   BaseOS                             22 k
     置き換え  centos-release.x86_64 8.2-2.2004.0.2.el8
     置き換え  centos-repos.x86_64 8.2-2.2004.0.2.el8
 kernel                                                x86_64                         4.18.0-348.7.1.el8_5                                             BaseOS                            7.0 M
 kernel-core                                           x86_64                         4.18.0-348.7.1.el8_5                                             BaseOS                             38 M
 kernel-modules                                        x86_64                         4.18.0-348.7.1.el8_5                                             BaseOS                             30 M
アップグレード中:
 NetworkManager                                        x86_64                         1:1.32.10-4.el8                                                  BaseOS                            2.6 M
 NetworkManager-libnm                                  x86_64                         1:1.32.10-4.el8                                                  BaseOS                            1.8 M

(中略)

# dnf updateを実行

# OS再起動してバージョンの確認
[root@test-server ~]# shutdouwn -r now
[root@test-server ~]# cat /etc/redhat-release
CentOS Linux release 8.5.2111

# /etc/yum.repos.d/の中身。CentOS-Linux-*のリポジトリがファイルが作成される。
[root@test-server yum.repos.d]# ls -la /etc/yum.repos.d/CentOS-*
-rw-r--r-- 1 root root  732  4月 19 14:10 CentOS-AppStream.repo.rpmsave
-rw-r--r-- 1 root root  713  4月 19 14:10 CentOS-Base.repo.rpmsave
-rw-r--r-- 1 root root  757  4月 19 14:10 CentOS-Extras.repo.rpmsave
-rw-r--r-- 1 root root  719  9月 15  2021 CentOS-Linux-AppStream.repo
-rw-r--r-- 1 root root  704  9月 15  2021 CentOS-Linux-BaseOS.repo
-rw-r--r-- 1 root root 1130  9月 15  2021 CentOS-Linux-ContinuousRelease.repo
-rw-r--r-- 1 root root  318  9月 15  2021 CentOS-Linux-Debuginfo.repo
-rw-r--r-- 1 root root  732  9月 15  2021 CentOS-Linux-Devel.repo
-rw-r--r-- 1 root root  704  9月 15  2021 CentOS-Linux-Extras.repo
-rw-r--r-- 1 root root  719  9月 15  2021 CentOS-Linux-FastTrack.repo
-rw-r--r-- 1 root root  740  9月 15  2021 CentOS-Linux-HighAvailability.repo
-rw-r--r-- 1 root root  693  9月 15  2021 CentOS-Linux-Media.repo
-rw-r--r-- 1 root root  706  9月 15  2021 CentOS-Linux-Plus.repo
-rw-r--r-- 1 root root  724  9月 15  2021 CentOS-Linux-PowerTools.repo
-rw-r--r-- 1 root root 1124  9月 15  2021 CentOS-Linux-Sources.repo
-rw-r--r-- 1 root root  735  4月 19 14:11 CentOS-PowerTools.repo.rpmsave

# まだCentOS 8系なので、以前、ミラーリストの差し替えが必要
[root@test-server yum.repos.d]# sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-*
[root@test-server yum.repos.d]# sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Linux-*

# migrationツール取得と実行
[root@test-server ~]# git clone https://github.com/AlmaLinux/almalinux-deploy.git
[root@test-server ~]# cd almalinux-deploy
[root@test-server ~]# bash almalinux-deploy.sh
(中略)

完了しました!
Run dnf distro-sync -y                                                OK
Restoring of alternatives is done                                     OK
Generating grub configuration file ...
File descriptor 5 (/var/log/almalinux-deploy.debug.log) leaked on vgs invocation. Parent PID 68385: /usr/sbin/grub2-probe
File descriptor 5 (/var/log/almalinux-deploy.debug.log) leaked on vgs invocation. Parent PID 68385: /usr/sbin/grub2-probe
File descriptor 5 (/var/log/almalinux-deploy.debug.log) leaked on vgs invocation. Parent PID 70483: /usr/sbin/grub2-probe
File descriptor 5 (/var/log/almalinux-deploy.debug.log) leaked on vgs invocation. Parent PID 70483: /usr/sbin/grub2-probe
done
All Secure Boot related packages which were not released by AlmaLinux are reinstalledOK

Migration to AlmaLinux is completed

# OS再起動とバージョン確認
[root@test-server ~]# shutdouwn -r now
[root@test-server ~]# cat /etc/redhat-release
AlmaLinux release 8.5 (Arctic Sphynx)

以上で、OSアップグレード作業終了です。おつかれさまでした。

感想

とっててよかったシステムバックアップ。

外部資料

almalinuxの移行
https://github.com/AlmaLinux/almalinux-deploy

1
3
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
3