Linux system boot boot process and service control

Source: Internet
Author: User

Just getting started the little friends are still confusing the system from the moment we press the power button, is how to carry out step by step, know that we enter the user name and password into the system to operate the computer, today we will write about the boot process and related services control.

A System Boot Process:

1. Power-on, BIOS-to-hardware power-on self-test

   加电自检,检测硬件设备,这是因为BIOS中包含了CPU的相关信息、设备启动顺序信息、硬盘信息、内存信息、时钟信息、PnP特性等等

2. Check boot order, boot from hard disk, read MBR (446 bytes)

   硬盘上第0Record,即主引导记录,它的大小是512字节,主引导程序的任务就是查找并且加载处在硬盘分区上的次引导程序。通过分区表查找活动分区,并将处在活动分区的次引导加载程序读取到内存里面运行。

3. Read the boot of Grub

 The primary function of the boot loader is to load the Linux kernel, and the secondary boot program (boot loader) will boot the operating system. When the machine boots its operating system, the BIOS reads the front 512  bytes (master boot record,mbr) on the boot media. Only one operating system's boot record can be stored in a single MBR, so when multiple operating systems are required, problems can occur, so a more flexible boot loader secondary boot loader will run in memory. The system reads the GRUB configuration information in memory (typically Menu.lst  or Grub.lst ) The Grub graphical interface will appear, allowing the user to choose what kernel to load and start different operating systems according to this configuration information. 
    如何查看你MBR的内容,那么你可以使用以下命令来查看:[[email protected] ~]# dd if=/dev/sda of=mbr.bin bs=512 count=1   #此处的/dev/sda为你的硬盘的类型,本次我们使用的为scsi,表示为/dev/sda 1+0in1+0out512 bytes (5120.0002801891.8 MB/s[[email protected] ~]# od -xa mbr.bin  #此处必须root身份运行的dd命令,读取你的第一个集成电子驱动器或者IDE驱动器的前512字节,并将他们写入mbr.bim文件.od命令则是以十六进制和ASCII码形式打印出这个二进制文件

4. Load kernel files (/boot directory)

 用户选择要加载的内核之后,次引导加载程序(GRUB)就会根据/boot/grub.conf配置文件中所设置的信息,从/boot/所在的分区上读取Linux内核映像,然后把内核映像加载到内存中并把控制权交给Linux内核。

5. Running the init process is always the first process

    • A. Reading the/etc/inittab configuration file
内核被加载后,第一个运行的程序便是/sbin/init(变成一个用户进程),该程序会读取/etc/inittab配置文件,init根据/etc/inittab配置文件来执行相应的脚本进行系统初始化,如设置键盘、字体,装载模块,设置网络等.其实/etc/inittab文件最主要的作用就是设定Linux的运行等级。
"Operating level settings under Linux:"0-Halt ( Do  not SetInitdefault toThis#关机1- SingleUser mode#单用户模式2-Multiuser, without NFS (the same as 3,ifYou Do  notHave networking)#字符界面, multi-user, no network mode3-Full multiuser mode#字符界面, multi-user mode4-Unused#保留, not used for the time being5-X11#图形界面, multi-user mode6-Reboot ( Do  not SetInitdefault toThis#重新启动

The setup form is ": Id:3:initdefault:", indicating that Linux is running on level 3

    • B. Do the system initialization/etc/rc.d/rc.sysinit
    在设定了运行等级后,Linux系统执行的第一个用户层文件就是/etc/rc.d/rc.sysinit脚本程序,它做的工作非常多,包括设定PATH、设定网络配置(/etc/sysconfig/network)、启动swap分区、设定/proc等等。
    • C. Control which programs and services are started/ETC/RC.D/RC, depending on the RunLevel, execute the corresponding run script according to the current runlevel.
    根据运行级别的不同,系统会运行rc0.d到rc6.d中的相应的脚本程序,来完成相应的初始化工作和启动相应的服务
    • D. Finally run a script/etc/rc.d/rc.local (let the administrator customize the start command)
    rc.local配置文件就是在一切初始化工作后,Linux留给用户进行个性化的地方,你可以进行一些开机加载的自定义设置,只限制于当前登录的用的个人设置。
    • E. Execute/bin/login program and enter login status
    到了加载此步骤的时候,那么系统已经运行到提醒用户进行用户名和密码输入登陆系统的过程了,到此为止,那么一系列的从你把主机的电源打开一直到你输入用户名和密码登陆系统之间全部启动过程。

Two Control and optimization of services:

    • Classification of services:
Category Characteristics
Services that run independently Fast response, but with more system resources
Services that rely on the XINETD service to run Slower response, but less resources
    • System Service Control

1. Common ways:

    - service  服务名称  控制类型    /etc/rc.d/init.d服务名称  控制类型    [root@localhost ~]# /etc/init.d/vsftpd status    vsftpd is stopped    [root@localhost ~]# service vsftpd start    Startingforvsftpd:                                [  OK  ]

2. control type

         - start:启动          - stop:停止          - restart:重新启动          - reload:重新加载          - status:查看服务状态
    • Operating level of the Linux system

1. View Run Level

[root@localhost ~]# runlevel 53使用runlevel命令,分别显示:5:切换前的运行级别、3:当前运行级别

2. Temporarily switch the run level

[root@localhost ~]# init 5[root@localhost ~]# runlevel 35使用init命令结合0-6运行级别参数
    • Optimizing the startup process
      1. System Services Administration Tools
      A) NTSYSV tools
特点:    提供一个交互式、可视化窗口    可以在字符终端运行    便于集中管理多个服务
用法:    ntsysv  --level  级别列表[[email protected]~]#ntsysv--level3  #此处表示以级别3设置所有服务
    • b) Chkconfig Tools
特点:    不提供交互式、可视化窗口    管理单个服务效率更高
Usage: View the startup status format of the system service: Chkconfig--list service Name [root@localhost~]# chkconfig--list vsftpd #查看vsftpd服务开机是否启动Vsftpd0:off   1:off   2:off   3:if   4:off   5:off   6:off   #此处的6个状态就是linux的运行状态 "off means not starting on means start"----------Set the Startup status format for system services: Chkconfig--level level list service name on|off[Root@localhost~]# chkconfig--level 3 vsftpd on[Root@localhost~]# chkconfig--list vsftpdVsftpd0:off   1:off   2:off   3: on    4:off   5:off   6:off----------Service Script Location:/etc/init.d----"/ETC/RC.D/INIT.D

To this end, whether the small partner understands how the system is started and the order in which the required configuration files are loaded at startup, is what we need to be in the IT line to start the system. Mastering this startup process, we can analyze and solve problems based on the boot order when the system is faulty.

Linux system boot boot process and service control

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.