Three ways to solve Linux system troubleshooting and repair techniques and case sharing

I found that Linux system will have some faults during the startup process, which will cause the system to fail to start properly. I have written several application single-user mode, GRUB command operation, and Linux rescue mode fault repair case to help everyone understand the solution of such problems. .

(1) Single-user mode

The Linux system provides a single-user mode (similar to Windows security mode) for system maintenance in a minimal environment. In single-user mode (run level 1), Linux boots into the root shell, the network is disabled, and only a few processes run. Single-user mode can be used to modify file system corruption, restore configuration files, move user data, and more.

The following is a typical example of several single-user mode repair system failures:

Case 1: The root password is forgotten

In single-user mode, Linux does not require a root password (Red Hat does not require a root password, but SuSe requires it. Different Linux systems are slightly different. This article uses Fedora Core 6 as an example), which makes it very easy to change the root password. It is important to understand how to enter single-user mode when the system boots into multi-user mode.

1. During the system startup process, the start interface will appear, press any key to enter the GRUB menu option. (If you do not want this prompt in the future, go directly to the GRUB menu option and delete the "hiddenmenu" item in the configuration file grub.conf.)

2. Press the “e” key to edit the GRUB boot menu option and press the “e” key to the GRUB screen. Use the arrow keys to move down to the kernel line and press the "e" key.

3. Add single at the tail cursor, press Enter to return to the previous screen, press “b” to boot, the system automatically enters single-user mode. If you want to change the root password, execute the command: sh-3.1# passwd root

After the change is successful, execute the command exit to exit and restart.

You can correct many problems that prevent the system from starting normally in single-user mode, such as:

1. Disable services that may abort the system, such as disabling the Samba service, execute: sh-3.1# chkconfig smb off The next time the system boots, the Samba service will not be started.

2. Change the system default run level If X Window fails to start or fails, you can edit the /etc/inittab file and log in as text. Change the initdefault boot level to 3:id:3:initdefault:

Case 2: Hard disk sector disorder

The most common problem encountered during the boot process is that the hard disk may have bad sectors or dirty sectors (data corruption), which is caused by abnormal power failure and abnormal shutdown.

This problem occurs. When the system starts up, the screen will display:

Press root password or ctrl+D:

At this point, enter the root password system to automatically enter single-user mode, enter:

Fsck -y /dev/hda6

(fsck detects the repair command for the file system, "-y" setting detects the error automatic repair, /dev/hda6 is the hard disk partition where the error occurred, please change this parameter according to the specific situation)

After the system repair is complete, restart it with the command "reboot".

Case 3, GRUB option setting error

"Error 15" shows that the system cannot find the kernel specified in grub.conf.

GRUB boot error message, we observed that because of typing errors, the kernel file "vmlinuz" became "vmlinux", so the system could not find the kernel executable file.

We can press any key to return to the GRUB editing interface, modify this error, press Enter and press the “b” key to boot normally. Of course, don't forget to change the grub.conf file here after entering the system.

This is a mistake that many beginner Linux users can easily make when modifying GRUB settings. When this black screen prompts, observe the error message and you can fix it.

(B) GRUB boot troubleshooting

I found that sometimes Linux will go directly to the GRUB command line interface (only the "grub>" prompt), and many users choose to reinstall GRUB or even reinstall the system.

In fact, in general, the most common causes of this failure are two:

First, the option setting in the GRUB configuration file is incorrect;

Second, the GRUB configuration file is missing (there are a few reasons, such as kernel file or image file corruption, loss, /boot directory error deletion, etc.)

If it is the first case, you can first repair the system through the GRUB command; if it is the second case, it will be repaired using the Linux rescue mode (described later in this article).

First, we need to understand the boot process of the GRUB boot system. The main configuration options in the grub.conf file are as follows:

(Note that the GRUB configuration file is /boot/grub/grub.conf, /etc/grub.conf is just a soft link to this file)

Title Fedora Core (2.6.18-1.2798.fc6)

Root (hd0,0)

Kernel /boot/vmlinuz-2.6.18-1.2798.fc6 ro root=LABEL=/ rhgb quiet initrd /boot/initrd-2.6.18-1.2798.fc6.img

among them:

The "title" section specifies the GRUB booted system:

The "root" section specifies the location of the /boot partition:

The "kernel" section specifies the location of the kernel file. The kernel load attribute is read-only ("ro") and the location of the specified root partition (root=LABEL=/);

"initrd" specifies the location of the image file.

So GRUB in the boot sequence is to first load the /boot partition, and then load the kernel and image files in turn.

Case

"title Fedora Core (2.6.18-1.2798.fc6)" was deleted by mistake

At this point, the system will automatically enter the "GRUB>" command line after startup, we can do the following operations in order to troubleshoot:

1. Find the partition where the /boot/grub/grub.conf file is located. GRUB> find /boot/grub/grub.conf(hd0,0)

2, check the grub.conf file error GRUB> cat (hd0,0) / boot / grub / grub.conf recommended system installation is set up, you should backup the grub.conf file, if there are backup files such as grub.conf.bak, Then you can view the backup file and compare it with the current file and find the error: GRUB>cat (hd0,0)/boot/grub/grub.conf.bak

3. After confirming the error, first complete the GRUB boot through the command line, and then enter the system and then repair the grub.conf file error:

1) Specify the /boot partition root (hd0,0)

2) Specify the kernel to load kernel /boot/vmlinuz-2.6.18-1.2798.fc6 ro root=LABEL=/ rhgb quiet

3) Specify the location of the image file initrd /boot/initrd-2.6.18-1.2798.fc6.img

Tip: GRUB supports tab key command completion function

4, boot boot from the /boot partition (hd0,0)

The command line mode can be called in the GRUB menu mode by pressing the "c" key, or it can be used to test the newly compiled kernel (set kernel, initrd boot new kernel and image file). Increasing knowledge of GRUB boot and Linux system boot knowledge will go a long way toward troubleshooting.
Three ways to solve Linux system troubleshooting and repair techniques and case sharing

(3) Linux rescue mode application

When the system cannot enter the single user mode or the boot problem that the GRUB command line cannot solve, we need to use the Linux rescue mode to troubleshoot.

Proceed as follows:

1. Insert the Linux installation CD (if you use a CD, put the first boot CD) into the CD-ROM drive, set the firmware CMOS/BIOS to boot the CD, and when the Linux installation screen appears, enter it at the "boot:" prompt. "linux rescue" Enter to enter rescue mode. (To learn more about the rescue mode, you can also press F5 to view)

2, the system will detect the hardware, boot the Linux environment on the CD, and prompt you to select the language used in the rescue mode (recommended to choose the default English, according to the author test, some Linux systems will appear garbled in Chinese); keyboard settings The default "us" is fine; the network settings can be based on the need, most of the fault repair does not require a network connection, you can not do this setting, select "No".

3, the next system will try to find the root partition, the mount prompt appears, set the default in rescue mode, the root partition of the hard disk will be mounted to the /mnt/sysimage directory of the CD Linux environment, the default option "continue" means mount permission For reading and writing: "Read-only" is read-only. If the detection fails, you can select "skip" to skip. Here, because you want to repair the system, you need to have read and write permissions, generally choose the default option "continue".

After entering the next step, the system prompts to execute the "chroot /mnt/sysimage" command, which can be mounted to the root directory of our hard disk system.

Case 1: Dual system startup repair

When we install a dual system environment, first install Linux and then install Windows; or Windows has been installed in a dual system environment. After reinstalling Windows, the GRB MBR (Master Boot Record) will be saved by the Windows system. Covered by the program NTLDR, the Linux system could not be booted.

1. If you want to restore dual system boot, first enter the rescue mode by the above method, execute the chroot command as follows: sh-3.1# chroot /mnt/sysimage

2. Switch the root directory to the root directory of the hard disk system, and then run the grub-install command to reinstall GRUB: sh-3.1# grub-install /dev/hda "/dev/hda" for the hard disk name, such as using a SCSI hard disk or Linux is installed on the second IDE hard drive. This setting needs to be adjusted accordingly.

3, and then execute the exit command, exit chroot mode and rescue mode (execute two exit commands): sh-3.1# exit After the system restarts, the dual system boot of GRUB boot will be restored.

Case 2: System configuration file loss repair

During the booting process, a very important process is that the init process reads its configuration file /etc/inittab, starts the system basic service program and the default running level service program to complete the system boot. If /etc/inittab is deleted or modified incorrectly, Linux will not start properly. At this time, such problems can only be solved by the rescue mode.

/etc/inittab file missing boot error example

1. The recovery method of the backup file enters the rescue mode. After the chroot command is executed, if there is a backup of this file (it is strongly recommended that the important data directory in the system, such as /etc, /boot, etc.) be backed up, copy the backup file directly. Go back and exit and restart.

If the configuration file is modified incorrectly, such as the typical /boot/grub/grub.conf and /etc/passwd file modification errors, you can directly correct the recovery.

Assuming the backup file /etc/inittab.bak is executed in rescue mode: sh-3.1# chroot /mnt/sysimage sh-3.1# cp /etc/inittab.bak /etc/inittab

2, no recovery method for backup files If some configuration files are lost or the software is accidentally deleted, and there is no backup, you can restore by reinstalling the software package.

First find out which RPM package /etc/inittab belongs to (even if the file is missing, because the RPM database exists, you can find the result):

Sh-3.1# chroot /mnt/sysimage sh-3.1# rpm -qf /etc/inittab initscripts-8.45.3-1

Exit chroot mode:

Sh-3.1# exit

Mount the installation CD that holds the RPM package (in rescue mode, the CD is usually mounted in the /mnt/source directory):

Sh-3.1# mount /dev/hdc /mnt/source

The RPM package of Fedora system is stored in the Fedora/RPMS directory of the CD. Other Linux storage locations are similar, I will not list them here;

In addition, because the root directory of the hard disk system to be repaired is under /mnt/sysimage, you need to specify its location using the --root option.

Overwrite the RPM package where the /etc/inittab file is installed:

Sh-3.1# rpm -ivh --placepkgs --root /mnt/sysimage /mnt/source/Fedora/RPMS/ initscripts-8.45.3-1.i386.rpm

The rpm command option "-replacepkgs" indicates that the installation is overwritten, and the file has been restored after the execution is completed.

If you want to extract only the /etc/inittab file in the RPM package for recovery, you can execute the command after entering rescue mode:

Sh-3.1# rpm2cpio /mnt/source/Fedora/RPMS/initscripts-8.45.3-1.i386.rpm | cpio -idv ./etc/inittab sh-3.1# cp etc/inittab /mnt/sysimage/etc

Note that when this command is executed, the file cannot be directly restored to the /etc directory. It can only be extracted to the current directory, and the path of the restored file name must be written to the full absolute path. After extracting the file successfully, copy it to the corresponding location in the /mnt/sysimage directory where the root partition is located.

The rescue mode is a powerful weapon for maintaining Linux. This article explains the application method with the above two examples, hoping to give the reader some inspiration. To solve the Linux system startup failure, you must fully understand the Linux boot process before you can effectively judge and handle the fault.

Portable Power Station

Portable Power Station also known as Portable Power Bank. Our product regulated DC Power, AC Pass-Through Charging, Wireless Fast Charger, Bluetooth Playback, Attentive Start, Car charger, Type-C ....... Large capacity meet the needs of all kinds of equipment.

Portable Power Station,Indoor Portable Power Station,Solar Portable Power Station,Portable Power Station With Bms

Jiangsu Zhitai New Energy Technology Co.,Ltd , https://www.jszhitaienergy.com