Have you ever wondered how long it took your Linux system to boot up? You may be looking to try to speed up the time it takes for your Linux system to be ready to use, or you may just be curious. Rather than getting out a stopwatch, let’s take a look at some Linux commands we can use to see how long it took to boot up Linux.
Check Boot Times On Linux using Systemd Analyze
Systemd is now in use on most Linux distributions. Systemd’s primary component is a “system and service manager”—an init system used to bootstrap user space and manage user processes. As such it plays a key role in a Linux systems boot up process.
The systemd suite has a bunch of tools that can be used to interact with your Linux system, and one in particular which will help us check the Linux boot time. The systemd-analyze command gives you information on how many services ran at the last start up and how long they took to start.
$ systemd-analyze
As you can see in the output below, I ran this to check the boot up time of my Ubuntu system:
$ systemd-analyze
Startup finished in 7.667s (kernel) + 32.773s (userspace) = 40.440s
multi-user.target reached after 32.693s in userspace
When systemd-analyze is ran without parameters, it will calculate the elapsed time until system startup is completed, broken down into kernel and userspace processes. In my example using my Ubuntu system you can see the total boot time was just over 40 seconds, with the kernel start up being just under 8 seconds and the user space taking almost 33 seconds.
Now, this is useful and a great summary, but what if we wanted more detail. This is where the systemd-analyze blame command comes in. systemd-analyze blame
gives me a list of all the processes started at boot time, and the list is sorted by the elapsed time before the process has fully launched. Let’s take a look:
$ systemd-analyze blame
31.127s apt-daily-upgrade.service
10.966s gdm.service
10.302s snapd.service
6.743s cloud-init-local.service
5.811s vncserver@:1.service
4.323s man-db.service
3.370s lvm2-monitor.service
3.109s cloud-init.service
3.037s dev-nvme0n1p1.device
2.859s systemd-udev-settle.service
2.157s systemd-networkd-wait-online.service
The output clearly shows the services that were started during the start-up process and how long each took to successfully start up. If you are looking to reduce the start up time for your Linux system it’s useful to consult this list and determine if there are any un-needed services you can disable to help speed up the Linux boot process.
You can also use the systemd-analyze critical-chain command to visualise service dependencies to help you understand why a particular service took a certain amount of time to start. For example:
$ systemd-analyze critical-chain snapd.service
The time when unit became active or started is printed after the "@" character.
The time the unit took to start is printed after the "+" character.
snapd.service +10.302s
└─basic.target @21.275s
└─sockets.target @21.273s
└─snapd.socket @21.263s +6ms
└─sysinit.target @21.185s
└─cloud-init.service @18.069s +3.109s
└─systemd-networkd-wait-online.service @15.894s +2.157s
└─systemd-networkd.service @15.443s +446ms
└─network-pre.target @15.439s
└─cloud-init-local.service @8.693s +6.743s
└─systemd-remount-fs.service @3.794s +102ms
└─systemd-journald.socket @3.553s
└─system.slice @3.338s
└─-.slice @3.338s
This can be very useful for troubleshooting slow starting services!
How to Check Linux Last Boot Time
As well as knowing how long it took to start your Linux system, it’s also useful to know when it last started up. We can check the Linux last boot time using a number of tools. First of all, we can simply type uptime
to see how long our linux system has been powered on:
$ uptime
\ 13:40:51 up 19 min, 1 user, load average: 0.00, 0.02, 0.06
To get a list of the last few start up times we can use the last reboot command:
$ last reboot
reboot system boot 5.11.0-1022-aws Sun Dec 19 13:21 still running
reboot system boot 5.11.0-1022-aws Thu Dec 16 19:34 - 23:35 (04:01)
Finally (though there are likely many more ways to do this out there!), we can use the who
command, with the -b
option:
$ who -b
system boot 2021-12-19 13:21
Great! Now you know how to find out when your Linux system was last started!
Summary
In this tutorial you have learned how to find out the linux boot time using the systemd-analyze command. We had a look at how to list the start up times of individual services involved in the start-up process.
Finally we went through how to check the Linux last boot time using a number of different commands.