Linux boot process

Source: Internet
Author: User

The following is the boot process for the entire Linux system:

Linux Boot Step

Start

Bios

Grub/lilo

Kernel Boot

Init

Rc.sysinit

Rc

Mingetty

Login

Shell

Login System

A BIOS self-Test

After the computer is plugged in, the BIOS posts the post, and then reads the boot block from the hard disk, floppy disk, or CDROM according to the boot order set in the BIOS. The Linux system starts booting at the address oxFFFF0 in the bios of the human. The 1th step of the BIOS is the power-on post self-test. The job of post is to detect the hardware. The 2nd step of the BIOS is to enumerate and initialize the local device. The BIOS consists of two parts: The post code and the runtime service. When post is completed, it is cleaned out of memory, but the BIOS runtime service remains in memory and the target operating system can use these services.

The BIOS runtime searches for devices that are active and bootable, in the order defined by the CMOS settings. The boot device can be a floppy disk, a CD-ROM, a partition on the hard disk, a device on the network, or even a USB flash. Typically, a Linux system is booted from the hard disk, where the master boot Record (MBR) contains the primary boot loader. The MBR is a 512-byte sector that is located on the first sector of the disk (0-channel 0-cylinder 1-sector). When the MBR is loaded into RAM, the BIOS will give control to the MBR.

If you want to view the contents of the MBR, the user needs to run the following command as the root user:

#dd If=/dev/had of=mbr.bin bs=512 count=1
Read a 1+0 block.
Output of 1+0 blocks
#od –xa Mbr.bin
... ...

It reads the first 512 bytes of content from/dev/had (the first IDE disk) and writes it to the Mbr.bin file. The OD command prints the contents of this binary file in 16 binary and ASCII format.

Two Start Grub/lilo

Both grub and Lilo are boot loaders. The boot loader is used to boot the operating system. When the machine boots its operating system, the BIOS reads the first 512 bytes (master boot record) on the boot media. Only one operating system's boot record can be stored in a single MBR, so when more than one operating system is required, there is a problem and a more flexible bootloader is required.

All boot loaders work in a similar way to meet common purposes, but there are many differences between Lilo and Grub:

Lilo does not have an interactive command interface, while Grub has;
Lilo does not support network booting, while Grub supports it;
Lilo stores information that can boot the operating system in the MBR.

If you modify the Lilo configuration file, you must rewrite the Lilo first stage boot loader to the MBR. This is a more dangerous option than grub, because an incorrectly configured MBR may make the system unable to boot. When using grub, if the configuration file is misconfigured, it simply goes to the GRUB command-line interface by default.

Three Load kernel

The next step is to load the kernel image into memory, and the kernel image is not an executable kernel, but a compressed kernel image. Usually it is a zimage (compressed image, less than 512KB) or a bzimage (larger compressed image, greater than 512KB), which is compressed in advance using zlib. In front of this kernel image is a routine that implements a small set of hardware settings, decompressing the kernel contained in the kernel image, and then putting it into high-end memory. If there is an initial RAM disk image, it will be moved to memory and marked for later use. The routine then invokes the kernel and starts the process of booting the kernel.

Four Executing the INIT process

The init process is the starting point for all processes in the system, and after the kernel is booted inside, the INIT program is loaded within the process space, and its process is 1. The init process is the initiator and controller of all processes. Because it is the first process to run on any Linux-based system, the number (PID) of the Init process is always 1.

The INIT process has the following two functions.

The first function of the INIT process is to play the role of ending the parent process. Because the init process is never terminated, the system can always be sure of its existence and refer to it when necessary. If a process is terminated before the end of all the child processes it derives from, the case must be referenced with Init. At this point, those child processes that have lost the parent process will have Init as their parent process.

The second function of Init is to run the appropriate program at a specific runlevel to manage the various runlevel. Its role is defined by the/etc/inittab file.

Kivu Initializing with the/etc/inittab file

Init's job is to execute the corresponding script according to/etc/inittab, to initialize the system, such as setting up the keyboard, font, loading module, setting up the network and so on.

1 . /etc/rc.d/rc.sysinit

The following line is in the configuration file for init:
Si::sysinit:/etc/rc.d/rc.sysinit

Rc.sysinit is the first script executed by INIT, which mainly performs some system initialization work. Rc.sysinit is an important script that runs at every run level, and it mainly does the work of activating swap partitions, checking disks, loading hardware modules, and other tasks that need to be prioritized. The/etc/rc.d/rc.sysinit mainly completes the same initialization work in each operation mode. Including:

Set the initial $path variable;
Configure the network;
Initiate exchange for virtual memory;
Attune hostname of the system;
Check the root file system for necessary repairs;
Check the root file system quota;
Open user and group quotas for the root file system;
Re-loading the root filesystem in read/write mode;
Clears the mounted File system table/etc/mtab;
Enter the root file system into the mTAB;
Prepare the system for loading modules;
Find the relevant files of the module;
Check the file system for necessary repairs;
Load all other file systems;
Clear/etc/mtab,/etc/fastboot and/etc/nologin;
Delete UUCP and lock files;
Delete obsolete subsystem files;
Delete outdated PID files;
Set the system clock;
Activates the swap partition;
Initializes the serial port;
Loading the module.

2 . /etc/rc.d/rcx.d/[ks]

After Rc.sysinit executes, it returns to Init and proceeds to the execution of the/ETC/RC.D/RC program. For example, run Level 5, Init executes the following in configuration file Inittab:
15:5:WAIT:/ETC/RC.D/RC 5

This line indicates that running with the 5 parameter/ETC/RC.D/RC,/ETC/RC.D/RC is a shell script that accepts 5 as a parameter to execute all RC startup scripts under the/ETC/RC.D/RC5.D directory,/etc/rc.d/ The startup scripts in the RC5.D directory are actually some linked files, not the actual RC startup scripts, and the actual RC startup scripts are actually in the/ETC/RC.D/INIT.D directory. These RC startup scripts have a similar usage, and they generally accept stat, stop, restart, status, and so on.

The RC startup script in/ETC/RC.D/RC5.D is usually a link file that begins with K or S, and a startup script starting with S will run with the start parameter. If you find that the corresponding script also has a K link and is already running (with the file under/var/lock/subsys as the flag), the daemons that have been started are stopped first with the stop parameter and then rerun. This is done to ensure that when Init changes the RunLevel, all associated daemons are restarted.

As to which Daemons will be run at each run level, the user can chkconfig from the row settings. The common daemons are as follows.

AMD: Automatically installs the NFS daemon.
APMD: Advanced Power Management daemon.
Arpwatch: Log and build a database that corresponds to the Ethernet address and IP address that you see on the LAN interface.
Outofs: Automatically installs the management process AutoMount, which is related to NFS and relies on NIS.
Crond:linux The daemon of the scheduled task under the system.
Named:dns server.
Netfs: Installs NFS, samba, and NetWare network file systems.
Network: Activates a scripted program that has configured the networking interface.
NFS: Opens the NFS service.
Portmap:rpcportmap Manager, which manages RPC service-based connections.
SendMail: Mail server sendmail.
Smb:samba file sharing/printing service.
Syslog: A script that allows the system to boot Syslog and klogd the system log waiting process.
xfs:x Window font server that provides font sets for local and remote X servers.
XINETD: Support a variety of network services Core Daemon, can manage wuftp, sshd, Telnet and other services.

When these daemons are started, the RC program is finished and then goes back to Init to proceed to the next step.

3 . Executive/etc/ec.d/rc.local

The operating modes 2, 3, and 5 in RHEL 4 have/etc/rc.d/rc.local as the last of the initialization scripts, so users can add in this file their own commands that need to be executed after other initialization work and before logging in. When maintaining a Linux system, you will typically encounter situations in which the system administrator needs to modify the power-on or shutdown command scripts. If the changes are only useful when booting the boot, and the changes are not significant, consider simply editing the/etc/rc.d/rc.local script. This command script is executed at the last step of the boot process.

Six Execute/bin/login Program

The login program will prompt the user to enter the account number and password, and then code and confirm the correctness of the password, if the account and password match, then for the users to initialize the environment, and give control to the shell, that is, waiting to login.

Login will receive the user name parameter from Mingetty, then login will parse the user name. If the user name is not root and there is a/etc/nologin file, login outputs the contents of the Nologin file and exits. This is typically used to prevent non-root users from logging on during system maintenance. Only the terminal registered in/etc/securetty allows the root user to log on, and if the file does not exist, root can log on at any terminal. The/etc/usertty file is used to make additional access restrictions to the user, and there are no additional restrictions if the file does not exist.

After parsing the user name, login will search/etc/passwd and/etc/shadow to verify the password and set up additional information about the account, such as what the home directory is and what shell to use. If no home directory is specified, the home directory is set to the root directory by default, and the shell type is set to/bin/bash by default if no shell is specified.

After the login program succeeds, it will then output the last login information (recorded in/var/log/lostlog) to the corresponding terminal, and check whether the user has new mail (recorded in the corresponding user of/usr/spool/mail), and then start setting up various environment variables. For bash, the system first looks for the/etc/profile script file and executes it, and then executes it if there is a. bash_profile file in the user's home directory, in which case other configuration files may be called, and after all the configuration files are executed, the various environment variables are set. , a familiar command-line prompt appears, and the entire startup process is over.

Linux boot 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.