Linux Startup Process
Linux Startup Process:
POST --> BIOS (Boot Sequence) --> MBR (bootloader, 446 byte) --> Kernel --> initrd (initramfs) --> (ROOTFS) -->/sbin/init (/etc/inittab)
Kernel design style:
Single Kernel:
All functions are in the same kernel. Linux uses a single kernel, but adopts the microkernel design. LWP (light weight pprocess ).
Core:
/Boot/vmlinuz-verison
Dynamic Loading of ko (dedicated kernel module of kernel object ).
Kernel module (ko):/lib/modules/KERNELVERISON/
Common commands for loading kernel modules:
# Insmod
# Modprobe
Microkernel:
Make other functions into sub-kernels. Windows Solaris. True multithreading.
Features provided by the kernel:
File System
Process Management
Memory Management
Network Management
Security Features
Driver
Kernel initialization process:
1. device detection.
2. driver initialization
The driver module may be loaded from the initrd (initramfs (RHEL6) component.
3. Mount the root file system (rootfs) in read-only mode ).
4. Load the first process init (PID = 1) in the user space)
Initrd:
A middle-layer system provides the necessary basic driver at system startup, generates a temporary root, and provides the kernel with the basic driver required to access the real root file system. After the kernel is successfully mounted to the root file system,/proc,/sys, And/dev under the temporary root will be moved to the real root.
Ramdisk --> initrd RHEL5 simulates memory usage as a disk.
Ramfs --> initramfs RHEL6 simulates memory usage as a disk.
# Switch chroot TEMPROOTDIR [COMMAND] to the root directory temporarily
For example:
# Chroot/tmp/virroot/bin/csh
# Ldd FILE: displays the shared libraries that binary files depend on.
Init:
The first process started by the system.
Binfile path:
/Sbin/init
/Etc/init
/Bin/init
The kernel will search for init in the above directory order in sequence. If no init can be found, the kernel will execute/bin/sh.
Configuration file:
/Etc/inittab
Each line records a service (process) to be started or run ).
Set the task:
1. Set the default running level.
2. Run the system initialization script.
/Etc/rc. d/rc. sysinit
3. Run the service scripts in the directory corresponding to the specified running level in the following order.
/Etc/rc. d/init. d
/Etc/rc. d/rcNUM. d
/Etc/rc. d/rc. local
4. Set the action of ctrlaltdel.
5. define whether the ups power supply is executed in case of power failure or recovery.
6. Start the virtual terminal (level 2345 ).
1: 2345: respawn:/sbin/mingetty tty1
...
6: 2345: respawn:/sbin/mingetty tty6
7. Start the graphic terminal (level 5 ).
X: 5: respawn:/etc/X11/perofdm-nodaemon
The structure of each line is as follows:
Id: runlevels: action: process
Id: Service parameter id, 1 ~ 4 characters.
Id default RUNLEVEL
Si system initialization
L0 ~ L6 specifies RUNLEVEL
Ca intercepts ctrl + alt + del
Pf Power Supply Failure
Pr power recovery
NUM: configure the NUM virtual terminal
X start x Service
Runlevels: the level at which the server runs.
Action: The action executed under an event.
Initdefault sets the default running level.
Sysinit system initialization.
When the wait level is switched to this level, it is executed.
Restart ctrlaltdel.
Powerfail power supply failure.
After the power of powerokwait fails, the power will be restored before the power is turned off.
Respawn restarts once the program is terminated.
Process: Specifies the program to run. It defines the absolute path.
/Etc/init/*. conf
The files in this directory are many. conf files generated after the inittab file is sliced. All are written based on event-driven.
Restart init:
# Init q
# Telinit q
# Kill-HUP 1
RUNLEVEL:
The difference between different levels is that the services started are different.
0: halt
1: single user mode
Log on as an administrator without authentication.
2: muw.user mode no NFS
Do not start servers related to domain functions such as NFS.
3: muw.user mode text mode
Command Line Mode
4: reseved
Retention level, not defined for the moment.
5: muw.user mode graphic mode
Graphic Mode
6: reboot
Set the running level:
Modify/etc/inittab
View the running level:
# Runlevel
LSATLEVEL CURRENTLEVEL
LASTLEVEL indicates the previous level, and N indicates that no switchover is performed. CURRENTLEVEL indicates the current level.
Switch the running level:
# Init [OPTION] LEVEL
[OPTION]
LEVEL
0 Shutdown
1 single user mode
2. Command Line Mode (NFS is not enabled)
3. Command Line Mode
4. Retention Mode
5 graphic interface
6. Restart
S single user mode
S single user mode
/Etc/rc. d/rc. sysinit
Set the basic environment of the system and complete the following tasks:
1. Activate udev and selinux.
2. Set the kernel parameters according to the/etc/sysctl. conf file.
Run sysctl-p.
3. Set the system clock.
4. Load the keyboard ing.
5. Enable swap partition.
Run swapon-a-e.
6. Set the host name to read the HOSTNAME parameter from/etc/sysconfig/network.
7. File System check. Check and mount other file systems according to/etc/fstab. In addition, after no error occurs, the root is remounted in read/write mode.
8. Initial enclosure hardware.
Define the module in/etc/modprobe. conf
ISA and PnP Devices
USB device
9. Start RAID and LVM
10. Uninstall initrd if necessary
11. initialize the serial device. Perform initialization according to/etc/rc. serial. This script is unavailable by default and needs to be created by yourself.
12. Clear expired lock files (/var/lock/subsys/*) and IPC files.
13. Reset the disk parameters according to/etc/sysconfig/harddisk DEVICE.
/Etc/rc. d/init. d /*
Service scripts in the SysV style are stored under/etc/rc. d/init. d. There is a link file/etc/init. d -->/etc/rc. d/init. d.
Configuration file:
/Etc/sysconfig/service script with the same name
The script must take at least the following parameters:
Start | stop | restart | status | reload | condrestart (conditional restart, started restart, not started .)
Common Features of the script:
# Chkconfig: RUNLEVELS SS KK
RUNLEVELS startup level
RUNLEVELS can use-to indicate links with no level starting with SNUM by default, that is, all links starting with KNUM.
SS startup priority
KK disabled priority
When you use the chkconfig command to create a link for this script in the rcNUM. d directory, RUNLEVEL indicates that files starting with SNUM are created by default. Otherwise, links starting with KNUM are created by default. The start priority behind S is the number represented by SS, and the close priority behind K is the number represented by KK. Generally, SS + KK = 99.
# Description: DESCRIPTIONS
Description. You can describe the simple functions of this script. You can use \ To continue rows.
/Etc/rc. d/rc. local
/Etc/rc. d/rcNUM. d/S99local -->/etc/rc. d/rc. local
/Etc/rc. local -->/etc/rc. d/rc. local
The final service executed at system startup should be a script. Commands that are not convenient to define as services can be written into them and executed before the user logs on.
For example, the welcome content displayed in the command line mode login mode.
GRUB: GRand uniied Bootloader
Grub startup process:
Stage1: packed in MBR. The purpose is to guide stage2.
Stage1.5: used to identify common file systems.
Stage2: Located in the partition where the kernel is located. /Boot/grub /.
/Etc/grub. conf
Grub configuration file. Is the link file, pointing to/boot/grub. conf
The main content is as follows:
Default = 0
Set the title number starting from 0 by default.
Timeout = 5
Wait for the timeout value to be selected. The Unit is seconds.
Splashimeage = (hd0, 0)/grub/palash.xmp.gz
Specifies the grub background image.
Hidenmenu
Whether to hide the menu.
Password -- md5 PASSWORD
Set the password for GRUB editing. You can use a grub-md5-crypt to generate an encrypted password.
Title TITLENAME
The kernel title or OS name, which can be freely modified.
Root (hdDISKNUM, PARTNUM)
Specify the device and partition where the Kernel File is located. For grub, all hard disks are displayed as hd. DISKNUM indicates the disk sequence number, and PARTNUM indicates the partition sequence number.
Kernel KERNEL CMDLINE
Specify the kernel path that is passed to the kernel. The parameter file can be seen in/proc/cmdline.
Initrd INIDRD
Specifies the initrd path.
Password -- the md5 PASSWORD used to start the kernel or OS.
Install grub:
# Fdisk DEVICE
/Dev/PART1 for boot
/Dev/PART2 for sysroot
# Mkdir/DIR/boot
# Mount/dev/PART1/DIR/boot
# Grub-install -- root-directory =/DIR DEVICE
In this way, ensure that the partition where the Kernel File is located is mounted on/boot. Grub can automatically find/boot by specifying the parent directory of/boot.
# Vim/DIR/boot/grub. conf
Fix grub:
Install grub stage1:
# Grub
Grub> root (hdDISKNUM, PARTNUM) specifies the disk and partition where the kernel is located.
Grub> setup (hdDISKNUM) installs grub on the specified hard disk.
Grub> quit
Grub. conf file loss:
After grub is started.
Grub> find (hdDISKNUM, PARTNUM )/
Press the tab key to display related files.
Grub> root (hdDISKNUM, PARTNUM)
Grub> kernel/KERNEL
Grub> initrd/INITRD
Grub> boot
# Mingetty [OPTION] Start the terminal
[OPTION]
-- Loginprog =/bin/login starts the program that is interrupted. The default value is/bin/login.
# Agetty [OPTION] prot baudrate replaces the getty command.
[OPTION]
-L login programe specifies the LOGIN program
-N requires no user name. You do not need to enter logon information. Use with-l.
For example:
# Agetty-l/bin/bash 38400 log on to bash and set the baud rate to 38400.
# Stty [OPTION] device setting changes and displays terminal devices.
[OPTION]
-F -- file = DEVICE: open and use the specified DEVICE.
SETTING:
Size: displays the number of rows (columns.
Speed: displays the terminal speed.
For example:
# Stty-F/dev/console size physical Terminal
25 80 25 rows and 80 columns.
# Stty-F/dev/console speed
38400 characters per second
# Chkconfig [OPTION]
Specify the SysV script to automatically create a link under/etc/rcNUM. d.
[OPTION]
-- List SERVICE lists the startup settings of all independent daemon. All settings are displayed without parameters.
-- Add SERVICE
Automatically create a link and add the SERVICE to the SERVICE list controlled by chkconfig. The next system start takes effect.
-- Del SERVICE
Delete all linked files of the SERVICE.
-- Level [RUNLEVELS] SERVICE on | off
The specified level is RUNLEVELS, and the SERVICE is started or disabled. You do not need to specify RUNLEVLES for the instantaneous daemon. RUNLEVELS can be omitted. The default value is 2345.
Common linux shutdown and restart commands:
Shutdown
Halt
-P power off
It must be used with the exec command.
Reboot
Poweroff
Init 0
Init 6
# Exec execution file, and replace the parent process with a child process.
For example:
# Exec halt-p
Type of the daemon:
Independent daemon
Instantaneous daemon
It does not need to be associated with the running level.
Xinetd: super daemon. Manage all transient daemon processes. The running level needs to be associated.
This article permanently updates the link address: