Laruence's linux Private food-Chapter 1 startup process, module management and loader, and Chapter 2

Source: Internet
Author: User

Laruence's linux Private food-Chapter 1 startup process, module management and loader, and Chapter 2

20.1 Linux Startup Process Analysis

Linux Startup Process:

After you press the power on, the computer hardware actively reads the BIOS to load hardware information and perform self-testing on the hardware system. After that, the system will actively read the first device that can be started (set by the BIOS ), now you can read the boot loader. The boot loader specifies the Kernel File to start and actually loads the kernel into the memory for decompression and execution, in this case, the kernel can be active in the memory and detect all hardware information and load appropriate drivers to run the host. After the kernel detects the hardware and loads the driver, you can log on.

1) Load BIOS hardware information and perform self-testing, and obtain the first device that can be started according to the settings

2) read and execute the first boot Loader (grub, spfdisk, and other programs) that starts the MBR in the device)

3) According to the boot loader settings, the kernel starts to detect the hardware and load the driver.

4) after the hardware driver is successful, the Kernel will actively call the init process, and the init will obtain the run-level information.

5) run the/etc/rc. d/rc. sysinit file in init to prepare the operating environment for software execution.

6) init runs run-level to start each service.

7) run the/etc/rc. d/rc. local file in init.

8) init executes the terminal simulation program mingetty to start the login process and waits for the user to log on.

 

Main functions of Boot Loader:

Menu provided: users can choose different startup options, which is also an important function of Multi-boot.

Load the Kernel File: directly point to the executable program section to start the operating system.

Transfer another loader: transfers the bootstrap load function to another loader.

 

Problem 1): Each operating system has its own boot loader. for multiple operating systems, each operating system must use its own loader to load its own operating system kernel, however, there is only one MBR in the system. How can I install windows and linux on a single host at the same time?

Answer: Because boot loader has a menu function, you can choose a different kernel to start it. Because of the control transfer function, you can load the loader in other boot sector (the default layout of the loader in windows has the control transfer function, so you cannot use the loader in windows to load the loader in linux)

 

Problem 2): If linuux is installed on a SATA hard disk, you can use INT13 of the BIOS to obtain the boot loader and kenerl files to start it, then, the kernel starts to take over the system and checks the hardware and tries to mount the root directory to obtain additional drivers. But the kernel does not know the SATA disk at all, so the driver of the SATA disk needs to be loaded. Otherwise, the root directory cannot be mounted, but the SATA driver is in/lib/modules, the root directory cannot be mounted. How can I read the driver in/lib/modules?

Answer: solve the problem through the Virtual File System. Generally, the file name is/boot/initrd. The file can be loaded to the memory through boot loader. The file is decompressed and simulated into a root directory in the memory. The simulation provides an executable program in the file system in the memory, this program is used to load the kernel modules required during the startup process, usually drivers for file systems and hard disk interfaces such as USB, RAID, LVM, and SCSI. After loading, the kernel will be re-called/sbin/init to start the subsequent normal process.

(If linux is installed on the disk of the IDE interface and ext2/ext3 file system is used by default, linux can be started smoothly without initrd)

 

After the kernel is loaded and the hardware detection and driver are loaded, the host hardware is ready. At this time, the kernel will actively call the first process, that is,/sbin/init (PID of init is 1). The main function of/sbin/init is to prepare the environment for software execution, including system Host Name, network settings, language processing, file system format, and startup of other services. All operations are planned through the init configuration file/etc/inittab.

An important setting option of inittab is run level.

0 -- halt (direct system shutdown)

1 -- single user mode)

2 -- Multi-user, without NFS (similar to run level3, but no NFS service)

3 -- Full multi-user mode (Full text mode with network functions)

4 -- unused (system reserved function)

5--X11 (similar to run level3, but loading X Windows)

6 -- reboot (restart)

 

In the/etc/inittab, there is a sentence: "si: sysint:/etc/rc. d/rc. sysinit indicates that you must set up the entire system environment before starting to load various system services, mainly using/etc/rc. d/rc. sysinit shell script to set the system environment

 

Start System services and related STARTUP configuration files (/etc/rc. d/rc N &/etc/sysconfig)

The meaning of/etc/rc. d/rc5 is as follows:

Obtain the directory of the script to be executed by using the parameter #1 ($1), that is, by/etc/rc. d/rc 5 can get the/etc/rc5.d/directory to prepare the script program for processing.

Find/etc/rc5.d/K ?? * Start with/etc/rc5.d/K ?? * Stop operation

Find/etc/rc5.d/S ?? * Start with/etc/rc5.d/S ?? * Start Operation

(All files under/etc/rc5.d are links to the directory/etc/init. d started by the stand alone service)

For example,/etc/rc5.d/K91capistop -->/etc/init. d/capistop

/Etc/rc5.d/S10networkstart -->/etc/init. d/networdkstart

The numbers after S and K indicate the execution sequence of the file. S99local is/etc/rc. d/rc. local is the final execution.

 

User-Defined boot Startup Program (/etc/rc. d/rc. local)

If you want to perform any work at startup and directly write it to/etc/rc. d/local, the job will be automatically loaded at startup.

 

The main configuration file used during startup:

1) module:/etc/modprobe. conf (this file mostly lies in the module used by the hardware in the specified system. If the system detects an incorrect driver, or you need to manually process the file when you want to use an updated driver for related hardware configuration)

2) several files under/etc/sysconfig:

The authconfig file mainly sets the user's identity authentication mechanism, including whether to use local/etc/passwd,/etc/shadow, etc.

Clock: this file is used to set the linux host's loss. You can use Greenwich Mean Time or local time.

I18n is used to set the usage of some languages.

Keyboard & mouse: Set the keyboard and mouse format

Network can be used to set whether to start the network, and set the Host Name and gateway information.

Network-scripts is mainly used to set the NIC

 

Switch run level: init N

Display current run level: runlevel (the left side of the output result indicates the previous runlevel, and the right side indicates the current runlevel)

Init 0 Shutdown

Init 6 restart

 

 

20.2 kernel and kernel module

Storage location of the kernel and kernel module:

Kernel:/boot/vmlinuz or/boot/vmlinuz-version

RAMDisk:/boot/initrd (/boot/initrd-version) required for Kernel Decompression)

Kernel module:/lib/modules/version/kernel or/lib/modules/$ (uname-r)/kernel

Kernel source code:/usr/src/linux or/usr/src/kernels (available only after installation, not installed by default)

Kernel version:/proc/version

System kernel functions:/proc/sys/kernel

 

Kernel Modules and dependencies:

The/lib/modules/$ (uname-r)/modules. dep file records the dependencies of modules supported by the kernel.

For example, if the NIC Driver is named a. ko, how can I update the kernel dependency?

You can use the depmod command (depmod [-Ane])

Cp a. ko/lib/module/$ (uname-r)/kernel/driver/net

Depmod

 

View the kernel module:

Lsmod

After lsmod is Used, the system displays the existing modules in the kernel, including the module name module, the module size, and whether the module is Used by other modules.

Modinfo [-adln] [module_name | filename]

For example, modinfo wmi

 

Kernel module loading and deletion:

If you want to manually load the module, we recommend that you use the modprobe command to load the module, because modprobe will take the initiative to find modules. after the dep content first overcomes the module dependency, the dish determines which modules need to be loaded. In insmod, a user loads a module with a complete file name, and does not actively analyze the module dependency.

Modprobe [-lcfr] module_name

Insmod [/full/path/module_name] [parameters]

For example, try to load the cifs. ko file system module.

Insmod/lib/module/$ (uname-r)/kernel/fs/cifs. ko

Lsmod | grep cifs

Delete module: rmmod [-fw] module_name

 

 

20.3 Boot Loader: Grub

The program code execution and setting value loading of boot loader are divided into two stages for execution.

Stage1: run the boot loader main program (this main program must be installed in the startup zone, that is, MBR or boot sector, because MBR is too small, therefore, MBR or boot sector usually only installs the minimum main program of boot loader and does not install the relevant configuration files of loader)

Stage2: load all configuration files and Related Environment Parameter files (including the file system definition and main configuration file menu. lst) through boot loader. Generally, the configuration files are under/boot.

 

One of the final tasks required to install the grub main program in MBR is to load the kernel file from the disk so that the kernel can smoothly drive the hardware of the entire system.

The hard disk code of grub, such as hd (0, 0), indicates that the first hard disk code found is (hd0), and the first partition of the hard disk is (hd0, 0)

 

/Boot/grub/menu. lst (grub. cfg)

Default = 0 default start option, use the first Start Menu

Timeout = 5 if the keyboard is not moved within 5 seconds, use the default menu to start

Whether the full menu interface is displayed during hiddenmenu second reading

 

The time required for initrd is:

The disk where the root directory is located is a connection interface such as SATA, USB, or SCSI.

The file system of the root user is in special formats such as LVM and RAID.

The file system where the root directory is located is a non-traditional "known" File System for Linux.

Other modules that must be provided during kernel Loading

 

You can use the mkinitrd command to recompile the initrd file.

Mkinitrd [-v] [-- with = Module name] initrd file name kernel version

Example 1: use the default mkinitrd function to create an initrd virtual hard disk file

Mkinitrd-v initrd _ $ (uanem-r) $ (uname-r)

Example 2: add the initrd file of the 8139too Module

Mkinitrd-v -- with = 8139too initrd_vbirdtest $ (uname-r)

 

Install grub (grub-install is to install grub-related files to the device and wait for them to be read at startup, but you also need to set the configuration file menu. after lst, use grub shell to install the grub main program to MBR or boot sector)

Grub-install [-- root-directory = DIR] INSTALL_DEVICE

Example 1: Install grub under the MBR of the current system. My system is/dev/had.

Grub-install/dev/hda

Example 2: My/home is independent of/dev/sda3. How to install grub to/dev/sda3?

Grub-install -- root-directory =/home/dev/sda3

 

Vga settings in kernel functions

Tty1 ~ Tty6 resolution

First, check whether the kernel function parameter FRAMEBUFFER_CONSOLE is supported.

Grep 'framebuffer _ console'/boot/config-3.2.0-23-generic-pae (supported if config framebuffer console = y appears)

Modify resolution vi/boot/grub/menu. lst (or add the red part to the grub. cfg file)

Menuentry 'ubuntu, Linux 3.2.0-67-generic-pae' -- class Ubuntu -- class gnu-linux -- class gnu -- class OS {
Recordfail
Gfxmode $ linux_gfx_mode
Insmod gzio
Insmod part_msdos
Insmod ext2
Set root = '(hd0, msdos1 )'
Search -- no-floppy -- fs-uuid -- set = root c6008246-e4ee-490f-bec6-3f72108424dd
Linux/boot/vmlinuz-3.2.0-67-generic-pae root = UUID = c6008246-e4ee-490f-bec6-3f72108424dd ro quiet splash $ vt_handoffVga = 1, 790
Initrd/boot/initrd. img-3.2.0-67-generic-pae
}

790 corresponds to the resolution of 1024*768, and there are other parameters, such as 784 ~ 795,769,771,773,775

 

20.4 solve startup Problems

1) forgot password

A. Restart

B. After the grub menu is started, press "e" on the menu to enter the menu settings

Grub edit & gt; kernel/vmlinuz-2.6.18-92.e15 ro root = LABEL =/rhgb quietSingle

(My ubuntu should be linux/boot/vmlinuz-3.2.0-67-generic-pae root = UUID = c6008246-e4ee-490f-bec6-3f72108424dd ro quiet splash $ vt_handoffSingle)

Press enter and press B to start and enter the single-user maintenance mode.

C. after entering the single-user mode, you can execute shell and enter passwd to re-root the password. After executing init 5, you can switch to the X Window Interface.

 

2) init configuration file Error

A. After grub is started

Grub edit & gt; kernel/vmlinuz-2.6.18-92.e15 ro root = LABEL =/rhgb quietInit =/bin/bash

Change the first process init called by the kernel to/bin/bash.

B. Input mount-o remount and rw/in shell (remount the root directory to read/write)

Mount-a (refer to/etc/fstab to remount the file system)

C. Perform the rescue work. After the rescue is completed, restart it once.

 


Grub problems of CentOS

Yes. If your grub program is installed on the hard disk of Windows, you must have the hard disk of Windows when starting another disk with centos. Because the grub program is first found when the system starts. After you select the system you want to start, grub will guide you to the desired start sector, to load the core of your system, and then start the system. This grub is like a guide, so if you don't have a Windows hard disk, there will be no guide, then what do you know how to go ahead? You may want to use that disk when I open Centos. you can install grub on that disk. For example, after entering the system, grub-install/dev/hdb, however, this may cause another problem. Changing the hard disk may lead to a name change. For example, if hda is changed to hdb, The system won't be able to enter the next time! We recommend that you do not remove the hard disk. My language is poor, and it does not really solve your problem. I hope I can help you a little bit!

I don't know if you have read "Bird brother's Linux basic learning (the third edition)" (a classic book with PDF format on the Internet, which is very classic. I suggest you check it out ), chapter 1, boot process, module management and Loader is very useful to you.

What is linux used in the course of Private food teaching by laruence's linux?

Fedora System
In this case, the redhat centos fedora command and the server configuration location are almost the same.
Centos is recommended.

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.