Linux Boot Load process

Source: Internet
Author: User

Directory

1 Introduction to boot loading

2 General loading process

2.1 Loading the BIOS

2.2 Read MBR

2.3 Boot Loader

2.4 Loading the kernel

2.5 init sets the operating level according to the Inittab file

2.6 Init Process Execution Rc.sysinit

2.7 Booting the kernel module

2.8 Scripting with different run levels

2.9 Executive/etc/rc.d/rc.local

2.10 Execute/bin/login program, enter login status

3 environment variable loading

3.1 Load Order Description


Introduction to boot Loading


The boot process refers to the entire process from powering on the computer until Linux displays the user login screen. Analyzing the Linux boot process is also a great way to get an insight into the workings of the Linux core.


General loading process


1. Load BIOS


Powering on the computer, first loading the BIOS information, the BIOS information is so important that the computer must find it at the very beginning. The BIOS contains information about the CPU, device boot sequence information, hard disk information, memory information, clock information, and so on.

After that, the computer knows which hardware device to read. After the BIOS has given control of the system to the first sector of the hard disk, Linux is now controlling the system.


2. Read MBR


The first sector of the No. 0 track on the hard disk is called the MBR, which is the master boot record, which is the master boot recording, the size is 512 bytes, but it contains pre-boot information, partition table information.

Can be divided into two parts: the first part is the boot (pre-boot) area, accounting for 446 bytes, the second part is divided into partitioned table (PARTITION pable), a total of 66 bytes, recording the partition information of the hard disk. One of the functions of the Preboot zone is to find the partition marked Active (active) and read the boot area of the active partition into memory.

When the system locates the MBR of the hard disk specified by the BIOS, it is copied to the physical memory where the 0X7C00 address resides. The content that is copied to the physical memory is boot Loader, to the computer system level that is LILO or grub.


3. Boot loader


Boot Loader is a small program that runs before the operating system kernel runs. With this applet, we can initialize the hardware device and build a mapping of the memory space to bring the system's hardware and software environment to a suitable state in order to prepare for the final call to the operating system kernel.

Grub as one of the most used programs for booting the system, we need to get to know, here is our AX3 SP3 grub boot file

# grub.conf generated by Anaconda

# Note that you don't have the to rerun grub after making changes to the This file

# notice:you has a/boot partition. This means

# all kernel and INITRD paths is relative to/boot/, eg.

# root (hd0,0)

# kernel/vmlinuz-version RO root=/dev/hda2

# initrd/initrd-version.img

#boot =/dev/hda

Default=0 #此项为默认以启动第一个title

Timeout=5 #等待五秒

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

Hiddenmenu

Title Asianux Server 3 (quartet SP4) (2.6.18-194.13.AXS3)

Root (hd0,0) #指定系统的根在hd0, 0 i.e. (first partition of first piece of device)

kernel/vmlinuz-2.6.18-194.13.axs3 ro root=label=/#指定kernel文件

initrd/initrd-2.6.18-194.13.axs3.img #指定initrd文件


4. Load the kernel


Init sets the operating level according to the Inittab file


After the core is loaded, the first program executed by the core is/sbin/init, and the first goal of this program is, of course, to determine how the host is going to log in! This will have to be/sbin/init to load/etc/inittab information!

/etc/inittab has the following section, explains the function of each terminal, and the default access to the terminal mode

# Default RunLevel. The runlevels used by RHS is:

# 0-halt (do not set Initdefault to this)

# 1-single User mode

# 2-multiuser, without NFS (the same as 3, if you don't have networking)

# 3-full Multiuser mode

# 4-unused

# 5-x11

# 6-reboot (do not set Initdefault to this)

#

Id:3:initdefault:

According to the above information we have learned that:

0: Turn off the machine

1: Single User login mode

2: Multi-user login, similar to 3, but no network

3, multi-user login character mode

4, temporarily not used

5, enter the X11 graphical interface

6, restart the system

"Id:3:initdefault:" This is set to the system default to enter the terminal mode, do not set 0 and 6 mode, or the system will not start or continue to restart


Init Process Execution Rc.sysinit


After setting the operating level, the Linux system executes the first user layer file is the/etc/rc.d/rc.sysinit script program, set path, set the network configuration (/etc/sysconfig/network), start swap partition, set/ Proc and so on.

/etc/rc.d/rc.sysinit has roughly done the following:

1. Set the preset path: ( PATH)

2. Set the network status: The system will read/etc/sysconfig/network

3. Start swap swap partition

4. Check the file system: The system will check for some directories that may exist, such as/fsckoptions and/forcfsck and/fastboot

And so on, when the system has an abnormal shutdown phenomenon (such as sudden power outages, etc.), then Linux will automatically force

To check the root file system (checking root filesystems).

5. Clear the/etc/mtab;

6. Mount Root and/proc file system

7. Check the file system: Same as before, when the previous/fastboot checked, it will check your other sectors with fsck (using fsck)

8. Hang up other file systems

9. Setting the console font

10. Open Quota

11. Remove unnecessary files, such as lock, PID

12. Set Clock

13.serial Port Initialization

14. Put the boot message through the DMESG into the/VAR/LOG/DMESG


5. Start the kernel module


Executing scripts at different run levels


When the system finishes executing the/etc/rc.d/rc.sysinit,/etc/inittab directs the system to run the appropriate script rc0.d to RC6.D.

Enter the/etc/rc.d/rc3.d/directory, we will find a lot of K or S start link to. /init.d/script file, actually we're doing the script file in/etc/rc.d/init.d.

The execution ls-l output results are:

lrwxrwxrwx 1 root root 2011-11-02 s05kudzu. /init.d/kudzu

Note that: s for the boot needs to load the execution of the script file, K for power-on does not need to load the execution of the script file, the number is priority, the lower the priority, the more first to execute.

We can use Chkconfig to manage its running state.


Executive/etc/rc.d/rc.local


If you open this file, there is a word, read it, you will be the role of this command at a glance:

# This script is executed *after* all and the other init scripts.

# can put your own initialization stuff in here if you don ' t

# want to does the full Sys V style init stuff.

Rc.local is the place where Linux is left to the user to personalize after all initialization work. You can put the things you want to set up and start up here.


Execute/bin/login program, enter login status


At this time, the system has entered the waiting for the user input username and password, you can already use your own account login system.


6. Environment variable Loading


Load Order Description


When you first log in to Linux, start the/etc/profile file, and then start the ~/.bash_profile in the user directory if the ~/.bash_profile file exists, because the ~/.bash_ The following code is typically found in the profile file:

If [-f ~/.BASHRC]; Then

. ./BASHRC

Fi

So the ~/.BASHRC file is executed. And in ~/.BASHRC, the following code is generally available:

if [-F/ETC/BASHRC]; Then

. /bashrc

Fi

Therefore, ~/.BASHRC will call the/ETC/BASHRC file. Finally, when you exit the shell, the ~/.bash_logout file is also executed.

Order of execution:/etc/profile, ~/.bash_profile, ~/.BASHRC,/ETC/BASHRC, ~/.bash_logout

For the scope of each file, the following instructions were found on the Web:

(1)/etc/profile: This file sets the environment information for each user of the system, and the file is executed when the user logs on for the first time. and collect the shell settings from the configuration file of the/ETC/PROFILE.D directory.

(2)/ETC/BASHRC: Executes this file for each user running the bash shell. When the bash shell is opened, the file is read.

(3) ~/.bash_profile: Each user can use this file to enter the shell information dedicated to their own use, when the user log on, the file is only executed once! By default, he sets some environment variables to execute the user's. bashrc file.

(4) ~/.BASHRC: This file contains bash information dedicated to your bash shell, which is read when you log in and every time you open a new shell.

(5) ~/.bash_logout: Executes the file each time it exits the system (exiting the bash shell). In addition, the variables set in/etc/profile (global) can be applied to any user, while the variables set in ~/.BASHRC, etc. (local) only inherit variables from/etc/profile, they are "parent-child" relationships.

(6) ~/.bash_profile is interactive, login way into bash run ~/.BASHRC is the interactive non-login way into bash usually the two settings are roughly the same, so the former usually calls the latter


This article is from the "Gentoo" blog, be sure to keep this source http://linuxgentoo.blog.51cto.com/7678232/1599564

Linux Boot Load 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.