Linux Start-up process

Source: Internet
Author: User
Tags crypt network function

CENTOS6 Start-up process

Analytical:

CENTOS6 START Process:

1, POST: power-on self-test, hardware environment (. Load BIOS hardware information to get the first boot device)
2, Grub 1 First 446 bytes (read boot loader (GRUB) of the first boot device MBR)
3, GRUB 1.5 load/boot partition file system (core operating system load core information, the core began to decompress, and try to drive all the hardware devices)
4. Grub 2/boot/grub/grub.conf defines the kernel file (core execution init program, and obtains the default running information)
5. Vmlinuz Load//boot/initramfs.xxx (version number). IMG (init program execution/etc/rc.d/rc.sysinit file)
6,/sbin/init/etc/inittab id:3: (. Boot core plug-in module)
7. rc.sysinit (each batch file (scripts) that the Init executes runs on)
8,/etc/rc3.d/s,kxxx---/etc/init.d/xxx (init execution/etc/rc.d/rc.local)
chkconfig--level N service on off
9,/ETC/RC/LOCL (Execute/bin/login program, waiting for user login)
10. Login (start with Shell to control the host after login)

1. POST

power-on-self-test: Power-on self-test is a major part of the BIOS function. Responsible for the completion of CPU, motherboard, memory, hard disk subsystem, display subsystem and other hardware conditions detection.

BIOS: Basic input and output system, which holds the most important basic inputs and outputs of computer systems, System Information settings, power-on and self-test programs, and system startup bootstrap programs.

CMOS: Save the motherboard setup time and other parameters, rely on the motherboard of the CMOS button battery.

2, BootLoader

The boot loader, Windows uses the bootloader is Ntloader, can only boot Windows system, Linux uses bootloader early have Lilo (Linux LOader), The GRUB0.97 version of the 6 series is now available in the 7 series using GRUB2.

3. GRUB

Grub consists of three phases:

    1. 1th stage: Stored in the first 446 bytes of MBR
    2. Stage 1.5: Phase 1.5 is stored in 1-27 sectors; Because the GRUB1 stage needs to read the GRUB2 phase of the program and configuration files, but the GRUB2 phase of the program is stored in the disk/boot partition, you want to read the files in the partition must have a drive file system driver module, The 1.5 stage is to do this thing.
    3. 2nd stage: On the disk-enabled/boot partition (/boot/grub/), select the kernel version interface at startup, and the configuration file is responsible for phase 2nd.

Function:

    1. Provides a boot menu, and provides an interactive interface
    2. Load the user-selected kernel or operating system
    3. Provides a protection mechanism for menus

Grub configuration file (/boot/grub/grub.cfg)

Default=0  #默认titletimeout =5 #grub菜单选择超时时间splashimage = (hd0,0)/grub/splash.xpm.gz #grub菜单背景图片hiddenmenu # Hide Grub Selection Menu Password--md5 | ----Encrypted  password #加密方式和口令, for GRUB encryption to prevent into the single-user mode change password, password using the following command generated
# grub-md5-crypt  generate MD5 Password # grub-crypt generate sha12 Password
Title Red Hat Enterprise Linux 6 (2.6.32-642.el6.x86_64)        root (hd0,0) #指定的是/boot partition "hd0,0" on the disk represents the first partition        of the first disk kernel/vmlinuz-2.6.32-642.el6.x86_64 ro root=uuid=e1d36be7-5027-4847-9d80-135ac9fb798e Rd_NO_LUKS rd_NO_LVM LANG=en _us. UTF-8 rd_no_md sysfont=latarcyrheb-sun16 crashkernel=auto  keyboardtype=pc keytable=us rd_NO_DM rhgb Quiet # The CmdLine parameter passed to the        kernel  is initrd/initramfs-2.6.32-642.el6.x86_64.img #指定initramfs文件的所在路径, note: (Here the "/" is relative to the/boot partition)

If grub is damaged we can fix it with the following command

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

What to do if the grub configuration is missing:

The command line interface of GRUB is entered at boot time, but the kernel and RAMDisk cannot be found, so we can start the system by manually specifying parameters and paths.

Help: Get assistance list help KEYWORD: Details find (hd#,#)/path/to/somefile:root (hd#,#) Kernel/path/to/kernel_file: Set the kernel file used for this boot Additional support for the CmdLine parameter initrd/path/to/initramfs_file: Set to provide additional files for the selected kernel RAMDisk boot: Boot boot selected kernel

Specify root (refers to the/boot partition), kernel Specify the kernel, initrd specify the RAMDisk file, then boot can start the system, enter the system and re-edit the/boot/grub.cfg file to fix the problem

4, kernel itself initialization
    1. Detect all hardware devices that can be identified
    2. Load the hardware driver (with the help of the RAMDisk load driver)
    3. Mount the root file system as read-only
    4. The first application running user space:/sbin/init
5, RAMDisk

In the 2nd stage of grub, only the/boot partition can be recognized, this time the kernel begins to initialize, after the hardware has been detected to find the root, but there is no driver, so this time need to use RAMDisk to drive the hardware. In the CentOS5 series Chinese pieces named/boot/inird,6 and 7 have been changed to Initramfs.

The Initramfs also provides a root filesystem that includes hardware-driven drivers to mount the real root filesystem with this virtual root file system in the kernel.

The Initramfs file is generated by the current environment when the system is installed.

If this file is damaged we can also use the tool to fix:

# mkinitrd/boot/initramfs-' uname-r '. img ' uname-r ' to re-create RAMDisk file for the kernel currently in use
6. Init initialization

Init program starts the system's first process INIT, which is responsible for creating all service processes after system startup

Types of init programs:

    • Centos5.x:sysv
    • Centos6.x:upstart
    • Centos7.x:systemd

Related files for initialization:

    • /etc/inittab: Define the system default boot level
Id:3:initdefault:
    • /ETC/INIT/CONTROL-ALT-DELETE.CONF: Setting Press CTRL + ALT + Del will restart
Start on control-alt-deleteexec/sbin/shutdown-r now "Control-alt-delete pressed"
    • /etc/init/tty.conf
    • /etc/init/start-ttys.conf
    • /etc/init/rc.conf
    • /etc/init/prefdm.conf
7. System level (centos6.x)
    • 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

Init #: Switch to # level

RunLevel: View the current run level and the previous RunLevel

Example: Entering single-user mode

1) During the boot process see booting ... The countdown Word press the ESC key

2) Press the A key to modify the startup parameters, add 1 after quiet (single user mode)

3) Press ENTER to start, enter the single-user mode, you can directly modify the root password, or you can modify some other service profile errors caused by the system can not enter the normal mode of operation.

8. System initialization script (/etc/rc.d/rc.sysinit)
    1. Set host name
    2. Set Welcome info
    3. Activating Udev and SELinux
    4. Mount the file system defined in the/etc/fstab file
    5. Detects the root file system and re-mounts the root file system in read-write mode
    6. Setting the system clock
    7. Activating swap Devices
    8. Setting kernel parameters According to the/etc/sysctl.conf file
    9. Activating LVM and software RAID devices
    10. Load drivers for additional devices
    11. Cleanup operations
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

Default Level: 3, 5

Toggle Level: Init #

viewing level: RunLevel; Who-r

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

Note: At normal level, the last service s99local is not linked to/etc/rc.d/init.d a service script, but instead points to the/etc/rc.d/rc.local script

Commands that are inconvenient or do not need to be written as service scripts to be placed in the/etc/rc.d/init.d/directory and run automatically when you want to power on, can be placed directly in the/etc/rc.d/rc.local file

/etc/rc.d/rc.local run After you specify a run-level script

Custom modifications can be made according to the situation

GRUB Installation

(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#)

Cat/proc/cmdline Kernel Parameters

GRUB recognizes hard drive devices

(hd#,#)

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

#: partition number, indicated by number; numbering starting from 0

(hd0,0) First hard disk, first partition

Linux Start-up process

Related Article

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.