systemd.runカーネルパラメータ(systemdデバイスの要求/希望など)でネットワークを待ちます。

systemd.runカーネルパラメータ(systemdデバイスの要求/希望など)でネットワークを待ちます。

私はそれを使用していますカーネルsystemd.runパラメータManjaro ARMを初めて起動するときは、ホスト名の設定、デフォルトのユーザーの追加など、いくつかの自動設定タスクを適用し、パッケージのインストールを除いてすべてがうまく機能しますpacmanpacmanたとえば、すべてのパッケージを更新してvimをインストールしたいとします。

pacman -Syu --noconfirm
pacman -S --noconfirm vim

たとえば、これを行うと、各画像に対してさまざまなエラーが発生します。

+ pacman -Syu --noconfirm
:: Synchronizing package databases...
 core downloading...
 extra downloading...
 community downloading...
error: failed retrieving file 'core.db' from manjaro.mirrors.lavatech.top : Could not resolve host: manjaro.mirrors.lavatech.top
warning: too many errors from manjaro.mirrors.lavatech.top, skipping for the remainder of this transaction
error: failed retrieving file 'extra.db' from manjaro.mirrors.lavatech.top : Could not resolve host: manjaro.mirrors.lavatech.top
error: failed retrieving file 'community.db' from manjaro.mirrors.lavatech.top : Could not resolve host: manjaro.mirrors.lavatech.top
error: failed retrieving file 'core.db' from ftp.nluug.nl : Could not resolve host: ftp.nluug.nl

ローカルサーバーとインターネットドメインをpingしようとしました。

+ ping -c1 192.168.0.19
ping: connect: Network is unreachable

そのため、スクリプトの実行中にネットワーク接続が確立されていないようです。頑張ったsystemd.wantsしかし、まだ動作しません。ネットワークは利用できません。また、次systemd.wantsのような別の単位を試してみましたcmdline.txt

systemd.wants=systemd-networkd.service
systemd.wants=systemd-networkd-wait-online.service
systemd.wants=network-online.target
systemd.wants=dhcpcd.service

systemdディレクティブ/boot/cmdline.txt:

systemd.run=/boot/my_init_wrapper.sh systemd.run_success_action=reboot systemd.unit=kernel-command-line.target systemd.wants=systemd-networkd.service

~からsystemd-run-generatorrun3つのオプション(、run_success_actionおよび)だけが言及されていますrun_failture_actionが、最初の文書を誤って理解しているように見えるので、それを理解できないようですsystemd.run.generator。 systemdユニット自体がさまざまな種類の依存関係を指定できるため、この点を知りたいです。カーネルでこれを指定する他の方法はありますかcmdline.txt

ラズベリーパイ4で試してみてください。ただし、この質問はsystemdに固有のものであるため、piで実行しているのかsystemdを持つ他のシステムで実行しているのかは関係ありません。だから私はこれをRPIプラットフォームではなく一般的なLinuxの質問としてここに投稿します。

ベストアンサー1

この場合は、納品せず、少なくとも部品については通常のsystemd.runサービスとして使用する方が良いと思います。ConditionFirstBoot=yespacman

~によると手動、そのようなユニットを参照する方が良いfirst-boot-complete.target

[Unit]
Description="Update packages & install vim"
ConditionFirstBoot=yes
Wants=first-boot-complete.target
Before=first-boot-complete.target
Wants=network-online.target
After=network-online.target

[Service]
#optional ping test
#ExecCondition=/usr/bin/ping -c 2 -w 2 manjaro.org
#not running arch - adapt pacman path if need be:
ExecStart=/usr/bin/pacman -Syu --noconfirm
ExecStart=/usr/bin/pacman -S --noconfirm vim

[Install]
WantedBy=default.target

pingテストは面白いかもしれません。「オンライン」の意味についての不確実性


最初の開始条件はマニュアルで引用されます。

最初の開始条件 =

ブールパラメータを使用します。この条件は、システムが初めて起動するかどうかによってデバイスの状態を決定するために使用できます。これはほぼ/etc/満たされないことを意味します(詳細は参考資料の「最初の起動意味」を参照machine-id(5))。これは、/etc/工場リセット後の最初の起動時、または新しいシステムインスタンスの最初の起動時に設定するために使用できます。

堅牢性のために、ユニットはConditionFirstBoot=yes最初に自分自身を命令し、first-boot-complete.targetこの手動目標を引き付ける必要がありますWants=。これにより、最初の起動が中断された場合は、次のシステム起動中にそのデバイスが再起動されます。

このオプションがカーネルコマンドラインで指定されている場合systemd.condition-first-boot=(ブール値を使用)、この条件付き検証結果は無視され、/etc/machine-id存在確認よりも優先されます。

おすすめ記事