Linux rescue mode
Modify/etc/fstab,/etc/rc. d/RC. improper Operations on system startup files such as sysinit will cause Linux to fail to access, and a rescue disk can be easily repaired. This method is suitable for restoring the system without a rescue disk.
Select Linux from the GRUB menu, and press E and E to enter the editing mode,
Kernel (hd0, 0)/vmlinuz root =/dev/hda2....
Init =/bin/bash. After modification, press enter to guide B.
The modified boot information is similar to the following:
Kernel (hd0, 0)/vmlinuz root =/dev/hda2 init =/bin/bash
In this way, the boot system can obtain a bash shell
The system is read-only. First, use fsck to check the system.
Fsck-A/dev/hdax process the root partition X is the root Partition Number, such as hda2
Fsck-r-a-A processes other partitions
If the system is restarted normally last time, the system is uninstalled normally,
Can directly mount the system to read-write without the fsck check
Mount/proc
Mount/-O remount, RW
Swapon-A opens any swap Partition
Source/etc/profile load user environment
After the system is repaired, Remount the system to RO, and restart the system safely.
Mount/-O remount, Ro
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)
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. The system will try to find the root partition.
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 mounting 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" 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
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. In this case, only the rescue mode can be used to solve such problems.
1. Recovery Methods for backup files
Enter the rescue mode. After the chroot command is executed, if the file is backed up (we strongly recommend that you back up important data directories in the system, such as/etc and/boot ), 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/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 deleted by mistake and there is no backup, you can reinstall the software package to recover it. First find the RPM package of/etc/inittab (even if the file is lost, because there is an RPM database, you can find the results ):
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 package of the RPM ora system is stored in the ora/RPMS directory of the disc. Its Linux storage location is similar, which is not listed 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/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.