Analysis of Linux init system initialization, Part 1: sysvinit, initsysvinit

Source: Internet
Author: User

Analysis of Linux init system initialization, Part 1: sysvinit, initsysvinit

This article Reprinted from: http://www.ibm.com/developerworks/cn/linux/1407_liuming_init1/index.html

(I learned how to use the personal component)

In recent years, the init process of Linux has undergone two major evolution, and the traditional sysvinit has faded out of the historical stage. The new init system UpStart and systemd have their own characteristics, more and more Linux releases adopt systemd. This article briefly introduces the use and principles of these three init systems. Every Linux system administrator and system software developer should understand them to better manage systems and develop applications. This is the first part of the series. It mainly describes the features and usage of sysvinit.

What is the Init system? the history and status quo of the init system

Start the Linux operating System first from the BIOS [BIOS is the acronyms of the English "Basic Input Output System". After literal translation, the Chinese name is "Basic Input and Output System ".In fact, it is a setCalculationComputerInternalMotherboardPreviousROMChipOnProgram, It storesComputerThe most important basic input/output programSelf-check program and system self-Start program after startup, which can be read and written from CMOSSystem settingsSpecific information.Its main function is to provide computers with the most underlying and direct hardware settings and control .] Start, go to boot loader [Boot Loader is a small program that runs before the operating system kernel runs. Through this small program, we can initialize hardware devices and build a map of memory space to bring the system's hardware and software environment to a suitable state, in order to prepare the correct environment for the final call to the operating system kernel. Generally, Boot Loader relies heavily on hardware, especially in the embedded world. Therefore, it is almost impossible to build a general Boot Loader in the embedded world. However, we can still summarize some general concepts of Boot Loader to guide the design and implementation of specific Boot Loader .], The bootloader loads the kernel and initializes the kernel. The last step of kernel Initialization is to start the init process with pid 1. This process is the first process in the system. It generates all other user processes.

Init exists as a daemon and is the ancestor of all other processes. The init process is unique and can complete tasks that cannot be completed by other processes.

The Init system can define, manage, and control the behavior of the init process. It is responsible for organizing and running many independent or related initial chemical operations (hence called the init system), so as to bring the computer system into the running mode of a user reservation.

It is useless to run the kernel only. The init system must replace the system into an operational state. For example, after the shell is started, human-computer interaction is available, which allows the computer to execute some booking programs to complete practical tasks. Alternatively, you can start the X graphics system to provide a better human-machine interface and perform tasks more efficiently. Here,The shell or X system on the Character interface is a preset running mode.

In most Linux distributions, the init System and System V [System V, also known as AT&T System V, are one of the many Unix operating systems. It was initially developed by AT&T and released for the first time in 1983. A total of four major versions of System V are released: versions 1, 2, 3, and 4. System V Release 4, or SVR4, is the most successful version and becomes the source of Common UNIX features, such as "SysV initialization script" (/etc/init. d), used to control System startup and shutdown. System V Interface Definition (SVID) is a standard Definition of how System V works.] Compatible, called sysvinit. This is the most familiar init system. Some release versions such as Slackware use the BSD-style Init system, which is rarely used and will not be involved in this article. Other releases such as Gentoo are customized. Ubuntu and RHEL use upstart instead of the traditional sysvinit. Fedora has used a new init system called systemd since version 15.

We can see that different releases adopt different init implementations. This series of articles focuses on three main Init systems: sysvinit, UpStart and systemd. Understand their respective design features and briefly introduce their usage.

Linux is mainly used in the era of servers and PCs. SysVinit runs very well and its concept is simple and clear. It mainly depends on Shell scripts, which determines its biggest weakness: It is too slow to start. This disadvantage is not important for servers that seldom restart. When Linux is applied to mobile terminal devices, slow startup becomes a major problem. For faster start, people began to improve sysvinit, and two major new-generation init systems, upstart and systemd, were successively introduced. Upstart has been developed for more than eight years and has replaced sysvinit in many systems. Systemd appeared late, but the development is faster, and there is a tendency to replace upstart.

The first part of this article briefly introduces sysvinit.

Ysvinit Overview

Sysvinit is a system V-style init System. As its name suggests, it originated from the system V series UNIX. It provides higher flexibility than the BSD-style init system. Is a popular UNIX init system that has been used by various Linux distributions for decades.

Running level

Sysvinit uses the term runlevel to define the "Reservation running mode ". Sysvinit checks whether the '/etc/inittab' file contains the 'initdefault' item. This indicates whether the init system has a default running mode. If there is no default running mode, you will enter the system console and manually decide the running mode to enter.

The Running Mode in sysvinit describes the running Modes of various system reservations. There are usually eight running modes, namely, the running mode 0 to 6 and S or s.

Each Linux release version has different definitions for the running mode. However, 0, 1, and 6 have been unanimously agreed by everyone:

  • 0 Shutdown
  • 1 single user mode
  • 6. Restart

The work scope of various running modes is usually defined in the/etc/inittab file.For example, RedHat defines runlevel 3 and 5. Run Mode 3 initialize the system to shell mode on the Character interface; run mode 5 initialize the system to GUI Mode. For the command line interface or GUI, the running Modes 3 and 5 are complete and formal compared with other running modes, and the computer can complete the tasks required by the user. Modes 1 and S are often used for troubleshooting and recovery after system faults.

Obviously, in these different operating modes, the processes that the system needs to initialize and run are different from those that need to be initialized. For example, run Mode 3 does not need to start the X system. You only need to specify the mode to enter, and sysvinit will be responsible for executing all the initialization work required for this mode.

Sysvinit running sequence

Sysvinit uses scripts, file naming rules, and soft links to implement different runlevels. First, sysvinit needs to read the/etc/inittab file. Analyze the content of this file and obtain the following configuration information:

  • Runlevel to be accessed by the System
  • Definition of captured key combinations
  • Define power fail/restore scripts
  • Start getty and the virtual console

After obtaining the configuration information, sysvinit performs the following steps in sequence to initialize the system to the reserved runlevel X.

  • /Etc/rc. d/rc. sysinit
  • /Etc/rc. d/rc and/etc/rc. d/rcX. d/(X indicates the running level 0-6)
  • /Etc/rc. d/rc. local
  • X Display Manager (if needed)

First, run rc. sysinit to execute some important system initialization tasks. In RHEL5 of RedHat (RHEL6 already uses upstart), rc. sysinit mainly performs the following work.

  • Activate udev and selinux
  • Set kernel parameters defined in/etc/sysctl. conf
  • Set system clock
  • Load keymaps
  • Enable swap Partition
  • Set Host Name)
  • Root partition check and remount
  • Activate RAID and LVM Devices
  • Enable Disk Quota
  • Check and mount all file systems
  • Clear expired locks and PID files

After completing the above work, sysvinit starts to run the/etc/rc. d/rc Script. Based on different runlevels, the rc Script opens the rcX. d directory (X is runlevel) for runlevel, and finds and runs all the startup scripts stored in this directory. Each runlevel X has a directory named/etc/rc. d/rcX. d.

Many different scripts are stored in these directories. Scripts whose names start with "S" are the scripts that should be run at startup. The numbers following "S" define the execution sequence of these scripts. The scripts in the/etc/rc. d/rcX. d directory are actually some soft link files, and the actual script files are stored in the/etc/init. d directory. As follows:

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.