本文记录Ubuntu24.04在启动时网络设备未连接,因此由于systemd-networkd-wait-online.service导致启动时间过长的问题,并最终在/etc/netplan/50-cloud-init.yaml配置文件中增加参数得以解决的过程。

问题现象

通常情况下系统的网络设备在启动时不会立即建立连接,此时systemed-networkd-wait-online.service就会产生一个2min的超时等待。

Ubuntu24.04启动延时日志

下面是使用systemd-analyze查看启动时间:

blduan@ubuntu24:~$ sudo systemd-analyze
Startup finished in 32.202s (kernel) + 2min 4.345s (userspace) = 2min 36.548s
graphical.target reached after 2min 4.284s in userspace.

解决方法

netplan的配置文件中增加option: true

blduan@ubuntu24:~$ sudo cat /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        ens33:
            dhcp4: true
            optional: true
        ens38:
            dhcp4: true
            optional: true
    version: 2

验证结果:

blduan@ubuntu24:~$ sudo systemd-analyze
Startup finished in 32.692s (kernel) + 3.928s (userspace) = 36.620s
graphical.target reached after 3.820s in userspace.

根据开发人员的策略,以后systemd-networkd-wait-online可能默认会被禁用,如果存在optional: false则启用,存在optional:t true则禁用。

参考文档

Bug #2060311 “Setting “optional: true” to overcome he timeout “J…” : Bugs : Netplan (launchpad.net)

Job systemd-networkd-wait-online.service start running - Thomas-Krenn-Wiki-en