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

Centos system startup process for learning notes

2025-02-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

The startup process of the CentOS system:

Brief introduction:

(kernel level) POST-read-> BootSequence (in BIOS)-> BootLoader (in MBR)-> Kernel (load the root file system with ramdisk)-- > rootfs (readonly)-- > / sbin/init (the first program in user space)

(startup process in user space): / sbin/init (read / etc/inittab) [centos5,6,7 differs slightly here]

Set the default run level (1)-- > run the system initialization script, complete system initialization (2)-- > turn off the services that need to be stopped at the corresponding level, start the services that need to be enabled at the corresponding level (3)-- > set the login terminal (4) [--> start the graphics terminal] (5 is not required)

Talk more about kernel-level system startup:

POST: power on self-test

ROM:CMOS (complementary metal oxides)

BIOS:Basic Input and Output System (basic input / output system)

ROM+RAM

Boot Sequence:

Find each boot device in order, and the first device with a boot program is the device to be used for this startup.

Bootloader: boot loader, program

Linux:

LILO:LIinux LOader

GRUB:Grand Uniform Bootloader (Unified Boot Loader

GRUB 0.X:Grub Legacy (centos5)

GRUB 1.X:Grub2 (centos7)

Boot loader function: provides a menu that allows the user to select the system to boot or a different kernel version; load the user-selected kernel into a specific space in the RAM, decompress, expand, and then transfer system control to the kernel

Where is the bootloader loaded? Load into MBR (except UEFI)

Additional introduction MBR:Master Boot Record (Master Boot record)

Total 512bytes of MBR:

Pre-446bytes: put bootloader

64bytes:fat (partition table)

2bytes:55AA magic number (if 55AA means MBR is valid)

Load Kernel:

Self-initialization:

Detect all recognizable hardware devices

Load hardware drivers; (it is possible to load drivers with ramdisk)

Mount the root file system read-only

Run the first application in user space: / sbin/init

Note: after the kernel init starts, the following tasks will be left to init, and the kernel will leave it (except for privileged operations).

Type of init program:

CentOS 5-:SysV init

Configuration file: / etc/inittab

CentOS 6:Upstart

Configuration file: / etc/inittab

/ etc/init/*.conf

CentOS 7:Systemd

Configuration file: / usr/lib/systemd/system/, / etc/systemd/system/

Note: when centos starts, the kernel runs the first application in user space, init, and then all subsequent tasks are managed by the application in user space.

One of the features of the Linux kernel: using buffering and caching to speed up file access on disk

Ramdisk-replace with-> ramfs (a speed-up mechanism)

To CentOS 5ramfs: initrd

Can be created by a tool program: mkinitrd

CentOS 6,7: initramfs

Tool programs: dracut, mkinitrd

Summary: kernel-level system initialization is as follows:

System initialization process (kernel level):

POST-read-> BootSequence (in BIOS)-- > BootLoader (in MBR)-- > Kernel (load the root file system with ramdisk)-- > rootfs (readonly)-- > / sbin/init (the first program in user space)

Note: the amount of bootloader code is very small, in order to simplify the concise period 2 kernal bootloader itself can not drive the logical volume, then obviously he cannot access the files on the logical volume, so we put the kernel file on the logical volume and bootloader cannot be loaded, so at this time the kernal can only be placed on the basic disk

The above is centos kernel-level startup

=

The following is about / sbin/init: it varies from system to system, so introduce it separately

That is, the system startup process in user space.

CentOS 5: SysV init

Basic mastery:

Operation level: a mechanism set for the operation or maintenance of a system.

0-6:7 level

0: shutdown, shutdown

1: single user mode (single user), root user, no authentication required; maintenance mode

2. Multi-user mode (multi user), which starts the network function, but not the NFS; maintenance mode.

3. Multi-user mode (mutli user), fully functional mode; text interface

4. Reservation level: there is no special purpose at present, but it is accustomed to using the same level 3 functions.

5. Multi-user mode (multi user), fully functional mode, graphical interface

6. Restart, reboot

Default level: 3, 5

Level switching: init #

Level View:

Who-r

Runlevel

Configuration file: / etc/inittab

Each line defines an action and the corresponding process (centos5)

Id:runlevels:action:process

Id: the identifier of a task

Runlevels: at which level to start this task; #, #, or empty, indicating all levels

Action: under what conditions to start this task

Process: task

Action:

Wait: execute once when waiting to switch to the level of this task

Respawn: once this task is terminated, restart it automatically

Initdefault: sets the default run level; at this point, process omits

Sysinit: sets the initialization mode of the system. The / etc/rc.d/rc.sysinit script is usually specified here.

For example:

Id:3:initdefault: (default runlevel is 3)

Si::sysinit:/etc/rc.d/rc.sysinit (set system initialization mode)

Level

L0:0:wait:/etc/rc.d/rc 0

L1:1:wait:/etc/rc.d/rc 1

.

L6:6:wait:/etc/rc.d/rc 6

Example: / etc/rc.d/rc 3

It means to start or shut down the service controlled by the service script in the / etc/rc.d/rc3.d directory, as explained below:

Knights: the service to be stopped; the smaller the number, the more priority it is to shut down; the dependent service shuts down first, then the dependent service shuts down

Slots: the service to be started. The smaller the number, the more priority it is to start. The dependent service starts first, while the dependent service starts later.

Rc script function: take a run-level number as a parameter

Rc scripting framework:

For srv in / etc/rc.d/rc#.d/K*; do

$srv stop

Done

For srv in / etc/rc.d/rc#.d/S*; do

$srv start

Done

Script execution method under the directory / etc/init.d/* (/ etc/rc.d/init.d/*):

# / etc/init.d/SRV_SCRIPT {start | stop | restart | status}

# service SRV_SCRIPT {start | stop | restart | status}

Eg: [root@bucktan init.d] # / etc/init.d/network restart

Shutting down interface eth0: [OK]

Shutting down loopback interface: [OK]

Bringing up loopback interface: [OK]

Bringing up interface eth0: Determining if ip address 172.18.26.6 is

Chkconfig command: controls / etc/init.d/ the startup or shutdown status of each service script at all levels

View: chkconfig-- list [name]

Add: chkconfig-- add name means "name" is managed by chkconfig

One of the script definition formats for services that can be added:

#! / bin/bash

#

# chkconfig: LLL (level) NN (startup priority) NN (g off)

# description:

Delete: chkconfig-- del name

Modify the specified link type:

Chkconfig [--level LEVELS] name

-- level LEVELS: specifies the level to control; default is 2345

Note: at a normal level, the last service S99local started is not linked to a script under / etc/init.d, but to / etc/rc.d/rc.local (/ etc/rc.local) script; therefore, when a program that is inconvenient or does not need to be written as a service script expects to boot and run automatically, it can be placed directly in this script file.

Other examples: tty1:2345:respawn:/usr/sbin/mingetty tty1

......

Tty6:2345:respawn:/usr/sbin/mingetty tty6

When our level is any of 2345, we will run the mingetty program, which opens the terminal

(1) mingetty knowledge startup terminal. For login, mingetty will call login login program; thus login program will call login.

(2) in addition to mingetty, there are other programs such as getty to open the virtual terminal.

System initialization script: what does / etc/rc.d/rc.sysinit do and its function

Note: this script is a good example of learning scripts.

(1) set the host name

(2) set welcome information

(3) activate udev and selinux

(4) Mount all file systems defined in the / etc/fstab file

(5) detect the root file system and remount the root file system in read-write mode

(6) set the system clock

(7) set kernel parameters according to / etc/sysctl.conf file

(8) activate lvm and soft raid devices

(9) activate swap device

(10) load drivers for additional devices

(11) cleanup operation

Summary (startup process in user space): / sbin/init (read / etc/inittab)

Set the default run level (1)-- > run the system initialization script, complete system initialization (2)-- > turn off the services that need to be stopped at the corresponding level, start the services that need to be enabled at the corresponding level (3)-- > set the login terminal (4) [--> start the graphics terminal] (5 is not required)

Note: the difference between centos6,7 and 5 is described below.

CentOS 6:

Init program: upstart, but still / sbin/init, its configuration file:

/ etc/init/*.conf, / etc/inittab (used only to define the default run level)

Note: * .conf is a upstart-style configuration file

RcS.conf

Rc.conf

Start-ttys.conf

CentOS 7:

Init program: systemd, configuration file: / usr/lib/systemd/system/*, / etc/systemd/system/*

Fully compatible with the SysV scripting mechanism; therefore, the service command is still available; however, it is recommended that you use the systemctl command to control the service

# systemctl {start | stop | restart | status} name [.service]

At this point, the introduction of centos system startup is over.

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

Network Security

Wechat

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

12
Report