76

NetworkManager-wait-online.service fails at boot and it delays my startup

Sandeep C
  • 1,081

4 Answers4

80

Some code runs off the network

In some multi-user environments part of the boot-up process can come from the network. For this case systemd defaults to waiting for the network to come on-line before certain steps are taken.

Majority of Desktop Users

Unlike some multi-user environments most Ubuntu desktop users have the Operating System and drivers on their hard disks, SSDs or Live Boot USBs.

There is a glitch where some users wait an extremely long time for network to come up during boot. In this case the recommendations is to set the maximum wait time to 30 seconds. A better way is to simply disable the service at boot time.

For many users 10 to 15 seconds can be sliced off the parallel boot time by using:

sudo systemctl disable NetworkManager-wait-online.service

After you sign on you will likely get a message bubble stating you've now been connected to the network (WiFi or Ethernet access to Internet).

  • Is it needed if I use a wireless keyboard and mouse as input to my system (works with a wireless receiver adapter plugged into USB port)? – Porcupine Jun 15 '18 at 15:10
  • 1
    No its not needed for USB. – WinEunuuchs2Unix Jun 15 '18 at 15:11
  • @Also , if I use a bluetooth keyboard and mouse, will it be needed (I am considering buying one)? – Porcupine Jun 15 '18 at 15:15
  • 2
    Bluetooth is often embedded in WiFi card so I'm not sure on that one. – WinEunuuchs2Unix Jun 15 '18 at 17:37
  • Any idea why this service would still show up in systemd-analyze even after it has been disabled? – damluar Jan 01 '19 at 00:39
  • @damluar Sorry if you already know, but after disabling you have to reboot and then run systemd-analyze again. That said you can use systemctl status NetworkManager-wait-online.service to verified it was disabled correctly. – WinEunuuchs2Unix Jan 01 '19 at 01:05
  • status command tells active (exited), although I disabled it and rebooted multiple times. Any idea why disable won't be respected? – damluar Jan 01 '19 at 19:29
  • @damluar status should be reporting: Active: inactive (dead). You can post your problem as a new question and hopefully someone has experienced this before or read a bug report on it. – WinEunuuchs2Unix Jan 01 '19 at 19:52
  • 5
    Why does it take so long to get a connection? I'm connected via Gigabit. – Powerriegel Jun 08 '19 at 08:02
  • 1
    @Corni That is an excellent question but I'm not an expert on LAN/WAN/WiFi topology. I imagine it is something to do with negotiating new leases but that is just a guess. If you're really curious you can post that as a new question on this site. For me it's a shrug shoulders: it is what it is fact of life. – WinEunuuchs2Unix Jun 08 '19 at 15:25
  • It might be better to fix the reasons why NetworkManager-wait-online takes so long. It always takes several seconds, but when it times out, there is usually a configuration error. Also, services preferably don't require network up and should not order them self after After=network-online.target. If you do that, then only services that actually ask for it will be delayed. The only reason to disable NetworkManager-wait-online is if you have special requirements and you want to replace it by your own service/script. – thaller Mar 25 '20 at 16:52
  • Tried to disable the service on a Raspberry Pi Zero W, didn't get any appreciable improvement in boot time, definitely not the 7 seconds that appeared in sudo systemd-analyze blame – Pietro Battiston Jan 14 '24 at 16:15
13

It appears that this service simply waits, doing absolutely nothing, until the network is connected, and when this happens, it changes its state so that other services that depend on the network can be launched to start doing their thing.

So, it appears that this service is absolutely benign, it does not waste any time during boot, and it actually constitutes an optimization, so you are only going to make things worse if you disable it.

(Services that need the network will start before the network is up, at a time when many other services are also starting up and contention is high, and these services will be unable to do anything useful, so they will just keep retrying to connect to the network, until the network finally comes up.)

  • 3
    "it does not waste any time during boot" may be utterly untrue

    systemd-analyze critical-chain revealed that it was delaying boot by 7 seconds for absolutely no reason, my laptop is booting from local disk and does not need to wait for network.

    – reducing activity Feb 20 '22 at 06:01
  • @reducingactivity are you sure it is delaying your boot 7 seconds? Or is it just delaying the start of components that need network until after your wifi has connected? (which may well take 7 seconds or more.) Please post your detailed findings. – Mike Nakis Feb 20 '22 at 06:05
  • 3
    systemd-analyze help has critical-chain [UNIT...] Print a tree of the time critical chain of units See https://gist.github.com/matkoniecz/27031a4918944cb556e1742930e6d927 - NetworkManager-wait-online.service takes time from 2.5s after time 0 to 10s after time 0, with +7.392s on a critical patch. Though it is possible that after disabling something else will be on the critical path, I need to recheck it. – reducing activity Feb 20 '22 at 08:27
  • 1
    https://gist.github.com/matkoniecz/27031a4918944cb556e1742930e6d927 - dropped from over 12 seconds to below 6. – reducing activity Feb 20 '22 at 08:59
  • Okay, I did not expect that. I do not know. I raise my hands. I give up. – Mike Nakis Feb 20 '22 at 09:08
6

From the man page:

NAME

systemd-networkd-wait-online.service, systemd-networkd-wait-online - Wait for network to come online

DESCRIPTION

systemd-networkd-wait-online is a oneshot system service (see systemd.service(5)), that waits for the network to be configured. By default, it will wait for all links it is aware of and which are managed by systemd-networkd.service(8) to be fully configured or failed, and for at least one link to be online. Here, online means that the link's operational state is equal or higher than "degraded". The threshold can be configured by --operational-state= option.

Pablo Bianchi
  • 15,657
waltinator
  • 36,399
  • My service on Kubuntu 18.04.1 is called NetworkManager-wait-online.service and running man returns that there is no man page. Presumably this is a case of bad naming, or a missing link connecting man NetworkManager-wait-online.service with the man page named services you mention? – pbhj May 21 '19 at 15:07
0

For me this is the case because my Cisco switch wasn't configured spanning-tree portfast on the interface my workstation connects to the switch on. For whatever reason the switch takes a long time to bring up the interface if portfast is not configured.

You wouldn't want to enable portfast on a switch interface that has more than one downstream computers connected to it - probably results in only one computer having connectivity. But then again if you have multiple downstream computers connected to the switch interface (via a switch for example) then you wouldn't see this behavior in the first place.

ekeyser
  • 239