はじめに
昔、RHEL6を以前のマイナーバージョンにダウングレードするという記事を書きましたが、すでに時代はRHEL8。歳をとるわけだなぁ、、、と思いつつ、同じテーマでRHEL8ではどうやるのかという質問をもらったので、ここに手順を書いておきます。
環境はIBM CloudのClassic Infrastructureを利用し、RHEL8.2からRHEL8.1にダウングレードの手順を試したいと思います。
1. 現行の確認
バージョン情報
[root@rhel8syasuda ~]# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.2 (Ootpa)
カーネル情報
[root@rhel8syasuda ~]# uname -a
Linux rhel8syasuda.IBM.cloud 4.18.0-193.el8.x86_64 #1 SMP Fri Mar 27 14:35:58 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
本当はgrubbyで設定しようと思ったが、grubbyの出力結果が/boot/boot
のようになっている時点で、ちゃんと機能していないように思えるので、従来のRHEL7のようにgrub2-mkconfigを利用する方針とする。
[root@rhel8syasuda ~]# grubby --default-kernel
/boot/boot/vmlinuz-4.18.0-193.el8.x86_64
[root@rhel8syasuda ~]# ls -l /boot/boot/vmlinuz-4.18.0-193.el8.x86_64
ls: cannot access '/boot/boot/vmlinuz-4.18.0-193.el8.x86_64': No such file or directory
[root@rhel8syasuda ~]# grubby --info /boot/boot/vmlinuz-4.18.0-193.el8.x86_64
The param /boot/boot/vmlinuz-4.18.0-193.el8.x86_64 is incorrect
[root@rhel8syasuda ~]# ls -l /boot/vmlinuz-*
-rwxr-xr-x. 1 root root 8913760 3月 27 09:48 /boot/vmlinuz-4.18.0-193.el8.x86_64
2. ダウングレードしたいカーネルのインストール
[root@rhel8syasuda ~]# dnf --showduplicates list kernel.x86_64
Updating Subscription Management repositories.
Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs) 65 kB/s | 2.4 kB 00:00
Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs) 75 kB/s | 2.8 kB 00:00
Installed Packages
kernel.x86_64 4.18.0-193.el8 @61d6b9c41d9db3a899772c5688ddfefe
Available Packages
kernel.x86_64 4.18.0-80.el8 rhel-8-for-x86_64-baseos-rpms
kernel.x86_64 4.18.0-80.1.2.el8_0 rhel-8-for-x86_64-baseos-rpms
kernel.x86_64 4.18.0-80.4.2.el8_0 rhel-8-for-x86_64-baseos-rpms
kernel.x86_64 4.18.0-80.7.1.el8_0 rhel-8-for-x86_64-baseos-rpms
kernel.x86_64 4.18.0-80.7.2.el8_0 rhel-8-for-x86_64-baseos-rpms
kernel.x86_64 4.18.0-80.11.1.el8_0 rhel-8-for-x86_64-baseos-rpms
kernel.x86_64 4.18.0-80.11.2.el8_0 rhel-8-for-x86_64-baseos-rpms
kernel.x86_64 4.18.0-147.el8 rhel-8-for-x86_64-baseos-rpms
kernel.x86_64 4.18.0-147.0.2.el8_1 rhel-8-for-x86_64-baseos-rpms
kernel.x86_64 4.18.0-147.0.3.el8_1 rhel-8-for-x86_64-baseos-rpms
kernel.x86_64 4.18.0-147.3.1.el8_1 rhel-8-for-x86_64-baseos-rpms
kernel.x86_64 4.18.0-147.5.1.el8_1 rhel-8-for-x86_64-baseos-rpms
kernel.x86_64 4.18.0-147.8.1.el8_1 rhel-8-for-x86_64-baseos-rpms
kernel.x86_64 4.18.0-193.el8 rhel-8-for-x86_64-baseos-rpms
kernel.x86_64 4.18.0-193.1.2.el8_2 rhel-8-for-x86_64-baseos-rpms
kernel.x86_64 4.18.0-193.6.3.el8_2 rhel-8-for-x86_64-baseos-rpms
kernel.x86_64 4.18.0-193.13.2.el8_2 rhel-8-for-x86_64-baseos-rpms
kernel.x86_64 4.18.0-193.14.3.el8_2 rhel-8-for-x86_64-baseos-rpms
kernel.x86_64 4.18.0-193.19.1.el8_2 rhel-8-for-x86_64-baseos-rpms
この記事によると、RHEL8.1のカーネルバージョンは4.18.0-147
のようなので、RHEL8.1の中でも最も新しい4.18.0-147.8.1.el8_1
を導入する。
[root@rhel8syasuda ~]# dnf install -y kernel-4.18.0-147.8.1.el8_1
[root@rhel8syasuda ~]# ls -l /boot/vmlinuz-*
-rwxr-xr-x. 1 root root 8110944 Sep 15 20:50 /boot/vmlinuz-0-rescue-7f489ab43caa4310a618203de4919569
-rwxr-xr-x. 1 root root 8110944 Feb 25 2020 /boot/vmlinuz-4.18.0-147.8.1.el8_1.x86_64
-rwxr-xr-x. 1 root root 8913760 Mar 27 09:48 /boot/vmlinuz-4.18.0-193.el8.x86_64
3. デフォルトのカーネルブートエントリーを変更する
/etc/default/grub
にGRUB_DEFAULT=saved
とGRUB_DISABLE_SUBMENU=true
を追加。
-
GRUB_DEFAULT=saved
を利用することで、/boot/grub2/grubenv にあるsaved_entry ディレクティブで指定されたカーネルを読み込むように指示される。 -
GRUB_DISABLE_SUBMENU=true
を利用することで、サブメニューを利用しなくなる。サブメニューだとINDEX指定が複雑になるのでこの指定を入れておく。
[root@rhel8syasuda ~]# vi /etc/default/grub
(編集)
[root@rhel8syasuda ~]# cat /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="net.ifnames=0 biosdevname=0 quiet elevator=noop pti=off nomodeset nofb vga=normal console=tty1 console=ttyS0 console=hvc0 root=UUID=3d5c084c-e24a-4ee6-9997-3c998821533f rw "
GRUB_SERIAL_COMMAND="serial --speed=38400 --unit=0 --word=8 --parity=no --stop=1"
GRUB_TIMEOUT=5
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
カーネル情報をブートエントリーに反映
[root@rhel8syasuda ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
この結果、3つめのメニューに4.18.0-147.8.1.el8_1.x86_64が登録されていることを確認することができる。(1番上が0, 2番目が1, 3番目が2・・・とindexが割り振られる)
[root@rhel8syasuda ~]# awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
Red Hat Enterprise Linux (4.18.0-193.el8.x86_64) 8.2 (Ootpa)
Red Hat Enterprise Linux (4.18.0-193.el8.x86_64) 8.2 (Ootpa) (recovery mode)
Red Hat Enterprise Linux (4.18.0-147.8.1.el8_1.x86_64) 8.2 (Ootpa)
Red Hat Enterprise Linux (4.18.0-147.8.1.el8_1.x86_64) 8.2 (Ootpa) (recovery mode)
Red Hat Enterprise Linux (0-rescue-7f489ab43caa4310a618203de4919569) 8.2 (Ootpa)
Red Hat Enterprise Linux (0-rescue-7f489ab43caa4310a618203de4919569) 8.2 (Ootpa) (recovery mode)
4.18.0-147.8.1.el8_1.x86_64は2番目のindexなので2を指定
[root@rhel8syasuda ~]# grub2-set-default 2
indexの確認
[root@rhel8syasuda ~]# head -2 /boot/grub2/grubenv
# GRUB Environment Block
saved_entry=2
[root@rhel8syasuda ~]# dnf downgrade redhat-release
[root@rhel8syasuda ~]# reboot
4. 動作確認
[root@rhel8syasuda ~]# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.1 (Ootpa)
[root@rhel8syasuda ~]# uname -a
Linux rhel8syasuda.IBM.cloud 4.18.0-147.8.1.el8_1.x86_64 #1 SMP Wed Feb 26 03:08:15 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
おまけ
grubbyがうまく動いていない・動かない理由は調査が必要(何か有効にするための設定とかがあるんですかね?詳しい人教えてください!敢えて記載していませんが、新規にカーネルを導入した後に、grubby --default-kernel
を使って/boot/loader/entries/
配下のconfigを指定してみましたが、それだとうまく動きませんでした)
2021/09/14追記:
IBM CloudのVPC環境だと以下でうまくいった。なぜ???
# grubby --set-default=/boot/vmlinuz-4.18.0-240.el8.x86_64
The default is /boot/loader/entries/2e19d5c71bef485bb9c3025eb8a3df76-4.18.0-240.el8.x86_64.conf with index 3 and kernel /boot/vmlinuz-4.18.0-240.el8.x86_64
# grubby --default-kernel
/boot/vmlinuz-4.18.0-240.el8.x86_64
# reboot