📅 June 19, 2017
What’s this? You installed Linux to a speedy M.2 NVMe SSD but boot times are not as fast as expected?
It might be a software issue. When Linux boots from power on, it runs a number of services before you ever see the login screen. Some of these services have timeouts and increase delays. Other services might be completely unnecessary, but they are loaded during boot anyway.
By disabling unneeded services, the Linux boot time can be reduced by a few seconds.
What Services Are Loaded?
Before we know what to disable, we need to see what services are loading. systemd-analyze is a built-in program that allows us to see what services were loaded during boot time and how long each took to load.
Running systemd-analyze by itself shows the total boot time.
There are two parts: kernel and userspace. The userspace is where we have the most control, and disabling services will reduce the time for this part. The kernel boot time tends to remain the same.
In this example, the total boot time after BIOS POST is 10.453 seconds. This means the login screen appears ~10 seconds following POST (Power-On Self Test). Since the POST is under the control of the motherboard’s BIOS, there is nothing we can do about this for now. Tweaking the BIOS is another subject. However, tweaking the BIOS and disabling unneeded services may be combined together in order to reduce the boot time further.
This example shows a system that has already had a few sof the most time-consuming services disabled. The original boot time was ~20 seconds: ~8s (kernel) + 12s (userspace). By disabling services, the userpace time was reduced to 1.804 seconds — a noticeable improvement.
Generating a Graphic
Besides text, we can use systemd-analyze plot to produce an image illustrating the userspace service boot times.
systemd-anaylze plot > boot.svg
How Do I Disable a Service?
Run the systemctl command as root with the name of the service. For example, if you do not need ModemManager.service, disable it like this:
sudo systemctl disable ModemManager.service
The service pppd-dns.service (used for dial-up modems) is probably unnecessary for most modern systems, so disable it in the same way:
sudo systemctl disable pppd-dns.service
The name of the service is the same as it appears in the output of systemd-analyze blame. Remember that the name is case sensitive. Use the full name that includes the .service part.
Which Services Should I Disable?
By default, systemd-analyze blame lists services from the top to bottom by order of the longest time, so focus on the topmost services since they are what slow down the boot time. In every Linux installation I had, the NetworkManager-wait-online.service was the biggest culprit to long boot times. It added 8 seconds to every boot for no reason whatsoever — and I did not need this service to run the system or use networking. Disabling this one service alone reduced the Linux boot time by 8 seconds. Wow!
sudo systemctl disable NetworkManager-wait-online.service
My system boots and networking functions perfectly without this service.
Other services I disabled included:
On a Linux Mint 18.1 installation, disabling these services reduced the userspace boot time to ~1.8 seconds. On another Linux Mint 18.1 system, the userspace boot time was reduced to 1.001s.
Services that consume less than 50ms can usually be ignored, but those requiring 100ms or more are worth investigating. Services will be disabled upon the next system boot.
Some services are required, and disabling them will cause parts of your system not to function properly. Many are “bonus” services that add little to the value of an installation. For example, VirtualBox (if installed) requires the vboxdrv.service, but the other services it installs
are unnecessary for my purposes, so I disabled them. VirtualBox runs as good as it always does in the absence of these extra three services.
Enabling a Service
Service descriptions can be esoteric, so search for exact descriptions online before disabling one. If you disable a service that your system needs, you can always enable it again.
sudo systemctl enable <service-name.service>
Other times, a needed service will be loaded even if you disable it. On the next boot, the service might load if it is required by another part of the system. This can vary, so educate yourself about what the various services do so you can best determine whether to keep it or not.
Sometimes, you will have nothing to rely upon besides trial and error.
Does Distribution Matter?
Yes. Different services might be loaded for different distributions, so run systemd-analyze blame to find out which ones take the most time to load. For example, Xubuntu 17.04 will load services not loaded during a Linux Mint boot. To reduce the boot time of Xubuntu, I disabled these services:
Xubuntu went from 17.821s to 11.936s boot time.
Before: 10.321s (kernel) + 7.499s (userspace) = 17.821s After: 10.316s (kernel) + 1.619s (userspace) = 11.936s
Six seconds might not sound like much, but it is a noticeable improvement. Every second counts.
Why So Many Services?
A typical Linux installation cannot read your mind or understand your usage intentions, so it loads a greatest common denominator of services hoping to please everyone and produce a working system.
In practice, some of these services can be disabled to reduce the boot time and conserve system resources, such as memory and CPU utilization.
Service information is more of an art than a science due to the lack of reference material. Research is your best friend, but expect to dig and discover like an archaeologist in order to decide whether or not to disable a service.
But when unneeded services are deemed unnecessary and safely disabled, your Linux system’s boot process will feel quicker and make you appreciate the new, speedy SSD you installed. Have fun exploring!