Article directory
- Boot process
-
- significance
- process
-
- 1.power on
- 2.POST power on self-test
- 3. The BIOS program reads the disk MBR and loads the grub2 program into the memory.
- 4. The grub program reads vmlinuz and initramfs under disk/boot into memory
- 5. The systemd process starts the service corresponding to the specified run level
- 6. When all services are started, execute the command in the /etc/rc.local script
- 7. Read the /etc/fstab file and load the real file system
- 8. Start the login process, log in the user and load the user environment variable initialization file
- question
Boot process
Press the power button to enter your username and password to get into what's going on behind the scenes
significance
- Master how to make a certain software start automatically when booting
- The computer cannot start normally. What is the reason? Find out which link has the problem.
- To prevent hackers from implanting Trojans, check where hackers will put Trojans.
process
1.power on
2.POST power on self-test
Power-on self-test: Power-on self-test (POST, Power On Self Test). Refers to the behavior of the computer system when it is powered on (BIOS program), including testing of the CPU, system motherboard, basic memory, extended memory, system ROM BIOS and other devices. If an error is found, prompt or warn the operator. Simplifying or speeding up this process allows the system to start up quickly.
Who will complete the power-on self-test—> the BIOS program on the motherboard ?
BIOS program
The BIOS program is the abbreviation of the English "Basic Input Output System". When translated literally, the Chinese name is the Basic Input Output System. BIOS is the first software loaded when a personal computer starts.
It is a set of programs solidified on a ROM chip on the motherboard of the computer. It saves the computer's most important basic input and output programs, post-boot self-test programs and system self-starting programs. It can read and write system settings from CMOS. Specific information, its main function is to provide the computer with the lowest and most direct hardware settings and control. In addition, BIOS also provides some system parameters under the operating system. System hardware changes are hidden by BIOS, and programs can use BIOS functions. Instead of controlling the hardware directly, modern operating systems ignore the abstraction layer provided by the BIOS and control the hardware components directly.
rom chip: read only memory --》read-only memory
ram chip: random access memory (abbreviation of random access memory)-》readable and writable
**CMOS: It is a chip that stores BIOS parameter configuration, including CPU configuration, time configuration, startup sequence configuration, BIOS password, which can be read and written, not read-only** BIOS is a program that reads the CMOS
chip Parameters
How to enter BIOS?
VMware virtual machine:
Turn on the computer and press F2 or operate as shown below
Desktop computer:
Turn on the computer and press DEL or delete key to enter.
Laptop computer:
Different manufacturers have different
F2
F8
F12
F2+fn
F1~F12
boot sequence
The first boot sequence: hard drive.
The second boot sequence: cdrom optical drive----》Install the system.
The third boot sequence: removable device Removable device-》U disk, removable hard disk--》Install the system.
The fourth boot sequence: Network --》Start from the network-》Install the server in the network and start--》Install
You can adjust the startup sequence with + -
It is recommended to set a password for your laptop's BIOS to prevent others from adjusting your boot sequence through the BIOS, entering the USB disk to boot, and stealing your laptop's data.
It is recommended to set the password simply, so as not to forget it - "For desktops and laptops, you can remove the battery from the motherboard and clear all configurations to delete the password.
3. The BIOS program reads the disk MBR and loads the grub2 program into the memory.
MBR: Master Boot Record, the place where the Linux system is started. It is a special location in the disk (track 0, sector 1 -> 512 bytes), where the real startup program grub or grub2 is stored.
4. The grub program reads vmlinuz and initramfs under disk/boot into memory
vmlinuz: bootable, compressed linux kernel
initramfs: initial ram fs initializes the random access memory file and provides the kernel program with an initialized memory file system image file, including drivers, tool programs, and supporting files--"Temporary root file system image file
lsinitrd views kernel image initialization files
[root@felix_server boot]# lsinitrd initramfs-3.10.0-1160.el7.x86_64.img |more
You can see that initramfs is similar to a root file system
5. The systemd process starts the service corresponding to the specified run level
After vmlinuz and initramfs are loaded into the memory, the first process systemd will be started. The systemd process starts the service corresponding to the specified run level.
runlevel
Before centos7
Running level: It is an older concept (already eliminated in centos7). Different programs will be started in different levels, which serves as a classification. 0 Shutdown init 0 1 Single-user mode 2
Multi
-
user mode, cannot be used in the network NFS function
3 fully multi-user mode, can use the network and many people log in at the same time, log in to the system is the character interface init 3 --> generally the run level 3 4 is not
enabled
5 graphical interface mode, can use the network and at the same time Many people log in. The graphical interface to log in to the system is init 5
6. Restart init 6.
View current run level
[root@felix_server boot]# runlevel
N 3
N means there is no other previous run level
3 means the current run level
After centos7
run level configuration file
[root@felix_server system]# vim /etc/inittab
View default runlevel
[root@felix_server boot]# systemctl get-default
multi-user.target
Modify the default run level
[root@felix_server system]# systemctl set-default graphical.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target.
[root@felix_server system]# systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
The relationship between .service files and service startup
For example, enter the /etc/systemd/system/multi-user.target.wants multi-user level file to create a service link to the sshd service, so that sshd can start automatically at boot.
Multiple user level file locations
[root@felix_server system]# cd /etc/systemd/system
[root@felix_server system]# ls
[root@felix_server system]# cd multi-user.target.wants/
[root@felix_server multi-user.target.wants]# ls
Setting a program to start automatically at boot is actually creating a .service link file in this directory.
[root@felix_server multi-user.target.wants]# systemctl disable sshd 关闭sshd服务开机自启
Removed symlink /etc/systemd/system/multi-user.target.wants/sshd.service. 取消软链接
[root@felix_server multi-user.target.wants]# systemctl enable sshd 开启sshd服务开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/sshd.service to 增加软链接 /usr/lib/systemd/system/sshd.service.
The relationship between .service files and systemd processes
The role of the sshd.service file: In fact, it tells systemd what this service does, how to start, how to stop, and how to restart
[root@felix_server system]# systemctl stop sshd
[root@felix_server system]# systemctl start sshd
[root@felix_server system]# systemctl restart sshd
Behind systemctl is to tell systemd to start, stop, and restart a service.
Systemd will call the corresponding service file, find the name of the corresponding program, and perform related operations.
Programs installed by yum will have a corresponding service file,
but compiled and installed programs do not have a service file. We need to manually create a new service file ourselves and store it in the multi-user.target.wants directory. Then we can use systemctl start mode start
6. When all services are started, execute the command in the /etc/rc.local script
After all services in the run level file are started, the commands in the /etc/rc.local script will be executed.
[root@felix_server system]# vim /etc/rc.local
7. Read the /etc/fstab file and load the real file system
The function of the /etc/fstab file: tells the Linux system to mount other partitions on the disk and load the real file system, so that users can use the data of all partitions on this disk and read files.
8. Start the login process, log in the user and load the user environment variable initialization file
Check the login process
[root@felix_server system]# ps aux|grep login
root 680 0.0 0.3 26384 1744 ? Ss 14:46 0:00 /usr/lib/systemd/systemd-logind
root 1646 0.0 0.2 112828 988 pts/0 S+ 16:30 0:00 grep --color=auto login
terminal type
When logging in, the Linux system provides us with 6 login terminals
[root@server ~]# w
16:40:23 up 18:36, 4 users, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 145月23 47.00s 0.27s 0.27s -bash
root pts/1 192.168.223.1 14:59 7.00s 0.50s 0.00s w
root tty2 16:39 23.00s 0.02s 0.02s -bash
root tty3 16:40 15.00s 0.01s 0.01s -bash
TTY, terminate type, the terminal that comes with the Linux system, the most authentic, there are 6 terminals that can be used directly
Switching method: ctrl+alt+F1~F6
tty1 Directly log in to the first terminal of the Linux system ctrl+alt+F1
tty2 ctrl+alt+F2
pts is a terminal (pseudo terminal) simulated by the simulator, for example: pts/0
pts/1
pts/2 simulated by the xshell remote login tool
question
1. There is a problem in a certain part of the boot process. Can the machine be started? For example, the /boot partition is deleted or the MBR is damaged?
cannot
2. Where can Trojans hide? Achieve self-starting at boot
- Create a service file in the multi-user level file directory
- Add /etc/rc.local
- When loading user environment variables, write initialization files ~/.bashrc, etc.
- Start scheduled tasks and execute them regularly