Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to start Linux in 1 second

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to start Linux in 1 second". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

It is very important for automation equipment to start the system as quickly as possible. The system can be started in a time that the user cannot perceive, which means that when there is no need to work, the power can be completely cut off instead of hanging into a dormant state. Based on Atmel AT91 series system on chip and NAND flash memory, after a series of optimization, the startup time of Linux system is reduced from the initial 11 seconds to the final 656 milliseconds.

Background knowledge

The system needs to go through many processes from power on to full startup. A simplified startup process probably consists of:

Hardware reset

Start the bootstrap program (bootloader)

Operating system initialization

Application execution

The hardware is very critical, but the hardware is generally difficult to change. The subsequent optimization is mainly aimed at the bootstrap, Linux kernel and applications.

Bootstrap optimization

The bootstrap program mainly completes the basic setting of CPU, dealing with ARM tags (ATAGS,ARM TAGS) or device tree (device trees), switching storage management unit (MMU,Memory Management Unit) and so on.

For U-Boot, the common optimization methods are:

Delete unwanted functions: such as network loading, if you don't need it, remove the code directly.

Turn off unwanted features

Turn off kernel image verification

Turn off bootstrapper output

Shutdown start delay

The bootstrap of the general function is modified into an optimized initial program loader (Initial Program Loader,IPL). For U-Boot, it can be realized through SPL (Second Program Loader, second phase program loader).

Kernel optimization

The Linux kernel is designed to be very flexible and can be configured to optimize the required functions. Therefore, optimizing the kernel is essential for system startup speed.

First of all, remove all unwanted drivers and reduce the content loaded by the kernel as much as possible, which can greatly shorten the system startup time. Secondly, there are many kernel options that may need to be further tried, such as kernel compression. For embedded systems, LZO compression is usually a good choice. Finally, you can speed up startup by customizing some startup parameters. For example, the "lpj=" parameter can be used to preset the value of the number of beats (loops per jiffy,lpj) required for each cycle to prevent the system from automatically calculating at startup. In this way, more than 100ms time can be saved in ARMv5-based systems.

For kernel startup optimization, the kernel startup time chart can be drawn through the bootgraph.pl script (script/bootgraph.pl located in the kernel source code) to analyze the most time-consuming areas of startup. This script is very simple to use, and directly takes the output of dmesg as its input to generate the svg chart:

Dmesg perl scripts/bootgraph.pl > output.svg

The resulting chart is as follows:

Each color segment in the figure represents the initialization time of a function. You can simply turn off unwanted features, or make specific optimizations for functions.

In addition to the kernel itself, the file system in which the kernel resides also has a great impact on system startup. UbiFS is a good choice for systems that use flash memory chips as storage. It can tolerate accidental power outages and has excellent mounting speed to ensure that the system starts quickly.

Application optimization

After the kernel finishes booting the system, the next step is to execute the application. For the optimization of the application, there are two main parts, one is that the application takes over the INIT process that starts, and the other is to optimize the way the application is linked.

A standard SystemV INIT program that needs to execute a bunch of startup scripts. For embedded systems, most of them are meaningless. The other part, such as mounting the file system, can be implemented by the application itself. You can then specify the INIT process as the application directly through the "init=" parameter in the kernel startup parameters.

The application of dependent dynamic link libraries is looked up in the following order:

The path specified by the LD_PRELOAD environment variable (usually corresponding to file / etc/ld.so.preload)

The path specified by the DT_RPATH entry in the ELF .dynamic section, if the DT_RUNPATH entry does not exist

The path specified by the environment variable LD_LIBRARY_PATH, but is ignored if the executable has setuid/setgid permission; specifying-library-path at compile time will overwrite the path

The path specified by the DT_RUNPATH entry in the ELF .dynamic section

The path in the ldconfig cache (usually corresponds to / etc/ld.so.cache file). If the link option of-z nodeflib is used when compiling, this step is skipped.

/ lib, then / usr/lib path, if the-z nodeflib link option is used, this step is also skipped

Therefore, you can speed up the link speed by putting the dynamic link libraries that the application depends on into the priority search path as much as possible. It is particularly important to note that the location of the dynamic link library on the host may be inconsistent with that on the target system, which increases the loading time of the dynamic link library when the application is executed.

This is the end of "how to start Linux in 1 second". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report