system boot and kernel management

Source: Internet
Author: User
Tags echo command network function

system boot and kernel management


CentOS 5 and 6 start-up process

Service Management

Grub Management

Homemade Linux

Start debugging

Compiling the installation kernel


Linux composition


Linux:kernel+rootfs

Kernel

Process Management,

Memory Management,

Network Management,

Drivers,

File System,

Security features

ROOTFS: Programs and GLIBC

Libraries: function sets, functions, calling interfaces (header file is responsible for description)

Procedure call: Procedure, no return value

Function call: Functions program: Binary Execution file

Kernel design Genre:

Single core (monolithic kernel): Linux integrates all functions into the same program

Micro-core (micro kernel): Windows, Solaris each feature is implemented using a separate subsystem



Linux kernel Features: support modularity:. KO (Kernel object)

Such as: File system, hardware driver, network protocol support dynamic loading and unloading of kernel modules

Part:

Core files:/boot/vmlinuz-version-release RAMDisk:

Auxiliary pseudo-Root system

CentOS 5:/boot/initrd-version-release.img

centos6,7:/boot/initramfs-version-release.img

Module file:/lib/modules/version-release



CENTOS6 START Process


1. Load the BIOS hardware information to get the first boot device.

2. Read the boot loader (grub) information for the first boot device MBR

3. Load core operating system information, the core begins to decompress, and attempts to drive all hardware devices.

4. The kernel executes the INIT program and obtains the running information.

5.Init execute the/etc/rc.d/rc.sysinit file.

6. Launch the core plug-in module (/etc/modprobe.conf).

7.Init execution of individual batch files (scripts).

8.Init execution/etc/rc.d/rc.local.

9. Execute the/bin/login program and wait for the user to log in.

10. Start with the Shell to control the host after logging in.


Start process


Post:power-on-self-test, power-on self-test, is a major part of the BIOS function. Responsible for the CPU, motherboard, memory, hard disk subsystem, display subsystem, serial parallel interface, keyboard, CD-ROM drive and other hardware conditions detection. The Rom:bios,basic input and output system holds the most important basic input and output programs for computer systems, System Information settings, power-on and self-test programs, and system startup bootstrap programs. Ram:cmos complementary Metal oxide Semiconductor, save the parameters of the settings in order to find the boot device, the first device with a boot program for this boot device


Bootloader: bootloader, boot loader

Windows:ntloader, just start the OS

Linux: Feature rich, provide menus that allow users to choose which system to boot or different kernel versions, load the user-selected kernel into a specific space in memory, unzip, expand, and transfer control of the system to the kernel

Lilo:linux LOader

Grub:grand Unified Bootloader

GRUB 0.x:grub Legacy, GRUB2


Mbr:446:bootloader, 64: Partition table, 2:55AA

Grub:primary boot loader:1st stage,1.5 stage secondary boot loader:2nd stage, partition file

Kernel

Self-initialization:

Detect all hardware devices that can be identified

Load the hardware driver (possibly with RAMDisk load driver)

Mount the root file system as read-only

The first application running user space:/sbin/init


Types of init programs:

Sysv:init, before CentOS 5

Configuration file:/etc/inittab

Upstart:init,centos 6

Configuration files:/etc/inittab,/etc/init/*.conf

SYSTEMD:SYSTEMD, CentOS 7

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


RAMDisk

One of the attributes in the kernel: use buffering and caching to speed up file access on disk

RAMDisk-Ramfs Increase speed

CentOS 5:INITRD, tool program: MKINITRD

CentOS 6:initramfs, utility program: MKINITRD, Dracut

System initialization: POST--Bootsequence (BIOS)--Bootloader (MBR)--Kernel (ramdisk)--ROOTFS (read-only) init (SYSTEMD)



/sbin/init CentOS 5

Operating level: Set for the purpose of operation or maintenance of the system; 0-6:7 Levels

0: Turn off the machine

1: Single user mode (root automatic login), one, maintenance mode

2: Multi-user mode, start the network function, but do not start NFS; Maintenance mode

3: Multi-user mode, normal mode, text interface

4: Reserved level, can be same as 3 level

5: Multi-user mode, Normal mode, graphical interface

6: Restart

Default Level: 3, 5 Toggle level: Init #

viewing level: RunLevel; Who-r


Init initialization


Init reads its initialization file:/etc/inittab

Initial runlevel (Run level)

System initialization Scripts

Script directory corresponding to run level

Capturing a keyword order

Define UPS Power terminal/recovery scripts

Generate Getty in Virtual Console

Initialize x at run Level 5


CentOS5 's Inittab file


Configuration file:/etc/inittab

Each row defines an action and the process that corresponds to it

Id:runlevel:action:process Action:

Wait: Switch to this level to run once;

Respawn: This process terminates and the restart is

Initdefault: Setting the default runlevel; process omitted

Sysinit: Sets the system initialization mode, which is typically specified here

/etc/rc.d/rc.sysinit

Ca::ctrlaltdel:/sbin/shutdown-t3-r now

Id:3:initdefault:

Si::sysinit:/etc/rc.d/rc.sysinit

L0:0:WAIT:/ETC/RC.D/RC 0

L1:1:WAIT:/ETC/RC.D/RC 1 ...

L6:6:WAIT:/ETC/RC.D/RC 6



Centos6/etc/inittab and related documents


/etc/inittab

Set the system default run level

Id:3:initdefault:

/etc/init/control-alt-delete.conf

/etc/init/tty.conf

/etc/init/start-ttys.conf

/etc/init/rc.conf

/etc/init/prefdm.conf



User space Initiation Process


/etc/rc.d/rc.sysinit: System Initialization script

(1) Set host name

(2) Setting welcome information

(3) Activate Udev and SELinux

(4) Mount the file system defined in the/etc/fstab file

(5) Detecting the root file system and re-mounting the root filesystem in read and write mode

(6) Setting the system clock

(7) Activate swap device

(8) Set kernel parameters according to/etc/sysctl.conf file

(9) Activating LVM and software RAID devices

(10) Loading drivers for additional devices

(11) Cleaning operation




Description: RC N--and means read/etc/rc.d/rcn.d/

k*: k##*:# #运行次序; The smaller the number, the more it runs; the smaller the number of services, usually dependent on other services

s*: s##*:# #运行次序; The smaller the number, the more first it runs; the smaller the number of services, usually the services that are dependent on


for SRV in/etc/rc.d/rcn.d/k*; Do

$srv stop

Done for


SRV in/etc/rc.d/rcn.d/s*; Do

$srv start

Done



Chkconfig command



Chkconfig command

To view the startup or shutdown settings for a service at all levels:


Chkconfig [--list] [name]

Add to:

SYSV service scripts are placed in/ETC/RC.D/INIT.D (/ETC/INIT.D)

Chkconfig--add Name

#!/bin/bash

#LLLL indicates the initial level at which to start,-indicates that neither is started

# chkconfig:llll nn nn

Delete:

Chkconfig--del name modifies the specified link type

Chkconfig [--level levels] name <on|off|reset>

--level llll: Specifies the level to be set; 2345 is omitted

NTSYSV command



Services managed by xinetd



Service command:

Manually Manage service Services service Start|stop|restart

Service--status-all

Transient state

(Transient) service is managed by the XINETD process

The incoming request was first XINETD agent

Configuration files:/etc/xinetd.conf,/etc/xinetd.d/<service>

Links with libwrap.so file

Services with Chkconfig control:

Chkconfig TFTP on



Crack root Password



Summary:/sbin/init----(/etc/inittab)--Set the default run level--run the system initial script, complete system initialization--(Close the service you need to shut down) boot needs to start service--Set the login terminal

The CentOS 6 init program is: Upstart, its profile:/etc/inittab,/etc/init/*.conf, configuration file syntax follows upstart configuration file syntax format, and CentOS5 different



Grub Legacy


CentOS 6 startup process: POST-to-boot Sequence (BIOS)--Boot Loader-Kernel (RAMDisk)--Rootfs-- >/sbin/init (/etc/inittab,/etc/init/*.conf)--Set default run level--system initialization script Rc.sysinit-off or start the corresponding level of service--> ; Start the terminal


Grub:grand Unified Bootloader

Grub 0.x:grub Legacy

Grub 1.X:GRUB2

Grub Legacy:

Stage1:mbr

STAGE1_5:MBR sector, allowing bootloader in Stage1 to identify the filesystem on the partition where the stage2 resides

Stage2: Disk partition (/boot/grub/)



Configuration files:/boot/grub/grub.conf <--/etc/grub.conf stage2 and kernels are typically placed on a basic disk partition


Function:

(1) Provides a boot menu, and provides an interactive interface

A: Kernel parameters

E: Edit mode, for editing menus

C: Command mode, interactive interface

(2) Loading the user-selected kernel or operating system

Allow parameters to be passed to the kernel

To hide the boot menu

(3) provides a protection mechanism for the menu

To certify the Edit boot menu

To enable authentication for the kernel or operating system



Identify the hard drive device:

(hd#,#)

hd#: Disk number, expressed as a number; numbering starting from 0

#: Partition number, expressed in numbers; Numbering starting from 0

(hd0,0) First hard disk, first partition

To start the system manually on the GRUB command line interface:

grub> Root (hd#,#)

grub> kernel/vmlinuz-version-release ro Root=/dev/device

Grub> initrd/initramfs-version-release.img

grub> Boot



Configuration file:/boot/grub/grub.conf


default=#: Sets the default Startup menu item, and the entry (title) number starts at 0

timeout=#: Specifies the duration of the menu item Wait option selection

Splashimage= (hd#,#)/path/to/xpm_file: Menu background picture file path

Hiddenmenu: Hide menu Password [--md5] STRING: Start Menu Edit Authentication

Title Title: Defines the menu item "caption", which can appear multiple times

Root (hd#,#): Grub finds the device partition where the Stage2 and kernel files are located;

Kernel/path/to/vmlinuz_file [PARAMETERS]: Boot kernel

Initrd/path/to/initramfs_file: Kernel-matched Ramfs file

Password [--MD5] STRING: Authentication when starting the selected kernel or operating system



GRUB Encryption


Grub-md5-crypt command

To break the root password:

When you start the system, set its run level 1


Enter single-user mode:

(1) Edit the Grub menu (select the title to edit, then use the e command);

(2) After the selected kernel 1, s, s or single can be added;

(3) In the kernel line, type "B" command



GRUB Installation


To install Grub:


(1) Grub-install

Install Grub Stage1 and stage1_5 to/dev/disk disk and copy grub-related files to the Dir/boot directory

Grub-install--root-directory=dir/dev/disk

(2) Grub

grub> Root (hd#,#)

grub> Setup (hd#)



Self-made Linux system



Partitioning and creating file systems

Fdisk/dev/sdb

Divided into two necessary partitions

/DEV/SDB1 corresponds to/boot/dev/sdb2 corresponding root

/MKFS.EXT4/DEV/SDB1

Mount Boot

Mkdir/mnt/boot

Mount/dev/sdb1/mnt/boot

Installing GRUB

Grub-install--root-directory=/mnt/dev/sdb



Recovering kernel and Initramfs files

cp/boot/vmlinuz-2.6.32-642.el6.x86_64/mnt/boot/

Cp/boot/initramfs-2.6.32-642.el6.x86_64.img/mnt/boot

Create a grub.conf file

Vim/mnt/boot/grub.conf

Kernel/vmlinuz-2.6.32-642.el6.x86_64

Root=/dev/sda2 selinux=0 Init=/bin/bash

Chroot/mnt/sysroot


Create a first-level catalog

Mkdir/mnt/sysroot

Mount/dev/sdb2/mnt/sysroot

Mkdir–pv/mnt/sysroot/{etc,lib,lib64,bin,sbin,tmp,var,usr,sys,proc, Opt,home,root,boot,dev,mnt,media}

Copy bash and related library files


Rescue environment



Required when the root file system is unusable, such as/bin/mount delete

No special requirements for the system

Boot from CD (Boot.iso or install CD # #)

Booting from USB drive (made by Boot.iso)


File system reorganization

Anaconda will ask if the file system should be mounted

/mnt/sysimage/*

/mnt/stage2

$PATH include the directory of the hard disk

File system Nodes

Provide system-specific device files

Mknod Understanding Major/minor # ' s


System configuration file Missing repair



During booting, it is important for the INIT process to read its configuration file/etc/inittab, start the System Basic service program and the default operating level of the service program to complete the system boot, if/etc/inittab mistakenly delete or modify the error, Linux will not start properly. At this point, only through rescue mode can solve such problems.


Reply Method with backup file

Recovery method with no backup files


Backup File Recovery method: Enter rescue mode, after the execution of the chroot command, if there is a backup of this file (it is strongly recommended that the system of important data directories, such as/etc,/boot, etc. to be backed up), directly copy the backup files back, quit the restart. If it is a configuration file modification error, such as comparing the typical/boot/grub/grub.conf and/etc/passwd file modification errors, you can also directly fix the recovery. If you have a backup file/etc/inittab.bak, execute it in rescue mode:

sh-3.1# Chroot/mnt/sysimage

sh-3.1# Cp/etc/inittab.bak/etc/inittab



Recovery method without backup files if some of the configuration files are missing or the software is mistakenly deleted, and no backup can be restored by reinstalling the package, first find out which RPM package/etc/inittab belongs to

# Chroot/mnt/sysimage

# Rpm-qf/etc/inittab Initscripts-9.03.49-1.el6.centos.x86_64

Exit Chroot Mode:

# exit

Mount the installation disc that holds the RPM package (in rescue mode, the disc is usually mounted in the/mnt/source directory):


# Mount/dev/sr0/mnt/source CENTOS6 system rpm packages are stored in the CD package directory, in addition, because the root directory of the hard disk system to be repaired under/mnt/sysimage, you need to use the-root option to specify its location. Overwrite the RPM package where the/etc/inittab file is installed:

# RPM-IVH--replacepkgs | force/mnt/source/packages/initscripts-9.03.49-1.el6.centos.x86_64.rpm where the rpm command option "--replacepkgs" means overwrite the installation, after execution completes, The file has been restored.



If you want to extract only the/etc/inittab files in the RPM package for recovery, you can execute the command after entering rescue mode:

# rpm2cpio/mnt/source/packages/initscripts-9.03.491.el6.centos.x86_64.rpm| Cpio-idv./etc/inittab


# CP etc/inittab/mnt/sysimage/etc Note When this command executes, the file cannot be restored directly to the/etc directory, but only to the current directory, and the path where the recovered file name is located is written in full. Once the file is extracted successfully, copy it to the location in the/mnt/sysimage directory where the root partition is located.




Kernel compilation


Single kernel system design, but fully learn the advantages of micro-core design system for the kernel to introduce a modular mechanism.


Kernel components:

Kernel: Kernel core, generally bzimage, usually in the/boot directory, the name is vmlinuz-version-release;


Kernel object: Kernel objects, typically placed in

/lib/modules/version-release/

[]: N

[m]: M

[*]: Y

Auxiliary files: RAMDisk

Initrd

Initramfs



Kernel version


In-run kernel:

uname command:

Uname-print System Information

uname [OPTION] ...

-N: Displays the node name;

-R: Display version-release;

-A: Show All information



Kernel module commands



Lsmod command: Displays kernel modules already loaded by the core

The content displayed is from:/proc/modules file

Modinfo command: Displays detailed description information for the module

Modinfo [-K kernel] [modulename|filename ...]

-N: Show only module file path

-P: Display module parameters

-a:author

-d:description

-l:license

Lsmod |grep Xfs;modinfo XFS



Kernel module Management



modprobe command:

Loading or unloading kernel modules

modprobe [-C Config-file] [modulename] [module parame-ters ...]


Configuration file:

/etc/modprobe.conf,

/etc/modprobe.d/*.conf


modprobe [-r] ModuleName ...



Depmod command: Kernel module dependency file and System Information mapping file Generation tool

To mount or unload a kernel module:


Insmod command: Specifies the module file, does not automatically resolve the dependent module

insmod [filename] [module Options ...]

Insmod ' Modinfo–n exportfs '

Lnsmod ' Modinfo–n xfs '


Rmmod

Rmmod [ModuleName]

Rmmod XFS

Rmmod Exportfs



/proc Directory



/proc directory: The kernel uses its own internal state information and statistics, as well as configurable parameters to output parameters through the proc pseudo-file system: Read-only: Output information writable: Acceptable user-specified "new value" to configure a function or feature of the kernel


/proc/sys

(1) The SYSCTL command is used to view or set many parameters in this directory

Sysctl-w Path.to.parameter=value

Sysctl-w kernel.hostname=mail.magedu.com

(2) The echo command can also modify the values of most parameters by means of redirection

echo "VALUE" >/proc/sys/path/to/parameter

echo "Websrv" >/proc/sys/kernel/hostname


system boot and kernel management

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.