When you boot up your system, it passes through a sequence of events before presenting you with the login screen. Have you ever checked how long your system takes to boot? Generally, it all occurs within seconds or a few minutes but we do not know the exact time. Sometimes due to some reasons, you might be required to find the exact time your system takes to boot. Regardless of the reason why you want to know it, there is a systemd-analyze utility that can let you know the exact time your Linux system takes to boot.
Although you can use a clock or stopwatch to monitor this time when your system starts booting but that is not feasible for every situation especially for running servers which you can hardly reboot. For instance, if you have a server running critical services and you are required to find the time your system takes to boot. In this case, you need to reboot the server, which cannot be possible at every time.
In this article, you will learn to find how long your Linux system takes to boot and how to reduce this time if it is booting slowly.
- The procedure discussed in this article has been tested on Ubuntu 20.04 LTS. The same procedure can be performed in any Linux distribution with systemd enabled.
- To open the command line Terminal, use the Ctrl+Alt+T keyboard shortcut.
What is systemd-analyze?
Systemd-analyze is a tool that can be used to learn the system’s last boot up statistics. With the systemd-analyze tool, you can find the information about how much time the system took to boot and also how much time each unit took to start. Fortunately, you do not need to install this tool, as it is a built-in systemd tool. You can verify it using the following command in Terminal:
$ which systems-analyze
The output will display the full path of the executable command.
Finding the time system takes to boot
In order to find the time system takes to boot, simply type system-analyze without any command-line argument in the Terminal:
When you execute the above command, the systemd-analyze tool computes the time taken by the system until the boot is completed, broken down into kernel and userspace.
As you can see in the above screenshot, the total boot time of our system is 32.378 s. seconds and is broken down into:
- Kernel: 6.074s
- Userspace: 26.304s
Investigate/Troubleshoot slow bootup
If boot time is higher, you need to find which service is slowing down the boot process. You can find it using the systemd-analyze blame command. This command lists all the running services that started at the boot time along with the time they took. With this information, you can optimize the system’s boot time.
Issue the following command in Terminal in order to find which service to blame for the slow booting process:
$ sudo systemd-analyze blame
This command lists the services started at the boot time along with the time each service took to initialize. The list is sorted by the elapsed time in the descending order.
The blame list can be quite long, usually, the first 10 entries are enough to find the highly time taking services. Therefore, pipe the output of the above command to “head” command as follows:
$ sudo systemd-analyze blame | head
You can also print the output in the form of a tree of the time-critical chain of events. Issue the following command in Terminal to do so:
$ systemd-analyze critical-chain
In the output, you will see a chain of events sorted by the time (when the service became active) in the descending order. The value after the“@” character in each event is the time when the service became active. While the value after the “+” character in each unit shows the time the service took to start.
From the output you received from the above commands, you can easily find out which service takes longer to start and in return causing your system to boot slowly. Start from the top and disable the services that took longer to start as long as they are not required to start at boot. Moreover, disable all the services which although takes less time but are not required at boot as they also affect the system boot time.
In order to disable any service, use the following syntax:
$ sudo systemctl disable service-name
That is all there is to it! In this article, you have learned how to use the systemd built-in tool to find out the time your system takes to boot. If it is taking longer to boot, you can also find those services which are responsible for it and disable them to improve bootup time. However, note that some default services are required to start at boot, so it is not recommended to disable any service without knowing what it actually does, otherwise, you might get into trouble.