Home >System Tutorial >LINUX >Make your Linux system start up quickly: Tips and methods to optimize startup time
In the modern computer world, startup time is one of the crucial factors. Sometimes, we need to quickly start the server or computer for higher efficiency and better user experience. In Linux systems, optimizing startup time is very important. This article will introduce how to use various tools to analyze and improve the boot time of your Linux system.
Quick start or quick restart plays a vital role in various situations. In order to maintain high availability and better performance of all services, fast startup of embedded devices is crucial. Consider a telecommunications device running a Linux operating system that does not have fast boot enabled. All systems, services, and users that rely on this particular embedded device may be affected. It is very important for these devices to maintain high availability of their services, and for this, fast startup and restart play a crucial role.
A glitch or shutdown of a piece of telecommunications equipment, even for just a few seconds, can cause havoc for countless users on the Internet. Therefore, for many time-critical devices and telecommunications equipment, it is very important to incorporate quick boot functions into their devices to help them get back to work quickly. Let us understand the Linux boot process from Figure 1.
Figure 1: Startup process
Monitoring tools and startup process
There are a number of factors that users should be aware of before making changes to their machine. This includes the computer's current startup speed, as well as services, processes, or applications that are hogging resources and adding to startup time.
Startup diagram
To monitor the startup speed and various services started during startup, users can use the following command to install:
sudo apt-get install pybootchartgui
Every time you start, the startup graph will save a png file in the log, allowing users to view the png file to understand the system startup process and services. To do this, use the following command:
cd /var/log/bootchart
Users may need an application to view png files. Feh is an X11 image viewer for console users. Unlike most other image viewers, it does not have a sophisticated graphical user interface, but it is only used to display images. Feh can be used to view png files. You can install it using the following command:
sudo apt-get install feh
You can use feh xxxx.png to view png files.
Figure 2: Startup diagram
Figure 2 shows a bootstrap image png file being viewed.
systemd-analyze
However, the boot image is no longer required for Ubuntu 15.10 and later versions. To get brief information about startup speed, use the following command:
systemd-analyze
Figure 3: Systemd-analyze output
Chart 3 shows the output of the command systemd-analyze.
The command systemd-analyze blame is used to print a list of all running units based on the time taken to initialize. This information is very useful and can be used to optimize startup time. systemd-analyze blame will not show services with type=simple because systemd considers these services to be started immediately; therefore, the delay in initialization cannot be measured.
Figure 4: Output of systemd-analyze blame
Figure 4 shows the output of systemd-analyze blame.
The following command prints a tree chain of time-critical service units:
command systemd-analyze critical-chain
Figure 5 shows the output of the command systemd-analyze critical-chain.
Figure 5: Output of systemd-analyze critical-chain
Steps to Reduce Startup Time
Shown below are some of the various steps that can be taken to reduce startup time.
BUM (Boot Manager)
BUM is a run-level configuration editor that allows initialization services to be configured at system startup or restart. It shows a list of every service that can be started at boot time. Users can turn individual services on and off. BUM has a very clear graphical user interface and is very easy to use.
In Ubuntu 14.04, BUM can be installed using the following command:
sudo apt-get install bum
To install it in 15.10 and later versions, download the package from the link http://apt.ubuntu.com/p/bum.
以基本的服务开始,禁用扫描仪和打印机相关的服务。如果你没有使用蓝牙和其它不想要的设备和服务,你也可以禁用它们中一些。我强烈建议你在禁用相关的服务前学习服务的基础知识,因为这可能会影响计算机或操作系统。图 6 显示 BUM 的图形用户界面。
图 6:BUM
编辑 rc 文件
要编辑 rc 文件,你需要转到 rc 目录。这可以使用下面的命令来做到:
cd /etc/init.d
然而,访问 init.d 需要 root 用户权限,该目录基本上包含的是开始/停止脚本,这些脚本用于在系统运行时或启动期间控制(开始、停止、重新加载、启动启动)守护进程。
在 init.d 目录中的 rc 文件被称为运行控制run control脚本。在启动期间,init 执行 rc 脚本并发挥它的作用。为改善启动速度,我们可以更改 rc 文件。使用任意的文件编辑器打开 rc 文件(当你在 init.d 目录中时)。
例如,通过输入 vim rc ,你可以更改 CONCURRENCY=none 为 CONCURRENCY=shell。后者允许某些启动脚本同时执行,而不是依序执行。
在最新版本的内核中,该值应该被更改为 CONCURRENCY=makefile。
图 7 和图 8 显示编辑 rc 文件前后的启动时间比较。可以注意到启动速度有所提高。在编辑 rc 文件前的启动时间是 50.98 秒,然而在对 rc 文件进行更改后的启动时间是 23.85 秒。
但是,上面提及的更改方法在 Ubuntu 15.10 以后的操作系统上不工作,因为使用最新内核的操作系统使用 systemd 文件,而不再是 init.d 文件。
图 7:对 rc 文件进行更改之前的启动速度
图 8:对 rc 文件进行更改之后的启动速度
E4rat
E4rat 代表 e4 减少访问时间reduced access time(仅在 ext4 文件系统的情况下)。它是由 Andreas Rid 和 Gundolf Kiefer 开发的一个项目。E4rat 是一个通过碎片整理来帮助快速启动的应用程序。它还会加速应用程序的启动。E4rat 使用物理文件的重新分配来消除寻道时间和旋转延迟,因而达到较高的磁盘传输速度。
E4rat 可以 .deb 软件包形式获得,你可以从它的官方网站 http://e4rat.sourceforge.net/下载。
Ubuntu 默认安装的 ureadahead 软件包与 e4rat 冲突。因此必须使用下面的命令安装这几个软件包:
sudo dpkg purge ureadahead ubuntu-minimal
现在使用下面的命令来安装 e4rat 的依赖关系:
sudo apt-get install libblkid1 e2fslibs
打开下载的 .deb 文件,并安装它。现在需要恰当地收集启动数据来使 e4rat 工作。
遵循下面所给的步骤来使 e4rat 正确地运行并提高启动速度。
Figure 9 and Figure 10 show the difference between boot times before and after installing e4rat. An improvement in startup speed can be noticed. The boot time before using e4rat was 22.32 seconds, however after using e4rat the boot time was 9.065 seconds.
Figure 9: Startup speed before using e4rat
Figure 10: Startup speed after using e4rat
Some Easy Adjustments
Good startup speed can also be achieved with very small adjustments, two of which are listed below.
SSD
Using a solid state device instead of a regular hard drive or other storage device will definitely improve boot speed. SSDs also help speed up file transfers and running applications.
Disable GUI
Graphical user interfaces, desktop graphics, and window animations take up a lot of resources. Disabling the GUI is another great way to get good startup speeds.
In short, through this article, we learned how to use various tools to diagnose and optimize the startup time of Linux systems. Whether it is reducing the number of services, removing unnecessary modules, or optimizing file systems or applications, these methods can effectively reduce the startup time of the Linux system and provide us with a smoother and more efficient experience.
The above is the detailed content of Make your Linux system start up quickly: Tips and methods to optimize startup time. For more information, please follow other related articles on the PHP Chinese website!