Ubuntu 22.04

Prev Next

VPC環境で利用できます。

NAVERクラウドプラットフォーム Ubuntu 22.04サーバのカーネルアップデート方法について説明します。

本ガイドは、NAVERクラウドプラットフォームで新規作成したサーバを基準に作成したため、ユーザーのサーバ環境と異なる場合があります。ユーザーのサーバ環境はセキュリティハードニングや複数の設定などの様々な理由で、カーネルアップデートやサーバの再起動に影響を及ぼすことがあります。したがって、次の事項を熟知した後、カーネルアップデートを実行してください。

  • 実際のサーバのカーネルをアップデートする前に、サーバイメージを使用してレプリカサーバを作成します。作成したレプリカサーバでカーネルアップデートを実行し、正常に再起動できるか確認します。再起動後に運用ステータスに切り替わったら、サービスに問題がないか確認します。十分に検証し、問題がない場合のみカーネルアップデートを実行してください。
  • GPUサーバの場合、カーネルバージョンに合う GPUドライバがインストールされている場合のみ正常に動作します。更新したカーネルが GPUドライバと互換性がない場合、GPUサーバが正常に動作しない場合があります。したがって、GPUドライバの互換性を確認した後、カーネルアップデートを実行してください。関連情報は、GPUドライバガイドをご確認ください。
参考

本カーネルアップデートガイドは、今後定期的なアップデートを提供しません。したがって、最新の情報を確認したり、他のカーネルバージョンをインストールする場合は、当該ガイドを参照して別途でタスクを実行してください。
ガイドに明示されているカーネルバージョンは一例であり、必要に応じて他のカーネルバージョンを十分にテストしてからインストールしてください。

注意
  • ユーザーサーバのカーネルアップデートはユーザーの責任で行う必要があり、カーネルアップデートにより発生するトラブルに対して NAVERクラウドプラットフォームは責任を負いません。
  • カーネルアップデートや再起動中はサーバの正常な使用が不可な場合があり、これによる復旧はサポートしていません。また、カーネルアップデートの失敗時のサーバ復旧はサポートしていません。
  • カーネルを更新する前にマイサーバイメージで作成したバックアップは、バックアップが不要になるまで保存してください。
  • このガイドと関連したトラブルに対しては、別途サポートは提供されません。

アップデート可能なカーネルバージョンの確認

Ubuntu 22.04サーバのカーネルを更新する方法は、次の通りです。

基本的に Repository URLは NCP Repo(http://repo.ncloud.com)に設定されます。ただし、パブリック IPアドレスを保有していたり NATが構成された Private Subnet環境では、NCP Repoの代わりに外部 Public Mirrorサイトを使用できます。

参考

NCP Repoは、外部アクセスが制限される VPC Private Subnetなどのユーザー環境をサポートするために、NAVERクラウドプラットフォームが提供するリポジトリです。
NCP Repoは年4回しか同期されないので、最新のパッチを素早く適用するには、外部 Public Mirrorサイトに変更することをお勧めします。詳細は、Linux OS Repository設定点検ガイドをご参照ください。

  1. カーネルアップデートを適用するサーバにリモートアクセスします。
  2. サーバに適用するカーネルバージョンを確認します。
    root@ubuntu2204:~# apt-cache search linux-image-5.15.0 | grep -E 'linux-image-5\.15\.0-1+.*generic'
    linux-image-5.15.0-100-generic - Signed kernel image generic
    linux-image-5.15.0-101-generic - Signed kernel image generic
    linux-image-5.15.0-102-generic - Signed kernel image generic
    linux-image-5.15.0-105-generic - Signed kernel image generic
    linux-image-5.15.0-106-generic - Signed kernel image generic
    linux-image-5.15.0-107-generic - Signed kernel image generic
    linux-image-5.15.0-112-generic - Signed kernel image generic
    linux-image-5.15.0-113-generic - Signed kernel image generic
    linux-image-5.15.0-116-generic - Signed kernel image generic
    linux-image-5.15.0-117-generic - Signed kernel image generic
    linux-image-5.15.0-118-generic - Signed kernel image generic
    linux-image-5.15.0-119-generic - Signed kernel image generic
    linux-image-5.15.0-121-generic - Signed kernel image generic
    linux-image-5.15.0-122-generic - Signed kernel image generic
    linux-image-5.15.0-124-generic - Signed kernel image generic
    

カーネルアップデート

Ubuntu 22.04サーバのカーネルを更新する方法は、次の通りです。

参考

本ガイドでは、Ubuntu 22.04サーバでカーネルバージョンを 5.15.0-124-genericにアップグレードする例を提供します。
ガイドを参照する時点でインストール可能なカーネルバージョンが異なる場合がありますので、他のバージョンも十分にテストしてからインストールしてください。

  1. カーネルアップデートを適用するサーバにリモートアクセスします。

  2. サーバのカーネルバージョンを確認します。

    root@ubuntu2204:~# uname -r
    5.15.0-94-generic
    
  3. サーバに接続されたリポジトリ情報を確認します。

    root@ubuntu2204:~# grep ^deb /etc/apt/sources.list  
    deb http://repo.ncloud.com/ubuntu jammy main restricted
    deb http://repo.ncloud.com/ubuntu jammy-updates main restricted
    deb http://repo.ncloud.com/ubuntu jammy universe
    deb http://repo.ncloud.com/ubuntu jammy-updates universe
    deb http://repo.ncloud.com/ubuntu jammy multiverse
    deb http://repo.ncloud.com/ubuntu jammy-updates multiverse
    deb http://repo.ncloud.com/ubuntu jammy-backports main restricted universe multiverse
    deb http://repo.ncloud.com/ubuntu jammy-security main restricted
    deb http://repo.ncloud.com/ubuntu jammy-security universe
    deb http://repo.ncloud.com/ubuntu jammy-security multiverse
    
  4. リポジトリで提供するカーネルバージョンを確認します。

    root@ubuntu2204:~# rm -rf /var/cache/apt/archives/*
    root@ubuntu2204:~# rm -rf /var/lib/apt/lists/*
    root@ubuntu2204:~# apt clean
    root@ubuntu2204:~# apt update 
    Hit:1 http://repo.ncloud.com/ubuntu jammy InRelease
    Get:2 http://repo.ncloud.com/ubuntu jammy-updates InRelease [128 kB]
    Get:3 http://repo.ncloud.com/ubuntu jammy-backports InRelease [127 kB]
    Get:4 http://repo.ncloud.com/ubuntu jammy-security InRelease [129 kB]
    
    ... 省略 ...  
    
    Fetched 11.1 MB in 2s (5,400 kB/s)                                
    Reading package lists... Done  
    
    root@ubuntu2204:~# apt policy linux-image-5.15.0-124-generic
    linux-image-5.15.0-124-generic:
      Installed: (none)
      Candidate: 5.15.0-124.134
      Version table:
         5.15.0-124.134 500
            500 http://repo.ncloud.com/ubuntu jammy-updates/main amd64 Packages
            500 http://repo.ncloud.com/ubuntu jammy-security/main amd64 Packages
    
  5. 確認したバージョンのカーネルをインストールします。
    新規インストールパッケージ、アップデートパッケージ、削除パッケージのリストを詳細に確認した後、異常がない場合 Yを入力してインストールを完了します。

    root@ubuntu2204:~# apt install linux-{image,headers}-5.15.0-124-generic
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    The following packages were automatically installed and are no longer required:
      eatmydata libeatmydata1 python-babel-localedata python3-babel python3-certifi python3-jinja2 python3-json-pointer python3-jsonpatch python3-jsonschema python3-markupsafe python3-pyrsistent python3-requests python3-tz python3-urllib3
    Use 'apt autoremove' to remove them.
    The following additional packages will be installed:
      linux-headers-5.15.0-124 linux-modules-5.15.0-124-generic
    Suggested packages:
      fdutils linux-doc | linux-source-5.15.0 linux-tools linux-modules-extra-5.15.0-124-generic
    The following NEW packages will be installed:
      linux-headers-5.15.0-124 linux-headers-5.15.0-124-generic linux-image-5.15.0-124-generic linux-modules-5.15.0-124-generic
    0 upgraded, 4 newly installed, 0 to remove and 176 not upgraded.
    Need to get 49.4 MB of archives.
    After this operation, 231 MB of additional disk space will be used.
    Do you want to continue? [Y/n] Y
    
    ... 省略 ...   
    
    Found linux image: /boot/vmlinuz-5.15.0-124-generic
    Found initrd image: /boot/initrd.img-5.15.0-124-generic
    Found linux image: /boot/vmlinuz-5.15.0-94-generic
    Found initrd image: /boot/initrd.img-5.15.0-94-generic
    Found linux image: /boot/vmlinuz-5.15.0-92-generic
    Found initrd image: /boot/initrd.img-5.15.0-92-generic
    Warning: os-prober will not be executed to detect other bootable partitions.
    Systems on them will not be added to the GRUB boot configuration.
    Check GRUB_DISABLE_OS_PROBER documentation entry.
    done
    Scanning processes...                                                                                                                                                                                                                                                                       
    Scanning linux images...                                                                                                                                                                                                                                                                    
    
    No services need to be restarted.
    
    No containers need to be restarted.
    
    No user sessions are running outdated binaries.
    
    No VM guests are running outdated hypervisor (qemu) binaries on this host.
    
  6. インストールが完了したら、起動可能なすべてのカーネルバージョンを確認します。

     root@ubuntu2204:~# dpkg -l | grep linux-image | grep ii
     ii  linux-image-5.15.0-124-generic        5.15.0-124.134                          amd64        Signed kernel image generic
     ii  linux-image-5.15.0-92-generic         5.15.0-92.102                           amd64        Signed kernel image generic
     ii  linux-image-5.15.0-94-generic         5.15.0-94.104                           amd64        Signed kernel image generic
    
  7. 起動時に最新カーネルバージョンをデフォルト値として選択できるように設定します。

    root@ubuntu2204:~# sed -i 's/GRUB_DEFAULT=.*/GRUB_DEFAULT=saved/g' /etc/default/grub
    
    root@ubuntu2204:~# grep "GRUB_DEFAULT" /etc/default/grub
    GRUB_DEFAULT=saved
    
    root@ubuntu2204:~# grub-set-default "Advanced options for Ubuntu>Ubuntu, with Linux 5.15.0-124-generic"
    
    root@ubuntu2204:~# grub-editenv list
    saved_entry=Advanced options for Ubuntu>Ubuntu, with Linux 5.15.0-124-generic   
    
    root@ubuntu2204:~# update-grub
    Sourcing file `/etc/default/grub'
    Sourcing file `/etc/default/grub.d/init-select.cfg'
    Generating grub configuration file ...
    Found linux image: /boot/vmlinuz-5.15.0-124-generic
    Found initrd image: /boot/initrd.img-5.15.0-124-generic
    Found linux image: /boot/vmlinuz-5.15.0-94-generic
    Found initrd image: /boot/initrd.img-5.15.0-94-generic
    Found linux image: /boot/vmlinuz-5.15.0-92-generic
    Found initrd image: /boot/initrd.img-5.15.0-92-generic
    Warning: os-prober will not be executed to detect other bootable partitions.
    Systems on them will not be added to the GRUB boot configuration.
    Check GRUB_DISABLE_OS_PROBER documentation entry.
    done
    
  8. 最新カーネルバージョンを有効にするには、サーバを再起動します。

    root@ubuntu2204:~# sync;reboot
    
    参考

    サーバの再起動に失敗した場合、カーネルアップデートが正常に行われなかったことを意味します。この場合は、カーネルアップデートの復元を参照して以前のカーネルバージョンに戻してください。

  9. サーバに再ログインして新しいカーネルが有効になっているか確認します。

    root@ubuntu2204:~# uname -r
    5.15.0-124-generic
    
    参考

    アップデートしたカーネルが正常に適用されたか確認するには、カーネルアップデートの確認を参照してカーネルのインストール状況をご確認ください。

カーネルアップデートの確認

アップデートしたカーネルが正常に適用されたか確認する方法は、次の通りです。

  1. サーバへリモートアクセスします。
  2. カーネルパッケージがインストールされているかを確認します。
    root@ubuntu2204:~# dpkg -l | grep linux-image-5.15.0-124-generic
    ii  linux-image-5.15.0-124-generic        5.15.0-124.134                          amd64        Signed kernel image generic
    
  3. /bootディレクトリに initramfsファイルと vmlinuzファイルが作成されているかを確認します。
    root@ubuntu2204:~# ls -l /boot/initrd.img-5.15.0-124-generic
    -rw-r--r-- 1 root root 46553441 Oct 23 14:48 /boot/initrd.img-5.15.0-124-generic
    
    root@ubuntu2204:~# ls -l /boot/vmlinuz-5.15.0-124-generic
    -rw------- 1 root root 11700328 Sep 28 03:47 /boot/vmlinuz-5.15.0-124-generic
    
  4. grub.cfgファイルに最新カーネル設定が登録されているかを確認します。
    root@ubuntu2204:~# awk -F"--class" '/menuentry/ && /with Linux/ {print $1}' /boot/grub/grub.cfg | awk '{print i++ " : " $5,$6,$7,$8}' | sed -e "s/'/ /g"
    0 : 5.15.0-124-generic   
    1 : 5.15.0-124-generic (recovery mode) 
    2 : 5.15.0-94-generic   
    3 : 5.15.0-94-generic (recovery mode) 
    4 : 5.15.0-92-generic   
    5 : 5.15.0-92-generic (recovery mode)
    

カーネルアップデートの復元

カーネルのアップデート後にサーバの再起動が正常に行われない場合、更新する前のカーネルに戻す必要があります。インストールされたカーネルの中で色んなバージョンに復元することができ、本ガイドではカーネルをアップデートする直前に使用したカーネルバージョンに復元する方法について説明します。

参考

サーバの再起動問題を解決するために Single modeに入り、サーバの復旧を試行することもできます。Single modeの起動方法は、サーバ復旧ガイドをご参照ください。

  1. NAVERクラウドプラットフォームコンソールの VPC環境で、 i_menu > Services > Compute > Serverメニューを順にクリックします。

  2. Server メニューをクリックします。

  3. サーバリストから復旧するサーバを選択した後、 [サーバアクセスコンソール] ボタンを選択します。

  4. grub起動画面でブートカーネルを以前のバージョンに選択して再起動します。

    • Ubuntu 22.04 grub起動画面
      kernel-update-kvm-ubuntu22_console01

      kernel-update-kvm-ubuntu22_console02

  5. 起動が完了したら、サーバのカーネルバージョンを確認します。

    root@ubuntu2204:~# uname -r
    5.15.0-94-generic
    
  6. 現在有効になっているカーネルバージョンを確認します。

    root@ubuntu2204:~# awk -F"--class" '/menuentry/ && /with Linux/ {print $1}' /boot/grub/grub.cfg | awk '{print i++ " : " $5,$6,$7,$8}' | sed -e "s/'/ /g"
    0 : 5.15.0-124-generic   
    1 : 5.15.0-124-generic (recovery mode) 
    2 : 5.15.0-94-generic   
    3 : 5.15.0-94-generic (recovery mode) 
    4 : 5.15.0-92-generic   
    5 : 5.15.0-92-generic (recovery mode)
    
  7. 起動時にデフォルトのカーネルバージョンを以前のバージョンのカーネルバージョンにリセットします。

    root@ubuntu2204:~# sed -i 's/GRUB_DEFAULT=.*/GRUB_DEFAULT=saved/g' /etc/default/grub
    
    root@ubuntu2204:~# grep "GRUB_DEFAULT" /etc/default/grub
    GRUB_DEFAULT=saved
    
    root@ubuntu2204:~# grub-set-default "Advanced options for Ubuntu>Ubuntu, with Linux 5.15.0-94-generic"
    
    root@ubuntu2204:~# grub-editenv list
    saved_entry=Advanced options for Ubuntu>Ubuntu, with Linux 5.15.0-94-generic    
    
    root@ubuntu2204:~# update-grub
    Sourcing file `/etc/default/grub'
    Sourcing file `/etc/default/grub.d/init-select.cfg'
    Generating grub configuration file ...
    Found linux image: /boot/vmlinuz-5.15.0-124-generic
    Found initrd image: /boot/initrd.img-5.15.0-124-generic
    Found linux image: /boot/vmlinuz-5.15.0-94-generic
    Found initrd image: /boot/initrd.img-5.15.0-94-generic
    Found linux image: /boot/vmlinuz-5.15.0-92-generic
    Found initrd image: /boot/initrd.img-5.15.0-92-generic
    Warning: os-prober will not be executed to detect other bootable partitions.
    Systems on them will not be added to the GRUB boot configuration.
    Check GRUB_DISABLE_OS_PROBER documentation entry.
    done
    
  8. (オプション)変更されたカーネルバージョンが正常に起動するか確認するために、サーバを再起動します。

    root@ubuntu2204:~# sync;reboot
    
  9. (オプション)サーバに再ログインして起動有無とカーネルバージョンを確認します。

    root@ubuntu2204:~# uname -r
    5.15.0-94-generic