Linux Startup fault repair

Source: Internet
Author: User
Article Title: Linux system startup fault repair. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

During Linux Startup, some faults may occur, causing the system to fail to start normally, this article lists several typical fault repair cases of application single-user mode, GRUB command operation, and Linux rescue mode to help readers understand how to solve such problems.

I. 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: 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:

At this time, enter the root password system 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 2: 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. When the system is started, the screen shown is displayed. Press any key to enter the GRUB menu option.

Go to GRBU menu options

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. The GRUB screen is displayed after the "e" Key is pressed.

GRUB boot menu options

Press the arrow keys to move down to the kernel row and press the "e" key to obtain the editing interface displayed in:

Kernel line editing interface

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. To change the root password, run the following command:

Sh-3.1 # passwd root

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

In single-user mode, we can correct many problems that prevent the system from starting normally. For example, 1. Disable services that may stop the system. If Samba is disabled, execute: sh-3.1 # chkconfig smb off the Samba service will not be started 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 3: GRUB option setting error

Is the console information that the system administrator does not want to see. "Error 15" indicates that the system cannot find the kernel specified in grub. conf.

GRUB boot error message

We observed that the Kernel File "vmlinuz" was converted into "vmlinux" due to incorrect typing, so the system could not 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.

Ii. troubleshooting through GRUB Guidance

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.

Iii. Application of 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)

Enter rescue mode

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 the following prompt appears: Mount settings

By default, in rescue mode, the root partition of the hard disk is mounted to the/mnt/sysimage directory of the CD Linux environment. The default option "continue" indicates that the Mount permission is read/write: "Read-only" is Read-only. If detection fails, you can select "skip" to 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" indicates the hard disk name. 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 # After the exit 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. Assume there is a backup file/etc/inittab. run sh-3.1 # chroot/mnt/sysimage sh-3.1 # cp/etc/inittab in rescue mode. 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 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, 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 where the rpm Command Option "-- replacepkgs" indicates overwriting the installation, after the execution is complete, the file is restored.

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/inittab sh-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.

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: 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.