Section II begins
Core (kernel). is a compressed file, before using the core, you have to unzip it before you can load the main memory.
The directory where the core and core modules are located:
? Core:/boot/vmlinuz or/boot/vmlinuz-version.
? Core decompression Required RAM Disk:/boot/initramfs (/boot/initramfs-version).
? Core modules:/lib/modules/version/kernel or/lib/modules/$ (uname-r)/kernel.
The/lib/modules/$ (uname-r)/MODULES.DEP file records the dependencies of the modules that are supported at the core, and the Modules.dep file checks that the kernel directory contains dependencies for the following folders:
Arch: Projects related to the hardware platform, such as the level of the CPU and so on;
Crypto: The encryption technology supported by the core, such as MD5 or DES, etc.;
Drivers: Some hardware drivers, such as display adapter, network card, PCI-related hardware and so on;
FS: Filesystems supported by the core, such as VFAT, ReiserFS, NFS, etc.;
LIB: some function libraries;
NET: Network-related protocol data, as well as Firewall module (net/ipv4/netfilter/*) and so on;
Sound: Various modules related to audio;
? Core source code:/usr/src/linux or/usr/src/kernels/(to be installed only, presets not installed)
? Additional parameter settings for Core modules:/etc/modprobe.d/*conf
If the core is successfully loaded into the system, then there will be a few messages logged:
? Core version:/proc/version
? System core Function:/proc/sys/kernel/
Command
Build/lib/modules/$ (uname-r)/modules.dep file #depmod [-ane]
Options and Parameters:
Without any parameters, Depmod will proactively analyze the current core module and re-write to/lib/modules/$ (uname-r)/modules.dep.
-A: If you add the-a parameter, then Depmod will search for a newer module than the MODULES.DEP, and if a new module is found, it will be updated.
-N: does not write to MODULES.DEP, but outputs the result to the screen (standard out);
-E: Displays the name of the non-executable module that is currently loaded
#lsmod show the module status of the Linux core.
The data format is: module name module size (size) Whether this module is used by other modules (used by)
#modinfo [-ADLN] [module_name|filename] Check the module inside the core, check "a module file"
Options and Parameters:
-A: Lists only the author's name;
-D: List only the description of the modules (description);
-L: List only authorizations (license);
-N: Lists only the detailed path of the module.
#insmod [/full/path/module_name] [parameters] The module that the user loads a full file name by itself and does not actively analyze the module dependencies. To find the full file name of the module yourself
[[email protected] ~]# insmod/lib/modules/$ (uname-r)/kernel/fs/fat/fat.ko #载入 Cifs.ko This "file system" module
Remove the module #rmmod [-FW] module_name. To find the full file name of the module yourself
Options and Parameters:
-F: Forces the module to be removed, whether or not it is being used;
#modprobe [-CFR] module_name load module. Does not need to know the complete module file name, also overcomes the module the dependency question
Options and Parameters:
-C: List all the current system modules! (More detailed code-name correspondence table)
-F: Force the module to load;
-r: Similar to Rmmod, that is, removing a module
The program code execution of the boot loader is divided into two stages (stage) for execution of the set value load:
? Stage 1: Execute the boot loader main program. The main program must be installed in the boot area, i.e. MBR or boot sector. Since the MBR is a chunk within the first sector of the entire hard disk, at best the entire size is 446 bytes, because MBR or boot sector usually installs only the minimum main program of boot loader, and does not have the relevant configuration file of loader installed;
? Stage 2: Main program Load configuration file:
Load all configuration files and related environment parameter files (including file system definition and main profile grub.cfg) through boot loader, in general, the configuration files are under/boot.
Configuration files related to GRUB2 are placed in the/boot/grub2/directory, the most important thing in boot/grub2/directory is the configuration file (grub2.cfg) and the definition of various file systems! After reading the file system definition data, loader is able to recognize the file system and read (load) the core files within the filesystem.
Advantages of GRUB2:
? Recognize and support a large number of file systems, and can use GRUB2 's main program directly in the file system to search for the core file name;
? When the boot, you can "edit and modify the boot setting project", similar to the command mode of bash;
? Configuration files can be dynamically searched without the need to reinstall the GRUB2 after modifying the configuration file. That is, we only need to modify the/boot/grub2/grub.cfg inside the setting, the next time the power on will be effective!
GRUB2 identification of the hard drive: (hd0,1)
? The hard drive code is wrapped up in parentheses ();
? Hard drives are expressed in HD, followed by a set of numbers;
? Use "search Order" as the number of the hard drive! (This important!)
? The first hard drive to find is number No. 0, the second is number 1th, and so on. Since the BIOS can adjust the boot order of the disk, the number of the disk corresponding to the (HdN) N is likely to change
? The first partition of each hard drive is codenamed 1, and so on.
So, the whole drive code is:
The code of the hard drive search order in GRUB2
First (MBR) (hd0) (HD0,MSDOS1) (Hd0,msdos2) (HD0,MSDOS3) ....
The second (GPT) (HD1) (HD1,GPT1) (HD1,GPT2) (HD1,GPT3) ....
The third (HD2) (hd2,1) (hd2,2) (hd2,3) ....
/boot/grub2/grub.cfg file does not exist
Grub.cfg file content is too complex, the amount of data is very large, GRUB2 official note does not recommend that we manually modify. We can make changes through the following files and directories:
/etc/default/grub The primary environment configuration file.
Content in the file:
Grub_timeout=5 # Specifies the number of seconds the preset countdown reads seconds
Grub_default=saved # Specifies which menu the preset is to boot from, and the preset boot menu means
Grub_disable_submenu=true # If you want to hide the sub-menu, it is usually good to hide!
grub_terminal_output= "Console" # Specifies the terminal format of the data output, by default through the text terminal
grub_cmdline_linux= "Rd.lvm.lv=centos/root rd.lvm.lv=centos/swap crashkernel=auto rhgb quiet" # is inside the menuentry brackets Core parameters of linux16 project follow-up
Grub_disable_recovery= "True" # Cancel the creation of the rescue menu
The relevant configuration file within the/etc/grub.d/directory. menu to build the script. Documents must be documented in the catalogue:
00_header: Mainly in the establishment of initial display projects, including the need to load the module analysis, screen terminal format, countdown seconds, whether the menu needs to be hidden and so on, most of the variables set in the/etc/default/grub, Probably will be used in this script to reconstruct grub.cfg.
10_linux: Based on the analysis of the files under/boot, trying to find the right Linux core and read the file system modules and parameters required by this core is found and set to Grub.cfg after the script has been run. Because this script will have all the core files in/boot corresponding to a menu, so the number of core files, your boot menu project more. If you don't want the old core to appear on the menu in the future, it can be handled by removing the old core.
30_os-prober: This script defaults to the system to find other partition inside the operating system, and then the operating system into a menu to deal with it. If you do not want to allow other operating systems to be detected and turned on, then you can add "grub_disable_os_prober=true" inside the/etc/default/grub to cancel the operation of this file.
40_custom: If you have other menu items that you would like to manually add to your own, or if you have other needs, here are some suggestions to add!
o directly specify the core boot
o Transfer of loader control through Chainloader
Initramfs
In general, the core provided by each distribution will be accompanied by a Initramfs file.
Reasons for Initramfs: The core modules are placed in the/lib/modules/$ (uname-r)/kernel/directory, but these core modules can be read only when the root directory (/) is mounted. The root directory cannot be mounted when the core itself does not have a driver for the disk, and there is no way for the driver to get it. Cause the contradiction between the two situations. Failed to understand the whole process???
Initramfs Working principle:
1, the/lib/modules/directory under the "boot process must be required module" package into a file named Initramfs file.
2, in the boot, through the host's INT 13 hardware function to read out and decompress the file.
3, Initramfs files in-memory simulation into the root directory, the virtual file system simulation (Initial RAM disk) contains hard disk modules (such as USB, SCSI, etc.) and the file system, so the core kernel can know the actual disk, you can carry out the actual root directory of the mount.
The time required for INITRAMFS is:
? The root directory disk is a SATA, USB, or SCSI connection interface;
? The root directory is located in the file system for LVM, RAID and other special formats;
? When the root directory resides in a file system that is not known to traditional Linux;
? Other modules that must be provided at core load time.
The solution to the forgotten root password
(1) Press Systemctl reboot to restart
(2) Enter the boot screen, press E to enter the editing mode on the menu that can be turned on, then add the Rd.break parameter to deal with the core project of linux16
3. Press [crtl]+x to start the boot
4, boot after the completion of the screen will appear the following similar screen, at this time, please note that you should be in the Ram Disk environment, not the original environment, so the root of the things under the system is not related to your original Oh! And your system should be mounted to the/sysroot directory, so you have to do this:
Generating "/run/initramfs/rdsosreport.txt"
Enter emergency mode. Exit the shell to continue.
Type "Journalctl" to view system logs.
You might want to save "/run/initramfs/rdsosreport.txt" to a USB stick or/boot
After mounting them and attach it-a bug report.
switch_root:/# # No password required to get root privileges!
switch_root:/# Mount # Check the mount point! must find/sysroot is right!
..... (omitted earlier) .....
/dev/mapper/centos-root on/sysroot type XFS (Ro,relatime,attr,inode64,noquota)
switch_root:/# Mount-o Remount,rw/sysroot # mount for Mount command,-O followed by "," separated parameters, Remount: Re-mount, rw: erasable,/sysroot for Mount point
switch_root:/# Chroot/sysroot # represents the directory to which the root directory is "temporarily" switched to chroot. Therefore,/sysroot will be temporarily used as the root directory
sh-4.2# echo "YOUR_ROOT_NEW_PW" | passwd--stdin Root # Set the root account with a new password of YOUR_ROOT_NEW_PW
sh-4.2# Touch/.autorelabel # lets the system automatically use the default SELinux type to re-write the SELinux security document to each file at boot time.
sh-4.2# exit
switch_root:/# reboot
Unable to boot due to file system error
The most error-prone setting leads to the inability to boot smoothly, usually/etc/fstab this file, especially when the user is Quota/lvm/raid, the easiest to write the wrong parameters, and without mount-a to test the mount, immediately restart directly.
1. Enter the root password for rescue
2, Mount-o remount,rw/#输入命令将根目录挂载成可擦写
3, if it is the case of sector confusion, enter FSCK.EXT3 or Xfs_repair command to check/dev/md0 and other partitions.
3.1. When "clear [y/n]" appears, enter "Y"
Command
Grub2-mkconfig-o/boot/grub2/grub.cfg generate a new grub.cfg file
Dracut [-FV] [--add-drivers list] Initramfs file Core version redo Initramfs files
Options and Parameters:
-F: Forced compilation of Initramfs, overwriting old files if Initramfs file already exists
-V: Shows how the Dracut works
--add-drivers list: In the original default core module, add some of the modules you want! The module is located in the core directory/lib/modules/$ (UNAME-R)/kernel/*
Initramfs: That's the name you need! It's best to start with Initramfs, back to version and function
Core version: Presets are, of course, the core version of the current operation, but you can also manually enter different versions!
In fact, Dracut also has a lot of features, such as the bottom of a few parameters can also refer to see:
--modules: Load the Dracut required module (core module), available in module/usr/lib/dracut/modules.d/directory
--GZIP|--BZIP2|--XZ: Try which compression method to use for Initramfs compression. Preset use gzip!
--filesystems: Add some additional file system support!
Grub2-install [--boot-directory=dir] Install_device installation grub2
Options and Parameters:
--boot-directory=dir that dir is the actual directory, using the Grub2-install preset will grub2 all the files copied to the/boot/grub2/*, if you want to copy to other directories and devices, you have to use this parameter.
Install_device Installed device Code!
Actual operation error: Grub2-install: Error:/usr/lib/grub/x86_64-efi/modinfo.sh doesn ' t exist. Please specify--target or--directory.
19.3.5 test and installation grub2--didn't read it.
2018-04-24 "Bird Brother's Linux private cuisine Basic Study (Fourth Edition)" chapter 19th, boot process, module management and loader_2 notes