Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Linux Rescue Mode

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you the "example analysis of Linux rescue mode", the content is simple and easy to understand, clear organization, I hope to help you solve doubts, let Xiaobian lead you to study and learn the "example analysis of Linux rescue mode" article.

Linux Rescue Mode Applications

When a system cannot even enter single-user mode or has boot problems that the GRUB command line cannot resolve, we need to use Linux rescue mode for troubleshooting.

The procedure is as follows:

1. Put the Linux installation CD (if using CD, put the first boot CD) into the optical drive, set the firmware CMOS/BIOS to CD boot, when the Linux installation screen appears, enter "linux rescue" after the "boot: " prompt to enter rescue mode. (For rescue mode details, press F5 to view)

2. The system will detect the hardware, guide the Linux environment on the CD, and prompt you to select the language used in rescue mode in turn (it is recommended to select the default English, according to the author's test, some Linux systems will appear garbled when selecting Chinese); the keyboard setting is good with the default "us"; the network setting can be set according to needs, most fault repairs do not require network connection, you can not set this setting, 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 of the CD-ROM Linux environment. The default option "continue" means that the mount permission is read and write: "Read-only" is read-only. If the detection fails, you can select "skip" to skip. Here, because you want to repair the system, you need to have read and write permissions. Generally, the default option "continue" is selected.

After entering the next step, the system prompts 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 a dual system environment, install Linux first and then install Windows; or Windows that has been installed in a dual system environment is damaged, and after reinstalling Windows, the MBR(Master Boot Record) that saves GRUB will be overwritten by the Windows bootloader NTLDR, causing the Linux system to fail to boot.

1. If you want to restore dual system boot, first enter rescue mode with the above method and execute chroot command as follows: sh-3.1# chroot /mnt/sysimage

2. Switch 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" is the name of the hard disk. If you use SCSI hard disk or Linux to install it on the second IDE hard disk, this setting should be adjusted accordingly.

3. Then execute the exit command in turn to exit chroot mode and rescue mode (execute the exit command twice): sh-3.1# exit After system restart, the dual system boot of GRUB boot will be restored.

Case 2: System Configuration File Loss Repair

During system boot, an important process is that the init process reads its configuration file/etc/inittab, starts the system basic service program and the default run-level service program to complete the system boot. If/etc/inittab is deleted or modified incorrectly, Linux will not start properly. At this point, only rescue mode can solve such problems.

/etc/inittab file missing boot error example

1, there is a backup file recovery method to enter the rescue mode, after executing the chroot command, if there is a backup of this file (it is strongly recommended that important data directories in the system, such as/etc,/boot, etc., be backed up), directly copy the backup file back, and exit the restart.

If it is a configuration file modification error, such as the typical/boot/grub/grub.conf and/etc/passwd file modification error, you can also directly correct the recovery.

Assuming there is a backup file/etc/inittab.bak, execute in rescue mode:

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

If some configuration files are lost or software is deleted by mistake, and there is no backup, you can restore them by reinstalling the software package.

First find out which RPM package/etc/inittab belongs to (even if the file is missing, because there is an 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 that stores the RPM package (in rescue mode, the CD is usually mounted in the/mnt/source directory):

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

The RPM packages for Fedora are stored in the Fedora/RPMS directory on CD-ROM. Other Linux storage locations are similar, so I won't list them here.

Also, because the root directory of the hard disk system to be repaired is under/mnt/sysimage, you need to specify its location using the--root option.

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 "--displackgs" indicates that the installation is overwritten and that the file has been restored after execution.

If you want to extract only the/etc/inittab file from 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 that when executing this command, files cannot be directly restored to the/etc directory, but can only be extracted to the current directory, and the path of the restored file name must be written completely. After extracting the file successfully, copy it to the corresponding location under the/mnt/sysimage directory where the root partition is located. Rescue mode is a powerful weapon to maintain Linux and solve the startup failure of Linux system. It is necessary to fully understand the boot process of Linux in order to effectively judge and deal with the failure. That's all for "Example Analysis of Linux Rescue Mode." Thanks for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report