Troubleshooting and repairing common Linux systems

Source: Internet
Author: User

one, common system failure:


The server can start normally is very good, but because the administrator mistakenly operation, or the physical sector damage to the disk can be fatal to the system, so that the system can not start, then as an administrator you can not sit idly by? This requires the administrator to be able to respond to various errors in the system that caused the system to fail to boot.

We know that the system start-up is divided into multiple steps, any one link error will make the system can not start, so like the key data is best to do the backup work to avoid errors can not be addressed. Because some data can be repaired, and some of the data is not repairable, the following discussion of the repairable part of the data repair it:

1. Grub corruption in MBR, 1_5 phase of data corruption, 2-stage grub corruption

2. initramfs*.img file corruption, kernel file corruption

3./boot/grub/grub.conf file is missing

4./etc/fstab lost, unable to mount Root and other file systems

5. All files are missing from the/boot directory

6. Root Password Forgotten

7. Set password for grub, take effect at boot, protect root password from malicious modification, etc.

second, the Common fault judgment:

When the system does not start, there will be many different error prompts or error phenomena, the administrator can judge for different phenomena in what part of the problem, in order to solve the problem, the remedy

1. 1 stage and 1_5 stage problems when the boot completes after the BIOS self-Test direct error

650) this.width=650; "alt=" 11.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652500869890.png "title=" 1473652500869890.png "height=" width= "563"/>


2. The previous two phases passed smoothly, and the file was lost or/boot/under the kernel file and initramfs*.img when the program called/boot/grub/grub.conf when the second phase of the/boot/was executed. File loss will cause the card in the second stage: the loss of the Initramfs file will be in the boot after the boot selection kernel startup is stuck, there is no hint (defined in the/boot/grub/grub.conf configuration file timeout time, will be over the countdown, Then without any hint) if it is lost grub.conf is going to enter grub> prompt by admin to specify the kernel file and Initramfs file location

Kernel file missing error:

650) this.width=650; "alt=" 22.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652526636388.png "title=" 1473652526636388.png "height=" width= "574"/>

grub.conf file Missing:

650) this.width=650; "alt=" 33.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652537372062.png "title=" 1473652537372062.png "height=" width= "576"/>

3. /etc/fstab lost:

The system can boot, but the boot will be stuck for a long time, because many services wait timeout can not start, at this time the disk by default to read-only mount Root, this mount is mounted at boot, because there is no fstab file so unable to re-mount the root file system and other systems, no runlevel

4. set the password for Grub to boot into the kernel when the boot, want to modify the grub and kernel parameters or enter the system need to input a password, of course, forget such a password can only use CD-ROM boot into the rescue mode to modify the configuration file/etc/grub/grub.conf Delete the corresponding password line

650) this.width=650; "alt=" 44.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652568735859.png "title=" 1473652568735859.png "height=" 285 "width=" 611 "/>

Password modification required for grub

650) this.width=650; "alt=" 55.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652581525840.png "title=" 1473652581525840.png "/>

Password Required for boot:

650) this.width=650; "alt=" 66.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652592213220.png "title=" 1473652592213220.png "height=" width= "602"/>

third, fault repair:

1. Use the disc to boot into rescue mode:

This model is introduced because most of the system repair needs to enter this mode, so first to introduce this mode how to enter it!

(1) When booting the BIOS to see the prompt is generally press ESC or F2 key, enter the startup item selection, different versions of the BIOS difference is larger, here will not introduce, of course, if it is a USB drive or network boot, just choose the time to do the corresponding choice

650) this.width=650; "alt=" 77.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652621884289.png "title=" 1473652621884289.png "/>

(2) Access to the classic rescue mode interface via CD-ROM:

650) this.width=650; "alt=" 88.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652632358905.png "title=" 1473652632358905.png "/>

Note: The first of these is the installation or upgrade of an existing system, the second is a completely new installation of the new operating system, the system does not have an operating system is optional. The third item is the rescue mode we're talking about! Items fourth and fifth are from local hard disk boot and memory detection

(3) After selecting the rescue mode is a large series of CD-ROM startup log kernel loading information, and finally let us choose the language, choose the keyboard type, the default choice of English and US-type keyboard mode on the line!

650) this.width=650; "alt=" 99.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652646471933.png "title=" 1473652646471933.png "height=" 332 "width=" 567 "/>

(4) The next step is to set up the network, if the direct boot from the local do not need the network, if necessary network of course Choose Yes

650) this.width=650; "alt=" 991.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652679485994.png "title=" 1473652679485994.png "/>

(5) Finally in the rescue mode will be prompted to mount your system root to/mnt/sysimage, as well as storage in the San when selecting advanced information, as I was repaired locally, directly continue can

650) this.width=650; "alt=" 992.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652706941820.png "title=" 1473652706941820.png "height=" 407 "width=" 538 "/>

Next the kernel will detect your root file system on which hard disk, and will return the prompt information, here I will repair the first CentOS 6.8 system Select OK, select Confirm again, your root mount to/mnt/sysimage, you can execute chroot/mnt/ Sysimage the root of the file system to the root of your original operating system, because you are now on the root of the disc, and finally will again prompt your root file system mount path, select OK, then there will be three options to start a shell.

650) this.width=650; "alt=" 993.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652721169173.png "title=" 1473652721169173.png "/>

650) this.width=650; "alt=" 994.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652751352032.png "title=" 1473652751352032.png "/>



(6) Finally entered the shell, and returned to our familiar command line mode! After entering the shell we can make various repairs!


2. Repair the GRUB program:

According to the previous graphical tips to repair grub needs: Enter the rescue mode, switch root, install grub, install after two exit, select Restart, you need to note that installation grub may sometimes need to perform two times to repair, if error, can be executed again

650) this.width=650; "alt=" 995.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652771991074.png "title=" 1473652771991074.png "/>

The command to fix grub Grub-install depends on the files in the/boot/grub/directory

650) this.width=650; "alt=" 996.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652789533589.png "title=" 1473652789533589.png "height=" width= "562"/>

When these files are not available, Grub-install can generate these files.


3. kernel file or initramfs*.img file is missing


When these two files are lost, the system is stuck at the grub> prompt. Also enter rescue mode to install the kernel, or generate initramfs*.img files

Re-install kernel files into rescue mode: Install kernel files to generate both kernel files and Initramfs files, or use commands to generate them separately

650) this.width=650; "alt=" 997.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652889751670.png "title=" 1473652889751670.png "height=" width= "569"/>

Generate Initramfs File separately command: It uses inverted single quotation marks to generate the current kernel version number, and after the command to give the command a version of the parameters, because the same version as the current version, so also use reverse single quotation marks to generate the version number: The following two commands the first one is for rhel6 version, The following is the version of Rhel5

650) this.width=650; "alt=" 998.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652905533074.png "title=" 1473652905533074.png "height=" width= "582"/>


4. grub.conf configuration file format and repair:

650) this.width=650; "alt=" 999.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652920844214.png "title=" 1473652920844214.png "height=" 249 "width=" 598 "/>


default=0 : The first kernel boot is defined when a startup item without a kernel menu is selected.

timeout=5: defines a time-out period of 5s without any action

Splashimage= (hd0,0)/grub/splash.xpm.gz defines the background image of the kernel selection menu when booting, can not write this line, but the error will also cause the machine can not start!

hidemenu: Hide Kernel Selection menu, press any key to appear the selection menu, can not write this line

Title: Kernel Name Title

Root (hd0,0): relative to the following kernel and INITRD global definition root is the first partition of the first disk, where root is not the true root, but the boot/boot partition, because the bootloader boot has not loaded the kernel and Partition The loaded kernel needs to drive the load/partition and kernel via the/boot partition

Kernel: defines the kernel file location and passes the necessary parameters to the kernel file. and specify where the/partition is located

INITRD: includes the necessary driver to load the root partition and can extract the virtual root in memory to load the real kernel file

If you just lose the/boot/grub/grub.conf file, you can see the grub> command line at boot, directly specify the directory of kernel and Initramfs files can be started, and then start writing files, of course, you can write the file in rescue mode, Save reboot Machine


5./etc/fstab file Missing:

If this is the first time, the system will be started according to the/etc/mtab file, the second time will be reported many errors, the file system is not properly mounted, system logs, system services and many other problems will occur, because the system by default is read-only boot, and so long after the system will start, At this time the system does not mount the necessary file system such as root, there is no runlevel, can re-mount the file system for read-write mode, of course, you can also modify the root to read-write mode when the system starts. Writing/etc/fstab


6. if both the/boot directory and the/etc/fstab file are missing:

need to first enter the rescue mode to write the/etc/fstab file restart, re-enter the system repair/boot. It is important to note that if the file system is built on a logical volume, when the/etc/fstab is lost, To activate the volume group of the logical volume after the system is activated, the logical volume is activated, the Vgchange-ay activates all logical volumes with the command, mounts the active root, boot and other partitions to the temporary directory, and writes the/etc/fstab information to the mounted root partition (note at this time if/ usr//var and other directories are separate partitions that also need to be written to the/etc/fstab file, because if many of the commands and library files that are not mounted on both partitions are called to fail, many of the system's commands depend on the library files under these two directories, and so on, after they are written, restart, Let the system identify the current mounted root partition to reinstall Grub, and the kernel, and write a/boot/grub/grub.conf file restart to


7. Fix root password forget:


(1) Rhel6 and Previous versions

Boot after the BIOS self-test Press any key, enter the kernel selection menu, by the following information, press A can pass parameters to the kernel

650) this.width=650; "alt=" Z1.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652938573931.png "title=" 1473652938573931.png "/>

The system starts the first user program is INIT, according to the configuration of the Inittab file into the system initialization, you can directly enter the digital 1,s,s,single, either, or Init=/bin/bash, the front is entered in single-user mode, Behind is the direct launch of the/bin/bash without entering user mode.

650) this.width=650; "alt=" Z2.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473652952360756.png "title=" 1473652952360756.png "/>

You can change the root password directly after entering:

650) this.width=650; "alt=" Z3.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473653039559535.png "title=" 1473653039559535.png "height=" width= "637"/>

(2) version of RHEL7:

Also enter the kernel selection interface:

650) this.width=650; "alt=" Z4.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473653105618647.png "title=" 1473653105618647.png "height=" 284 "width=" 642 "/>

Press the E key to enter the edit mode: Find linux16 start this line: Move the cursor to the RO, after the second half of the line is deleted, be careful not to delete initrd this line! After deleting, enter Rd.break, and type ctrl+x to execute

650) this.width=650; "alt=" Z5.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473653233630167.png "title=" 1473653233630167.png "height=" 267 "width=" 651 "/>

Emergency mode:

650) this.width=650; "alt=" Z6.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473653124923240.png "title=" 1473653124923240.png "/>

Perform a re-mount root partition for read-write mode, change the current root, modify the root password, execute

Touch/.autorelabel (because SELinux is turned on by default, so you want to re-label the system files, it is a bit slow to perform this process on exit, you need to wait patiently), exit exit two times.

650) this.width=650; "alt=" Z7.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473653261492906.png "title=" 1473653261492906.png "height=" width= "615"/>

650) this.width=650; "alt=" Z9.png "src=" http://www.178linux.com/ueditor/php/upload/image/20160912/ 1473653277183853.png "title=" 1473653277183853.png "/>

Wait for the end of the boot, at this time rhel7 password has been updated!


The restoration of Linux is not a day's work requires our joint efforts to accumulate experience for a long time, maintain it!



This article from "Jackcui" blog, reproduced please contact the author!

Troubleshooting and repairing common Linux systems

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: info-contact@alibabacloud.com 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.