The systemd-analyze Command
Improving the boot performance of a system can provide reduced boot wait times and a means to learn more about how certain system files and scripts interact with one another. Linux provides a tool called systemd-analyze that can be used to show timing details about the boot process, including an svg plot showing units waiting for their dependencies. You can see which unit files are causing your boot process to slow down.
To see how much time was spent in kernelspace and userspace on boot, simply use:
Tip: If you boot via UEFI and use a boot loader which implements systemd's Boot Loader Interface (which currently systemd-boot and GRUB do), systemd-analyze can additionally show you how much time was spent in the EFI firmware and the boot loader itself.
To list the started unit files, sorted by the time each of them took to start up:
$ systemd-analyze blame
The output looks like the example below:
pbmac@pbmac-server $ systemd-analyze blame 13.085s udisks2.service 11.744s systemd-fsck@dev-disk-by\x2duuid-ad74f5a8\x2d188a\x2d4282\x2d93 10.343s uml-utilities.service 10.275s NetworkManager-wait-online.service 9.368s NetworkManager.service 7.723s systemd-fsck@dev-disk-by\x2duuid-3709f1b7\x2d6417\x2d413e\x2da4 7.439s accounts-daemon.service 6.079s ModemManager.service 5.377s colord.service 5.168s dev-sda2.device 5.044s dev-sda1.device 4.864s apt-daily.service 4.745s snapd.service 4.393s systemd-journal-flush.service
The first column is simply the time it took to execute a service, and the second column is the service that was being started.
The lsof Command
Linux considers everything as files and maintains folders. So “Files or a File ” is very important in Linux. While working in Linux system there might be several files and folders which are being used; some of them would be visible and some not. The lsof command stands for List of Open Files. This command provides a list of files that are currently open. Basically, it gives the information to find out the files which are open by which process. With one go, it lists out all open files to the output console. It cannot only list common regular files but it can list a directory, a block special file, a shared library, a character special file, a regular pipe, a named pipe, an internet socket, a UNIX domain socket, and many others. It can be combined with grep command and can be used to do advanced searching and listing.
$lsof [ OPTIONS ][user name]
The lsof command prints each file that has been opened by a process.The output information is:
- The name of the command or process
- The PID
- The user who issued the command
- The file descriptor - FD
- The type of the file
- The device where the file exists
- The size of the file
- The name of the file
pbmac@pbmac-server $ lsof COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME systemd 1 root cwd DIR 8,1 4096 2 / systemd 1 root rtd DIR 8,1 4096 2 / systemd 1 root txt REG 8,1 1612152 131627 /lib/systemd/systemd systemd 1 root mem REG 8,1 1700792 131961 /lib/x86_64-linux-gnu/libm-2.27.so systemd 1 root mem REG 8,1 121016 131006 /lib/x86_64-linux-gnu/libudev.so.1.6.9 systemd 1 root mem REG 8,1 43304 130850 /lib/x86_64-linux-gnu/libjson-c.so.3.0.1 systemd 1 root mem REG 8,2 34872 401674 /usr/lib/x86_64-linux-gnu/libargon2.so.0 systemd 1 root mem REG 8,1 18680 131675 /lib/x86_64-linux-gnu/libattr.so.1.1.0
"Improving performance/Boot process" by Multiple contributors is in the Public Domain, CC0"
lsof command in Linux with Examples" by Bhumika_Rani, Geeks for Geeks is licensed under CC BY-SA 4.0