Home System Tutorial LINUX Make your Linux system start up quickly: Tips and methods to optimize startup time

Make your Linux system start up quickly: Tips and methods to optimize startup time

Feb 10, 2024 pm 08:12 PM
linux linux tutorial linux system linux command shell script embeddedlinux Getting started with linux linux learning

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.

Make your Linux system start up quickly: Tips and methods to optimize startup time

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
Copy after login

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
Copy after login

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
Copy after login

You can use feh xxxx.png to view png files.

Make your Linux system start up quickly: Tips and methods to optimize startup time

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
Copy after login
Make your Linux system start up quickly: Tips and methods to optimize startup time

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.

Make your Linux system start up quickly: Tips and methods to optimize startup time

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
Copy after login

Figure 5 shows the output of the command systemd-analyze critical-chain.
Make your Linux system start up quickly: Tips and methods to optimize startup time

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
Copy after login

To install it in 15.10 and later versions, download the package from the link http://apt.ubuntu.com/p/bum.

以基本的服务开始,禁用扫描仪和打印机相关的服务。如果你没有使用蓝牙和其它不想要的设备和服务,你也可以禁用它们中一些。我强烈建议你在禁用相关的服务前学习服务的基础知识,因为这可能会影响计算机或操作系统。图 6 显示 BUM 的图形用户界面。

Make your Linux system start up quickly: Tips and methods to optimize startup time

图 6:BUM

编辑 rc 文件

要编辑 rc 文件,你需要转到 rc 目录。这可以使用下面的命令来做到:

cd /etc/init.d
Copy after login

然而,访问 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 文件。

Make your Linux system start up quickly: Tips and methods to optimize startup time

图 7:对 rc 文件进行更改之前的启动速度

Make your Linux system start up quickly: Tips and methods to optimize startup time

图 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
Copy after login

现在使用下面的命令来安装 e4rat 的依赖关系:

sudo apt-get install libblkid1 e2fslibs
Copy after login

打开下载的 .deb 文件,并安装它。现在需要恰当地收集启动数据来使 e4rat 工作。

遵循下面所给的步骤来使 e4rat 正确地运行并提高启动速度。

  • Access the Grub menu during startup. This can be done by holding down the shift key while the system is booting.
  • Select the usual boot option (kernel version) and press e.
  • Find the line starting with linux /boot/vmlinuz and add the following code at the end of the line (press the spacebar after the last letter of the sentence): init=/sbin/e4rat-collect or try – quiet splash vt.handsoff =7 init=/sbin/e4rat-collect.
  • Now, press Ctrl x to continue booting. This allows e4rat to collect data after launch. Work on this machine and spend the next two minutes opening and closing applications.
  • Access the log file by going to the e4rat folder and using the following command: cd /var/log/e4rat.
  • If you don't find any log files, repeat the above process. Once the log file is ready, access the Grub menu again and press e for your option.
  • Enter single at the end of the same line that you have edited previously. This gives you access to the command line. If other menus appear, select Resume normal boot. If you somehow can't get to the command prompt, press Ctrl Alt F1.
  • After you see the login prompt, enter your login information.
  • Now enter the following command: sudo e4rat-realloc /var/lib/e4rat/startup.log. This process takes a while, depending on your machine's disk speed.
  • Now use the following command to restart your machine: sudo shutdown -r now.
  • Now, we need to configure Grub to run e4rat on every boot.
  • Access grub files using any editor. For example, gksu gedit /etc/default/grub.
  • Find the line starting with GRUB CMDLINE LINUX DEFAULT= and add the following line between the quotes and before any options: init=/sbin/e4rat-preload 18.
  • It should look like this: GRUB CMDLINE LINUX DEFAULT = init=/sbin/e4rat- preload quiet splash.
  • Save and close the Grub menu and update Grub using sudo update-grub.
  • Restart the system and you will notice a significant change in startup speed.

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.

Make your Linux system start up quickly: Tips and methods to optimize startup time

Figure 9: Startup speed before using e4rat

Make your Linux system start up quickly: Tips and methods to optimize startup time

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

vscode terminal usage tutorial vscode terminal usage tutorial Apr 15, 2025 pm 10:09 PM

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Where to write code in vscode Where to write code in vscode Apr 15, 2025 pm 09:54 PM

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

See all articles