Linux system startup process

Source: Internet
Author: User

In the following order, we will briefly say the Linux system start-up process, this is for CentOS6

First, POST

First of all, we also call the power-on self-test, when we press the powered on, the motherboard chip will be composed of the first to send a reset command to the CPU after the chipset detects that the power supply is stable after the reset instruction, the CPU will jump to the boot code location in the BIOS; The BIOS first detects whether critical devices, such as internal display, graphics, and so on, are normal.

Second, (BIOS) boot sequence

Boot order: Find the first device that has a boot program, in the order in which it is set in the motherboard.

Third, MBR (Bootloader)

First we need to understand what is MBR,MBR (Mater boot Record), which is the master boot record. Its location is 512 bytes of money in the first sector. Where Bootloader is the first 446 bytes in the 512 bytes, and a program is loaded in the bootloader, bootloader is used to provide a menu that allows the user to select a system to boot or a different kernel version , load the user-selected kernel into a specific space in memory, unzip, expand, and transfer control of the system to the kernel.

We mentioned above that there are 512 bytes in the MBR, where bootloader occupies 446 bytes, 64 bytes are partitioned by the disk, and 2 bytes are the end flags. Where a program is installed in this 446 byte, which we call grub. There are three more stages in grub, and these three phases are also part of the system-initiated steps. We look at the grub file under it with CentOS 6

[[email protected] ~]# ls /boot/grub/ #grub位于boot目录下

device.map grub.conf minix_stage1_5 stage2

e2fs_stage1_5 iso9660_stage1_5 reiserfs_stage1_5 ufs2_stage1_5

fat_stage1_5 jfs_stage1_5 splash.xpm.gz vstafs_stage1_5

ffs_stage1_5 menu.lst stage1 xfs_stage1_5

As above: You can see the Stage1, *_stage1_5, and Stage2 files, which represent the three stages of the Grub boot, respectively.

1, Stage1: Execute bootloader Main program

The first stage is the main program that executes the boot loader, which must be installed in the ScanDisk, or MBR. Because the MBR is too small, the MBR usually installs the minimum program for boot loader and does not have the relevant configuration file for loader installed.

2, *_stage1_5: Link stage1 and stage2 a channel

3, Stage2, main program load configuration file

The third stage is to load all the configuration files and related environment parameter files through the boot loader, of course these configuration files are placed in the/boot/grub directory. There is an important file grub.conf under the/boot/grub directory. Where grub.conf defines a lot of information when the system starts up, as follows:

grub.conf File Contents:
default=: Select the kernel or system of the first few title configuration, each title starts with 0 numbering;
timeout=#: The timeout of the menu display is long;
Splashimage=/path/to/some-image_file: Specify menu background picture, this picture can only be 14bits color, xpm format, gzip compression;
Hiddenmenu: Hide menu;
Tiltle Title SIRING: The caption displayed in the menu;
Root: Specifies the boot partition;
Kernel: Indicates the location of the kernel;
INITRD: Indicates the location of the Initramfs.

[[email protected] ~]# cat /boot/grub/grub.conf

# grub.conf generated by anaconda

#

# Note that you do not have to rerun grub after making changes to this file

# NOTICE: You have a /boot partition. This means that

# all kernel and initrd paths are relative to /boot/, eg.

# root (hd0,0)

# kernel /vmlinuz-version ro root=/dev/mapper/vg0-root

# initrd /initrd-[generic-]version.img

#boot=/dev/sda

default=0

timeout=5

splashimage=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

title CentOS 6 (2.6.32-504.el6.x86_64)

root (hd0,0)

kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=/dev/mapper/vg0-root rd_NO_LUKS rd_NO_DM LANG=en_US.UTF-8 rd_LVM_LV=vg0/swap rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg0/root KEYBOARDTYPE=pc KEYTABLE=us rhgb crashkernel=auto quiet rhgb quiet

initrd /initramfs-2.6.32-504.el6.x86_64.img

Final bootloader loading kernel file

Iv. Kernel+ramdisk


650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" 1297DCFD-6D4A-4C14-8B8D-AFD9F4256CFF "border=" 0 "alt=" 1297DCFD-6D4A-4C14-8B8D-AFD9F4256CFF "src=" http://s3.51cto.com/wyfs02/M00/72/DC/ Wkiol1xu4bfb2inqaadrgo8augo004.jpg "" 618 "height=" 339 "/>

As my system by default, this interface is hidden, we set the grub.conf in this file is hidden by default. When booting up, we press any key to enter this interface. One of these is the functionality that GRUB provides. The specific functions are as follows:

         1, provides menus, and provides interactive interfaces
                 e: Enter edit mode;
                 A: Modify kernel parameters directly;
                 C: Enter command line mode.
            2, select the kernel or system to start
allows you to pass the boot parameters to the kernel;
Select interface can be hidden.

650) this.width=650; "Style=" background-image:none; border-bottom:0px; border-left:0px; padding-left:0px; padding-right:0px; border-top:0px; border-right:0px; padding-top:0px "title=" 0717a3fc-bdbd-4310-969a-5462609a7dc4 "border=" 0 "alt=" 0717a3fc-bdbd-4310-969a-5462609a7dc4 "src=" http://s3.51cto.com/wyfs02/M01/72/DC/ Wkiol1xu4b2hhut1aafdvqsy7ga866.jpg "" 808 "height=" 341 "/>
3. Provide mechanism for editing function
You can add a password for the specified kernel.

As shown, we can see that our kernel,kernel is the kernel program of the operating system, and all the hardware and software are communicated through kernel. The Vmlinuz file in is the kernel that is used when powering on.
Also appears in INITRD (initial ramdisk), which is the file system that the activation system must load.
When kernel is loaded into memory and needs to load the corresponding driver to identify the filesystem, INITRD acts as a temporary system that is mounted on the rootfs to assist kernel to load the driver

V. Init (/SBIN/INIT) sets the default run level

/sbin/init uses the. conf configuration file in the/etc/init/directory to configure the system, and then calls the/etc/rc.d/rc.sysinit file to initialize the system. Init executes the/etc/rc.d/rc.sysinit file to prepare the operating environment (such as network, time zone, etc.) for the software execution.

In the process of system configuration, Init detects the default runlevel (RunLevel) of the system and makes the corresponding configuration according to the information of RunLevel, explaining the runlevel when the service is started, here is just a description of the 7 operational levels of CentOS:

Operating level: For the operation of the system or maintenance and other applications for the purpose of setting;

0-6:7 Levels

0: Turn off the machine

1: Single user mode (root, no login required), one, maintenance mode;

2: Multi-user mode, will start the network function, but will not start NFS; maintenance mode;

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

4: Reserved level, can be the same as 3 levels;

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

6: Restart

The default level for our system at startup is 3 or 5, so how do we see the current system's runlevel and switching levels?

[[email protected] ~]# runlevel #查看系统的级别前面指的是之前的模式,后面指的是当前所在模式

N 3

[[email protected] ~]# init 5 #切换当前系统级别5表示图形界面,这样我们的图形界面就启动了

Vi. use of the/etc/rc.d/rc.sysint initial system

The main contents of the initialization system are:

1, set the host name: Read the hostname parameter in the/etc/sysconfig/network file, and set the host name;
2, printing text welcome information;
3. Activation of SELinux and udev;
4. Mount the other file systems defined in the/etc/fstab file;
5, activate swap;
6. Detect the root file system and re-mount it in read and write mode;
7, set the system clock;
8, set the kernel parameters according to/etc/sysctl.conf;
9. Activation of LVM and raid;
10, loading the driver of additional equipment;
11, cleaning work.

Seven, start or close the specified service

Starts the specified level by default for the service that is started, stopping the service at the specified level by default to OFF.

The/etc/rc.d/directory contains scripts that are executed when different runlevel starts or shuts down in the RC0.D-RC6.D 7 directories.

[[email protected] ~]# ls /etc/rc.d/ #查看系统级别

init.d rc0.d rc2.d rc4.d rc6.d rc.sysinit

rc rc1.d rc3.d rc5.d rc.local

[[email protected] ~]# ls /etc/rc.d/rc3.d/ #我们以运行级别3来查看其下的内容

K01smartd K75quota_nld S13cpuspeed S26acpid

K05wdaemon K84wpa_supplicant S13irqbalance S26haldaemon

K10psacct K87multipathd S13iscsi S26udev-post

K10saslauthd K87restorecond S13rpcbind S28autofs

K15htcacheclean K89rdisc S15mdmonitor S50bluetooth

K15httpd K99rngd S20kdump S55sshd

K30spice-vdagentd S01sysstat S20lldpad S80postfix

K35vncserver S02lvm2-monitor S21fcoe S82abrt-ccpp

K50dnsmasq S07iscsid S22messagebus S82abrtd

K50netconsole S08ip6tables S23NetworkManager S90crond

K60nfs S08iptables S24nfslock S95atd

K69rpcsvcgssd S10network S24rpcgssd S99firstboot

K73winbind S11auditd S25blk-availability S99local

K74ntpd S11portreserve S25cups

K75ntpdate S12rsyslog S25netfs

Note: The file system starting with S will start by default when the file system starts with K, the default is closed # #的范围是从0到99, the smaller the number, the higher the priority

The last boot is the rc.local file, if you want to start with a surprise script or command, directly write him to/etc/rc.d/rc.local, then the action will be automatically loaded when the start.

Eight, login (Start login interface)

Linux system startup process

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.