How to start Linux in 1 seconds _linux Shell

Source: Internet
Author: User
Tags dmesg

Starting the system as fast as possible is very important for automation equipment. The system is able to start at a time that the user cannot perceive, which means that the power supply can be completely disconnected when no work is needed, rather than suspend into hibernation. Based on the Atmel AT91 series on-chip systems and NAND flash, after a series of optimizations, Linux system startup time, from the initial 11 seconds, down to the final 656 milliseconds.

Background knowledge

The system has to go through a lot of processes from power up to full start-up. A simplified start-up process might include:

Hardware Reset
Boot loader (bootloader)
Operating system initialization
Application execution
Hardware is critical, but hardware is generally difficult to change. Subsequent optimizations, primarily for the bootstrapper, Linux kernel, and application deployment.

Bootstrapper optimizations

The bootstrapper mainly completes the basic CPU setup, handles ARM tags (atags,arm tags) or the device tree (device trees), and switches the storage snap-in (mmu,memory Management unit).

For U-boot, the most common optimization methods are:

Remove the function: such as Network load, if not required, then directly remove the code it;
To turn off unwanted features
Turn off kernel mirroring verification
Turn off bootstrapper output
Turn off startup delay

Modify the generic functionality of the bootstrapper to an optimized initial loader (Initial program LOADER,IPL), which can be implemented through SPL (Second program Loader, second stage loader) for U-boot.

Kernel optimization

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

First of all, remove all not drive, as much as possible to reduce kernel load content, can greatly shorten the system startup time. Second, there are a number of kernel choices that may require further experimentation, such as kernel compression, which is usually a good choice for embedded systems, Lzo compression. Finally, some startup parameters can be customized to speed up the start up. For example, you can use the "lpj=" parameter to preset the value of the number of Beats (loops per JIFFY,LPJ) required for Each loop to avoid the system automatically extrapolating at startup. This can save more than 100ms of time in a ARMv5 based system.

For kernel-initiated optimizations, you can use the bootgraph.pl script (located in kernel source script/bootgraph.pl) to draw a kernel-initiated time-consuming chart to analyze where the boot time is most time-consuming. This script is very simple to generate an SVG diagram by directly using the output of DMESG as its input:

Copy Code code as follows:

DMESG | Perl scripts/bootgraph.pl > Output.svg

The resulting chart is shown below,

Each color segment in the diagram represents the initialization time of a feature. You can simply turn off unwanted features or perform specific optimizations for functionality.

In addition to the kernel itself, the file system in which the kernel resides also has a significant 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 the system starts quickly.

Application optimization

After the kernel completes the system startup, it is followed by the execution of the application. For application optimization, there are two main parts, one for the application to take over the initiated Init process and the other for optimizing the way the application is linked.

Standard SYSTEMV init program that requires a bunch of startup scripts to execute. For embedded systems, most of them are meaningless. The other part, such as mounting the file system, can be implemented by the application itself. The init process can then be specified directly as an application through the "init=" parameter in the kernel startup parameters.

Dynamic link libraries that apply dependencies are found in the following order:

Ld_preload the path specified by the environment variable (general corresponding 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 environment variable Ld_library_path the path specified, but ignores the path if the executable has Setuid/setgid permissions, and specifies that--library-path will overwrite the path at compile time;

The path specified by the Dt_runpath entry in the ELF. Dynamic section;
The path in the Ldconfig cache (typically corresponding to the/etc/ld.so.cache file), which is skipped if the link option of-Z nodeflib is used at compile time;
/lib and then/usr/lib the path, and if you use the-Z nodeflib link option, this step is also skipped;

As a result, you can accelerate the link speed by placing the application-dependent dynamic-link libraries on the path of priority lookup. For a cross compilation environment, it is particularly necessary to note that the location of the dynamic link library on the host and the locations on the target system may be inconsistent, which increases the load time of the dynamic link library when the application executes.

Summarize

Based on the three optimization points mentioned above, you can reduce the startup time of the system from the initial 11s to 656ms (data reference the Altenberg of the embedded Linux Conference held in Dublin). From hardware to boot to the kernel and finally to the application, each boot step has its own place to optimize, and with some simple optimizations, it can reduce the startup time of the system.

Start and turn off network card commands under Ps:linux

Ifup, Ifdown:linux command
Real-time manual modification of some network interface parameters, you can use ifconfig to achieve, if you want to directly to the configuration file, that is, in the/etc/sysconfig/network-scripts inside the IFCFG-ETHX and other files set parameters to start, It has to be done through Ifdown or ifup.

Copy Code code as follows:

[Root@linux ~]# ifup {interface}
[Root@linux ~]# Ifdown {interface}
[Root@linux ~]# ifup eth0
 

Ifup and Ifdown are just too easy. These two programs are actually script, it will go directly to the/etc/sysconfig/network-scripts directory to search for the corresponding configuration file, such as Ifup eth0, it will find ifcfg-eth0 the contents of the file, and then set. For Ifcfg-eth0 settings, refer to the previous chapter for instructions on connecting to the Internet.

However, since these two programs are primarily the search settings file (IFCFG-ETHX) for startup and shutdown, make sure that the IFCFG-ETHX exists in the correct directory before using it, or it will fail to start. In addition, if you set or modify the network interface with Ifconfig eth0, you can no longer shut down in Ifdown eth0 mode. Because Ifdown will analyze compare current network parameter and ifcfg-eth0 whether match, do not match, will abandon this operation. Therefore, after the use of ifconfig modified, should be ifconfig eth0 down to be able to close the interface.

How to make Linux network card boot automatically

The command to activate the network card is: ifconfig eth0 up you know the command, you do a script, put on the startup project on it.

It is recommended to modify the NIC profile by editing the network card configuration file to save in the/etc/sysconfig/network-scripts directory, the first network card file is Ifcfg-eth0, the second is ifcfg-eth1, and so on, so if you have a piece, Then you enter the command Vi/etc/sysconfig/network-scripts/ifcfg-eth0, after opening, will Onboot=no, change to Onboot=yes, (if not, manually add Onboot=yes), save exit, Restart the service.

Copy Code code as follows:

echo "Onboot=yes" >>/etc/sysconfig/network-script/ifcfg-eth0

Add Onboot=yes to/etc/sysconfig/network-scripts to set up the network to boot automatically

The above content is introduced in 1 seconds to start the Linux method, to start the Linux related knowledge interested friends to study together.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.