Linux system start-up process and do a little Linux

Source: Internet
Author: User

The role of the kernel
Process Management: inter-process switching
Memory Management: Memory space split into kernel space and user space
IO Management: The use of the underlying hardware must be implemented from within, not by the user-space process to implement
File System Management
Driver Management
Security management: including NetFilter module and SELinux module, etc.

Design pattern of the kernel
Single Core: modules are integrated within the kernel (Linux is a single core)
Microkernel: Modules are standalone, with load (Windows is a microkernel)
Ps:1.linux is a single core, but the design idea of micro-core is widely adopted.
2. Kernel modules are closely related to the kernel, once the kernel is changed, all the modules can no longer be used

Single thread: Only one execution flow
Multithreading: There are multiple execution flows

Boost Program Execution speed
1, must seek multi-threaded development mode
2. The running host must have multiple or multi-core CPUs

START Process
1. POST (Power on and self test): power-on- test
Check that your hardware is working properly
The BIOS program in the CMOS is loaded into the CPU to detect the hardware, and then the system kernel is found on the specified device according to the set boot order.

BIOS basic functions (very important)
1. Check the hardware
2. Get hardware Information
3. Specify the boot order (bootsquence)

2. Find the kernel
"The file system cannot be used directly because there is no kernel, so the file system deleted kernel file cannot be found"
Mbr
446:bootloader, find kernel on file system "bootloader specifies how to load the kernel"
64: Partition Table
2: Magic number
Load kernel steps (important)
1) Find the MBR (bootloader) on the specified device
2) Load kernel files (vmlinuz-xxx) according to bootloader guidelines
3) The boot partition is then used as the root partition to obtain basic information about the system (hardware, software)
PS: Because the bootloader can execute the system load kernel, therefore, the kernel is located in the partition must be a special partition, this partition can not be accessed by the file system, the partition name is:/boot
partitions in the system (the first partition must be boot)


/: Root partition (above 5G)
/boot: Boot partition boot
"When manually partitioning, the first point must be the boot partition"
/proc:

/sys: Pseudo File system partition

/swap: Swap partition




Kernel (kernel)
Source: kernel.org
Binary:/boot/vmlinuz-xxx (compressed storage, support self-extracting)
Binary Benefits:
Save memory and storage space
Improve IO

3. Start the user space process


Start user space process:/sbin/init
1) by the file system function in the kernel to find and execute/sbin/init, will produce a process with ID 1, the process name is init
2) init generates user space

Load Driver
"It's impossible to load all the drivers into the kernel"
When installing Linux, the final step is to execute a script that collects basic information about the system, hardware, software, drivers, and compresses the information into a single file, called the initrd-version number in centos5.x. img;centos6.x is called initramfs-version number. img

So when the kernel is loaded into memory, it will be loaded into memory with INITRD/INITRAMFS, and INITRD will be expanded in memory to use the kernel space in memory as the root partition, where there is a driver that the current system is requesting to use.

The root generated by INITRD is also a virtual root, which switches to the real root after the user space is started


chroot command
Role: Toggle Root

PS: Summary start-up process
Post-->bios (bootsequence)-->mbr (bootlader)-->vmlnuz,initrd (INITRAMFS)-->/sbin/init (/etc/inittab)

Introduction to/etc/inittab

Program:/sbin/init
Configuration file:/etc/inittab (Vim/etc/inittab)
Linux run level (mode)
0-halt (do not set Initdefault to this) (shutdown)
1-single user mode (usually used to repair the system)
2-multiuser, without NFS (the same as 3, if you don't have networking) (to resolve a system boot exception due to network non-conduction)
3-full multiuser mode (multi-user modes at the character level)
4-unused (System hold function)
5-x11 (graphical interface, if graphical interface must be installed)
6-reboot (do not set Initdefault to this) (restart)

* View Level
# RunLevel
Return: N 3
N: Indicates no switching level
Toggle Level
# init N

Inittab detailed
Format:
Id:level:action:process

Introduction to Action
Initdefault: Setting the default Level
Sysinit: Specifies the script to be executed during system initialization
Wait: waits for the operation to be performed at a specified level
Ctrlaltdel: Sets the action triggered when the user presses CTRL + ALT + DEL
Powerfail: Sets the action to be taken when a power loss occurs
Respawn: Specify terminal

A program that starts or shuts down at a specified level during Linux system startup
Where to store the program:/ETC/INIT.D
After the program joins the system service, the connection file is automatically generated
# chkconfig--add Toe
program's link file location:/etc/rc.d/rcn.d
/etc/rc0.d
/etc/rc1.d
/etc/rc2.d
/etc/rc3.d
/etc/rc6.d
Seven operating levels corresponding to the system, respectively

When the system starts, the level is judged first (assuming a level of 3)
After judging the level, the program starting with all s starts under/ETC/RCN.D, all programs that begin with K are closed

Attention:
Once a program is added to the system service, the linked file is automatically created under/ETC/RCN.D
Grub Boot system starts up in three stages
Stage1: In fact, using the bootloader in the MBR to complete the kernel retrieval
stage1.5: In the boot partition, used to identify the file system, this stage is only useful when partitioning
Stage2: Use the program in the/boot/grub/grub.conf to complete the final boot of the system

Grub.conf Detailed (vim/boot/grub/grub.conf)

Default=0 #指定默认使用哪个内核文件, 0 represents the first
Timeout=5 #设置开机等待时间 (try to change it yourself)
Splashimage= (hd0,0)/grub/splash.xpm.gz #开机背景图片, can also be modified but the format of the photo must be the same as the system
Hiddenmenu #隐藏菜单
Title CentOS (2.6.32-431.el6.x86_64) #开机提示信息
Root (hd0,0) #指定内核文件所在分区, this represents the first partition of the first disk
kernel/vmlinuz-2.6.32-431.el6.x86_64 (Specify kernel) ro root=/dev/mapper/vg_chenxiaoxu-lv_root rd_lvm_lv=vg_chenxiaoxu/lv_ Swap Rd_no_luks rd_no_md Crashkernel=auto lang=zh_cn. UTF-8 (Specify language) rd_lvm_lv=vg_chenxiaoxu/lv_root (specify root partition location) keyboardtype=pc keytable=us rd_no_dm rhgb quiet
Initrd/initramfs-2.6.32-431.el6.x86_64.img


Basic use of grub (forget the Linux password can be modified)
1. Enter the Grub interface: Press ENTER during wait time
The available commands
E: Enter the editing interface (actually edit/boot/grub/grub.conf)
A: Editing kernel features
C: Enter command line mode
2. Enter edit mode
E: Enter edit mode
C: Ibid.
B: Boot to enter the system
O: Add a new line
D: Delete
3, edit kernel line
"Modify this row to set the operating mode of the system"
After the original content, write a 1, enter single-user mode, and then return to the grub.conf edit interface
Press B to start booting into the system
4. Set the password for grub
Modify grub.conf to add a field passwd
The way is:
Add a line above title
Password 123
Note: It is not safe to add the plaintext password, so look underneath.

5. Set the encrypted password to grub
1) generate an encrypted password

2) Add the password to the/boot/grub/grub.conf
Password--md5 $1$4ixmm$uxtahohwyyqtdtdlk/9no/

--MD5: Is the specified encryption method large called MD5 encryption
Installing grub on a new disk

(premise: To add a new disk size of 1G, you must use a single file as a disk file, save this file to a place that is easy to find,

1) This new disk must be partitioned in advance
2) This new disk must be mounted to a directory on the system


There are two ways to install
The first way: Grub-install to install
Second way: Install in grub mode

Mode Two: Grub mode installation
# Grub
Grub >
Break the first stage of grub
Bootloader (MBR-446)
# dd If=/dev/zero OF=/DEV/SDA bs=1 count=1 (Bubble machine)
Fix the first stage of grub
1) Enter Grub mode
# Grub
2) test the number of the root partition
# root (hd#,#) PS: Here The hd# is the disk number, #是分区编号
Message appears: FileSystem type unkown indicates that the partition is not the boot location
3) Install GRUB on the same disk as the root partition (bootloader)
To install the GRUB format:
Grub > Setup (hd#) ps:hd# indicates that grub is installed on the specified disk

Mode one: Grub-install mode installation
Format: Grub-install--root-directory= path
Note: This path refers to the partition where the boot is located
1) Partitioning operations
Partition
Formatting
Mount
# Mount/dev/sdb1/media
2) Install Grub
# Gurb-install--root-directory=/media/dev/sdb

module-related commands
Lsmod
Module names that have been loaded and dependent modules
Modinfo
Format: Modinfo module name
Function: Displays a mo detailed information
Depends: The module on which the module depends
FileName: Where to save the module
Description: Description information of the module
Modprobe
Format: Modprobe module name
Function: Dynamic Loading module

MODPROBE-R Module Name: Unload module

Insmod
Format: insmod/patt/to/module name
Function: Load Module

Rmmod
Format: Rmmod module name
Function: Unload module


Example: viewing display floppy module information

View the trust information of the module
# Modinfo Floppy

See if the module has been loaded
# Lsmod | grep floppy
Floppy 61447 0

Uninstalling this module
# Modprobe-r Floppy
# Lsmod | grep floppy

Reload This module
# modprobe Floppy
# Lsmod | grep floppy
Floppy 61447 0



Prepare a new disk
Installing GRUB
Write a grub.conf
Porting several common commands to this disk LS CD mkdir ...



Make a simple Linux
1. Add a hard drive and create two partitions
1) Create a partition
/dev/sdb1->200m
/deb/sdb2->xx
2) Mount Partition
SDB1-/media/boot
SDB2-/media/sysroot

2. Install grub on the hard drive
# Grub-install--root-directory=/media/boot/dev/sdb

3. Transplant kernel and INITRD

4. Necessary directory for creating the system
    bin
    sbin
    etc/rc.d
     var
    usr
    tmp
    home
     Root
    proc
    sys
    meida
    MNT
    lib
    lib64
   
5, porting system commands
     Bash
    Mount
    cd
    ls
    CP br>    mkdir
    rm
    Touch
   
6, Create a software link to bash sh

7. Generating the Grub configuration file
Default=0
timeout=10
Title My mini Linux
Root (hd0,0)
Kernel/vmlinuz ro root=/dev/sda2 Quiet selinux=0 init=/bin/bash
Initrd/initramfs.img

8. Create an init program to complete the system initialization
1) Create Init
#!/bin/bash
Echo-e "Wellcome to Linux \033[32m zxhk \033[0m"
# mount-n-T proc Proc/proc
Mount-n-T Sysfs Sysfs/sys
Mount-n-O remount,rw/dev/sda2/
/bin/bash
2) Give execution permission

3) Modify grub.conf

9, Import network function module
    1) Import command
   
    2) porting the NIC module
         # cp ' Modinfo e1000 | head-n1 | awk ' {print $} '/media/sysroot/lib/

3) Modify init to load the NIC module
#!/bin/bash
Echo-e "Wellcome to Linux \033[32m zxhk \033[0m"
# mount-n-T proc Proc/proc
Mount-n-T Sysfs Sysfs/sys
Insmod/lib/e1000.ko
Ifconfig eth0 10.100.0.112 netmask 255.255.0.0
Ifconfig lo 127.0.0.1 netmask 255.0.0.0
Mount-n-O remount,rw/dev/sda2/
/bin/bash

Author: Xiaoxiang Rain Wrong

Linux system start-up process and do a little Linux

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.