Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Boot process and Service Control of Linux system

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Boot process and Service Control of Linux system

System boot is the beginning of the operating system. Before the user can log in to the system normally, the boot process of linux completes a series of initialization tasks and loads the necessary programs and command terminals to prepare the user for login.

One: an overview of the boot process

​ 1, post

​ 2, MBR Boot

​ 3, GRUB menu

​ 4. Load the linux kernel

​ 5, init process initialization

Two: boot MBR sector failure

The ​ MBR boot record is located in the first sector of the physical hard disk, also known as the main boot sector. it contains not only part of the data of the system boot program, but also the partition table record of the whole hard disk. When the main boot sector fails, you may not be able to enter the boot menu, or you may not be able to find the correct partition location to load the system, and you are likely to enter a black screen when booting the host through the hard drive. The way to solve this problem is to back up the files in advance, boot into the first aid mode with the installation CD, and restore from the backup files.

(1) backup MBR sector data

Because the MBR sector contains the partition table records of the entire hard disk, the backup files for that sector must be stored in other storage devices.

First, you need to create a disk (sdb) to back up the original data to the newly created disk.

(2) simulate MBR sector fault

Still use the dd command to artificially overwrite the record of the MBR sector in order to simulate the failure situation in which the MBR sector is destroyed.

(3) restore MBR sector data from backup

​ can no longer boot from the hard disk because the MBR sector is corrupted, so you need to boot from another operating system on the hard disk, or boot directly from the installation CD of the centos7 system. The goal is to get a shellu environment that can execute commands in order to recover the data in the MBR sector from the backup file.

Restart after destroying the data in the MBR sector (init 6). The installation wizard interface will appear on the virtual machine and enter "first aid mode".

After completing the restore operation, execute the "exit" command to exit the temporary shell environment, execute the "reboot" command, and the system will restart automatically.

Third: fix GRUB boot failure

​ GRUB is the default bootstrap used by most Linux systems, and you can choose to enter a different operating system by starting the menu. When the configuration file / boot/grub/grub.conf is missing, or when the critical configuration is wrong, the Linux host will be prompted with "grub >" after startup, unable to complete further startup operations.

On the virtual machine, first delete the configuration file and make a simulation fault, so that the linux host can not run normally.

After the restart, the symbolic interface of "grub >" will appear. At this time, you need to restart the client. Press the ESC key quickly when the vmware icon starts to read the bar, and go in and start the interface.

Enter first aid mode and start entering commands

Then exit the bash environment (exit) and restart (reboot). At this time, the GRUB failure has been removed, and the virtual machine can be turned on normally.

Four: forget the password of root user

When ​ forgets the password of the root user, it will not be able to log in to the linux system to perform management, maintenance and other tasks, but can only use some restricted functions through the login of other users. Therefore, it is necessary to reset the password of the root account in other ways.

Use the installed CD to enter the shell environment in first aid mode and directly execute the "passwd root" command to reset the root user's password.

Fifth, Linux system operation level and service control

For most system services, there are several common types of control:

Start (startup): run the specified system service program to realize the service function

Stop (stop): terminates the specified system service program and shuts down the corresponding function

Restart (restart): exit first, and then restart Yunxi's specified system service program

Reload (overload): do not quit the service program, just refresh the configuration

Status (View status): view the running status and related information of the specified system service

(1) check the running level of the system-- runlevel

(2) switch the running level of the system

When the user needs to convert the system to another runlevel, it can be done through the init program, as long as the number corresponding to the level (0# 6) is used as a parameter.

For example: change the run level from graphic mode (5) to character mode (3), and execute the "init 3" command. When you want to use the graphical interface again, execute "init 5" to switch back.

1. Open the terminal on the virtual machine and enter init 3, and then enter character mode.

There is another way to switch the run level-- the systemctl tool

2, now the default state is the graphical interface, if you want to directly open the character terminal mode, you have to do a linked file. Assign / lib/systemd/system/multi.user.target to / etc/systemd/system/default.target. Verifies whether the assignment is assigned to character terminal mode after the assignment is completed.

3. Check what types of services and ports are currently running-netstat-ntap. The sshd service appears, indicating remote login.

Want to check the status of sshd

The first method: view it in the form of a pseudo terminal and enter ntsysv. After entering, it looks like a graphical interface, but it is actually the interface of a character terminal. Find sshd.service, the proof with a * sign in front of it is self-starting. If you want to close it, click the space bar.

The second method: turn off boot self-startup, directly enter systemctl disable sshd.service

​ starts up and starts automatically. Enter systemctl enable sshd.service directly.

To see if it is off or on, enter systemctl is-enabled sshd

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report