Raspberry Pi 4の起動を速くする

ubuntu18.04をインストールしたRaspberry pi 4にsshでログイン出来るまでに2分あまりかかるのでその対策をした時のメモです。

状況:有線LANは外してwifiからログインしたいが、起動してからIPアドレスが認識できるまで2分間かかる。

dmesgコマンドでは原因がわからない

dmesgコマンドを使って起動時のログを表示してみましたが、それらしい原因をつかむことは出来ませんでした。

systemd-analyzeコマンドを見つけた

systemd-analyzeコマンドを使ってみると次の内容が表示されNetworkManager-wait-online.serviceが足を引っ張っているようです。
最後にsystemd-networkd-wait-online.serviceも起動しているので上のサービスを止めてみることにしました。

pi4@pi:~$ systemd-analyze blame
     2min 3.219s apt-daily.service
      2min 205ms systemd-networkd-wait-online.service
          7.348s cloud-init-local.service
          5.265s cloud-init.service
          2.928s lvm2-monitor.service
          2.884s dev-sda2.device
          2.445s cloud-config.service
          2.056s cloud-final.service
          1.473s udisks2.service
          1.205s networkd-dispatcher.service
          1.196s xrdp.service
          1.148s rc-local.service
           864ms ModemManager.service
           816ms snapd.service
           783ms NetworkManager.service
           682ms accounts-daemon.service
           650ms lxd-containers.service
           639ms alsa-restore.service
           600ms systemd-journal-flush.service
           593ms avahi-daemon.service
           567ms apport-autoreport.service
           564ms lm-sensors.service
           563ms systemd-udevd.service
           549ms systemd-timesyncd.service
           522ms systemd-logind.service
           520ms NetworkManager-wait-online.service
           456ms pppd-dns.service
           417ms rsyslog.service
           415ms systemd-remount-fs.service
           413ms keyboard-setup.service
           404ms systemd-udev-trigger.service
           271ms systemd-resolved.service
           268ms systemd-journald.service
           267ms lightdm.service
           260ms loadcpufreq.service
           241ms systemd-fsck@dev-disk-by\x2dlabel-system\x2dboot.service
           209ms networking.service
           186ms colord.service
           173ms ebtables.service
           172ms apport.service
           164ms ssh.service
           153ms polkit.service
           145ms snapd.seeded.service

Linux-不要デーモンの停止を参考にして

$sudo systemctl disable NetworkManager-wait-online.service

このサービスを止めてみた結果、wifi経由のIPアドレスは10秒以内に認識できるようになったもののsshでログイン出来るまでに、やっぱり2分間かかります。

となると、

2min 205ms systemd-networkd-wait-online.service

最後に表示されるこれが、待ち時間がタイムアウトしてsshが使えるようになったということなのでしょう。
検索してみるとこのサービスのタイムアウトはデフォルトで2minだそうなので、この推測があたっているようです。

ということで、systemd-networkd-wait-online.serviceのタイムアウト設定を変更する方法を探した結果、

/etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service

で設定できそうなので、このファイルにTimeoutSec=15(最初はなかった)を追加してみました。

#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Wait for Network to be Configured
Documentation=man:systemd-networkd-wait-online.service(8)
DefaultDependencies=no
Conflicts=shutdown.target
Requires=systemd-networkd.service
After=systemd-networkd.service
Before=network-online.target shutdown.target

[Service]
Type=oneshot
TimeoutSec=15
ExecStart=/lib/systemd/systemd-networkd-wait-online
RemainAfterExit=yes

[Install]
WantedBy=network-online.targetさい

再起動してみた結果、15秒でsystemd-networkd-wait-online.serviceがタイムアウトするようになりました。

15.157s systemd-networkd-wait-online.service
 6.350s cloud-init-local.service
 5.293s cloud-init.service
 2.464s dev-sda2.device
 2.444s cloud-config.service
 2.422s lvm2-monitor.service
 2.104s cloud-final.service
 1.306s networkd-dispatcher.service
 1.204s xrdp.service
 1.191s rc-local.service
 1.165s snapd.service
 1.143s udisks2.service
  933ms ModemManager.service
  785ms apport-autoreport.service
  673ms lxd-containers.service
  537ms accounts-daemon.service
  431ms systemd-udev-trigger.service
  424ms lm-sensors.service
  417ms keyboard-setup.service
  352ms systemd-remount-fs.service
  332ms systemd-logind.service
  322ms systemd-journal-flush.service
  279ms loadcpufreq.service
  268ms polkit.service
  265ms lightdm.service
  265ms systemd-journald.service
  245ms wpa_supplicant.service
  243ms systemd-resolved.service
  243ms systemd-udevd.service
  210ms networking.service
  209ms systemd-timesyncd.service
  198ms rsyslog.service
  196ms systemd-fsck@dev-disk-by\x2dlabel-system\x2dboot.service
  191ms avahi-daemon.service
  172ms ebtables.service
  170ms apport.service
  167ms alsa-restore.service
  157ms colord.service
  155ms ssh.service
  133ms xrdp-sesman.service
  126ms user@1001.service
  122ms systemd-tmpfiles-setup.service
  112ms sddm.service

一件落着(^^)/

 

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

CAPTCHA


日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)