CentOS 7 boot failure, password forgot how to do? How to optimize the service start? Taught you to solve!

Preface:

Until the problem we first look at the boot process boot:

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

Boot failure occurred mainly in the first three steps, mainly to check whether POST hardware damage, mainly to check the CPU and memory, so if this step is a problem we need to replace the hardware. Now I began to began to speak from MBR.

What is the MBR?

Typically, we MBR boot sector containing code called the master boot sector. Because this sector, boot code occupies most of the space, and therefore the habit of this sector is called MBR sector (referred to as MBR). Since this sector has borne a special management functions different from other common storage space on the disk, the entire disk space as the management of a particular space, it does not belong to any partition on the disk, thus formatting commands in the main partition space can not be cleared direct any recorded information. : Master boot sector composed of three parts (occupy a total of 512 bytes)
1. master boot program i.e. the master boot record (the MBR) (accounting for 446 bytes)
when FDISK program can be found in, for its hard disk transferred to the control system designated by the user and registered in the partition table of an operating system.
2. The partition table entry (DPT, Disk Partition Table)
by the partition table entries constituting four (16 bytes each).
Responsible for instructions on partitioning the disk, the contents of the disk media and when the user decides to use FDISK defined partitions. (Details omitted)
3. the end flag (2 bytes)
its value AA55, when the stored previous low, high in the post, i.e., appears 55AA (hex).

Repair MBR sector failure:

cause of issue:

  • Viruses, and other damage
  • Incorrect partitioning, disk read and write misuse

Symptom:

  • To find a boot program, start interrupt
  • Unable to load the operating system, the boot black

Solutions:

  • Backup file should be ready in advance
  • In CD-ROM boot into emergency mode
  • Restore from a backup file

Actual operation:

1. Before MBR boot sector recovery, we must ensure that there is a backup MBR boot sector of the disk in the other, let's first make a backup of the MBR boot sector. Because the boot sector is the first sector of the disk sda, size is 512 bytes, we need to back up data to come out of this sector.

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

2. After a good backup boot sector, we will destroy the boot sector to simulate the boot sector damaged boot failure, we only need to copy some junk files will be covered boot sector, then reboot and you will find that the system does not start properly .

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

3. At this point we need a disk drive system, is that you used to install the system U disk drive or CD-ROM drive will do. I use the CD image, they will plug into your device, and then reboot the device, press the [ESC] key while just opened, select CD-ROM boot in the boot menu and press in turn select the picture below.

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!
CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!
CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

4. After entering the wait for some enter "1" Enter, and then directly to enter into the terminal mode to the shell of a mirror.

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

5. Create a new directory, then back up to disk before sdb1 mount up.

输入:mkdir bak
输入:mount /dev/sdb1 /bak/

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

6. Copy the files sda.mbr.bak sdb1 backup boot sector sda, and then restart.

输入:dd if=/bak/sda.mbr.bak of=/dev/sda
输入:init 6

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

7. Start success.

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

What is GRUB?

Is a multi-operating system startup program from the GNU project. GRUB is a multi-start implementation of the specification, which allows the user to have more than one operating system in the computer, and select the operating system you want to run when the computer starts. GRUB on different cores may be used to select the operating system partition, boot parameters can also be used to transfer the cores.

Repair GRUB boot failure:

cause of issue:

  • GRUB boot loader in the MBR is destroyed
  • grub.conf file is missing, the boot configuration error

Symptom:

  • System boot stagnation, display "grub>" prompt

Solutions:

  • Try to manually enter the boot command
  • Enter emergency mode, rewritten or restored from a backup grub.conf
  • Grub program to rebuild MBR sector

Actual operation:

1. First we need to grub configuration file grub.cfg removed, to simulate damage grub boot failure, and then restart the system.

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

2. The steps to restore MBR and boot sectors of the same, we need a disk drive system, it is that you used to install the system U disk drive or CD-ROM drive will do. I use the CD image, they will plug into your device, and then reboot the device, press the [ESC] key while just opened, select CD-ROM boot in the boot menu and press in turn select the picture below.

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!
CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!
CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

3.进入后稍作等待,然后输入“1”回车,再直接回车,进入到一个镜像的shell终端模式。

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

4.首先加载系统镜像进入到bash环境,然后重新建立加载sda分区,最后重新构建grub菜单配置文件并退出bash环境。

输入:chroot /mnt/sysimage/
输入:grub2-install /dev/sda
输入:grub2-mkconfig -o /boot/grub2/grub.cfg
输入:exit

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

5.重启设备,稍作等待,启动成功。

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!
CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

Root密码重置:

1.当你忘记root的开机密码了,首先咱们用到的还是光盘镜像,步骤与上面的步骤相同,将它们插到你的设备上,然后重启设备,在刚开启时按下[ESC]键,在启动菜单中选择光盘启动,然后按下面图片依次进行选择。

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!
CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!
CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

2.进入后稍作等待,然后输入“1”回车,再直接回车,进入到一个镜像的shell终端模式。

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

3.先加载系统镜像进入到bash模式,直接用“passwd”命令重置密码,再用“exit”命令退出bash模式,输入“init 6”重启直接用新密码登录即可。

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

Systemd单元类型:

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

运行级别所对应的Systemd目标:

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

系统服务控制:

常用方式:

systemctl 控制类型 服务名称

常用控制类型:

  • start:启动
  • stop:停止
  • restart:重新启动
  • reload:重新加载
  • status:查看服务状态

Linux系统的运行级别:

查看运行级别:

  • runlevel命令:查看当前运行级别和切换前运行级别

用“runlevel”命令查看当前的运行级别和切换前运行级别,“5”表示当前的运行级别,“3”表示切换前的运行级别。
CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

  • systemctl工具:查看默认的运行级别
    输入“systemctl get-default”命令,查看系统的默认运行级别,“graphical”表示图形化界面。
    CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

临时切换运行级别:

  • init命令:命令参数是运行级别所对应的数字

1.用“init 3”进入字符界面,“3”是字符界面的运行级别。
CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

2.进入字符界面输入用户名“root”和用户密码登录,然后再用“init 5”命令进入图形化界面。
CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

  • systemctl工具:命令参数是具体的target

1.输入命令“systemctl isolate multi-user.target”进入字符界面,“multi-user”是字符界面的target。
CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

2.在字符界面输入用户名和密码,登录后再用命令“systemctl isolate graphical.target”命令进入图形化界面。
CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

更改默认运行级别:

我们将原来的默认运行级别“graphical”(图形化界面)更改为“multi-user”字符界面,这里其实就是创建一个“multi-user”的软链接“default.target”,并将原来同名的“graphical”的软链接删除。这里“-s”即使软链接,“-f”是删除软链接同名链接。直接输入命令“ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target”,然后查看默认运行级别已经修改成功,当你下次启动系统就会是字符界面了。
CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

系统服务管理工具:

ntsysv工具:

  • 提供一个交互式、可视化窗口
  • 可以在字符终端运行
  • 便于集中管理多个服务

我们直接输入命令“ntsysv”就能进入服务管理界面,我们可以看到每个服务前都有“[ * ] ” 或“[ * ]”,有“ * ”的表示开机自启,没有则不开机自启,我们可以通过“空格键”来更改服务的自启状态,当我们更改完毕只需按[tab]键来选择确定保存设置即可。
CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!
CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

systemctl工具:

  • 不提供交互式、可视化窗口
  • 管理单个服务效率更高

1.我们直接输入命令“systemctl disable sshd.service”,就能直接关闭“sshd”服务的开机自启,然后用命令“systemctl is-enabled sshd”查看一下“sshd”服务的自启状态,显示“disabled”不能自启。

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

2. We then "systemctl enable sshd.service" command to turn "sshd" service from start feature is turned on, and then view the display "enabled" the post.

CentOS 7 boot failure, password forgot how to do?  How to optimize the service start?  Taught you to solve!

Guess you like

Origin blog.51cto.com/14449541/2432504