メインコンテンツまでスキップ

Ubuntu22.04から24.04へ移行

備考

アップグレード前の確認事項

  • 22.04 LTSのセキュリティサポートは 2027年6月頃 まで有効です。
  • 作業前に一通り熟読し、作業フローを理解して下さい。
  • OSアップグレードのため、作業は慎重に実施してください。

1. 事前準備

1-1. スナップショットの作成

警告

アップグレード前に必ず、VPSのサーバー管理画面から現時点のスナップショット(バックアップ)を作成してください。
万一アップグレードに失敗した場合、素早く復旧できます。

1-2. 作業対象サーバログイン

ssh_ed25519の場合

1-3. ノード停止

sudo systemctl stop cardano-node

自動起動の停止

sudo systemctl disable cardano-node

1-4. システムアップデート

sudo apt update && sudo apt full-upgrade -y && sudo apt autoremove -y

1-5. LTSアップグレード設定の確認

grep Prompt /etc/update-manager/release-upgrades

Prompt=lts であること

1-6. Ubuntuバージョン確認

現在のバージョンを確認します。

lsb_release -d

Description: Ubuntu 22.04.* LTS

アップグレードコマンドの確認します。

which do-release-upgrade || sudo apt install ubuntu-release-upgrader-core -y

アップグレード可能なバージョンを確認します。

sudo do-release-upgrade -c

Checking for a new Ubuntu release
New release '24.04.* LTS' available.
Run 'do-release-upgrade' to upgrade to it.

アップグレード前にその他アップグレードが必要なパッケージがあるかどうか確認します。

apt list --upgradable

パッケージが表示されなければ問題ありません。

apt-mark showhold

何も表示されなければ問題ありません。

Details

ある場合 表示されたパッケージをアップグレードします。
以下は一例です。

apt list --upgradable

Listing... Done
gum/unknown 0.17.0 amd64 [upgradable from: 0.16.2]
sosreport/jammy-updates 4.10.2-0ubuntu0~22.04.1 amd64 [upgradable from: 4.9.2-0ubuntu0~22.04.1]

パッケージが hold 状態になっている場合があります。

apt-mark showhold

gum

holdされているパッケージを解除します。

sudo apt-mark unhold パッケージ名

パッケージを更新します。

sudo apt install パッケージ名

その後アップグレードします。

sudo apt full-upgrade -y

アップグレードが完了したら、再度以下を実行して更新可能パッケージが残っていないことを確認します。

apt list --upgradable

1-7. サーバー再起動

sudo reboot

2. Ubuntuアップグレード

"SSHで作業する場合"
  • 予備のSSHポートを開放してください。
    ※ただしAWSやIONOSなど、VPSサーバー管理画面からファイアウォールを設定する場合は、以下のコードは実行せずVPS管理画面から設定してください。
sudo ufw allow 1022/tcp
sudo ufw reload

確認

sudo ufw status numbered

2-1. アップグレード実行

SSH接続でアップグレードする場合、tmux環境内で実行します。

tmux new -s ubuntu-upgrade

tmuxセッション内でアップグレードを実行します。

sudo do-release-upgrade
"SSHが切断された場合(復帰方法)"

再接続後、以下で tmux に復帰できます。

tmux a -t ubuntu-upgrade

2-2. アップグレードメッセージ

以下、確認メッセージ例です。
ご利用のサーバーによって表示内容が異なる場合があります。 表示された内容をよく読んで下さい。

危険

設定ファイルに関する確認メッセージが表示された場合は、
必ず keep the local version currently installed(現在の設定を維持する) を選択してください。

サーバーによっては chronysshd など複数の設定ファイルで同様のメッセージが表示される場合がありますが、
いずれの場合も keep the local version currently installed を選択します。

1. Ubuntuの案内メッセージ(README)
y を入力後 Enter

Ubuntu is a Linux distribution for your desktop or server, with a fast
and easy install, regular releases, a tight selection of excellent
applications installed by default, and almost any other software you
can imagine available through the network.

We hope you enjoy Ubuntu.

== Feedback and Helping ==

If you would like to help shape Ubuntu, take a look at the list of
ways you can participate at

http://www.ubuntu.com/community/participate/

Your comments, bug reports, patches and suggestions will help ensure
that our next release is the best release of Ubuntu ever. If you feel
that you have found a bug please read:

http://help.ubuntu.com/community/ReportingBugs

Then report bugs using apport in Ubuntu. For example:

ubuntu-bug linux

will open a bug report in Launchpad regarding the linux package.

If you have a question, or if you think you may have found a bug but
aren't sure, first try asking on the #ubuntu or #ubuntu-bugs IRC
channels on Libera.Chat, on the Ubuntu Users mailing list, or on the
Ubuntu forums:

http://help.ubuntu.com/community/InternetRelayChat
http://lists.ubuntu.com/mailman/listinfo/ubuntu-users
http://www.ubuntuforums.org/


== More Information ==

You can find out more about Ubuntu on our website, IRC channel and wiki.
If you're new to Ubuntu, please visit:

http://www.ubuntu.com/


To sign up for future Ubuntu announcements, please subscribe to Ubuntu's
very low volume announcement list at:

http://lists.ubuntu.com/mailman/listinfo/ubuntu-announce


Continue [yN] y # y を入力後Enter

2. アップグレードを開始しますか?
y を入力後 Enter

Do you want to start the upgrade? 


54 packages are going to be removed. 172 new packages are going to be
installed. 630 packages are going to be upgraded.

You have to download a total of 1,419 M. This download will take
about 4 minutes with a 40Mbit connection and about 37 minutes with a
5Mbit connection.

Fetching and installing the upgrade can take several hours. Once the
download has finished, the process cannot be canceled.

Continue [yN] Details [d] y # y 入力後Enter

3. 変更されている chrony.conf の設定ファイルをどうしますか?
keep the local version currently installed を選択後 Enter

4. このサーバーのキーボード配列はどれですか?
English (US) を選択後 Enter

5. このマシンのキーボードに対応するレイアウトを選択してください。
English (US) を選択後 Enter

6. nginxの設定
デフォルトのN を入力後 Enter

Configuration file '/etc/nginx/nginx.conf'
==> Modified (by you or by a script) since installation.
==> Package distributor has shipped an updated version.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** nginx.conf (Y/I/N/O/D/Z) [default=N] ? n # n 入力後Enter

7. sudoersの設定
デフォルトのN を入力後 Enter

Configuration file '/etc/sudoers'
==> Modified (by you or by a script) since installation.
==> Package distributor has shipped an updated version.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** sudoers (Y/I/N/O/D/Z) [default=N] ? n # n 入力後Enter

8. sysctlの設定
デフォルトのN を入力後 Enter

Configuration file '/etc/sysctl.conf'
==> Modified (by you or by a script) since installation.
==> Package distributor has shipped an updated version.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** sysctl.conf (Y/I/N/O/D/Z) [default=N] ? n # n 入力後Enter

9. この変更された SSH 設定ファイルをどうしますか?
keep the local version currently installed を選択後 Enter

10. この変更された GRUB 設定ファイルをどうしますか?
keep the local version currently installed を選択後 Enter

11. GRUB(ブートローダー)をどのディスクにインストールするか?
/dev/sda 上でスペースキーを押して選択し、Tabキーを押して Ok を選択した後、Enter

12. 古い不要パッケージを削除しますか?
y を入力後 Enter

Remove obsolete packages? 


114 packages are going to be removed.

Removing the packages can take several hours.

Continue [yN] Details [d] y # y 入力後Enter

13. アップグレードが完了しました。再起動しますか?
y を入力後 Enter

System upgrade is complete.

Restart required

To finish the upgrade, a restart is required.
If you select 'y' the system will be restarted.

Continue [yN] y # y 入力後Enter

3. アップグレード確認(SSH接続)

3-1. 現在のUbuntuバージョン確認

lsb_release -d

No LSB modules are available.
Description: Ubuntu 24.04.4 LTS

3-2. ブラケットペーストモードOFF

grep -qxF 'set enable-bracketed-paste off' ~/.inputrc || echo 'set enable-bracketed-paste off' >> ~/.inputrc

3-3. SSH再接続

exit

SSHで再接続してください。

4. 依存関係再インストール

システムアップデート

sudo apt update -y && sudo apt upgrade -y
sudo apt install bc curl htop nano needrestart rsync ufw zstd automake build-essential pkg-config libffi-dev libgmp-dev libssl-dev libncurses-dev libsystemd-dev zlib1g-dev make g++ tmux git jq wget libtool autoconf liblmdb-dev -y
sudo apt install bc curl htop nano needrestart python3-pip python3-venv python3-full rsync ufw zstd automake build-essential pkg-config libffi-dev libgmp-dev libssl-dev libncurses-dev libsystemd-dev zlib1g-dev make g++ tmux git jq wget libtool autoconf liblmdb-dev -y
python3 -m venv ~/notify-venv
~/notify-venv/bin/pip install -U pip
~/notify-venv/bin/pip install watchdog pytz python-dateutil requests discordwebhook slackweb i18nice[YAML] python-dotenv

確認

~/notify-venv/bin/python -c "import watchdog, pytz, dateutil, requests, discordwebhook, slackweb, i18n, dotenv; print('OK')"

OKと表示されれば問題ありません。

デーモン再起動自動化

sudo grep -qxF "\$nrconf{restart} = 'a';" /etc/needrestart/conf.d/50local.conf || \
echo "\$nrconf{restart} = 'a';" | sudo tee -a /etc/needrestart/conf.d/50local.conf > /dev/null
sudo sed -i '/^\$nrconf{blacklist_rc}/d' /etc/needrestart/conf.d/50local.conf
sudo grep -qxF "\$nrconf{blacklist_rc} = [qr(^cardano-node\\.service$) => 0, qr(^cnode-blocknotify\\.service$) => 0, qr(^cnode-cncli-sync\\.service$) => 0,];" /etc/needrestart/conf.d/50local.conf || \
echo "\$nrconf{blacklist_rc} = [qr(^cardano-node\\.service$) => 0, qr(^cnode-blocknotify\\.service$) => 0, qr(^cnode-cncli-sync\\.service$) => 0,];" | sudo tee -a /etc/needrestart/conf.d/50local.conf > /dev/null

自動起動有効化

sudo systemctl enable cardano-node

ノードを起動します。

sudo systemctl start cardano-node

ノード同期状況の確認

sudo journalctl -u cardano-node -f

コンパイル済みHaskellパッケージ削除

cd ~/.cabal/store
rm -rf ghc-8.*
ヒント

予備SSHポート(1022)を削除する前に、現在のSSHポートを許可します。
※AWSやIONOSなどはVPS管理画面から削除してください。

ステータスを確認します。

sudo ufw status

以下の表示があればOK

Status: active

予備SSHポート(1022)を削除します。

sudo ufw delete allow 1022/tcp

確認

sudo ufw status numbered

5. エアギャップマシンアップグレード

5-1. 事前準備

  1. Ubuntuへログインし、主要ファイルのアクセス制限の解除
cd $NODE_HOME
chmod 700 vrf.skey
chmod 700 vrf.vkey
chmod 700 payment.vkey
chmod 700 payment.skey
chmod 700 stake.vkey
chmod 700 stake.skey
chmod 700 stake.addr
chmod 700 payment.addr
chmod u+rwx $HOME/cold-keys
cd $HOME/cold-keys
chmod 700 node.vkey
chmod 700 node.skey
  1. 次のディレクトリ(/home/$USER/cnode/home/cold-keys)を切り取って、外部ストレージに退避
  2. Ubuntuをシャットダウン(電源オフ)

5-2. VirtualBoxアップグレード

  1. VirtualBoxのダウンロードサイトにアクセスし、VirtualBox 7.*.* platform packagesWindows hostsまたはmacOSのリンクからダウンロードし、既存のVirtuialBoxに対して上書きインストールしてください。

5-3. システムアップデート

  1. VirtualBoxのマシン設定からネットワークを有効
  2. Ubuntuを起動
  3. ディスク容量の確認
df -h /root

Availの値が10G以上であることを確認します。

  1. Ubuntu設定から「電源管理」→「画面のブランク」→「しない」に設定
  2. アプリケーション一覧からsoftと検索し、「ソフトウェアとアップデート」を起動
  3. アップデート」タブのUbuntuの新バージョンの通知が「長期サポート(LTS)版」が選択されていることを確認して、「閉じる」ボタンを選択します。
  4. アプリケーション一覧からupdateと検索し、「ソフトウェアの更新」を起動
  5. 今すぐインストール」を選択します。
  6. パスワードを入力し、認証ボタンを選択します。
  7. インストール後再起動を求められたら再起動します。

5-4. Ubuntuアップグレード

!!! tip "アップグレード" 表示された内容に沿ってアップグレードしてください。
アップグレードには数十分かかります。

  1. アプリケーション一覧からupdateと検索し、「ソフトウェアの更新」を起動
  2. 今すぐインストール」を選択します。
  3. パスワードを入力し、認証ボタンを選択します。
  4. アップグレード」を選択
  5. パスワードを入力し、認証ボタンを選択します。
  6. ポップアップ(リリースノート)が表示されたら「アップグレード」を選択します。
  7. ポップアップ(アップグレードを開始しますか?)が表示されたら「アップグレードを開始」を選択します。
  8. ロック画面が無効になりました。」というポップアップが表示された場合、「閉じる」ボタンを選択します。
  9. 設定ファイルを置き換えるかと表示された場合、「そのまま」を選択します。
  10. サポートが中止された(あるいはリポジトリに存在しない)パッケージを削除しますか?」というポップアップが表示されたら、「削除」ボタンを選択します。
  11. すぐに再起動」ボタンを選択し、再起動してください。

5-5. GuestAddtionsアップグレード

  1. デバイス」タブから「Guest Additionsのアップグレード」を選択します。
  2. Ubuntuをシャットダウン(電源オフ)

5-6. 最終仕上げ

  1. ネットワークをオフ
  2. Ubuntuを起動
  3. ブラケットペーストモードをOFFに設定
echo "set enable-bracketed-paste off" >> ~/.inputrc
  1. 退避したディレクトリを配置
  2. ファイルの権限の変更
cd $NODE_HOME
chmod 400 vrf.skey
chmod 400 vrf.vkey
chmod 400 payment.vkey
chmod 400 payment.skey
chmod 400 stake.vkey
chmod 400 stake.skey
chmod 400 stake.addr
chmod 400 payment.addr
cd $HOME/cold-keys
chmod 400 node.vkey
chmod 400 node.skey
chmod a-rwx $HOME/cold-keys

6. sysctlの設定

バックアップを取得しておきます。

sysctl \
net.ipv4.conf.all.rp_filter \
net.ipv4.conf.default.rp_filter \
net.ipv4.icmp_echo_ignore_broadcasts \
net.ipv4.conf.all.accept_source_route \
net.ipv4.conf.default.accept_source_route \
net.ipv4.conf.all.accept_redirects \
net.ipv4.conf.default.accept_redirects \
net.ipv4.conf.all.secure_redirects \
net.ipv4.conf.default.secure_redirects \
net.ipv4.conf.all.log_martians \
net.ipv4.tcp_syncookies \
net.core.somaxconn \
net.ipv4.tcp_max_syn_backlog \
net.core.netdev_max_backlog \
net.ipv4.ip_local_port_range \
> "$HOME/sysctl-before-cardano-relay-$(date +%F).txt"
sudo tee /etc/sysctl.d/99-cardano-relay.conf > /dev/null << 'EOF'

# ------------------------------
# Security hardening
# ------------------------------

# Ignore ICMP broadcast
net.ipv4.icmp_echo_ignore_broadcasts = 1

# Disable source routing
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0

# Disable ICMP redirects
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0

# Log suspicious packets
net.ipv4.conf.all.log_martians = 1

# SYN flood protection
net.ipv4.tcp_syncookies = 1

# ------------------------------
# Relay network performance
# ------------------------------

# Increase TCP listen queue
net.core.somaxconn = 4096

# Increase SYN backlog
net.ipv4.tcp_max_syn_backlog = 4096

# Improve network buffer
net.core.netdev_max_backlog = 5000

# Increase ephemeral port range
net.ipv4.ip_local_port_range = 10000 65535

EOF

バックアップを取得しておきます。

sysctl \
net.ipv4.conf.all.rp_filter \
net.ipv4.conf.default.rp_filter \
net.ipv4.icmp_echo_ignore_broadcasts \
net.ipv4.conf.all.accept_source_route \
net.ipv4.conf.default.accept_source_route \
net.ipv4.conf.all.accept_redirects \
net.ipv4.conf.default.accept_redirects \
net.ipv4.conf.all.secure_redirects \
net.ipv4.conf.default.secure_redirects \
net.ipv4.conf.all.log_martians \
net.ipv4.tcp_syncookies \
> "$HOME/sysctl-before-cardano-bp-$(date +%F).txt"
sudo tee /etc/sysctl.d/99-cardano-bp.conf > /dev/null << 'EOF'

# ------------------------------
# Security hardening
# ------------------------------

# Ignore ICMP broadcast
net.ipv4.icmp_echo_ignore_broadcasts = 1

# Disable source routing
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0

# Disable ICMP redirects
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0

# Log suspicious packets
net.ipv4.conf.all.log_martians = 1

# SYN flood protection
net.ipv4.tcp_syncookies = 1

EOF

設定反映

sudo sysctl --system