LoginSignup
10
8

More than 1 year has passed since last update.

Linuxサーバ起動時のsystemd-networkd-wait-onlineの待機を解除する

Last updated at Posted at 2021-05-22

概要

Ubuntu Server 20.04 LTSをインストールしたワークステーションを起動するとき、Linuxカーネルが「Starting Wait for Network to be Configured...」というメッセージを出力したまま2分ほど停止し、その後タイムアウトエラーとなる事象が発生していた。ネットで調べたところ、タイムアウトまでの時間を短縮する方法は見つかったものの、エラーは残り続ける。巡り巡って最終的に英語のウェブサイトにたどりついたので、以下に一例として日本語の備忘録を残しておく。

systemd-networkd-wait-onlineはLinuxデーモンのひとつsystemdの一部で、ネットワークの接続が確立するまで待機するという動きをするものらしい。
セットアップしていたワークステーションにはLANポートが複数存在し、そのうちひとつは有効なネットワークに接続していたが、残りのポートにはLANケーブルを挿入していなかった。このため、残りのケーブルを刺していないLANポートでのネットワークへの接続確立まで待機しようとしたのが、今回の起動時の動きのようだ。なので、systemd-networkd-wait-onlineが起動するときに、LANケーブルが刺さっていないポートを無視するよう、以下の方法で設定ファイルに追記し、エラーの出力を回避する。
ちなみに、systemd-networkd-wait-onlineはデフォルトで最大2分間待機する仕様となっている。毎回決まって2分程度停止するのもそれが原因だった。

解決方法

sudo su -コマンドを使ってrootユーザでログイン。systemctl status systemd-networkd-wait-onlineでステータスを確認する。

root@hogehoge:~# systemctl status systemd-networkd-wait-online
● systemd-networkd-wait-online.service - Wait for Network to be Configured
     Loaded: loaded (/usr/lib/systemd/system/systemd-networkd-wait-online.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2021-05-22 15:22:08 JST; 3min 54s ago
       Docs: man:systemd-networkd-wait-online.service(8)
    Process: 901 ExecStart=/usr/lib/systemd/systemd-networkd-wait-online (code=exited, status=1/FAILURE)
   Main PID: 901 (code=exited, status=1/FAILURE)

May 22 15:20:08 hogehoge systemd[1]: Starting Wait for Network to be Configured...
May 22 15:22:08 hogehoge systemd-networkd-wait-online[901]: Event loop failed: Connection timed out
May 22 15:22:08 hogehoge systemd[1]: systemd-networkd-wait-online.service: Main process exited, code=exited, status=1/FAILURE
May 22 15:22:08 hogehoge systemd[1]: systemd-networkd-wait-online.service: Failed with result 'exit-code'.
May 22 15:22:08 hogehoge systemd[1]: Failed to start Wait for Network to be Configured.

Loaded:を確認すると、設定ファイルが/usr/lib/systemd/system/systemd-networkd-wait-online.serviceであることがわかる。このファイルパスを控えておく。

次に、networkctlコマンドでLANポートの状態を確認する。

root@hogehoge:~# networkctl
IDX LINK     TYPE     OPERATIONAL SETUP
  1 lo       loopback carrier     unmanaged
  2 eth0     ether    no-carrier  configuring
  3 eth1     ether    no-carrier  configuring
  4 eth2     ether    routable    configured
  5 eno1     ether    no-carrier  configuring

5 links listed.

LANケーブルを接続しているポートeth2だけがOPERATIONALがroutable、SETUPがconfiguredになっている。OPERATIONALがno-carrier、SETUPがcofiguringになってるポートは、OSに認識されているが、ネットワーク接続が確立されていないポートである(今回の例だとeth0eth1eno1)。このポート名もすべて控えておく。

そして、VimやEmacsといったエディタで設定ファイル/usr/lib/systemd/system/systemd-networkd-wait-online.serviceを開き、[Service]のExecStart=...行の末尾に、--ignore=控えたポート名を追記する。

root@hogehoge:~# vi /usr/lib/systemd/system/systemd-networkd-wait-online.service
(前省略)
[Service]
ExecStart=/usr/lib/systemd/systemd-networkd-wait-online --ignore=eth0 --ignore=eth1 --ignore=eno1
(後省略)

また、systemctl edit sytemd-networkd-wait-online.serviceコマンドでも編集が可。この場合、ファイルパスを指定する必要はなく、systemctlコマンドに付属するエディタで設定ファイルを開く。--fullオプションはお好みで。
無視するポートを指定するのではなく、タイムアウトまでの時間を変更したい場合は、--timeout=秒数--ignoreと同じように追記すればよい。

追記できたら、設定ファイルを保存してエディタを終了。rebootコマンドで再起動する。設定がうまくいっていれば、カーネル起動時のメッセージはスムーズに流れていく。
最後に念の為、もう一度systemctl status systemd-networkd-wait-onlineコマンドを入力して、状態を確認。

root@hogehoge:~# systemctl status systemd-networkd-wait-online
● systemd-networkd-wait-online.service - Wait for Network to be Configured
     Loaded: loaded (/usr/lib/systemd/system/systemd-networkd-wait-online.service; enabled; vendor preset: enabled)
     Active: active (exited) since Fri 2021-05-22 15:31:34 JST; 1min 5s ago
       Docs: man:systemd-networkd-wait-online.service(8)
    Process: 898 ExecStart=/usr/lib/systemd/systemd-networkd-wait-online --ignore=eth0 --ignore=eth1 --ignore=eno1 (code=exited, status=0/SUCCESS)
   Main PID: 898 (code=exited, status=0/SUCCESS)

May 22 15:31:31 hogehoge systemd[1]: Starting Wait for Network to be Configured...
May 22 15:31:34 hogehoge systemd-networkd-wait-online[898]: managing: eth2
May 22 15:31:34 hogehoge systemd[1]: Finished Wait for Network to be Configured.

Active:active (existed)になっていればOK。

参考

https://github.com/systemd/systemd/issues/5154
https://bbs.archlinux.org/viewtopic.php?id=256366

10
8
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
10
8