Linux Boot-Time

Jarret B

Well-Known Member
Staff member
Joined
May 22, 2017
Messages
336
Reaction score
361
Credits
11,504
When starting a Linux system you may see there are delays when certain updates are performed or new applications installed. To help speed up the Linux boot time you will need to determine where the time is being delayed the most.

There are four basic places where the delay can occur. These different areas are:
  1. Firmware
  2. Loader
  3. Kernel
  4. Userspace
Let’s look at these first to see what occurs during these stages.

Firmware

The firmware is the 'software' which is loaded by the hardware. For example, when your video card is powered on it has built-in code which makes it accessible to the Linux Operating System (OS). In this manner, the OS can control the aspects of the video card. Another example is motherboard firmware which can allow the OS to control the processor fan.

Every PC, Laptop, Server, etc. has firmware. The firmware can be updated in most cases by system updates. Most system updates are not automatic and must be downloaded from the system manufacturer. For example, if you have an AMD Radeon video card then you can go to the AMD website and possibly find an update for your video card.

NOTE: Even printers and other external devices can have firmware. These devices should not have any effect on the boot time. Only the internal devices or those involved in the system startup should matter. If you use an external hard drive for the OS to boot from then the firmware on the disk drive will matter.

Loader

After the firmware is loaded then the Boot Loader takes over the booting process. The Boot Loader will load the Linux kernel and the Linux RAM Disk (initrd).

One popular Boot Loader is the GRand Unified Bootloader (GRUB). There is usually a delay in the bootloader. It allows a user to select an option from a menu before a default option is selected when the timeout occurs.

Kernel

The Linux Kernel is software that interacts with the hardware through the software. Any applications on a system send commands to the kernel. The kernel will use the commands to communicate with the hardware. It also allows hardware to interact with the software.

One example is when a key is pressed on the keyboard. The hardware sends the information to the kernel which transmits a signal to the software noting a key was pressed. The same is true for a mouse click. When an icon is selected on the desktop a signal is sent to the kernel which interacts with the software to determine what occurs. The information is then sent to the kernel. The kernel sends signals to the hard drive to read a program.
The program is read into memory and executed. So, if you double-click on a web browser icon the program is loaded into memory and started.

Many things are controlled in the background by the kernel such as services, system updates, hardware control, etc.

User Space

Any other software not included in the firmware, boot loader and kernel is the userspace. These programs include all of the applications, drivers and other files on the system which can be executed.

The User Space is sometimes referred to as the 'userland'. In most cases, this section of the boot process will be the largest part of the Boot Time.

Determine Boot-Time

The quickest way to determine the Boot Time of these four sections is by issuing the following command in a Terminal:

systemd-analyze

Output similar to Figure 1 should be shown.

Figure 01.jpg

FIGURE 1

The Firmware took 8.76 seconds, the Loader took 5.974 seconds, the Kernel took 6.148 seconds and the User Space took 1 minute 33.466 seconds. The majority of the load time was in the User Space.

If you have a Firmware load time that is abnormally long then you can change things in your BIOS. Disabling unneeded features can help the Firmware boot time.

Issues with the Loader may require a reset of the options in the Boot Loader program. Check for any options which not needed.

Kernel load times are not an issue unless you have compiled the kernel for extra features. You may need to see what you have added that is not needed. You could also try a stock kernel and see if it loads faster.

You may also notice that the Graphical User Interface (GUI) was started in 1 minute and 10.144 seconds into the User Space loading.

The Userspace is usually the biggest part of the Boot-Time. The individual times on the User Space can be determined from a Terminal with the command:

systemd-analyze blame

The output is a list of all the items loading in User Space sorted from the longest load time first and the shortest last. An example is shown in Figure 2.

Figure 02.jpg

FIGURE 2

Looking at Figure 02 you can disregard the first line. The first line is a system update being performed in the background before the login took place. You can look down the list and see everything that loaded on the system. If you perform this listing and see something that you do not need then you can unload the program or disable the service.

After anything is changed you can reboot the system and check the command again to see how the boot time has changed. The process is a great way to optimize the boot time as well as lowering your memory usage if apps are removed and services disabled.

Removing an Application

There is a way to find an application more easily than on the listing from the systemd-analyze command. Let’s say on my output in Figure 02 there was a line from a program called XY1 which took over a minute to load. If I no longer needed the app then I may want to remove the program. In a Terminal I could type ‘sudo apt purge XY1’, but nothing happened because the program was not found.

To find the app I can run the command ‘dpkg -l | grep -i XY1’. The listing of programs found should include the program name. I can use the name to purge it by replacing the name in the ‘sudo apt purge’ command. Once the command completes, then you can run ‘sudo apt autoremove’ to finish uninstalling anything left that is not needed.

Stopping a Service

Some of the items listed in the output are services. These are denoted by the ending ‘.service’.

Just because a service is listed here does not mean that it remains active after boot. For instance, let’s look at the ‘snap.service’. I can run the command ‘systemctl show snap.service | grep ActiveState’. When I execute the command I get a response of ‘inactive’. This means that the service is not active. If I ran the command for the ‘libvirtd.service’ then it does come back as ‘active’.

If a service is active then you can stop the service with the command ‘systemctl stop libvirtd.service’. The command will stop the service until you reboot the system and it is restarted.

If you want to disable the service even after a reboot then there is a different command. The command to disable a service is ‘systemctl disable name.service’.

NOTE: When performing a ‘systemctl’ command you may need to run as Root by using ‘sudo’ at the beginning of the command.

Optimized System Boot-Time

I found a very good optimized system and found the times as:

Startup finished in 3.863s (firmware) + 13.494s (loader) + 1.637s (kernel) + 4.222s (userspace) = 23.218s
graphical.target reached after 4.217s in userspace


The ‘systemd-analyze blame’ command returned the following:

2.386s sendmail.service
946ms mysql.service
724ms systemd-random-seed.service
518ms logrotate.service
499ms systemd-resolved.service
351ms systemd-logind.service
313ms dev-nvme0n1p3.device
306ms systemd-journald.service
275ms apache2.service
271ms upower.service
217ms udisks2.service
205ms systemd-timesyncd.service
205ms accounts-daemon.service
152ms gpm.service
151ms edac.service
144ms lm-sensors.service
139ms loadcpufreq.service
135ms apparmor.service
130ms systemd-modules-load.service
117ms avahi-daemon.service
115ms bluetooth.service
113ms keyboard-setup.service
109ms systemd-udev-trigger.service
108ms ufw.service
99ms tmp.mount
95ms NetworkManager.service
91ms grub-common.service
87ms binfmt-support.service
86ms alsa-restore.service
77ms [mailto:systemd-fsck@dev-disk-by\x2duuid-277d9b73\x2d1fd1\x2d42e3\x2d9275\x2d1a6febaae04f.service]systemd-fsck@dev-disk-by\x2duuid-277d9b73\x2d1fd1\x2d42e3\x2d9275\x2d1a6febaae04f.service
77ms hddtemp.service
76ms [mailto:systemd-fsck@dev-disk-by\x2duuid-a9d8fee1\x2debd3\x2d45f8\x2db30b\x2de0d409fc0c9a.service]systemd-fsck@dev-disk-by\x2duuid-a9d8fee1\x2debd3\x2d45f8\x2db30b\x2de0d409fc0c9a.service
74ms [mailto:systemd-fsck@dev-disk-by\x2duuid-3d237d5c\x2dc81f\x2d472e\x2dad35\x2dc12a1ae3adc5.service]systemd-fsck@dev-disk-by\x2duuid-3d237d5c\x2dc81f\x2d472e\x2dad35\x2dc12a1ae3adc5.service
73ms [mailto:systemd-fsck@dev-disk-by\x2duuid-E87C\x2d35EF.service]systemd-fsck@dev-disk-by\x2duuid-E87C\x2d35EF.service
72ms blueman-mechanism.service
71ms ksm.service
67ms thermald.service
67ms motion.service
66ms [email protected]
66ms systemd-udevd.service
64ms saslauthd.service
62ms wpa_supplicant.service
55ms colord.service
52ms grub-initrd-fallback.service
51ms systemd-sysctl.service
51ms dev-disk-by\x2duuid-fcdd39a3\x2d8a94\x2d441b\x2d8245\x2d3388772a6ab9.swap
46ms cpufrequtils.service
44ms polkit.service
43ms kerneloops.service
42ms netfilter-persistent.service
38ms systemd-tmpfiles-setup.service
34ms networking.service
32ms sshguard.service
29ms fwupd-refresh.service
23ms console-setup.service
23ms boot-efi.mount
23ms ssh.service
22ms systemd-rfkill.service
20ms rsyslog.service
18ms systemd-journal-flush.service
18ms systemd-user-sessions.service
18ms plymouth-read-write.service
16ms home.mount
16ms proc-sys-fs-binfmt_misc.mount
16ms boot.mount
15ms var.mount
15ms [email protected]
14ms systemd-remount-fs.service
13ms systemd-tmpfiles-setup-dev.service
13ms plymouth-quit-wait.service
13ms systemd-update-utmp.service
13ms sys-kernel-config.mount
12ms [email protected]
12ms plymouth-quit.service
11ms systemd-tmpfiles-clean.service
10ms systemd-sysusers.service
9ms xdm.service
9ms sys-fs-fuse-connections.mount
8ms dev-hugepages.mount
8ms dev-mqueue.mount
8ms blk-availability.service
7ms e2scrub_all.service
7ms kmod-static-nodes.service
6ms [mailto:systemd-backlight@backlight:nvidia_0.service]systemd-backlight@backlight:nvidia_0.service
5ms [email protected]
5ms setvtrgb.service
4ms systemd-update-utmp-runlevel.service
3ms nvidia-persistenced.service
3ms ifupdown-pre.service
2ms rtkit-daemon.service
1ms mnt-huge.mount


Conclusion

The two simple commands can help you determine Boot Times for your system. From these times you can find any problems which are causing your system to boot slowly.

I hope this helps you optimize your system to improve boot performance.
 


Thanks Jarret for your absolute detailed process for optimizing linux desktop or server boot time.What i have observed if any heavy server more than 256GB RAM POST is always validates memory which takes too long at firmware level.Is that possible to avoid memory validation ? Will that is expected to affect system performance or reliability once up and performing business operations as per its nature.

I guess it is better to leave it as it may have adverse impact on server.

Also many servers either in production or development always have in built array controllers for local hard disks which is mostly used during server build for configuring RAID for OS Disk redundancy.Is something can be changed in BIOS as may be risk disk detection failures.

From last many years most of the servers also have multiple fiber cards installed for storage requirement of servers .I guess here is also no opportunity if we do not want to make server unstable and business loss of storage to write business data.

Once system enters into kernel phase and start init process it goes through startups of many services which is needed for smooth operations of server.Startup script also can be reviewed very very carefully to avoid multiple reboots to restore it back if selected wrongly.

As mentioned user area is main target which also depends what authentication services are used .For example if you are using AD authentication Client Server model i guess client have to be function before it gets login prompt which does not have opportunity to disable as it may broke authentication system.

I like the way each step is explained and tools available to have clear idea and finding the area where improvement have to be made it to boot faster.

Thanks for detailed instructions to optimize your linux system to improve boot performance.Keep guiding us.
 
Last edited by a moderator:
Hello Jarret
Iam a new user to Linux
I recently install Linux Lite 6.0 on a Lenovo g 505 laptop with AMD E1-2100 APU dual core 1ghz and with 8 gb ram 1600
iam noob in pc things and tryin to learn
i have done all the drivers installation and all the updates
the problem i have is networking.service takes a lot of time
i run the commands and i get these

elekk  ~  systemd-analyze
Startup finished in 11.969s (kernel) + 40.219s (userspace) = 52.188s
graphical.target reached after 40.126s in userspace
elekk  ~  systemd-analyze blame
28.880s networking.service
5.751s systemd-udev-settle.service
5.308s dev-sda3.device
3.411s blueman-mechanism.service
3.225s NetworkManager-wait-online.service
2.317s networkd-dispatcher.service
2.296s systemd-resolved.service
1.868s systemd-random-seed.service
1.467s accounts-daemon.service
1.413s avahi-daemon.service
1.314s systemd-logind.service
1.249s alsa-restore.service
1.247s udisks2.service
1.242s NetworkManager.service
1.124s systemd-udev-trigger.service
1.112s apparmor.service
1.033s grub-common.service
980ms systemd-journald.service
944ms lm-sensors.service
942ms systemd-rfkill.service
904ms polkit.service
904ms ModemManager.service
880ms e2scrub_reap.service
elekk  ~  systemd-analyze critical-chain
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.

graphical.target @40.126s
└─multi-user.target @40.126s
└─smbd.service @39.650s +473ms
└─nmbd.service @39.203s +437ms
└─network-online.target @39.176s
└─network.target @39.174s
└─networking.service @10.290s +28.880s
└─apparmor.service @8.681s +1.112s
└─local-fs.target @8.677s
└─zfs-mount.service @8.636s +39ms
└─zfs-import.target @8.632s
is it normal to have these loading times?
can u help me pls?
also i get lagg when i use internet it takes a lot of time to load twitch and watch a video
 
Welcome to the forums
the AMD E1-2100 is not the fastest of processors [its basic entry level]
do you have the correct network drivers installed,?
Run from the terminal inxi -Nn and paste back the results [you may need to install inxi from the repository]

Addendum
this machine came with a SATA 2 disc spinner hard-drive, you can improve its performance by swapping it for a SSD, [SSD's are SATA3] so you won't get the maximum design speed, but you will be surprised how much faster the seek time and the read/write speed is making for faster boot and quicker application loading times
 
Last edited:
Thanks for the reply
i have installed an ssd already i forgot to mention it
the results are
elekk  ~  inxi -Nn
Network:
Device-1: Qualcomm Atheros QCA8172 Fast Ethernet driver: alx
IF: enp1s0 state: up speed: 100 Mbps duplex: full mac: 20:1a:06:f6:67:c4
Device-2: Broadcom and subsidiaries BCM43142 802.11b/g/n driver: wl
IF: wlp2s0 state: dormant mac: 48:5a:b6:df:4d:f7
the value of networking.service is changing after reboots and it tends to consume more time and no less
 
your Ethernet [device1] appears ok so if your having problems with a wired connection to the router, check the wire for damage [swap it if you have a spare
your wi-fi [device 2] is showing dormant, check you have the BCM 43*** legacy drivers installed
 
sorry got called away,
although i was going to say the legacy drivers will probably work intermittently, you would need to update them, so that goes out the window , so next sugestion
If you have secure boot [look in bios] turn it off and re-boot , is the wi-fi now working? if no secure boot or wi-fi still not working try

sudo apt-get install --reinstall bcmwl-kernel-source
 
i run the command and i get this

eading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
Need to get 0 B/1774 kB of archives.
After this operation, 0 B of additional disk space will be used.
(Reading database ... 370889 files and directories currently installed.)
Preparing to unpack .../bcmwl-kernel-source_6.30.223.271+bdcom-0ubuntu10~22.04.1_amd64.deb ...
Removing all DKMS Modules
Done.
Unpacking bcmwl-kernel-source (6.30.223.271+bdcom-0ubuntu10~22.04.1) over (6.30.223.271+bdcom-0ubuntu10~22.04.1) ...
Setting up bcmwl-kernel-source (6.30.223.271+bdcom-0ubuntu10~22.04.1) ...
Loading new bcmwl-6.30.223.271+bdcom DKMS files...
Building for 5.15.0-67-generic
Building for architecture x86_64
Building initial module for 5.15.0-67-generic
EFI variables are not supported on this system
/sys/firmware/efi/efivars not found, aborting.
Done.

wl.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/5.15.0-67-generic/updates/dkms/

depmod.....
update-initramfs: deferring update (trigger activated)
Processing triggers for initramfs-tools (0.140ubuntu13.1) ...
update-initramfs: Generating /boot/initrd.img-5.15.0-67-generic
W: Possible missing firmware /lib/firmware/amdgpu/yellow_carp_gpu_info.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/vangogh_gpu_info.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/cyan_skillfish_rlc.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/cyan_skillfish_mec2.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/cyan_skillfish_mec.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/cyan_skillfish_me.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/cyan_skillfish_pfp.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/cyan_skillfish_ce.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/cyan_skillfish_sdma1.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/cyan_skillfish_sdma.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/sienna_cichlid_mes.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/navi10_mes.bin for module amdgpu
 
well i have gone as far as I can, another member may pick up on it later,
if your having problems with the Ethernet, do check the cables and connections to the router and the router settings,
 
i appreciate your time buddy thanks now i have to find out how i install the gpu drivers so far i read and watch so many videos and still cant do it
 
run inxi -G
If it has AMD on board graphics then they are fully supported by the Kernel drivers which are provided by AMD, no further divers should be needed
 
  • beer
Reactions: Zev


Top