Linux system can’t start problem and solutions (/etc/fstab file is damaged, GRUB file is damaged)

Although we don't want to, we will inevitably encounter some situations where the system cannot be started!
The reasons always come from various aspects, including hardware problems as well as software problems.

硬件方面(主板,内存,硬盘等)的话及时更换硬件就好。
而软件的问题就要进行修复了,常见的软件问题导致无法开机包括:
1.文件系统问题,如/etc/inittab、/etc/fstab文件配置错误、损坏丢失等。
2.非法关机,导致root文件损坏。
3.Linux内核崩溃
4.系统引导程序出错,如GURB文件丢失或损坏
。。。 。。。

The following uses Centos-7 system as a prototype to make some solutions

1. Loss of /etc/fstab file can not start

  • Simulate the damage of the /etc/fstab file, log in to the system to kill it
rm -rf /etc/fstab
  • And at this time you will find that the system cannot work anymore
  • It may be affected by the 6 version, subconsciously find it very troublesome, it is also a single user, rescue mode or something. Later, it was discovered that the absence of this file did not actually affect the inability to start.
  • It just became a read-only mode. I found out that I couldn't create anything, and the service or anything was gone. Then we tried to fix it.
  • Enter the following command to make the file system readable and writable
mount -o remount,rw /

Insert picture description here

  • At this time, you will find that you have permission to write, and then check the UUID of the partition
ls -l /dev/disk/by-uuid

Insert picture description here

  • Then /etc/fstabjust re-create the file. There are very few things mounted in the 7 system, which is not as complicated as 6.
  • If you don’t remember the content of the file, just create it from another same system (I took a look before deleting it and found that the content of the same system is the same, just write your own for uuid)
vi /etc/fstab

Insert picture description here

  • Then restart the system
reboot
  • Restart the network, you can use xshell to connect
systemctl restart network
  • At this time, I found that I have the permission to write, and the service is normal.
  • (I didn't find any other problems, and I don't know if this method is correct. If there are any problems, please let me know in the comment section)

2. GRUB file loss repair

  • Simulate grub file loss
rm -rf /boot/grub2
  • Restart the system, you will be prompted that the file is not found
    Insert picture description here

  • At this time, you can’t get into the system, you have to enter the rescue mode

  • Reboot the system, when entering the system, press ESCthe key, the following screen, select the third (analog BIOS).
    Insert picture description here

  • Select the third item to enter rescue mode
    Insert picture description here

  • Select the second item to enter the repair mode
    Insert picture description here

  • Select the serial number 1, enter the read-write mode
    Insert picture description here

  • Click enter to see this interface
    Insert picture description here

  • Start the restoration work below, first switch to the original management directory

chroot /mnt/sysimage/

Insert picture description here

  • Create a directory for grub2
mkdir /boot/grub2
  • Because the 7 version system has more mature commands, you can directly use the command to create
grub2-mkconfig -o /boot/grub2/grub.cfg
  • Then execute the following command (the disk where the system is located)
grub2-install /dev/sda
  • Check if there is a file generated, if there is, you can restart
    Insert picture description here
  • Can log in to the system
    Insert picture description here
  • By the way, one thing to note, because my selinux is closed, it can be started directly
  • If selinux is turned on, you need to restart and modify the GRUB configuration. Enter selinux=0 after centos/swap in the line at the beginning of linux 16; then ctrl+x will continue, and the startup will be successful.

Guess you like

Origin blog.csdn.net/qq_42527269/article/details/114008646