Ubuntu Server 启动过程中,比较慢 Job systemd-networkd-wait-online.service/start running

 

图片

 Job systemd-networkd-wait-online.service/start running

该问题通常出现在 ‌Ubuntu Server 或无图形界面的 Linux 系统‌ 中,表现为开机卡在 “A start job is running for Wait for Network to be configured” 提示,持续约 ‌30 秒至 2 分钟‌,之后系统会继续启动。这是由于 systemd-networkd-wait-online.service 服务默认等待所有网络接口配置完成并进入“可路由”状态,若网卡未连接网线、DHCP 响应慢或 WiFi 未连接,就会超时等待。


根本原因

  • 系统使用 systemd-networkd 管理网络(常见于 Ubuntu Server 18.04+)。
  • 该服务默认‌无超时限制‌或超时较长(如 120 秒),等待所有网络接口上线。
  • 若存在未连接的有线网卡、未配置的 WiFi 或虚拟机网卡,服务会一直等待。

 

解决办法

cd /etc/systemd/system/network-online.target.wants/

sudo vim systemd-networkd-wait-online.service

#在Service加入TImeoutStartSec=2sec

图片

 


#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  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)
ConditionCapability=CAP_NET_ADMIN
DefaultDependencies=no
Conflicts=shutdown.target
BindsTo=systemd-networkd.service
After=systemd-networkd.service
Before=network-online.target shutdown.target

[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/systemd-networkd-wait-online
RemainAfterExit=yes
TImeoutStartSec=2sec

[Install]
WantedBy=network-online.target

 


:wq 保存退出

shutdown - r now 重新启动即可
 
原文链接:

https://blog.csdn.net/beck_li/article/details/144189133

posted @ 2026-05-04 17:36  emanlee  阅读(6)  评论(0)    收藏  举报