`systemd-analyze` (in particular, `systemd-analyze critical-chain` and `systemd-analyze plot > plot.svg`) are useful to diagnose. On my system you can see that my graphical session waits for systemd-user-session.service, which waits for network.target, which waits for NetworkManager taking its sweet time, which isn't started before network-pre which waits until nftables is done loading rules, etc.
Optimizing the service order and their dependencies does wonders for boot time.
Why isn't this automatic? I'm pretty sure most of us have neither expertise not enthusiasm for that job.
Service optimization is basically deciding what your system doesn't need in order to function for your usage, and moving things you don't need to a late initialization with no dependents. A distribution dedicated for a particular machine usage and desktop environment could do some tuning on your behalf, but it is not generic.
I'm more curious why my car, which is fairly recent, doesn't start in 0.3s.
The powertrain and body control modules, assuredly running a RTOS, certainly do. The PCM for example controls when the spark plugs fire. If it did not boot instantly, the engine wouldn't run. If the BCM didn't boot, the doors wouldn't unlock nor would the key or PTS start the engine.
The user-facing infotainment crap is not necessary for the "car" part to function. You could physically remove it and the car would still be drivable.
This could be a very, very long list of hypothetical changes :)
Presumably the dock can be detached while booted, so the kernel should also be able to handle booting and only detect at some point that the dock has disappeared
Presumably, most faster boot OSes simply don't support as many devices. Amazon was able to get Firecracker to boot Linux damn near instantly by pretty much removing all hardware support from the kernel since they know for sure it's only ever running as a VM on a hypervisor they strictly control and won't change.
If you know for sure the devices you need, you can compile the kernel yourself and remove all the stuff you don't need and possibly even get rid of udev and just hardcode what it normally detects.
https://wiki.archlinux.org/title/Improving_performance/Boot_...
I haven’t really had any issues with Linux boot times for personal machines lately. I think the people that care most about getting into the sub-second range are the ones doing cloud VM stuff, spinning up lots of micro services or whatever.
Even without the stupid 20 seconds of firmware I can't do anything about, XP shows me an interactive desktop in half the time Linux does. Windows 7 is just as fast, and just as fully-featured as my desktop Linux install. Windows 11 still boots faster (and more reliably) than Linux despite the overhead of Windows Defender and drive signature checking.
I don't need 0.3 seconds of boot time on my desktop, but something a bit faster would be nice. I think my machine is so slow by the death of a thousand services all starting at boot.
systemd-analyze
And then systemd-analyze critical-chain
To see what is slowing it down?My system takes 10 seconds to boot apparently, with fairly minimal tuning (I boot from a USB drive so I try not to worry too much about this, hah!). But I don’t use a desktop environment or any of that sort of stuff, so it is probably not a good comparison.
Still, 45 seconds is pretty slow, I wonder if it is waiting for something that idles out; network interfaces or something like that.
I can disable a few things here and there, but whatever hardware detection takes place in the kernel (I assume Nvidia related things, it's always Nvidia it seems) isn't really somethint I can change. I can try disabling more POST parts, maybe, and disable Docker on boot to take off another second, but to shave everything down I'll probably need to reinstall.
Out of curiosity did you do some tuning or was the boot just faster than you guessed (if it is the latter, let’s all celebrate the fact that our computers have gotten fast enough to confuse us, haha! When XP actually came out I was a teenager with junky hand-me-down hardware, 45 second boots would have been a dream…).
Startup finished in 17.642s (firmware) + 9.467s (loader) + 20.168s (kernel) + 12.175s (userspace) = 59.453s graphical.target reached after 12.102s in userspace.
Subtract the slow motherboard firmware (17.642s) and me typing in my password (about 5s, nowhere close to the 9s+20s that the loader+kernel is taking to boot before systemd kicks in) and I get about 45 seconds of "this is what Linux and tools is actually doing before I can log in".
All Windows version from XP up to 7 were horrifically slow until modern SSDs came along. For years, you could take any Vista (or even XP) era computer, double or quadruple the RAM and insert an SSD, and it would feel like a completely new machine. You can still pick up a second hand high-end Windows 7 computer for cheap and use it for what you would otherwise spend $500-700 dollars on after ripping out the hard drive and installing an SSD.
Having used Windows 7 from a HDD for years, I can tell you for sure that Windows 7 sure didn't boot this fast when I first got it :)
(~0.2s is wasted on a dependency that shouldn’t be there, but I’m not prepared to resolve that)
Linux definitely can be fast, but in my experience it starts slowing down as you install more services and tools, and I'd need to reinstall and reconfigure from a clean slate to get back to normal speeds. I can make it quick again ny disabling a ron of services and features, but that just slows me down later in the process.
There's a weird tendency to put things into multi-user.target to have them run at boot, even if they are not actually required for user login. There's no actual need to start openssh before gdm, but that's how distros set things up.
On my machine (which I didn't alter from Ubuntu defaults) GDM runs after:
system.slice switcheroo-control.service dbus.socket plymouth-quit.service console-setup.service cloud-config.service gpu-manager.service rc-local.service systemd-journald.socket systemd-user-sessions.service basic.target plymouth-start.service getty@tty1.service fwupd.service sysinit.target
according to systemctl show gdm.service --property=Aftercloud-config is the weirdest one, but it has to do with locales and system configurations for automatically deployed systems (and after first install), I believe. getty@tty1.service is also strange, but doesn't even show up in systemd-analyze blame.
In my boot-analyze charts I don't really see that many problems with illogical start orders to be honest. systemd-networkd-wait-online seems to hold up a bunch of networking services but that depends on the rest of my network responding in time so I can't even blame it for that.
It's a cool trick that reminds me of Firecracker. It would be nice to see Linux use that trick as well, but with the existing issues for Linux ×+ hibernation + lockdown mode, I think it'll take a while before that's finished.