Linux system troubleshooting and repair skills

Source: Internet
Author: User

I found that some faults may occur during the Linux system startup, which causes the system to fail to start normally, I have written several fault repair cases for single-user application mode, GRUB command operation, and Linux rescue mode to help you understand how to solve these problems.

(1) single-user mode

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

The following lists several typical cases of system failure repair in single-user mode:

Case 1: root Password missing

In single-user mode, Linux does not need the root password (the Red Hat system does not need the root password, but the SuSe is required. Different Linux systems are slightly different. This article uses Fedora Core 6 as an example ), this makes it easy to change the root password. It is important to know how to enter the single-user mode when the system fails to boot into the multi-user mode.

1. During system startup, the start interface appears. Press any key to enter the GRUB menu option.

If you do not need this prompt in the future, go 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 options and press the "e" key on the GRUB screen. Move down to the kernel row with the arrow keys, and press the "e" key,

3. Add single to the cursor at the end of the line, press the Enter key to return to the previous screen, and press the "B" key for guidance. The system automatically enters the single-user mode. If you want to change the root password, run sh-3.1 # passwd root

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

In single-user mode, you can solve many problems that prevent normal system startup, such:

1. Disable services that may stop the system. If you disable the Samba service, run sh-3.1 # chkconfig smb off. The Samba service will not be started the next time the system boots.

2. Change the default running level of the system. If X Window cannot be started or fails, you can edit the/etc/inittab file and log on to the system in text mode. Change the initdefault boot level to 3: id: 3: initdefault:

Case 2: Drive sector disorder

The most common problem during startup is that the hard disk may have bad sectors or sector disorder (data corruption). This is often caused by abnormal power outages or abnormal shutdown. When the system is started, the screen displays:

Press root password or ctrl + D: Enter the root password to automatically enter the single-user mode, and enter "fsck-y/dev/hda6" (fsck is the file system detection and repair command, "-y" indicates that an error is automatically repaired./dev/hda6 indicates a hard disk partition with an error. Change this parameter based on the actual situation.) After the system recovers, run the "reboot" command to restart the instance.

Case 3: GRUB option setting error

"Error 15" indicates that the kernel specified in grub. conf cannot be found. GRUB boot error message. We can see that the Kernel File "vmlinuz" is converted into "vmlinux" due to incorrect typing, so the system cannot find the executable file of the kernel. You can press any key to return to the GRUB editing interface and modify this error. Press enter and save and press "B" to boot normally. Of course, do not forget to modify the error in the grub. conf file after entering the system. This is an error that many new Linux users can easily make when modifying GRUB settings. When this black screen prompt appears, observe the error message to fix it.

(2) troubleshooting through GRUB Guidance

I found that sometimes after Linux is started, the GRUB command line interface (only the "grub>" prompt is displayed) is directly displayed. At this time, many users choose to reinstall GRUB or even reinstall the system. In fact, the most common causes of this fault are: one is the option setting error in the GRUB configuration file, and the other is the loss of the GRUB configuration file (there are a few reasons, for example, the kernel or image file is damaged or lost, or the/boot directory is deleted by mistake.) In the first case, you can use the GRUB command to boot the system and fix it. In the second case, you need to use the Linux rescue mode (this article will be described later ).

First, we need to understand the GRUB boot system boot process, grub. the main configuration options in the conf file are as follows (note that the GRUB configuration file is/boot/grub. conf,/etc/grub. conf is only 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

The "title" segment specifies the GRUB-guided system: the "root" segment specifies the/boot partition location: the "kernel" segment specifies the location of the kernel file, when the kernel is loaded, the permission attribute is read-only ("ro") and the specified root partition location (root = LABEL =/); initrd specifies the location of the image file. Therefore, GRUB loads the/boot partition first and then the kernel and image files in sequence during boot.

Case: The "title Fedora Core (2.6.18-1.2798.fc6)" segment was accidentally deleted.

After the system is started, it automatically enters the "GRUB>" command line. To troubleshoot the problem, perform the following operations in sequence:

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

2. View grub. conf file error GRUB> cat (hd0, 0)/boot/grub. we recommend that you set grub after installing conf. conf file backup, if there is a backup file such as grub. conf. bak, now you can view the backup file, compared with the current file, found the error: GRUB> cat (hd0, 0)/boot/grub. conf. bak

3. After confirming the error, run the command line to complete the GRUB boot. after entering the system, fix the grub. conf file error: 1) Specify the/boot partition root (hd0, 0)

2) specify kernel load kernel/boot/vmlinuz-2.6.18-1.2798.fc6 ro root = LABEL =/rhgb quiet 3) specify the location of the mirror file initrd/boot/initrd-2.6.18-1.2798.fc6.img

Tip: GRUB supports the tab key command complementing function.

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

Command line mode can be called by pressing the "c" key in GRUB menu mode, or it can be used to test the newly compiled kernel (set the kernel and initrd to boot the new kernel and mirror file ). The knowledge of GRUB boot and Linux boot is helpful for troubleshooting.

(3) Application of the Linux rescue mode

When the system cannot connect to the single-user mode or the GRUB command line cannot solve the boot problem, we need to use the Linux rescue mode for troubleshooting. The procedure is as follows:

1. Place the Linux installation disc (if the CD disc is used, the first boot disc) into the optical drive, and set the firmware CMOS/BIOS as the boot disc. When the Linux installation screen appears, enter "linux rescue" at the "boot:" prompt and press enter to enter rescue mode. (For details about the rescue mode, press F5 to View Details)

2. The system detects the hardware, guides the Linux environment on the CD, and prompts you to select the language you want to use in rescue mode in sequence. (We recommend that you select the default English language. Based on the test conducted by the author, in some Linux systems, garbled characters are displayed when Chinese characters are selected. The default "us" is used for keyboard settings. network settings can be used as needed. Most fault fixes do not require network connections, select "No ".

3. Next, the system will try to find the root partition, and a mount prompt will appear. The default setting is in rescue mode. The root partition of the hard disk will be mounted to the/mnt/sysimage directory in the CD Linux environment, the default option "continue" indicates that the mounting permission is Read/write: "Read-only" indicates Read-only. If detection fails, you can skip the option "skip. In this example, you need to have the read and write permissions to fix the system. The default option is "continue ".

After entering the next step, the system prompts to run the "chroot/mnt/sysimage" command to mount the root directory 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 If Windows has already been installed in a dual-system environment damaged, after the Windows is re-installed, save the grub mbr (Master Boot Record, the Master Boot Record) will be overwritten by the Windows udf ntldr, causing Linux to fail to boot.

1. If you want to recover the dual-system boot, first use the above method to enter the rescue mode, and execute the chroot command as follows:

sh-3.1# chroot /mnt/sysimage

2. Switch the root directory to the root directory of the hard drive system, and then run the grub-install command to reinstall GRUB:

sh-3.1# grub-install /dev/hda

"/Dev/hda" is the name of the hard disk. For example, if you use a SCSI hard disk or Linux to install it on the second IDE hard disk, adjust this setting accordingly.

3. Execute the exit command in sequence to exit the chroot mode and rescue mode (execute the exit command twice ):

sh-3.1# exit

After the system is restarted, the GRUB-guided dual-system boot will be restored.

Case 2: Repair of system configuration file loss

During system boot, an important process is that the init process reads its configuration file/etc/inittab and starts the basic system service program and default running-level service program to complete system boot, if/etc/inittab is accidentally deleted or modified incorrectly, Linux cannot start normally, as shown in figure 7. In this case, only the rescue mode can be used to solve such problems.

/Etc/inittab file loss guide error example

1. Restore the backup file to 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.), copy the backup file back directly, and exit and restart. If the configuration file is modified incorrectly, for example, the typical/boot/grub. conf and/etc/passwd file are modified incorrectly, you can also directly fix the restoration. If the backup file/etc/inittab. bak is available, run the following command in rescue mode:

sh-3.1# chroot /mnt/sysimagesh-3.1# cp /etc/inittab.bak /etc/inittab

2. restoration without backup files. If some configuration files are lost or the software is deleted by mistake, and no backup is available, you can reinstall the software package to restore them, first, find the RPM package of/etc/inittab (even if the file is lost, you can find the result because the RPM database exists ): sh-3.1 # chroot/mnt/sysimage sh-3.1 # rpm-qf/etc/inittab initscripts-8.45.3-1

Exit the chroot mode:

sh-3.1# exit

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

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

The RPM packages of the Fedora system are stored in the ora/RPMS directory on the CD. The storage locations in other Linux systems are similar. I will not list them here. In addition, because the root directory of the hard drive system to be repaired is in/mnt/sysimage, you need to use the -- root option to specify its location. Overwrite the RPM package where the/etc/inittab file is installed:

sh-3.1# rpm -ivh ——replacepkgs ——root /mnt/sysimage /mnt/source/Fedora/RPMS/ initscripts-8.45.3-1.i386.rpm

The rpm Command Option "-- replacepkgs" indicates that the file has been restored after the installation is completed.

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

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

Note: When executing this command, you cannot directly restore the file to the/etc directory. You can only extract the file to the current directory, and the path of the recovered file name must be a complete absolute path. After the file is extracted, 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. The two examples above illustrate its application methods and hope to give readers some inspiration. To solve the Linux Startup fault, you must fully understand the Linux boot process to effectively judge and handle the fault.

[Edit responsibility:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.