In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Linux/Centos7 system management boot process and service control Linux system boot process solving common startup fault control Linux system services (core) optimizing startup tasks in Linux 1. Overview of the boot process (important)-- necessary process mastery
Post-BIOS (Basic Input/Output System), power on first, check whether the hardware (CPU, memory, graphics card, keyboard, etc.) has no problem, no problem loading driver
MBR Boot-- Microcode to find Boot disk
CPU first reads the BIOS program located in CMOS, looks for bootable devices one by one according to the boot order (Boot Sequence) set in BIOS, finds bootable devices, and reads MBR (Master Boot Record, master boot record) in the first sector of the device.
MBR exists in track 0 and sector 0 of the bootable disk and occupies 512 bytes. It is mainly used to tell the computer from which partition of the selected bootable device to load the boot loader (Boot loader). The following exists in MBR:
(1) Boot Loader occupies 446 bytes and stores information related to the operating system (OS), such as operating system name, operating system kernel location and so on. Its main function is to load the kernel and run in memory.
(2) Partition Table partition table, which occupies 64 bytes, and each primary partition occupies 16 bytes (this is why a hard disk can only have 4 primary partitions
(3) the validity mark of the partition table occupies 2 bytes. CPU reads MBR into memory and runs GRUB (GRUB and LILO are commonly used in Boot Loader, and now GRUB is commonly used). GRUB will load the kernel into memory to execute.
As shown above, we can see that the kernel file is manipulated in this configuration file by looking at the contents of line 100 of the / boot/grub2/grub.cfg file.
GRUB menu-A widely used multi-system bootstrap program. After system control is passed to GRUB, a startup menu will be displayed for the user to choose, load the kernel file according to the selection or default, and then transfer system control to the kernel.
Load kernel (kernel)-under the / boot directory, the Linux kernel is a special pre-compiled binary file between various hardware resources and system programs, which is responsible for resource allocation and scheduling.
Add: the following vmlinuz-3.10.0-693.el7.x86_64 is our kernel file. Under the / boot directory
[root@lokott ~] # ll / boot | grep "vmlinuz*"-rwxr-xr-x. 1 root root 5877760 October 23 12:20 vmlinuz-0-rescue-f18b1b17cb2b477f8cb451fffad48550-rwxr-xr-x. 1 root root 5877760 August 23 2017 vmlinuz-3.10.0-693.el7.x86_64 [root@lokott ~] # head-100 / boot/grub2/grub.cfg | tail-1linux16 / vmlinuz-3.10.0-693.el7.x86_64 root=UUID=d0f8b702-0aa9-4857-9551-2e1283d2f5f9 ro crashkernel=auto rhgb quiet LANG=zh_CN.UTF-8
Init process initialization-all the original cache is cleared, and after the necessary processes are loaded, external third-party processes (applications) are loaded (delayed startup)
Kernel initialization is performed as PID1 from initramfs / sbin/init. Copy it as systemd,systemd in Centos7 to start all units in initrd.target and mount the root file system / sysroot
1.1init process
The / sbin/init program is loaded and run by the Linux kernel, which is the first process in the system. The PID number is always 1.
Systemd unit type
Systemd target corresponding to run level
Where .service-- / lib/sysytemd/system
The file is stored in two parts-- meta-information (status information) and content
=
1.2Fix MBR sector failure
1. Cause of failure
Damage caused by viruses, * *, etc.
Incorrect partition operation, disk read and write misoperation
two。 Fault phenomenon
Unable to find bootstrap, startup interrupt
Unable to load operating system, black screen after boot
3. Solution idea
Back up the files in advance
Use the installation CD to boot into first aid mode
Restore from some files
Experiment 1-- experiment of simulating and repairing MBR sector faults
The process is as follows
Backup MBR sector data-add a hard drive for backup (must be backed up first)
(1) Partition, formatting, mounting
(2) back up the mbr boot sector to other disks
Backup = dd if=/dev/sda of=/abc/sda.mbr.bak bs=512 count=1 (/ abc is the mount point of another disk)
Simulated fault
Dd if=/dev/sda of=/abc/sda.mbr.bak bs=512 count=1
Restart: reboot-- > enable DHCP (system not found) and find out if there is a system that can be loaded on the Internet, but it can't be found.
Before repairing, you need a CD image and you need to connect and use it.
Load the first aid mode in the system image file
Load the kernel interface in the system image file
Press the ESC key when reading the note-select CD-ROM Drive--, select Troubleshooting--, select Rescue a Centos system (add: of course, the first two steps can be omitted if your image file is connected all the time)
4. Restore the backup data
The specific experimental steps and results are as follows:
Step one:
[root@localhost] # lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 40G 0 disk ├─ sda1 8:1 06G 0 part / boot ├─ sda2 8:2 020G 0 part / ├─ sda3 8:3 010G 0 part / home ├─ sda4 8:4 01K 0 part └─ sda5 8:5 04G 0 part [SWAP] sdb 8:16 020G 0 disk └─ sdb1 8:17 0 20G 0 part sr0 11:0 1 4.2G 0 rom / run/media/root/CentOS 7 x8634 [root@localhost] # mkfs.xfs / dev/sdb1meta-data=/dev/sdb1 isize=512 agcount=4 Agsize=1310656 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0data = bsize=4096 blocks=5242624, imaxpct=25 = sunit=0 swidth=0 blksnaming = version 2 bsize=4096 ascii-ci=0 ftype=1log = internal log bsize=4096 blocks=2560 Version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime = none extsz=4096 blocks=0 Rtextents=0 [root@localhost ~] # mount / dev/sdb1 / mnt [root@localhost ~] # df-hT | tail-1/dev/sdb1 xfs 20G 33m 20G 1% / mnt [root@localhost ~] # dd if=/dev/sda of=/mnt/sda.mbr.bak bs=512 count=1 has recorded 1x0 read-in and 1x0 write-out 512 bytes (512B) has been copied 0.000126274 seconds, 4.1 MB/ seconds [root@localhost ~] # ls / mnt/sda.mbr.bak
Step 2:
[root@localhost ~] # dd if=/dev/zero of=/dev/sda bs=512 count=1// garbage fill covers the contents of the first sector (simulated destruction) records 1: 0 read-in record 1-0 write-out 512 bytes (512B) replicated, 0.000139415 seconds, 3.7MB/ seconds [root@localhost ~] # reboot / / restart
Step 3:
When the system image file is connected all the time, the operation after restart is as follows:
(1) Select Troubleshooting-- enter
(2) Select Rescue a CentOS system-- enter
(3) enter the loading interface and wait a moment.
(4) enter the first aid interface and prepare to repair MBR. Enter 1, enter enter, pop up the dialogue below and enter again.
(5) input commands to repair sectors
=
1.3Fix GRUB boot failure
1. Cause of failure
GRUB bow in MBR | the pilot program is damaged.
Missing grub.conf file, incorrect boot configuration
two。 Fault phenomenon
System boot stagnates, displaying the "grub >" prompt
3. Solution idea
Try to enter the boot command manually
Enter first aid mode, rewrite or restore grub.conf from backup
Rebuild the grub program into the MBR sector
Experiment 2-- simulated repair of GRUB Boot failure experiment
The process is as follows:
Use the system first aid mode to enter the command character interface
Load the system in the mirror and enter the bash environment
Chroot / mnt/sysimage
Rebuilding the GRUB menu system
Grub2-install / dev/sda
Grub2-mkconfig-o / boot/grub2/grub.cfg
Exit
Reboot
The operation process and results of the experiment are as follows:
[root@localhost] # ll / boot/ total amount 136460 RW / RW / boot/ / RW / Mel. 1 root root 140894 August 23 2017 config-3.10.0-693.el7.x86_64drwxr-xr-x. 3 root root 17 November 14 11:37 efidrwxr-xr-x. 2 root root 27 November 14 11:38 grubdrwx-. 5 root root 14 November 97 11:42 grub2-rw-. 1 root root 69272056 November 14 11:41 initramfs-0-rescue-a33ccb7775134b0e83e04555d56fedb7.img-rw-. 1 root root 28281283 November 14 11:42 initramfs-3.10.0-693.el7.x86conversation 64.IMG Murray RWMI. 1 root root 16565979 November 14 11:43 initramfs-3.10.0-693.el7.x86q64kdump.IMGMUR RW Murray 1 root root 10181954 November 14 11:41 initrd-plymouth.img-rw-r--r--. 1 root root 293027 Aug 23 2017 symvers-3.10.0-693.el7.x86mm 64.gz Murrw. 1 root root 3228420 August 23 2017 System.map-3.10.0-693.el7.x86_64-rwxr-xr-x. 1 root root 5877760 November 14 11:41 vmlinuz-0-rescue-a33ccb7775134b0e83e04555d56fedb7-rwxr-xr-x. 1 root root 5877760 August 23 2017 vmlinuz-3.10.0-693.el7.x86_64 [root@localhost] # ll / boot/grub2 total consumption 32 Murray RW Muhami. 1 root root 84 November 14 11:42 device.mapdrwxr-xr-x. 2 root root 25 November 14 11:42 fonts-rw-r--r--. 1 root root 4235 November 14 11:42 grub.cfg-rw-r--r--. 1 root root 1024 November 14 11:42 grubenvdrwxr-xr-x. 2 root root 8192 November 14 11:42 i386-pcdrwxr-xr-x. 2 root root 4096 November 14 11:42 locale
Explain: as shown above, the grub directory under the / boot directory stores the background image and style of the startup menu, while the configuration file is stored in grub2.
(1) delete the configuration file to simulate the whole process
[root@localhost grub2] # cd / boot/grub2/ [root@localhost grub2] # lsdevice.map fonts grub.cfg grubenv i386-pc locale [root@localhost grub2] # rm-rf grub.cfg [root@localhost grub2] # init 6
The interface after restart is as follows: (unable to log in normally at this time)
(2) Guide the first aid mode and load the system image: when reading the note (faster) press ESC to enter the selection menu-- Select 3.CD-ROM Drive--, select Troubleshooting--, select Rescue a Centos system, and finally enter the following interface to operate.
After that, you can log in normally.
=
1.4 cracking the root password
1. Cause of failure
Forget root user password
two。 Fault phenomenon
Unable to perform administrative operations that require root permission
Without other available accounts, you will not be able to log in to the system
3. Solution idea
Enter first aid mode and reset the password
Experiment 3-- forgetting root user password
The process is as follows:
Load the mirror system and change the password directly
The operation process and results of the experiment are as follows:
(1) Select the image file as connected first.
(2) restart the local virtual machine
Press ESC to enter the selection menu while reading the note (faster)-- Select 3.CD-ROM Drive--, select Troubleshooting--, select Rescue a Centos system.
(3) use the chroot command and passwd root to set the root password; then exit and reboot can log in to root users normally
II. System service control 2.1 system service control command systemctl
Control type (option parameter)
Start: start stop: stop restart: restart (will interrupt the service, equivalent to stop first, then start) reload: reload (the configuration file will be reloaded, will not be interrupted) status: check the service status …
Example:
[root@localhost ~] # systemctl stop network / / stop network connection [root@localhost ~] # ifconfig | View ip information ens33: flags=4163 mtu 1500 ether 00:0c:29:56:d3:4a txqueuelen 1000 (Ethernet) RX packets 374bytes 28991 (28.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 50 bytes 6529 (6 KiB) TX errors 0 dropped 0 Overruns 0 carrier 0 collisions 0virbr0: flags=4099 mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52Partition 5400VOV 3709 txqueuelen 1000 (Ethernet) [root@localhost] # systemctl start network / / initiate network connection [root@localhost] # ifconfig | head ens33: flags=4163 mtu 1500 inet 192.168.68.130 netmask 255.255.255.0 broadcast 192.168.68.255 Inet6 fe80::7eb1:2dde:8a54:6927 prefixlen 64 scopeid 0x20 ether 00:0c:29:56:d3:4a txqueuelen 1000 (Ethernet) RX packets 379bytes 29759 (29.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 75 bytes 10116 (9.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: run level of the flags=73 mtu 655362.2Linux system
View run level
Runlevel Command systemctl tool
Temporarily switch the run level
Init Command systemctl tool 2.3 optimize the startup process
System service management tools
Ntsysv tool (pseudo-graphic interface)
Provides an interactive and visual window that can be run on character terminals to facilitate centralized management of multiple services
Systemctl tool
It is more efficient to manage a single service without providing interactive and visual windows
Further introduce the systemctl command with the following example
[root@localhost ~] # rpm-Q httpdhttpd-2.4.6-90.el7.centos.x86_64 [root@localhost ~] # netstat displays network connections, routing tables, interface status, camouflage connections, network link information, and multicast member groups. ^ C [root@localhost ~] # netstat-ntap | grep 80 [root@localhost ~] # systemctl start httpd [root@localhost ~] # netstat-ntap | grep 80tcp6 00: 80: * LISTEN 14793/httpd [root@localhost ~] # systemctl stop httpd [root@localhost ~] # netstat-ntap | grep 80 [root@localhost ~] # systemctl enable httpdCreated symlink from / etc/systemd / system/multi-user.target.wants/httpd.service to / usr/lib/systemd/system/httpd.service. [root@localhost ~] # systemctl is-enabled httpdenabled
Systemctl enable httpd is boot self-start, is-enabled is to display its status, shutdown and self-start is to enter reboot on disable and then use netstat to check whether there is a httpd service self-start on port 80. The specific operation is shown below.
[root@localhost ~] # netstat-ntap | grep 80tcp6 00: 80: * LISTEN 953/httpd [root@localhost ~] # systemctl disable httpdRemoved symlink / etc/systemd/system/multi-user.target.wants/httpd.service. [root@localhost ~] # systemctl is-enabled httpddisabled [root@localhost ~] # III.
This paper mainly explains the system boot process and service control and optimization in Linux system management, involving the following commands:
Exit, reboot, chroot, grub2-install, grub2-mkconfig, passwd, runlevel, ntsysv, systemctl, netstat, etc. Mainly to solve some problems in the boot process of the system, forced to crack the root password (in essence, forced replacement), and finally describes the service control command operation and some simple optimization operations.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.