Score:3

Ubuntu 20.04 - how can I stop waiting for NetworkManager.service during startup?

cn flag

I prefer network to setup itself when I start computer, but I prefer to boot earlier and have network connect while I type my password and so on.

Sadly, according to systemd-analyze critical-chain I am waiting for NetworkManager.service startup during boot.

Is there a way to change that so that it still does its network things and it is not delaying boot?

graphical.target @8.083s
└─multi-user.target @8.083s
  └─postfix.service @8.075s +7ms
    └─[email protected] @3.904s +4.169s
      └─network-online.target @3.880s
        └─network.target @3.880s
          └─NetworkManager.service @3.495s +384ms
            └─dbus.service @3.492s
              └─basic.target @3.472s
                └─sockets.target @3.472s
                  └─docker.socket @3.469s +2ms
                    └─sysinit.target @3.464s
                      └─snapd.apparmor.service @3.131s +332ms
                        └─apparmor.service @2.990s +136ms
                          └─local-fs.target @2.989s
                            └─run-snapd-ns-cups.mnt.mount @5.417s
                              └─run-snapd-ns.mount @4.544s
                                └─local-fs-pre.target @528ms
                                  └─keyboard-setup.service @376ms +152ms
                                    └─systemd-journald.socket @361ms
                                      └─system.slice @354ms
                                        └─-.slice @354ms
PonJar avatar
in flag
Network manager is introducing 384ms delay to the boot process. That is less than half a second. [email protected] has a larger delay. Are you under the impression the delay for network manager is 3.495 seconds?
reducing activity avatar
cn flag
@PonJar no, but this one is obviously misplaced and has no reason whatsoever to delay boot by even a millisecond. Though if that postfix service is the same postfix as one described as "Postfix is the default Mail Transfer Agent" then I will also need to find way to start it without delaying boot. It is absurd that I wait for this service to start, it should load while I type password. Good catch.
PonJar avatar
in flag
I’m sure it’s possible to alter the dependencies between services and targets by editing unit files. However you would have to think carefully about any unexpected consequences of doing so. There is an interesting question and answer about displaying dependencies and dependents of services here https://unix.stackexchange.com/questions/422097/systemd-find-dependants-of-service I guess you would need to get familiar with this if you want to change things such as making network manager not a dependency of graphical target. I assume you are familiar with unit file structure
darth_epoxy avatar
nl flag
Why don't you remove network-manager and test your boot scenario again. And then re install it, it's easy enough. https://askubuntu.com/questions/1091653/how-do-i-disable-network-manager-permanently
reducing activity avatar
cn flag
@darth_epoxy Because I want to change order of services on startup rather than to temporarily disable it.
Quasímodo avatar
jp flag
What happens if you remove `--no-daemon` from `/lib/systemd/system/NetworkManager.service`? Not sure how this affects other services, and, if it works, I bet there is a "right"TM place to do that change. This is so much easier in OpenRC...
reducing activity avatar
cn flag
@PonJar "However you would have to think carefully about any unexpected consequences of doing so." oh definitely, I plan to start tweaking once I have the new larger SSD with new system setup there - and only then start tweaking boot process. Though I really want to play with it, it is absurd that modern computers still need multiple seconds to boot. I suspect that relatively simple configuration changes can reduce boot time by more than 95%.
reducing activity avatar
cn flag
@PonJar "I assume you are familiar with unit file structure" - not yet, but I can become familiar with it.
PonJar avatar
in flag
If you search on here you will find plenty of questions and answers about improving boot time. If a 95% improvement was possible lots of people would be doing it. I suspect that the best you could do is to sleep your system rather than shut it down (but that may not be practical) On my systems the initial firmware and systemd-boot menu 3 second timeout (like grub) is the longest part of the boot process. Allowing login without a password speeds things up too. I use LXQt on Arch which is a very fast combination
reducing activity avatar
cn flag
@PonJar "If a 95% improvement was possible lots of people would be doing it." Sadly, this is not really true. Also, it is possible that 95% improvements are possible with my specific configuration but this does not generalize Boot time is still horrible, performance of computers is bad despite hardware getting amazingly better in last 30 years.
Score:2
ls flag

There are two approaches:

1. Edit override config (/etc/systemd/system/network-online.target.d/override.conf)

Type command sudo systemctl edit network-online.target

paste the following config lines

[Unit]
After=graphical.target

That will create an override config at /etc/systemd/system/network-online.target.d/override.conf, which will partially override /etc/systemd/system/network-online.target.

2. Edit unit directly (/etc/systemd/system/network-online.target)

Type command sudo systemctl edit network-online.target --full

Find After= in [Unit] section and change the value to graphical.target

If you accidentally break the configuration, you can find the original one at /lib/systemd/system/network-online.target.


  • sudo systemctl edit --force --full <your-service.service> to create a new service

  • man systemd.unit to read the manual

  • multi-user.target and graphics services are before graphical.target (ref)

man systemd.special to read special systemd units manual

network-online.target
Units that strictly require a configured network connection should pull in network-online.target (via a Wants= type dependency) and order themselves after it. This target unit is intended to pull in a service that delays further execution until the network is sufficiently set up. What precisely this requires is left to the implementation of the network managing service.

multi-user.target
A special target unit for setting up a multi-user system (non-graphical). This is pulled in by graphical. Units that are needed for a multi-user system shall add Wants= dependencies for their unit to this unit during installation. This is best configured via WantedBy=multi-user.target in the unit's [Install] section.

graphical.target
A special target unit for setting up a graphical login screen. This pulls in multi-user.target. Units that are needed for graphical logins shall add Wants= dependencies for their unit to this unit (or multi-user.target) during installation. This is best configured via WantedBy=graphical.target in the unit's [Install] section.

reducing activity avatar
cn flag
Note that at least for me it wants to edit `/etc/systemd/system/network-online.target.d/override.conf` which is empty. ("Put the following config lines between the comments.")
reducing activity avatar
cn flag
Just in case: do you maybe know how to apply such change with Ansible?
cpprust avatar
ls flag
@reducingactivity Sorry for confusing you, I have the comments `### Editing /etc/systemd/system/network-online.target.d/override.conf ### Anything between here and the comment below will become the new contents of the file` and `### Lines below this comment will be discarded` when I using `sudo systemctl edit network-online.target`. I think these comments is for convenience to reference the original config. (I am not sure why I have these comments, it's helpful tho) I have remove these sentence about comments and add one more approach, to avoid the confusion.
cpprust avatar
ls flag
@reducingactivity If I edit the config (`/etc/systemd/system/network-online.target.d/override.conf`) via text editor (e.g. `vim`), there are no comments exist. I think those comments are hints provide by `systemctl` only visible when edit through command.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.