Kernel Features: Process management, file system, hardware driver, memory management, security features: SELinux, network subsystem, standard library: glibc
The process is run on the CPU but the user process is controlled by the kernel, and the user process needs to complete the privileged instruction to trigger the soft interrupt from user mode to kernel mode, and the kernel to execute the privileged instruction and return the result to the user process.
Linux is a single-core architecture but it supports modularity, modules can be dynamically loaded or unloaded, the Linux kernel: core + peripheral Modules
Core:/boot/vmlinux-version-release
Modules:/lib/modules/version-release, kernel modules generally end with. KO: Kernel object
RAMDisk:/boot/initramfs-version-release.img: Useful when loading the root file system during kernel boot
Linux supports multiple versions of the kernel coexistence, in the above directory will be the system multi-version number
Linux system startup process: POST: Power-on self-test, CPU addressing space consists of Rom+ram: ROM (BIOS) will be replaced by EFI in the future.
Boot order: In order to find the boot device, the first device with a boot program is the boot device
Mbr:master boot record looks for the first sector of the boot device (sector): 512bytes composition (446:bootloader, 64:partation table, 2:5a)
Runs Bootloader:centos5/6linux as a traditional grub (GRand Unified Bootloader), provides a bootable kernel, and itself recognizes the file system of the partition where the kernel resides, When the kernel starts, Bootloader gives control to the kernel to exit itself.
The kernel and the RAMDisk are loaded with grub in memory, RAMDisk provides a hard drive module, and the kernel is run in memory in conjunction with the CPU
Kernel kernel boot: Initialize itself, identify the hardware, mount the driver, load the root file system read-only,/sbin/init, when the kernel starts the INIT process, the entire boot process ends
CentOS 5:sysv, init file on:/etc/inittab-/etc/rc.d/rc.sysinit
Entos 6 upstart,init file feature is divided into multiple files/etc/init/*.conf---/etc/rc.d/rc.sysinit
CentOS 7 Systemd: System Boot File/usr/lib/systemd/system/
Start Step one, CentOS 5:kernel starts the system first process based on the profile/etc/inittab/sbin/init
Set system default RunLevel: Total 7 levels 0-6:
0: Shutdown, 1: Single user mode, 2:multi user modes, non-fully multi-user mode does not support NFS function, 3: Full multiuser mode, text interface, 4: Unused, reserved level, 5: Full multi-user weapon, graphics interface, 6: restart. Toggle Level: Init #
Start step two, through the/etc/rc.d/rc.sysinit script, further initialize the system
Start step three, start the default startup service at the specified RunLevel, stop the service by default at the specified RunLevel, and under/etc/rc.d/there are various runlevel directories, each of which records the program running at that level, s##: Services started, k##: Stopped services, ##:01-99, The smaller the number, the higher the priority to start or close;
If the script expects to be able to be used by the Chkconfig command, add the following line to the script:
# Chkconfig:-85 15
-: When this script is controlled by chkconfig, which level is enabled by default, you can also specify a level such as: # chkconfig:345 85 15, when Chkconfig controls the program, it only takes effect on level 345. 85 to turn on priority. 15 to turn off priority. Add the following program:
Copy the script to/etc/init.d/, add the script startup item with Chkconfig--add and create the linked file at each boot level directory, Chkconfig--del delete the self-launch item, Chkconfig srv_script {On|off} Set the start or close key, default 2345, can also be set for a certain level related services such as: Chkconfig--level
/etc/rc.d/rc.local (/etc/rc.local): This script runs the last script for system boot completion.
Start Step four: Define the functions of some key combinations, usually ctrl+alt+delete
Start Step five: Initialize the character terminal
Start step Six: If necessary, start the graphics terminal
CentOS 6:/etc/inittab, defined by the/etc/init/*.conf configuration file, initializes the Init action, called by upstart, and the program is/sbin/init
/etc/rc.d/rc.sysinit: The system initialization script includes the following operations (setting hostname: Reading the hostname parameter in the/etc/sysconfig/network file, displaying the text welcome message, activating SELinux and Udev, mounting/etc Other file systems defined in the/fstab file, activating swap, detecting the root file system, re-mounting in read/write mode, setting the system clock, setting kernel parameters according to/etc/sysctl.conf, activating LVM and RAID devices, loading drivers for additional devices, cleaning operations)
Initialization process: POST-and (BIOS) boot sequence-to-MBR (bootloader)-Kernel + ramdisk (5 and 6 different file names, INITRD, Initramfs)- Mount Rootfs (RO)--/sbin/init (CentOS 5:/etc/inittab, centos6/etc/init/*.conf)
Set the default run level--use/etc/rc.d/rc.sysinit to initialize the system--start and close the specified service individually-->ctrl+alt+delete key combination--Start the character terminal--Start the graphics terminal
The Grub:grand Unified Bootloader,grub program consists of two segments: the STAGE1:MBR (0 cylinder 0 Track 1 sector) specifies the sector only for reading the subsequent file system. STAGE1_5:MBR Subsequent sectors mount the file system type. Stage2: Read the grub.conf configuration file and implement the boot function extension
Grub Features:
1, provide the menu, and provide interactive interface (e: Enter the edit mode after the kernel to add a single, and then press B to enter the one-user mode, C: Enter the command line interface mode)
2, select the kernel or system to boot (allow to pass the boot parameters to the kernel, select the interface can be hidden)
3, for the editing function to provide protection mechanism (choose to run the specified kernel must first enter the password, use the e command to enter the password first)
Grub command-line interface:
Root: Specifies which partition is the partition on which the system or kernel file is to be started, all hard drives are recognized as HD, and different hard disks are based on digital IDs: such as hd0, HD1, and so on, different partitions on the same hard disk, and also using a digital ID, such as root (hd0,0)
Find (DEVICE)/path/to/file, which is used to find the kernel on that partition.
Kernel: Specifies the kernel file to run, for example: kernel/vmlinuz-2.6.32-358.el6.x86_64 ro root=/dev/sda3, read-only mount the root filesystem needs to know the root file system location beforehand, RAMDisk file must be specified
INITRD: Specify the available RAMDisk files for the kernel to be run for example: initrd/initramfs-2.6.32-358.el6.x86_64.img
Boot: Start the previously configured kernel or system.
The grub.conf file is in the/boot/grub directory. Configuration file Content Description:
default=: Select the kernel or system of the title configuration, each title is numbered starting from 0
timeout=#: The timeout of the menu display is long;
Splashimage=/path/to/some_image_file: Specifies the background image of the menu; This image can only be 14bits color, xpm format, gzip compression;
Hiddenmenu: Hide Menu
Title: The caption displayed in the menu
Root (hd0,0): Specify Mount Drive letter
kernel/vmlinuz-2.6.32-504.12.2.el6.x86_64 ro root=/dev/sda2 selinux=0 init=/bin/bas: Specifies the kernel file and mount mode,
INITRD/INITRAMFS-2.6.32-504.12.2.EL6.X86_64.IMG: Specify RAMDisk file
GRUB Protection mechanism:
Generate Password: grub-md5-crypt
To protect editing functions such as (entering single-user mode and command-line mode), you need to add beyond the title: password--md5 password string
Protect the use of a kernel, you need to add the kernel corresponding to the title, password--md5 cipher string
How to install Grub: using the Grub-install command,
Installation mode one, installed on the current hard drive for example: GRUB-INSTALL/DEV/SDA
Installation mode Two, the second disk to add grub Common options:--root-directory=path, the path must be the kernel and the initrd file in the boot parent directory, for example: In/mnt/boot, the specified directory is/mnt, Mount Mode: Grub-install--root-directory=/mnt/dev/sdb
Summary start-up sequence: POST-and boot order (BIOS)--BootLoader (MBR)--kernel + ramdisk (temporary root)--root toggle (ROOTFS)--/sbin/init (with File)
Profile: Set default Run Level--Specify system initialization script for system initialization--start service (shutdown service) (/ETC/RC.D/RC#.D,/etc/rc.d/init.d/)-/etc/rc.d/rc.local --Set the function of the Ctrlaltdel combination--start terminal (Mingetty), and attach the login program (login) to the terminal and if the level is 5, start the X server
Nsswitch: Check if the user account no exists, resolve it to Uid;nsswitch is a library file, not a service: in/usr/lib64/libnss*,/lib64/libnss*
Pam:pluggable authentication module, user authentication, library (API):/lib64/security/*
Grub:grand Unified Bootloader, (Stage1, Stage1_5, Stage2)
Linux kernel: Single core, modular, kernel component:/boot/vmlinuz-version,/lib/modules/version/*.ko (Kernel object)
Kernel module Management: lsmod: Show kernel loaded module
Dynamic Loading module: unload: Modprobe-r mod_name or Rmmod mod_name, load: modprobe mod_name or Insmod/path/to/module_file, with Insmod the full path of the module must be indicated.
View module Details: Modinfo mod_name. Field Description: Depends display dependent module
command to check and generate inter-module dependencies: Depmod
Bash programming Function: callable: Where the function name appears, it is automatically replaced with the function body;
return value of function: return value of function execution Result: Code output ECHO, print, result returned after command execution
Execution status return value: The last command state result executed in the function body, the return value of the custom function execution state: return
Functions can accept parameters: Call function arguments in the body of the function: Positional parameters ($, $2,$#, $*, [email protected])