4

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
    └─postfix@-.service @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
  • 2
    Network manager is introducing 384ms delay to the boot process. That is less than half a second. postfix@-.service has a larger delay. Are you under the impression the delay for network manager is 3.495 seconds? – PonJar Jan 24 '23 at 12:59
  • 1
    @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.

    – reducing activity Jan 25 '23 at 17:44
  • 2
    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 – PonJar Jan 25 '23 at 21:35
  • 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 – darth_epoxy Jan 28 '23 at 05:03
  • @darth_epoxy Because I want to change order of services on startup rather than to temporarily disable it. – reducing activity Jan 30 '23 at 11:52
  • 1
    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... – Quasímodo Feb 01 '23 at 18:20
  • @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 Feb 02 '23 at 08:08
  • @PonJar "I assume you are familiar with unit file structure" - not yet, but I can become familiar with it. – reducing activity Feb 02 '23 at 08:12
  • 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 – PonJar Feb 02 '23 at 10:01
  • @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.

    – reducing activity Feb 13 '23 at 18:39

1 Answers1

2

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.

cpprust
  • 111
  • 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 Jan 30 '23 at 11:54
  • Just in case: do you maybe know how to apply such change with Ansible? – reducing activity Jan 30 '23 at 11:55
  • 1
    @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 fileand### Lines below this comment will be discardedwhen I usingsudo 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 Jan 30 '23 at 18:21
  • @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. – cpprust Jan 30 '23 at 18:31