Linux system startup process

Source: Internet
Author: User

System Startup process:

POST-To-BIOS (boot sequence boot sequence)--MBR (Bootloader,446byte)--Kernel---INITRD (INITRAMFS) --/sbin/init (/etc/inittab)


Kernel design style:

Single Core:

All functions are in one kernel. Linux uses a single kernel, but it uses a micro-kernel design idea. LWP (Lightweight process light weight pprocess).


Core:

/boot/vmlinuz-verison

Dynamic loading KO (Kernel object kernel dedicated module).


Kernel module (KO):/lib/modules/kernelver/

Common load kernel module commands:

#insmod

#modprobe



Micro-Kernel:

Make other functions into sub-cores. Windows Solaris. The true meaning of multithreading.


Features provided by the kernel:

File system

Process Management

Memory management

Network management

Security features

Driver Program


Kernel initialization process:

1. Device detection.

2. Driver initialization

The drive module may be loaded from the INITRD (Initramfs (RHEL6)) piece.

3. Mount the root file system (ROOTFS) in read-only mode.

4. Loading the first process init (pid=1) in user space


Initrd:

A middle-tier system in which the system starts is to provide the necessary basic drivers to generate a temporary root that provides the kernel with the basic drivers needed to access the real root file system. After the kernel successfully mounts the root filesystem, the/proc,/sys,/dev under the temporary root will be moved to the real root.


RAMDisk--and INITRD RHEL5 to simulate the memory as disk use.

Ramfs--and Initramfs RHEL6 to simulate the memory as disk use.


#chroot Temprootdir [COMMAND] temporarily switches to the root directory

For example:

#chroot/tmp/virroot/bin/csh


#ldd file displays the shared libraries that the binaries depend on.



Init:

The first process started by the system.

Bin file path:

/sbin/init


Configuration file:

/etc/inittab

Each row records a service (process) that is to be started or run.

Tasks set:

1. Set the default run level.

2. Run the system initialization script.

/etc/rc.d/rc.sysinit

3. Run the service class script under the corresponding directory for the specified run level.

/etc/rc.d/init.d

/etc/rc.d/rcnum.d

The/etc/rc.d/rc.local is finally executed.

4. Set the action of the Ctrlaltdel key combination.

5. Define the UPS power supply in the power failure or recovery is the operation performed.

6. Start the virtual terminal (level 2345).

1:2345:respawn:/sbin/mingetty tty1

...


7. Start the graphics terminal (Level 5).


The structure of each line is as follows:

Id:runlevels:action:process


ID: Marked.

Runlevels: At which level to run.

Action: What event is executed under.

Initdefault Set the default run level.

Sysinit system initialization.

The wait level is executed when it switches to this level.

Ctrlaltdel restart.

Powerfail power failure.

The power supply is restored before the powerokwait power is deactivated.

Respawn restarts once the program is terminated.


Process: The program to run.


Operating level:

The difference between the different levels is that the service started differently.

0:halt

1:single User mode

Login directly as an administrator without verification.

2:mulit User mode no NFS

Do not start the NFS feature

3:mulit User Mode text mode

Command-line mode

4:reseved

Reserved level, not defined temporarily.

5:mulit User Mode graphic mode

Graphics mode

6:reboot


Run-level settings:

Modify/etc/inittab


To view the run level:

#runlevel

Lsatlevel Thislevel

Where Lastlevel represents the previous level, n means that it has not been switched. Thislevel represents the current level.


#who-R


/etc/init/*.conf

The files in this directory are many. conf files that are generated after the Inittab file is sliced. are written on an event-driven basis.


/etc/rc.d/rc.sysinit

Tasks Completed:

1. Activate Udev and SELinux.

2. Set the kernel parameters according to the/etc/sysctl.conf file.

3. Set the system clock.

4. Load the keyboard mapping.

5. Enable the swap partition.

6. Set host name hostname.

7. The root file system is detected and re-mounted in read-write mode after error-free.

8. Initialize the drivers for peripheral hardware devices, such as RAID and LVM devices.

9. Start disk quotas.

10. According to/etc/fstab, check and mount other file systems.

11. Clean Up Expired locks (/proc/lock) and PID files.



/etc/rc.d/init.d/*

Service class script, SysV style, stored under/ETC/RC.D/INIT.D. There is a link file/etc/init.d point to/ETC/RC.D/INIT.D.


The script accepts at least the following parameters:

Start|stop|restart|status

Reload|configtest


Script Common features:

#chkconfig: Runlevels SS KK

Runlevels Boot level

Runlevels can be used-to indicate that there are no levels default to the Snum beginning of the link, that is, all the links beginning with knum.


SS-Boot Priority

KK off priority


When you use the Chkconfig command to create a link for this script in the RCNUM.D directory, RunLevel represents the default creation of a file that begins with Snum, except that the level is created by default as a link beginning with Knum. The start priority at the rear of S is the number represented by SS, and the order of closing priority behind K is the number represented by KK. General ss+kk=99.


#description: Descriptions

Describes the information that the user describes as a simple function of this script. You can use \ to continue the line.





/etc/rc.d/rc.local

/etc/rc.d/rcnum.d/s99local and/etc/rc.local are their links.

The last service that is executed at the start of the system is exactly the script. An inconvenient definition of a service such as a command can be written to, and executed before the user logs on.


The system boot process is detailed:

Bootloader (MBR)

Lilo:linux LOader

Unable to boot 1024 partition after kernel. Large hard drives are not supported, but are suitable for embedded systems.


Grub:grand Unified Bootloader

Stage1: Installed in the MBR. The purpose is to guide stage2.


stage1.5: Used to identify common file systems.


Stage2: Located in the partition where the kernel resides. /boot/grub/.


Grub:

/etc/grub.conf

Grub configuration file. is a linked file, point to/boot/grub/grub.conf

The main contents are as follows:

Default=0

Set the title number of the default startup, starting with 0.


Timeout=5

Wait for the selection time-out. Unit is seconds.


Splashimeage= (hd0,0)/grub/palash.xmp.gz

Specifies the grub background picture.


Hiddenmenu

Whether to hide the menu.


Password--md5 password

Sets the password for the grub edit. You can use Grub-md5-crypt to generate an encrypted password.



Title TitleName

The kernel title or the name of the OS can be modified freely.

Root (Hddisknum,partnum)

Specifies the device and partition where the kernel files reside. For grub, all drives are displayed as HD. Disknum represents the disk ordinal, and partnum represents the partition ordinal.


Kernel kernel cmdline

Specifies that the kernel path is a parameter passed to the kernel. The parameter file can be seen in the/proc/cmdline.


INITRD INIDRD

Specifies the INITRD path.


Password Password boot the kernel or OS password.


Fix Grub:

Install Grub Stage1:

#grub

grub> Root (Hddisknum,partnum) specifies the disk and partition where the kernel resides.

grub> Setup (hddisknum) installs grub on the specified hard disk.

Grub> quit


#fdisk DEVICE

/dev/part1 used to do boot

/dev/part2 used to make sysroot.


#mkdir/dir/boot

#mount/dev/part1/dir/boot

#grub-install--root-directory=/dir DEVICE

This way to ensure that the kernel file is located on the partition mounted on/boot. Grub can automatically find/boot as long as it specifies the parent directory where/boot is located

#vim/dir/boot/grub.conf


grub.conf file Missing:

Operation after booting into grub.

Grub> Find (Hddisknum,partnum)/

Pressing the TAB key will display the relevant file.

grub> Root (Hddisknum,partnum)

Grub> Kernel/kernel

Grub> INITRD/INITRD

grub> Boot



#mingetty [OPTION] to start the terminal

[OPTION]

--loginprog=/bin/login The program that executes after the interrupt is started. The default is/bin/login.


#agetty [OPTION] PROT BaudRate overrides the Getty command.

[OPTION]

-L Login Programe Specify login procedure

-N does not require the user to enter a user name. Users are not required to enter login information. Use with-L.


For example:

#agetty-l/bin/bash 38400 Login bash and set the baud rate to 38400.



#stty [OPTION] device SETTING changes and displays the end device.

[OPTION]

-F--file=device Open and use the specified device

SETTING:

Size displays the number of row (rows) columns (columns).

Speed shows the terminal rate.

For example:

#stty-F/dev/console Size physical terminal

25 80 25 Row 80 column.

#stty-F/dev/console Speed

38400 38,400 characters per second


#chkconfig [OPTION]

Specifies a sysv style script that automatically creates a link under/ETC/RCNUM.D.

[OPTION]

The--list SERVICE lists the startup settings for all independent daemons. All settings are displayed without parameters.


--add SERVICE

Automatically creates a link that adds the service to the list of services controlled by the Chkconfig. The next system boot takes effect.


--del SERVICE

Delete the service all linked files.


--level [Runlevels] SERVICE On|off

Specifies that the level is runlevels,service started or closed. You do not need to specify runlevles for the transient daemon process. Runlevels can be omitted, omitting the default to 2,345 levels.




Type of daemon:

Independent Daemon Process


Transient daemon process

You do not need to associate to the RunLevel.

XINETD: Super daemon. Manages all transient daemons. The associated run level is required.


This article is from "Small Private blog" blog, please be sure to keep this source http://ggvylf.blog.51cto.com/784661/1614891

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.