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

What is the SysVinit mechanism in Linux system

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly explains "What is the SysVinit mechanism in Linux system", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's take you to learn "What is the SysVinit mechanism in Linux system"!

SysV init is a systemV-style init system, derived from the SystemV family UNIX as the name suggests. It offers a lot more flexibility than BSD-style init systems. The UNIX init system has been popular for decades and has been adopted by various Linux distributions.

1) What is System V?

System V, also known as AT&T System V, is one of many versions of the Unix operating system. It was originally developed by AT&T and first released in 1983. Four major versions of System V have been released: versions 1, 2, 3, and 4. SystemV Release4, or SVR4, was the most successful release and became the source of some UNIX common features, such as the SysV initialization script (/etc/init.d), which controls system startup and shutdown, and the SystemV Interface Definition(SVID), a standard definition of how SystemV works.

(2) Operation level of SysV init

SysV init uses the term runlevel to define the "scheduled run mode." SysV init checks if the '/etc/inittab' file contains the 'initdefault' entry. To tell the init system if it has a default run mode. If there is no default operating mode, the user will go to the system console and manually decide which operating mode to enter.

The operating modes in SysV init describe the operating modes for the various subscriptions of the system. There are usually eight operating modes, namely operating modes 0 to 6 and S or S.

Each Linux distribution defines a runtime mode differently. But 0, 1 and 6 received unanimous approval:

0 OFF

1 Single user mode

6 Restart

The scope of operation for each run mode is usually defined in the/etc/inittab file. For example, Red Hat defines runlevels 3 and 5. Run Mode 3 initializes the system to shell mode with a character interface; Run Mode 5 initializes the system to GUI mode. Both command line interfaces and GUIs, operating modes 3 and 5 are complete formal operating states relative to the other operating modes, and the computer can complete the tasks required by the user. Mode 1, S, etc. are often used for troubleshooting and recovery after system failure.

Obviously, the processes that the system needs to initialize and the initialization preparations that need to be made are different in these different operating modes. For example, operating mode 3 does not require the X system to be activated. The user only needs to specify which mode to enter, and SysV init performs all the initialization necessary for that mode.

(3) SysV init running sequence

SysV init cleverly uses scripts, file naming conventions and soft links to implement different runlevels. First, SysV init needs to read the/etc/inittab file. Analyzing the contents of this file, it gets the following configuration information:

runlevel the system needs to enter;

Capture the definition of a key combination;

Define the power fail/restore script;

Start getty and virtual console;

Once the configuration information is available, SysV init initializes the system to the subscribed runlevelX by performing the following steps in sequence:

/etc/rc.d/rc.sysinit

/etc/rc.d/rc and/etc/rc.d/rcX.d/(X stands for runlevels 0-6)

/etc/rc.d/rc.local

XDisplayManager (if required)

1) rc.sysinit script function

First, run rc.sysinit to perform some important system initialization tasks. In Red Hat RHEL5 (RHEL6 already uses UpStart), rc.sysinit does the following:

activate udev and selinux;

Set kernel parameters defined in/etc/sysctl.conf;

Set the system clock;

loading keymaps;

Activating swap partitions;

Set hostname;

Root partition checking and remount;

Activate RAID and LVM devices;

Enable disk quota;

Check and mount all file systems;

Clear expired locks and PID files;

2) rc.d script

After this, SysV init starts running the/etc/rc.d/rc script. Depending on the runlevel, the rc script will open the rcX.d directory for the runlevel (X is runlevel), find and run all startup scripts stored in that directory. Each runlevelX has one such directory called/etc/rc.d/rcX.d.

There are many different scripts stored in these directories. Scripts whose filenames begin with S are the scripts that should be run at startup, and the number following S defines the order in which they are executed. The scripts in/etc/rc.d/rcX.d are actually soft link files, and the actual script files are stored in/etc/init.d directory. As follows:

Script in rc5.d directory

The code is as follows:

[root@www~]#ll/etc/rc5.d/

lrwxrwxrwx1rootroot16Sep42008K02dhcdbd->../ init.d/dhcdbd

.... (middle omitted)...

lrwxrwxrwx1rootroot14Sep42008K91capi->../ init.d/capi

lrwxrwxrwx1rootroot23Sep42008S00microcode_ctl->../ init.d/microcode_ctl

lrwxrwxrwx1rootroot22Sep42008S02lvm2-monitor->../ init.d/lvm2-monitor

.... (middle omitted)...

lrwxrwxrwx1rootroot17Sep42008S10network->../ init.d/network

.... (middle omitted)...

lrwxrwxrwx1rootroot11Sep42008S99local->../ rc.local

lrwxrwxrwx1rootroot16Sep42008S99smartd->../ init.d/smartd

.... (omitted below)...

When all initialization scripts have been executed. SysV init runs the/etc/rc.d/rc.local script.

rc.local is the place Linux leaves to the user for personalization. You can put your own private settings and start-up things here, a Linux Server users generally more than one, so there is such a consideration.

(4) SysV init and system shutdown

SysV init is responsible not only for initializing the system, but also for shutting it down. When the system is shut down, close and clean up work needs to be done carefully and sequentially to ensure data consistency.

For example, you should stop services that read and write to the file system first, and then mount the file system. Otherwise the data will be lost.

This sequence is also controlled by the naming convention for all scripts in the/etc/rc.d/rcX.d/directory, where all scripts starting with K will be invoked when the system is shut down, and the number after the letter K defines their execution order.

These scripts are responsible for safely stopping services or other shutdown operations.

(5) SysV init management and control functions

In addition, after the system is started, the administrator also needs to manage and control the processes that have been started. The SysV init package contains a set of tools that control starting, running, and shutting down all other programs.

Stop the system.

Init is the init process entity of SysV init itself, running as pid1, and is the parent of all user processes. The primary role is to create processes during startup using the/etc/inittab file.

killall5 is the killall command of System V. Signals to processes other than its own session process, so it cannot kill the shell currently in use.

The last traceback/var/log/wtmp file (or the file specified by the-f option) shows all user logins since the file was created.

lastb works much like last, using the/var/log/btmp file by default to display all failed login attempts.

mesg controls access to user terminals by other users.

pidof Finds the process identification number (pid) of the program and outputs it to the standard output device.

poweroff equals shutdown-h-p, or telinit0. Shut down the system and cut the power.

reboot equals shutdown-r or telinit6. Restart the system.

runlevel reads the system log file (typically/var/run/utmp) and outputs the previous and current system runlevels to standard output devices.

shutdown Terminates the system in a safe manner, all logged-on users are notified that the system is about to terminate, and no new logged-on is permitted.

sulogin is called by init when the system enters single-user mode. Init also calls sulogin when it receives the-b option passed by the boot loader.

telinit is actually a connection to init that is used to pass single-character parameters and signals to init.

utmpdump Displays the contents of the/var/run/utmp file to standard output devices in a user-friendly format.

Wall sends messages to all logged in users with information privileges.

Different Linux distributions have developed additional tools to simplify the administration of the init system. For example, RHEL of Red Hat developed the initscripts package based on SysV init, which contains a large number of startup scripts (such as rc.sysinit), command line tools such as service, chkconfig, and even a graphical interface to manage the init system. Other Linux distributions also have initscript or init packages with other names to simplify SysV init administration.

Once you understand the mechanics of SysV init, in a minimalist SysV init-only system, you can call scripts to start and stop services directly, manually create inittabs, and create soft connections to accomplish these tasks. Therefore understanding the fundamentals and commands of SysV init is of utmost importance. You can even develop your own set of management tools.

At this point, I believe that everyone has a deeper understanding of "what is the SysVinit mechanism in Linux system", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

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: 280

*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