In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces you what are the Linux system fault repair and repair skills, the content is very detailed, interested friends can refer to, hope to be helpful to you.
I found that there will be some failures in the startup process of the Linux system, resulting in the system can not start normally. Here I have written several fault repair cases using single-user mode, GRUB command operation and Linux rescue mode to help you understand how to solve these problems.
I. single-user mode
The Linux system provides a single-user mode (similar to Windows security mode) and can be maintained in a minimal environment. In single-user mode (runlevel 1), Linux boots into the root shell, the network is disabled, and only a few processes are running. Single user mode can be used to modify file system corruption, restore configuration files, move user data, and so on.
Here are several typical cases of repairing system failures in single-user mode:
Case 1: forget the root password
In single-user mode, Linux does not need a root password (Red Hat systems do not need a root password, but SuSe does, and 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 fails to boot into multi-user mode.
1. During the startup of the system, the start interface will appear and press any key to enter the GRUB menu option. (if you want to avoid 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 options, press the "e" key after the GRUB screen. Move down to the kernel line with the arrow keys and press the "e" key
3. Add single at the trailing cursor, press enter to return to the previous screen, press the "b" key to boot, and 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 stop the system. For example, if you disable 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 default run level of the system. If X Window fails to start or fails, you can edit the / etc/inittab file, log in as text, and change the initdefault boot level to 3:id:3:initdefault:
Case 2: hard disk sector disorder
The most common problem encountered in the startup process is that the hard disk may have bad tracks or sector confusion (data damage), which is mostly caused by abnormal power outage and abnormal shutdown.
When this problem occurs, when the system starts, the screen displays:
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 is the file system detection and repair command, "- y" sets the error detected to automatically repair, / dev/hda6 is the hard disk partition where the error occurred, please change this parameter according to the specific situation)
After the system is repaired, 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 the typing error, the kernel file "vmlinuz" was typed as "vmlinux", so the system could not find the kernel executable file.
We can press any key to go back to the GRUB editing interface, correct this error, enter and save, press the "b" key to boot normally, of course, don't forget to modify the error here in the grub.conf file after entering the system.
This is a mistake that many novice Linux users are easy to make when modifying GRUB settings. When this black screen prompt appears, pay attention to observe the error message and fix it.
II. Troubleshooting of GRUB Boot
I have found that sometimes when Linux starts up, it goes 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, generally speaking, there are two most common causes of this failure:
First, the option settings in the GRUB configuration file are incorrect.
Second, the GRUB configuration file is missing (there are a few reasons, such as kernel file or image file corruption, loss, / boot directory deletion, etc.)
In the first case, you can boot the system first with the GRUB command and then repair it; in the second case, use the Linux rescue mode to fix it (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
Where:
The "title" section specifies the system that GRUB boots:
The "root" section specifies the location of the / boot partition:
The "kernel" section specifies the location of the kernel file, the permission attribute is read-only ("ro") when the kernel is loaded, and the location of the root partition is specified (root=LABEL=/)
"initrd" specifies the location of the image file.
So the GRUB boot sequence is to load the / boot partition first, and then load the kernel and the image file in turn.
Case "title Fedora Core (2.6.18-1.2798.fc6)" paragraph was mistakenly deleted
At this point, the system will automatically enter the "GRUB >" command line after startup. To troubleshoot the problem, we can do the following in turn:
1. Find the partition GRUB > find / boot/grub/grub.conf (hd0,0) where the / boot/grub/grub.conf file resides
2. Check grub.conf file error GRUB > cat (hd0,0) / boot/grub/grub.conf it is recommended to back up the grub.conf file after the system is installed. If you have a backup file such as grub.conf.bak, you can view the backup file at this time. Compared with the current file, you can find an 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 fix the grub.conf file error after entering the system:
1) specify / 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
Hint: GRUB supports tab key command completion function
4. Launch boot (hd0,0) from the / boot partition
Command-line mode can be invoked in GRUB menu mode by pressing the "c" key, or it can be used to test the newly compiled kernel (setting kernel, initrd to boot the new kernel and image files). Increased knowledge of GRUB boot and Linux system boot will be of great help to this type of troubleshooting.
Third, the application of Linux rescue mode
When the system can not even enter single-user mode or the boot problem that cannot be solved by GRUB command line, we need to use Linux rescue mode for troubleshooting.
The steps are as follows:
1. Put the Linux installation CD (if you use CD CD, put the first boot CD) into the CD drive, set the firmware CMOS/BIOS to CD boot, when the Linux installation screen appears, enter "linux rescue" after the "boot:" prompt to enter the rescue mode. (for more information about the rescue mode, you can also press F5 to view it.)
2, the system will detect the hardware, boot the Linux environment on the CD, and then prompt you to choose the language used in rescue mode (it is recommended to choose the default English, according to the author's test, some Linux systems choose Chinese will appear garbled); keyboard settings with the default "us"; network settings can be based on needs, most of the fault repair does not require network connection, but do not carry out this setting, select "No".
3. Next, the system will try to find the root partition, the mount prompt appears, and the default setting is in rescue mode. The root partition of the hard disk will be mounted to the / mnt/sysimage directory of the CD-ROM Linux environment. The default option "continue" means that the mount permission is read-write: "Read-only" is read-only. If the detection fails, you can choose "skip" to skip. Here, because you want to repair the system, you need to have read and write permissions, and generally choose the default option "continue".
After moving on to the next step, the system prompts you to execute 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 the dual-system environment, install Linux first and then install Windows;, or the Windows that has already installed the dual-system environment is damaged. After reinstalling Windows, the MBR (Master Boot Record, master boot record) of the GRUB will be overwritten by the bootstrap program NTLDR of the Windows system, causing the Linux system not to boot.
1. If you want to resume 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, change the root directory to the root directory of the hard disk system, and then execute the grub-install command to reinstall GRUB:sh-3.1# grub-install / dev/hda "/ dev/hda" to the hard disk name, such as using SCSI hard disk or Linux to install in the second IDE hard disk, this setting should be adjusted accordingly.
3. Then execute the exit command in turn, exit the chroot mode and rescue mode (execute two exit commands): after the sh-3.1# exit system is restarted, the dual system boot booted by GRUB will be restored.
Case 2: repair of missing system configuration files
During the boot period of the system, 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, and if / etc/inittab deletes or modifies the error by mistake, Linux will not be able to start normally. At this point, such problems can only be solved through the rescue model.
/ etc/inittab file missing boot error example
1. The recovery method for backup files enters the rescue mode. After executing the chroot command, if there is a backup of this file (it is strongly recommended to back up important data directories in the system, such as / etc, / boot, etc.), copy the backup files directly and exit and restart them.
If it is a configuration file modification error, such as the typical / boot/grub/grub.conf and / etc/passwd file modification errors, you can also directly correct and restore.
Assuming that there is a backup file / etc/inittab.bak, execute it in rescue mode:
Sh-3.1# chroot / mnt/sysimage sh-3.1# cp / etc/inittab.bak / etc/inittab
2. There is no way to restore backup files. If some configuration files are lost or the software is deleted by mistake, and there is no backup, you can restore it by reinstalling the software package.
First find out which RPM package / etc/inittab belongs to (even if the file is missing, because there is a RPM database, you can still 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 where the RPM package is stored (in rescue mode, the CD 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 CD-ROM Fedora/RPMS directory, and the locations of other Linux are more or less the same. I will not enumerate them here.
In addition, because the root directory of the hard disk system to be repaired is under / 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 installation is overwritten and the file has been restored after the execution is complete.
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: files cannot be directly restored to the / etc directory when this command is executed, but can only be extracted to the current directory, and the path where the restored file name is located should be written to a complete absolute path. After the file is successfully extracted, copy it to the appropriate location in the / mnt/sysimage directory where the root partition is located. Rescue mode is a powerful weapon to maintain Linux. To solve the fault of Linux system startup, we must fully understand the boot process of Linux in order to effectively judge and deal with the fault. What are the Linux system fault repair and repair skills shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.