Brief analysis of Linux initialization init system, part 1th: sysvinit

Source: Internet
Author: User

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

(I have added a personal ingredient to my study use)

In recent years, the INIT process of Linux system has undergone two major evolution, the traditional sysvinit has faded out of the historical stage, the new init system upstart and systemd each have the characteristic, but the more and more Linux distribution adopts the SYSTEMD. This article briefly describes the use and rationale of these three init systems, which each Linux system administrator and system software developer should know to better manage systems and develop applications. This article is the first part of the series, mainly on the characteristics and use of sysvinit.

What is the init system, the history and status of the init system

The

Linux operating system starts from the BIOS "BIOS is the English" basic Input Output system "abbreviation, literal translation comes after the Chinese name is" The basic import and export systems ". in fact, it is a set of cured to Count Computer inside Motherboard Previous ROM Chip on the Programs , which holds the Computer the most important basic input and output program , post-boot self-test program and system self-launcher, it can read and write from CMOS system settings specific information . The main function of the   is to provide the lowest-level, most direct hardware setup and control for the computer. "Start, next go to boot loader" boot loader is a small program that runs before the operating system kernel runs. With this applet, we can initialize the hardware device and establish a mapping of the memory space to bring the system's hardware and software environment to a suitable state to prepare the correct environment for the final call to the operating system kernel. Typically, Boot Loader is heavily dependent on hardware, especially in the embedded world. Therefore, it is almost impossible to build a generic Boot Loader in the embedded world. Nonetheless, we can still generalize some common concepts to boot Loader to guide the user-specific boot Loader design and implementation. ", loaded into the kernel by bootloader, for kernel initialization. with PID 1. This process is the first process of a system. It is responsible for generating all other user processes.

Init exists as a daemon, and is the ancestor of all other processes. The init process is unique and can accomplish tasks that other processes cannot accomplish.

The init system is able to define, manage, and control the behavior of the INIT process. It is responsible for organizing and running many independent or related initiation tasks (hence known as the init system), thus allowing the computer system to enter a mode of operation for a user's subscription.

Simply running the kernel is useless, and the system must be put into an operational state by the INIT system. For example, when the shell shell is started, there is human-computer interaction, so that the machine can perform some of the booking process to accomplish meaningful tasks. Or start the X graphics system to provide a better man-machine interface and perform tasks more efficiently. Here, the shell or X system of the character interface is a preset mode of operation.

The init system for most Linux distributions is and System V "System V, once also known as T System V, and is one of many versions of the UNIX operating system. It was originally developed by the T-T, which was released for the first time in 1983. A total of 4 major versions of System V were released: Versions 1, 2, 3 and 4. System V Release 4, or SVR4, is the most successful version and is the source of some common UNIX features, such as the "SysV init script" (/ETC/INIT.D), which is used to control system startup and shutdown, Systems v Interface Definition (SVID) is a standard definition of how system V works. "Compatible, is known as Sysvinit. This is one of the most familiar init systems. Some distributions, such as Slackware, use the BSD style Init system, which is less used and is not covered in this article. Other distributions, such as Gentoo, are custom-made. Ubuntu and RHEL use upstart instead of the traditional sysvinit. Fedora, however, started with version 15 with a new init system called SYSTEMD.

You can see that different distributions have different INIT implementations, and this series of articles is intended to tell you about three major init systems: Sysvinit,upstart and SYSTEMD. Learn about their design features, and briefly describe their use.

In the era when Linux is mainly used in servers and PCs, Sysvinit runs very well and the concept is simple and clear. It relies primarily on Shell scripting, which determines its biggest weakness: startup is too slow. On servers that are rarely restarted, this disadvantage is not important. When Linux is applied to mobile devices, the slow start becomes a big problem. In order to start faster, people began to improve the sysvinit, successively appeared the upstart and Systemd these two main new generation init system. Upstart has been developed for more than 8 years and has replaced sysvinit in many systems. Systemd appeared late, but developed faster and had a tendency to replace upstart.

In the first part of this article, we first briefly introduce Sysvinit.

Ysvinit Overview

The sysvinit is the System V-style init, which, as its name implies, originates from the System V series UNIX. It offers more flexibility than the BSD style init system. The UNIX init system, which has been popular for decades, has been used by various Linux distributions.

Run level

Sysvinit uses the term runlevel to define "the operating mode of the subscription". sysvinit Check if the '/etc/inittab ' file contains ' Initdefault ' entries . this tells the INIT system whether it has a default run mode. If there is no default operating mode, then the user enters the system console and manually decides which mode of operation to enter .

The operating mode in sysvinit describes the operating modes of various bookings of the system. There are typically 8 modes of operation, that is, running modes 0 to 6 and s or S.

Each Linux distribution has a different definition of the run mode. But 0,1,6 has been unanimously endorsed by everyone:

    • 0 Turn off the machine
    • 1 Single-User mode
    • 6 restart

The working range of various operating modes is usually defined in the/etc/inittab file. For example, RedHat defines RunLevel 3 and 5. Run mode 3 initializes the system to the shell mode of the character interface, and run mode 5 initializes the system to GUI mode . Whether it is a command line interface or a GUI, run mode 3 and 5 are fully formal running states relative to other operating modes, and the computer can perform the tasks the user needs. Pattern 1,s and so on are often used for troubleshooting and recovery after a system failure.

It is clear that these different modes of operation require the process of initialization and initialization of the system to be performed differently. For example, run mode 3 does not need to start the X system. The user only needs to specify which mode to enter, and Sysvinit will be responsible for performing all the initialization required for that pattern.

Sysvinit Run Order

Sysvinit cleverly uses scripts, file naming rules, and soft links to implement different runlevel. First, Sysvinit needs to read the/etc/inittab file. Analyzing the contents of this file, it obtains some of the following configuration information:

    • RunLevel the system needs to enter
    • Capturing the definition of a key combination
    • Defining Power Fail/restore Scripts
    • Start Getty and Virtual Consoles

Once the configuration information is obtained, SYSVINIT performs the following steps sequentially to initialize the system to the RunLevel X of the subscription.

    • /etc/rc.d/rc.sysinit
    • /ETC/RC.D/RC and/etc/rc.d/rcx.d/(X for Run level 0-6)
    • /etc/rc.d/rc.local
    • X Display Manager (if required)

First, run Rc.sysinit to perform some important system initialization tasks. In the RHEL5 of RedHat Company (RHEL6 has already used upstart), Rc.sysinit mainly completes the following work.

    • Activating Udev and SELinux
    • Setting the kernel parameters defined in/etc/sysctl.conf
    • Setting the system clock
    • Load Keymaps
    • Enable swap partition
    • Set host name (hostname)
    • Root partition Check and remount
    • Activating RAID and LVM devices
    • Turn on disk quotas
    • Check and mount all file systems
    • Purge outdated locks and PID files

After completing these tasks, Sysvinit starts running the/ETC/RC.D/RC script. Depending on the RUNLEVEL,RC script, you will open the RCX.D directory (X is runlevel) that should be runlevel, and locate and run all startup scripts that reside in that directory. Each runlevel X has one such directory, and the directory name is/ETC/RC.D/RCX.D.

There are many different scripts stored in these directories. The script whose file name starts with S is the script that should run at startup, and the number followed by S defines the order in which the scripts are executed. The scripts in the/ETC/RC.D/RCX.D directory are actually some soft link files, and the real script files are stored in the/ETC/INIT.D directory. As shown below:

Brief analysis of Linux initialization init system, part 1th: Sysvinit

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.